blob: 82fb51d2f192daf1a2407592a5aa2d8d5ad4ac3d [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_ARM
Kristian Monsen80d68ea2010-09-08 11:05:35 +01006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/base/bits.h"
8#include "src/bootstrapper.h"
9#include "src/code-stubs.h"
10#include "src/codegen.h"
11#include "src/ic/handler-compiler.h"
12#include "src/ic/ic.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013#include "src/ic/stub-cache.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000015#include "src/regexp/jsregexp.h"
16#include "src/regexp/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040017#include "src/runtime/runtime.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +010018
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019#include "src/arm/code-stubs-arm.h"
20
Kristian Monsen80d68ea2010-09-08 11:05:35 +010021namespace v8 {
22namespace internal {
23
24
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 Address deopt_handler = Runtime::FunctionForId(
29 Runtime::kArrayConstructor)->entry;
30
31 if (constant_stack_parameter_count == 0) {
32 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
33 JS_FUNCTION_STUB_MODE);
34 } else {
35 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000037 }
38}
39
40
41static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler = Runtime::FunctionForId(
45 Runtime::kInternalArrayConstructor)->entry;
46
47 if (constant_stack_parameter_count == 0) {
48 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
49 JS_FUNCTION_STUB_MODE);
50 } else {
51 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000053 }
54}
55
56
57void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
60}
61
62
63void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
66}
67
68
69void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
72}
73
74
75void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
78}
79
80
81void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
82 CodeStubDescriptor* descriptor) {
83 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
84}
85
86
87void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
88 CodeStubDescriptor* descriptor) {
89 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
90}
91
92
Kristian Monsen80d68ea2010-09-08 11:05:35 +010093#define __ ACCESS_MASM(masm)
94
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000095static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +010096 Condition cond);
Kristian Monsen80d68ea2010-09-08 11:05:35 +010097static void EmitSmiNonsmiComparison(MacroAssembler* masm,
98 Register lhs,
99 Register rhs,
100 Label* lhs_not_nan,
101 Label* slow,
102 bool strict);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100103static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
104 Register lhs,
105 Register rhs);
106
107
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000108void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
109 ExternalReference miss) {
110 // Update the static counter each time a new code stub is generated.
111 isolate()->counters()->code_stubs()->Increment();
Ben Murdoch257744e2011-11-30 15:57:28 +0000112
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000114 int param_count = descriptor.GetRegisterParameterCount();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000115 {
116 // Call the runtime system in a fresh internal frame.
117 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
118 DCHECK(param_count == 0 ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000119 r0.is(descriptor.GetRegisterParameter(param_count - 1)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000120 // Push arguments
121 for (int i = 0; i < param_count; ++i) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000122 __ push(descriptor.GetRegisterParameter(i));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100123 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124 __ CallExternalReference(miss, param_count);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100125 }
126
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000127 __ Ret();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100128}
129
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100130
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131void DoubleToIStub::Generate(MacroAssembler* masm) {
132 Label out_of_range, only_low, negate, done;
133 Register input_reg = source();
134 Register result_reg = destination();
135 DCHECK(is_truncating());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100136
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137 int double_offset = offset();
138 // Account for saved regs if input is sp.
139 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100140
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000141 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
142 Register scratch_low =
143 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
144 Register scratch_high =
145 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
146 LowDwVfpRegister double_scratch = kScratchDoubleReg;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100147
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148 __ Push(scratch_high, scratch_low, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100149
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000150 if (!skip_fastpath()) {
151 // Load double input.
152 __ vldr(double_scratch, MemOperand(input_reg, double_offset));
153 __ vmov(scratch_low, scratch_high, double_scratch);
154
155 // Do fast-path convert from double to int.
156 __ vcvt_s32_f64(double_scratch.low(), double_scratch);
157 __ vmov(result_reg, double_scratch.low());
158
159 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
160 __ sub(scratch, result_reg, Operand(1));
161 __ cmp(scratch, Operand(0x7ffffffe));
162 __ b(lt, &done);
163 } else {
164 // We've already done MacroAssembler::TryFastTruncatedDoubleToILoad, so we
165 // know exponent > 31, so we can skip the vcvt_s32_f64 which will saturate.
166 if (double_offset == 0) {
167 __ ldm(ia, input_reg, scratch_low.bit() | scratch_high.bit());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100168 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169 __ ldr(scratch_low, MemOperand(input_reg, double_offset));
170 __ ldr(scratch_high, MemOperand(input_reg, double_offset + kIntSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100171 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100172 }
173
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000174 __ Ubfx(scratch, scratch_high,
175 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
176 // Load scratch with exponent - 1. This is faster than loading
177 // with exponent because Bias + 1 = 1024 which is an *ARM* immediate value.
178 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
179 __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
180 // If exponent is greater than or equal to 84, the 32 less significant
181 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
182 // the result is 0.
183 // Compare exponent with 84 (compare exponent - 1 with 83).
184 __ cmp(scratch, Operand(83));
185 __ b(ge, &out_of_range);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100186
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187 // If we reach this code, 31 <= exponent <= 83.
188 // So, we don't have to handle cases where 0 <= exponent <= 20 for
189 // which we would need to shift right the high part of the mantissa.
190 // Scratch contains exponent - 1.
191 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
192 __ rsb(scratch, scratch, Operand(51), SetCC);
193 __ b(ls, &only_low);
194 // 21 <= exponent <= 51, shift scratch_low and scratch_high
195 // to generate the result.
196 __ mov(scratch_low, Operand(scratch_low, LSR, scratch));
197 // Scratch contains: 52 - exponent.
198 // We needs: exponent - 20.
199 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
200 __ rsb(scratch, scratch, Operand(32));
201 __ Ubfx(result_reg, scratch_high,
202 0, HeapNumber::kMantissaBitsInTopWord);
203 // Set the implicit 1 before the mantissa part in scratch_high.
204 __ orr(result_reg, result_reg,
205 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
206 __ orr(result_reg, scratch_low, Operand(result_reg, LSL, scratch));
207 __ b(&negate);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100208
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000209 __ bind(&out_of_range);
210 __ mov(result_reg, Operand::Zero());
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100211 __ b(&done);
212
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000213 __ bind(&only_low);
214 // 52 <= exponent <= 83, shift only scratch_low.
215 // On entry, scratch contains: 52 - exponent.
216 __ rsb(scratch, scratch, Operand::Zero());
217 __ mov(result_reg, Operand(scratch_low, LSL, scratch));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100218
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000219 __ bind(&negate);
220 // If input was positive, scratch_high ASR 31 equals 0 and
221 // scratch_high LSR 31 equals zero.
222 // New result = (result eor 0) + 0 = result.
223 // If the input was negative, we have to negate the result.
224 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
225 // New result = (result eor 0xffffffff) + 1 = 0 - result.
226 __ eor(result_reg, result_reg, Operand(scratch_high, ASR, 31));
227 __ add(result_reg, result_reg, Operand(scratch_high, LSR, 31));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100228
229 __ bind(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000230
231 __ Pop(scratch_high, scratch_low, scratch);
232 __ Ret();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100233}
234
235
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100236// Handle the case where the lhs and rhs are the same object.
237// Equality is almost reflexive (everything but NaN), so this is a test
238// for "identity and not NaN".
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000239static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100240 Condition cond) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100241 Label not_identical;
242 Label heap_number, return_equal;
243 __ cmp(r0, r1);
244 __ b(ne, &not_identical);
245
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000246 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
247 // so we do the second best thing - test it ourselves.
248 // They are both equal and they are not both Smis so both of them are not
249 // Smis. If it's not a heap number, then return equal.
250 if (cond == lt || cond == gt) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000251 // Call runtime on identical JSObjects.
252 __ CompareObjectType(r0, r4, r4, FIRST_JS_RECEIVER_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 __ b(ge, slow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000254 // Call runtime on identical symbols since we need to throw a TypeError.
255 __ cmp(r4, Operand(SYMBOL_TYPE));
256 __ b(eq, slow);
257 // Call runtime on identical SIMD values since we must throw a TypeError.
258 __ cmp(r4, Operand(SIMD128_VALUE_TYPE));
259 __ b(eq, slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260 } else {
261 __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
262 __ b(eq, &heap_number);
263 // Comparing JS objects with <=, >= is complicated.
264 if (cond != eq) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000265 __ cmp(r4, Operand(FIRST_JS_RECEIVER_TYPE));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100266 __ b(ge, slow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000267 // Call runtime on identical symbols since we need to throw a TypeError.
268 __ cmp(r4, Operand(SYMBOL_TYPE));
269 __ b(eq, slow);
270 // Call runtime on identical SIMD values since we must throw a TypeError.
271 __ cmp(r4, Operand(SIMD128_VALUE_TYPE));
272 __ b(eq, slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000273 // Normally here we fall through to return_equal, but undefined is
274 // special: (undefined == undefined) == true, but
275 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
276 if (cond == le || cond == ge) {
277 __ cmp(r4, Operand(ODDBALL_TYPE));
278 __ b(ne, &return_equal);
279 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
280 __ cmp(r0, r2);
281 __ b(ne, &return_equal);
282 if (cond == le) {
283 // undefined <= undefined should fail.
284 __ mov(r0, Operand(GREATER));
285 } else {
286 // undefined >= undefined should fail.
287 __ mov(r0, Operand(LESS));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100288 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100290 }
291 }
292 }
293
294 __ bind(&return_equal);
Steve Block1e0659c2011-05-24 12:43:12 +0100295 if (cond == lt) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100296 __ mov(r0, Operand(GREATER)); // Things aren't less than themselves.
Steve Block1e0659c2011-05-24 12:43:12 +0100297 } else if (cond == gt) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100298 __ mov(r0, Operand(LESS)); // Things aren't greater than themselves.
299 } else {
300 __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
301 }
302 __ Ret();
303
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000304 // For less and greater we don't have to check for NaN since the result of
305 // x < x is false regardless. For the others here is some code to check
306 // for NaN.
307 if (cond != lt && cond != gt) {
308 __ bind(&heap_number);
309 // It is a heap number, so return non-equal if it's NaN and equal if it's
310 // not NaN.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100311
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000312 // The representation of NaN values has all exponent bits (52..62) set,
313 // and not all mantissa bits (0..51) clear.
314 // Read top bits of double representation (second word of value).
315 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
316 // Test that exponent bits are all set.
317 __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits);
318 // NaNs have all-one exponents so they sign extend to -1.
319 __ cmp(r3, Operand(-1));
320 __ b(ne, &return_equal);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100321
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000322 // Shift out flag and all exponent bits, retaining only mantissa.
323 __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord));
324 // Or with all low-bits of mantissa.
325 __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
326 __ orr(r0, r3, Operand(r2), SetCC);
327 // For equal we already have the right value in r0: Return zero (equal)
328 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
329 // not (it's a NaN). For <= and >= we need to load r0 with the failing
330 // value if it's a NaN.
331 if (cond != eq) {
332 // All-zero means Infinity means equal.
333 __ Ret(eq);
334 if (cond == le) {
335 __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail.
336 } else {
337 __ mov(r0, Operand(LESS)); // NaN >= NaN should fail.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100338 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100339 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000340 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100341 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000342 // No fall through here.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100343
344 __ bind(&not_identical);
345}
346
347
348// See comment at call site.
349static void EmitSmiNonsmiComparison(MacroAssembler* masm,
350 Register lhs,
351 Register rhs,
352 Label* lhs_not_nan,
353 Label* slow,
354 bool strict) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000355 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100356 (lhs.is(r1) && rhs.is(r0)));
357
358 Label rhs_is_smi;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000359 __ JumpIfSmi(rhs, &rhs_is_smi);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100360
361 // Lhs is a Smi. Check whether the rhs is a heap number.
362 __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE);
363 if (strict) {
364 // If rhs is not a number and lhs is a Smi then strict equality cannot
365 // succeed. Return non-equal
366 // If rhs is r0 then there is already a non zero value in it.
367 if (!rhs.is(r0)) {
368 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
369 }
370 __ Ret(ne);
371 } else {
372 // Smi compared non-strictly with a non-Smi non-heap-number. Call
373 // the runtime.
374 __ b(ne, slow);
375 }
376
377 // Lhs is a smi, rhs is a number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000378 // Convert lhs to a double in d7.
379 __ SmiToDouble(d7, lhs);
380 // Load the double from rhs, tagged HeapNumber r0, to d6.
381 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100382
383 // We now have both loaded as doubles but we can skip the lhs nan check
384 // since it's a smi.
385 __ jmp(lhs_not_nan);
386
387 __ bind(&rhs_is_smi);
388 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
389 __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE);
390 if (strict) {
391 // If lhs is not a number and rhs is a smi then strict equality cannot
392 // succeed. Return non-equal.
393 // If lhs is r0 then there is already a non zero value in it.
394 if (!lhs.is(r0)) {
395 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
396 }
397 __ Ret(ne);
398 } else {
399 // Smi compared non-strictly with a non-smi non-heap-number. Call
400 // the runtime.
401 __ b(ne, slow);
402 }
403
404 // Rhs is a smi, lhs is a heap number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000405 // Load the double from lhs, tagged HeapNumber r1, to d7.
406 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
407 // Convert rhs to a double in d6 .
408 __ SmiToDouble(d6, rhs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100409 // Fall through to both_loaded_as_doubles.
410}
411
412
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100413// See comment at call site.
414static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
415 Register lhs,
416 Register rhs) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000417 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100418 (lhs.is(r1) && rhs.is(r0)));
419
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000420 // If either operand is a JS object or an oddball value, then they are
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100421 // not equal since their pointers are different.
422 // There is no test for undetectability in strict equality.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000423 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100424 Label first_non_object;
425 // Get the type of the first operand into r2 and compare it with
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000426 // FIRST_JS_RECEIVER_TYPE.
427 __ CompareObjectType(rhs, r2, r2, FIRST_JS_RECEIVER_TYPE);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100428 __ b(lt, &first_non_object);
429
430 // Return non-zero (r0 is not zero)
431 Label return_not_equal;
432 __ bind(&return_not_equal);
433 __ Ret();
434
435 __ bind(&first_non_object);
436 // Check for oddballs: true, false, null, undefined.
437 __ cmp(r2, Operand(ODDBALL_TYPE));
438 __ b(eq, &return_not_equal);
439
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000440 __ CompareObjectType(lhs, r3, r3, FIRST_JS_RECEIVER_TYPE);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100441 __ b(ge, &return_not_equal);
442
443 // Check for oddballs: true, false, null, undefined.
444 __ cmp(r3, Operand(ODDBALL_TYPE));
445 __ b(eq, &return_not_equal);
446
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000447 // Now that we have the types we might as well check for
448 // internalized-internalized.
449 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
450 __ orr(r2, r2, Operand(r3));
451 __ tst(r2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
452 __ b(eq, &return_not_equal);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100453}
454
455
456// See comment at call site.
457static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
458 Register lhs,
459 Register rhs,
460 Label* both_loaded_as_doubles,
461 Label* not_heap_numbers,
462 Label* slow) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000463 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100464 (lhs.is(r1) && rhs.is(r0)));
465
466 __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE);
467 __ b(ne, not_heap_numbers);
468 __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
469 __ cmp(r2, r3);
470 __ b(ne, slow); // First was a heap number, second wasn't. Go slow case.
471
472 // Both are heap numbers. Load them up then jump to the code we have
473 // for that.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000474 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
475 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100476 __ jmp(both_loaded_as_doubles);
477}
478
479
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000480// Fast negative check for internalized-to-internalized equality.
481static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100482 Register lhs, Register rhs,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000483 Label* possible_strings,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100484 Label* runtime_call) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000485 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100486 (lhs.is(r1) && rhs.is(r0)));
487
488 // r2 is object type of rhs.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100489 Label object_test, return_unequal, undetectable;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000490 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100491 __ tst(r2, Operand(kIsNotStringMask));
492 __ b(ne, &object_test);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000493 __ tst(r2, Operand(kIsNotInternalizedMask));
494 __ b(ne, possible_strings);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100495 __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100496 __ b(ge, runtime_call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000497 __ tst(r3, Operand(kIsNotInternalizedMask));
498 __ b(ne, possible_strings);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100499
Ben Murdoch097c5b22016-05-18 11:27:45 +0100500 // Both are internalized. We already checked they weren't the same pointer so
501 // they are not equal. Return non-equal by returning the non-zero object
502 // pointer in r0.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100503 __ Ret();
504
505 __ bind(&object_test);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100506 __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100507 __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100508 __ ldrb(r4, FieldMemOperand(r2, Map::kBitFieldOffset));
509 __ ldrb(r5, FieldMemOperand(r3, Map::kBitFieldOffset));
510 __ tst(r4, Operand(1 << Map::kIsUndetectable));
511 __ b(ne, &undetectable);
512 __ tst(r5, Operand(1 << Map::kIsUndetectable));
513 __ b(ne, &return_unequal);
514
515 __ CompareInstanceType(r2, r2, FIRST_JS_RECEIVER_TYPE);
516 __ b(lt, runtime_call);
517 __ CompareInstanceType(r3, r3, FIRST_JS_RECEIVER_TYPE);
518 __ b(lt, runtime_call);
519
520 __ bind(&return_unequal);
521 // Return non-equal by returning the non-zero object pointer in r0.
522 __ Ret();
523
524 __ bind(&undetectable);
525 __ tst(r5, Operand(1 << Map::kIsUndetectable));
526 __ b(eq, &return_unequal);
527 __ mov(r0, Operand(EQUAL));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100528 __ Ret();
529}
530
531
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000532static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
533 Register scratch,
534 CompareICState::State expected,
535 Label* fail) {
536 Label ok;
537 if (expected == CompareICState::SMI) {
538 __ JumpIfNotSmi(input, fail);
539 } else if (expected == CompareICState::NUMBER) {
540 __ JumpIfSmi(input, &ok);
541 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
542 DONT_DO_SMI_CHECK);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100543 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000544 // We could be strict about internalized/non-internalized here, but as long as
545 // hydrogen doesn't care, the stub doesn't have to care either.
546 __ bind(&ok);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100547}
548
549
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000550// On entry r1 and r2 are the values to be compared.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100551// On exit r0 is 0, positive or negative to indicate the result of
552// the comparison.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000553void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
554 Register lhs = r1;
555 Register rhs = r0;
556 Condition cc = GetCondition();
557
558 Label miss;
559 CompareICStub_CheckInputType(masm, lhs, r2, left(), &miss);
560 CompareICStub_CheckInputType(masm, rhs, r3, right(), &miss);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100561
562 Label slow; // Call builtin.
563 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
564
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000565 Label not_two_smis, smi_done;
566 __ orr(r2, r1, r0);
567 __ JumpIfNotSmi(r2, &not_two_smis);
568 __ mov(r1, Operand(r1, ASR, 1));
569 __ sub(r0, r1, Operand(r0, ASR, 1));
570 __ Ret();
571 __ bind(&not_two_smis);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100572
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100573 // NOTICE! This code is only reached after a smi-fast-case check, so
574 // it is certain that at least one operand isn't a smi.
575
576 // Handle the case where the objects are identical. Either returns the answer
577 // or goes to slow. Only falls through if the objects were not identical.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100578 EmitIdenticalObjectComparison(masm, &slow, cc);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100579
580 // If either is a Smi (we know that not both are), then they can only
581 // be strictly equal if the other is a HeapNumber.
582 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000583 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000584 __ and_(r2, lhs, Operand(rhs));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000585 __ JumpIfNotSmi(r2, &not_smis);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100586 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
587 // 1) Return the answer.
588 // 2) Go to slow.
589 // 3) Fall through to both_loaded_as_doubles.
590 // 4) Jump to lhs_not_nan.
591 // In cases 3 and 4 we have found out we were dealing with a number-number
592 // comparison. If VFP3 is supported the double values of the numbers have
593 // been loaded into d7 and d6. Otherwise, the double values have been loaded
594 // into r0, r1, r2, and r3.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000595 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100596
597 __ bind(&both_loaded_as_doubles);
598 // The arguments have been converted to doubles and stored in d6 and d7, if
599 // VFP3 is supported, or in r0, r1, r2, and r3.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000600 __ bind(&lhs_not_nan);
601 Label no_nan;
602 // ARMv7 VFP3 instructions to implement double precision comparison.
603 __ VFPCompareAndSetFlags(d7, d6);
604 Label nan;
605 __ b(vs, &nan);
606 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
607 __ mov(r0, Operand(LESS), LeaveCC, lt);
608 __ mov(r0, Operand(GREATER), LeaveCC, gt);
609 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100610
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000611 __ bind(&nan);
612 // If one of the sides was a NaN then the v flag is set. Load r0 with
613 // whatever it takes to make the comparison fail, since comparisons with NaN
614 // always fail.
615 if (cc == lt || cc == le) {
616 __ mov(r0, Operand(GREATER));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100617 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000618 __ mov(r0, Operand(LESS));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100619 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000620 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100621
622 __ bind(&not_smis);
623 // At this point we know we are dealing with two different objects,
624 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000625 if (strict()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100626 // This returns non-equal for some object types, or falls through if it
627 // was not lucky.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000628 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100629 }
630
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000631 Label check_for_internalized_strings;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100632 Label flat_string_check;
633 // Check for heap-number-heap-number comparison. Can jump to slow case,
634 // or load both doubles into r0, r1, r2, r3 and jump to the code that handles
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000635 // that case. If the inputs are not doubles then jumps to
636 // check_for_internalized_strings.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100637 // In this case r2 will contain the type of rhs_. Never falls through.
638 EmitCheckForTwoHeapNumbers(masm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000639 lhs,
640 rhs,
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100641 &both_loaded_as_doubles,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000642 &check_for_internalized_strings,
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100643 &flat_string_check);
644
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000645 __ bind(&check_for_internalized_strings);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100646 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000647 // internalized strings.
648 if (cc == eq && !strict()) {
649 // Returns an answer for two internalized strings or two detectable objects.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100650 // Otherwise jumps to string case or not both strings case.
651 // Assumes that r2 is the type of rhs_ on entry.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000652 EmitCheckForInternalizedStringsOrObjects(
653 masm, lhs, rhs, &flat_string_check, &slow);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100654 }
655
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656 // Check for both being sequential one-byte strings,
657 // and inline if that is the case.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100658 __ bind(&flat_string_check);
659
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000660 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r2, r3, &slow);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100661
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000662 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
663 r3);
664 if (cc == eq) {
665 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r2, r3, r4);
Ben Murdoch257744e2011-11-30 15:57:28 +0000666 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000667 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r2, r3, r4,
668 r5);
Ben Murdoch257744e2011-11-30 15:57:28 +0000669 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100670 // Never falls through to here.
671
672 __ bind(&slow);
673
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000674 if (cc == eq) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100675 {
676 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
677 __ Push(lhs, rhs);
678 __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual);
679 }
680 // Turn true into 0 and false into some non-zero value.
681 STATIC_ASSERT(EQUAL == 0);
682 __ LoadRoot(r1, Heap::kTrueValueRootIndex);
683 __ sub(r0, r0, r1);
684 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100685 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100686 __ Push(lhs, rhs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100687 int ncr; // NaN compare result
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000688 if (cc == lt || cc == le) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100689 ncr = GREATER;
690 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000691 DCHECK(cc == gt || cc == ge); // remaining cases
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100692 ncr = LESS;
693 }
694 __ mov(r0, Operand(Smi::FromInt(ncr)));
695 __ push(r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100696
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000697 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
698 // tagged as a small integer.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100699 __ TailCallRuntime(Runtime::kCompare);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000700 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100701
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000702 __ bind(&miss);
703 GenerateMiss(masm);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100704}
705
706
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100707void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
708 // We don't allow a GC during a store buffer overflow so there is no need to
709 // store the registers in any particular way, but we do have to store and
710 // restore them.
711 __ stm(db_w, sp, kCallerSaved | lr.bit());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000712
713 const Register scratch = r1;
714
715 if (save_doubles()) {
716 __ SaveFPRegs(sp, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100717 }
718 const int argument_count = 1;
719 const int fp_argument_count = 0;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100720
721 AllowExternalCallThatCantCauseGC scope(masm);
722 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000723 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100724 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000725 ExternalReference::store_buffer_overflow_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100726 argument_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000727 if (save_doubles()) {
728 __ RestoreFPRegs(sp, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100729 }
730 __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
731}
732
733
Steve Block44f0eee2011-05-26 01:26:41 +0100734void MathPowStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100735 const Register base = r1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000736 const Register exponent = MathPowTaggedDescriptor::exponent();
737 DCHECK(exponent.is(r2));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100738 const Register heapnumbermap = r5;
739 const Register heapnumber = r0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000740 const DwVfpRegister double_base = d0;
741 const DwVfpRegister double_exponent = d1;
742 const DwVfpRegister double_result = d2;
743 const DwVfpRegister double_scratch = d3;
744 const SwVfpRegister single_scratch = s6;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100745 const Register scratch = r9;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000746 const Register scratch2 = r4;
Steve Block44f0eee2011-05-26 01:26:41 +0100747
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100748 Label call_runtime, done, int_exponent;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000749 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100750 Label base_is_smi, unpack_exponent;
751 // The exponent and base are supplied as arguments on the stack.
752 // This can only happen if the stub is called from non-optimized code.
753 // Load input parameters from stack to double registers.
Steve Block44f0eee2011-05-26 01:26:41 +0100754 __ ldr(base, MemOperand(sp, 1 * kPointerSize));
755 __ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
756
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100757 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
Steve Block44f0eee2011-05-26 01:26:41 +0100758
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100759 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
Steve Block44f0eee2011-05-26 01:26:41 +0100760 __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
761 __ cmp(scratch, heapnumbermap);
762 __ b(ne, &call_runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100763
Ben Murdochc7cc0282012-03-05 14:35:55 +0000764 __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100765 __ jmp(&unpack_exponent);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000766
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100767 __ bind(&base_is_smi);
768 __ vmov(single_scratch, scratch);
769 __ vcvt_f64_s32(double_base, single_scratch);
770 __ bind(&unpack_exponent);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000771
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100772 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
Steve Block44f0eee2011-05-26 01:26:41 +0100773
Steve Block44f0eee2011-05-26 01:26:41 +0100774 __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
775 __ cmp(scratch, heapnumbermap);
776 __ b(ne, &call_runtime);
Steve Block44f0eee2011-05-26 01:26:41 +0100777 __ vldr(double_exponent,
778 FieldMemOperand(exponent, HeapNumber::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000779 } else if (exponent_type() == TAGGED) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100780 // Base is already in double_base.
781 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
Steve Block44f0eee2011-05-26 01:26:41 +0100782
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100783 __ vldr(double_exponent,
784 FieldMemOperand(exponent, HeapNumber::kValueOffset));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000785 }
Ben Murdoch85b71792012-04-11 18:30:58 +0100786
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000787 if (exponent_type() != INTEGER) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100788 Label int_exponent_convert;
789 // Detect integer exponents stored as double.
790 __ vcvt_u32_f64(single_scratch, double_exponent);
791 // We do not check for NaN or Infinity here because comparing numbers on
792 // ARM correctly distinguishes NaNs. We end up calling the built-in.
793 __ vcvt_f64_u32(double_scratch, single_scratch);
794 __ VFPCompareAndSetFlags(double_scratch, double_exponent);
795 __ b(eq, &int_exponent_convert);
796
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000797 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100798 // Detect square root case. Crankshaft detects constant +/-0.5 at
799 // compile time and uses DoMathPowHalf instead. We then skip this check
800 // for non-constant cases of +/-0.5 as these hardly occur.
801 Label not_plus_half;
802
803 // Test for 0.5.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000804 __ vmov(double_scratch, 0.5, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100805 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
806 __ b(ne, &not_plus_half);
807
808 // Calculates square root of base. Check for the special case of
809 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000810 __ vmov(double_scratch, -V8_INFINITY, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100811 __ VFPCompareAndSetFlags(double_base, double_scratch);
812 __ vneg(double_result, double_scratch, eq);
813 __ b(eq, &done);
814
815 // Add +0 to convert -0 to +0.
816 __ vadd(double_scratch, double_base, kDoubleRegZero);
817 __ vsqrt(double_result, double_scratch);
818 __ jmp(&done);
819
820 __ bind(&not_plus_half);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000821 __ vmov(double_scratch, -0.5, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100822 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
823 __ b(ne, &call_runtime);
824
825 // Calculates square root of base. Check for the special case of
826 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000827 __ vmov(double_scratch, -V8_INFINITY, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100828 __ VFPCompareAndSetFlags(double_base, double_scratch);
829 __ vmov(double_result, kDoubleRegZero, eq);
830 __ b(eq, &done);
831
832 // Add +0 to convert -0 to +0.
833 __ vadd(double_scratch, double_base, kDoubleRegZero);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000834 __ vmov(double_result, 1.0, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100835 __ vsqrt(double_scratch, double_scratch);
836 __ vdiv(double_result, double_result, double_scratch);
837 __ jmp(&done);
838 }
839
840 __ push(lr);
841 {
842 AllowExternalCallThatCantCauseGC scope(masm);
843 __ PrepareCallCFunction(0, 2, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000844 __ MovToFloatParameters(double_base, double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100845 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000846 ExternalReference::power_double_double_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100847 0, 2);
848 }
849 __ pop(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000850 __ MovFromFloatResult(double_result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100851 __ jmp(&done);
852
853 __ bind(&int_exponent_convert);
854 __ vcvt_u32_f64(single_scratch, double_exponent);
855 __ vmov(scratch, single_scratch);
856 }
857
858 // Calculate power with integer exponent.
859 __ bind(&int_exponent);
860
861 // Get two copies of exponent in the registers scratch and exponent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000862 if (exponent_type() == INTEGER) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100863 __ mov(scratch, exponent);
864 } else {
865 // Exponent has previously been stored into scratch as untagged integer.
866 __ mov(exponent, scratch);
867 }
868 __ vmov(double_scratch, double_base); // Back up base.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000869 __ vmov(double_result, 1.0, scratch2);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100870
871 // Get absolute value of exponent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000872 __ cmp(scratch, Operand::Zero());
873 __ mov(scratch2, Operand::Zero(), LeaveCC, mi);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100874 __ sub(scratch, scratch2, scratch, LeaveCC, mi);
875
876 Label while_true;
877 __ bind(&while_true);
878 __ mov(scratch, Operand(scratch, ASR, 1), SetCC);
879 __ vmul(double_result, double_result, double_scratch, cs);
880 __ vmul(double_scratch, double_scratch, double_scratch, ne);
881 __ b(ne, &while_true);
882
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000883 __ cmp(exponent, Operand::Zero());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100884 __ b(ge, &done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000885 __ vmov(double_scratch, 1.0, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100886 __ vdiv(double_result, double_scratch, double_result);
887 // Test whether result is zero. Bail out to check for subnormal result.
888 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
889 __ VFPCompareAndSetFlags(double_result, 0.0);
890 __ b(ne, &done);
891 // double_exponent may not containe the exponent value if the input was a
892 // smi. We set it with exponent value before bailing out.
893 __ vmov(single_scratch, exponent);
894 __ vcvt_f64_s32(double_exponent, single_scratch);
895
896 // Returning or bailing out.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000897 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100898 // The arguments are still on the stack.
899 __ bind(&call_runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000900 __ TailCallRuntime(Runtime::kMathPowRT);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100901
902 // The stub is called from non-optimized code, which expects the result
903 // as heap number in exponent.
904 __ bind(&done);
905 __ AllocateHeapNumber(
906 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
907 __ vstr(double_result,
908 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000909 DCHECK(heapnumber.is(r0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100910 __ Ret(2);
911 } else {
912 __ push(lr);
913 {
914 AllowExternalCallThatCantCauseGC scope(masm);
915 __ PrepareCallCFunction(0, 2, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000916 __ MovToFloatParameters(double_base, double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100917 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000918 ExternalReference::power_double_double_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100919 0, 2);
920 }
921 __ pop(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000922 __ MovFromFloatResult(double_result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100923
924 __ bind(&done);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100925 __ Ret();
926 }
Steve Block44f0eee2011-05-26 01:26:41 +0100927}
928
929
930bool CEntryStub::NeedsImmovableCode() {
931 return true;
932}
933
934
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000935void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
936 CEntryStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000937 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
938 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
939 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
940 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000941 CreateWeakCellStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000942 BinaryOpICStub::GenerateAheadOfTime(isolate);
943 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000944 StoreFastElementStub::GenerateAheadOfTime(isolate);
945 TypeofStub::GenerateAheadOfTime(isolate);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000946}
947
948
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000949void CodeStub::GenerateFPStubs(Isolate* isolate) {
950 // Generate if not already in cache.
951 SaveFPRegsMode mode = kSaveFPRegs;
952 CEntryStub(isolate, 1, mode).GetCode();
953 StoreBufferOverflowStub(isolate, mode).GetCode();
954 isolate->set_fp_stubs_generated(true);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100955}
956
957
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000958void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
959 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
960 stub.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100961}
962
963
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000964void CEntryStub::Generate(MacroAssembler* masm) {
965 // Called from JavaScript; parameters are on stack as if calling JS function.
966 // r0: number of arguments including receiver
967 // r1: pointer to builtin function
968 // fp: frame pointer (restored after C call)
969 // sp: stack pointer (restored as callee's sp after C call)
970 // cp: current context (C callee-saved)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000971 //
972 // If argv_in_register():
973 // r2: pointer to the first argument
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000974 ProfileEntryHookStub::MaybeCallEntryHook(masm);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000975
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000976 __ mov(r5, Operand(r1));
977
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000978 if (argv_in_register()) {
979 // Move argv into the correct register.
980 __ mov(r1, Operand(r2));
981 } else {
982 // Compute the argv pointer in a callee-saved register.
983 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2));
984 __ sub(r1, r1, Operand(kPointerSize));
985 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000986
987 // Enter the exit frame that transitions from JavaScript to C++.
988 FrameScope scope(masm, StackFrame::MANUAL);
989 __ EnterExitFrame(save_doubles());
990
991 // Store a copy of argc in callee-saved registers for later.
992 __ mov(r4, Operand(r0));
993
994 // r0, r4: number of arguments including receiver (C callee-saved)
995 // r1: pointer to the first argument (C callee-saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100996 // r5: pointer to builtin function (C callee-saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100997
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100998 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
999 int frame_alignment_mask = frame_alignment - 1;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001000#if V8_HOST_ARCH_ARM
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001001 if (FLAG_debug_code) {
1002 if (frame_alignment > kPointerSize) {
1003 Label alignment_as_expected;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001004 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
Steve Block1e0659c2011-05-24 12:43:12 +01001005 __ tst(sp, Operand(frame_alignment_mask));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001006 __ b(eq, &alignment_as_expected);
1007 // Don't use Check here, as it will call Runtime_Abort re-entering here.
1008 __ stop("Unexpected alignment");
1009 __ bind(&alignment_as_expected);
1010 }
1011 }
1012#endif
1013
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001014 // Call C built-in.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001015 int result_stack_size;
1016 if (result_size() <= 2) {
1017 // r0 = argc, r1 = argv, r2 = isolate
1018 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1019 result_stack_size = 0;
1020 } else {
1021 DCHECK_EQ(3, result_size());
1022 // Allocate additional space for the result.
1023 result_stack_size =
1024 ((result_size() * kPointerSize) + frame_alignment_mask) &
1025 ~frame_alignment_mask;
1026 __ sub(sp, sp, Operand(result_stack_size));
1027
1028 // r0 = hidden result argument, r1 = argc, r2 = argv, r3 = isolate.
1029 __ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
1030 __ mov(r2, Operand(r1));
1031 __ mov(r1, Operand(r0));
1032 __ mov(r0, Operand(sp));
1033 }
Steve Block44f0eee2011-05-26 01:26:41 +01001034
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001035 // To let the GC traverse the return address of the exit frames, we need to
1036 // know where the return address is. The CEntryStub is unmovable, so
1037 // we can store the address on the stack to be able to find it again and
1038 // we never have to restore it, because it will not change.
Steve Block1e0659c2011-05-24 12:43:12 +01001039 // Compute the return address in lr to return to after the jump below. Pc is
1040 // already at '+ 8' from the current instruction but return is after three
1041 // instructions so add another 4 to pc to get the return address.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001042 {
1043 // Prevent literal pool emission before return address.
1044 Assembler::BlockConstPoolScope block_const_pool(masm);
1045 __ add(lr, pc, Operand(4));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001046 __ str(lr, MemOperand(sp, result_stack_size));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001047 __ Call(r5);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001048 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001049 if (result_size() > 2) {
1050 DCHECK_EQ(3, result_size());
1051 // Read result values stored on stack.
1052 __ ldr(r2, MemOperand(r0, 2 * kPointerSize));
1053 __ ldr(r1, MemOperand(r0, 1 * kPointerSize));
1054 __ ldr(r0, MemOperand(r0, 0 * kPointerSize));
1055 }
1056 // Result returned in r0, r1:r0 or r2:r1:r0 - do not destroy these registers!
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001057
Ben Murdoch097c5b22016-05-18 11:27:45 +01001058 __ VFPEnsureFPSCRState(r3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001059
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001060 // Check result for exception sentinel.
1061 Label exception_returned;
1062 __ CompareRoot(r0, Heap::kExceptionRootIndex);
1063 __ b(eq, &exception_returned);
1064
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001065 // Check that there is no pending exception, otherwise we
1066 // should have returned the exception sentinel.
1067 if (FLAG_debug_code) {
1068 Label okay;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001069 ExternalReference pending_exception_address(
1070 Isolate::kPendingExceptionAddress, isolate());
Ben Murdoch097c5b22016-05-18 11:27:45 +01001071 __ mov(r3, Operand(pending_exception_address));
1072 __ ldr(r3, MemOperand(r3));
1073 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001074 // Cannot use check here as it attempts to generate call into runtime.
1075 __ b(eq, &okay);
1076 __ stop("Unexpected pending exception");
1077 __ bind(&okay);
1078 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001079
1080 // Exit C frame and return.
1081 // r0:r1: result
1082 // sp: stack pointer
1083 // fp: frame pointer
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001084 Register argc;
1085 if (argv_in_register()) {
1086 // We don't want to pop arguments so set argc to no_reg.
1087 argc = no_reg;
1088 } else {
1089 // Callee-saved register r4 still holds argc.
1090 argc = r4;
1091 }
1092 __ LeaveExitFrame(save_doubles(), argc, true);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001093 __ mov(pc, lr);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001094
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001095 // Handling of exception.
1096 __ bind(&exception_returned);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001097
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001098 ExternalReference pending_handler_context_address(
1099 Isolate::kPendingHandlerContextAddress, isolate());
1100 ExternalReference pending_handler_code_address(
1101 Isolate::kPendingHandlerCodeAddress, isolate());
1102 ExternalReference pending_handler_offset_address(
1103 Isolate::kPendingHandlerOffsetAddress, isolate());
1104 ExternalReference pending_handler_fp_address(
1105 Isolate::kPendingHandlerFPAddress, isolate());
1106 ExternalReference pending_handler_sp_address(
1107 Isolate::kPendingHandlerSPAddress, isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001108
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001109 // Ask the runtime for help to determine the handler. This will set r0 to
1110 // contain the current pending exception, don't clobber it.
1111 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1112 isolate());
1113 {
1114 FrameScope scope(masm, StackFrame::MANUAL);
1115 __ PrepareCallCFunction(3, 0, r0);
1116 __ mov(r0, Operand(0));
1117 __ mov(r1, Operand(0));
1118 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
1119 __ CallCFunction(find_handler, 3);
1120 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001121
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001122 // Retrieve the handler context, SP and FP.
1123 __ mov(cp, Operand(pending_handler_context_address));
1124 __ ldr(cp, MemOperand(cp));
1125 __ mov(sp, Operand(pending_handler_sp_address));
1126 __ ldr(sp, MemOperand(sp));
1127 __ mov(fp, Operand(pending_handler_fp_address));
1128 __ ldr(fp, MemOperand(fp));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001129
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001130 // If the handler is a JS frame, restore the context to the frame. Note that
1131 // the context will be set to (cp == 0) for non-JS frames.
1132 __ cmp(cp, Operand(0));
1133 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001134
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001135 // Compute the handler entry address and jump to it.
1136 ConstantPoolUnavailableScope constant_pool_unavailable(masm);
1137 __ mov(r1, Operand(pending_handler_code_address));
1138 __ ldr(r1, MemOperand(r1));
1139 __ mov(r2, Operand(pending_handler_offset_address));
1140 __ ldr(r2, MemOperand(r2));
1141 __ add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
1142 if (FLAG_enable_embedded_constant_pool) {
1143 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r1);
1144 }
1145 __ add(pc, r1, r2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001146}
1147
1148
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001149void JSEntryStub::Generate(MacroAssembler* masm) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001150 // r0: code entry
1151 // r1: function
1152 // r2: receiver
1153 // r3: argc
1154 // [sp+0]: argv
1155
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001156 Label invoke, handler_entry, exit;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001157
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001158 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1159
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001160 // Called from C, so do not pop argc and args on exit (preserve sp)
1161 // No need to save register-passed args
1162 // Save callee-saved registers (incl. cp and fp), sp, and lr
1163 __ stm(db_w, sp, kCalleeSaved | lr.bit());
1164
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001165 // Save callee-saved vfp registers.
1166 __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1167 // Set up the reserved register for 0.0.
1168 __ vmov(kDoubleRegZero, 0.0);
1169 __ VFPEnsureFPSCRState(r4);
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001170
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001171 // Get address of argv, see stm above.
1172 // r0: code entry
1173 // r1: function
1174 // r2: receiver
1175 // r3: argc
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001176
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001177 // Set up argv in r4.
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001178 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001179 offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001180 __ ldr(r4, MemOperand(sp, offset_to_argv));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001181
1182 // Push a frame with special values setup to mark it as an entry frame.
1183 // r0: code entry
1184 // r1: function
1185 // r2: receiver
1186 // r3: argc
1187 // r4: argv
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001188 int marker = type();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001189 if (FLAG_enable_embedded_constant_pool) {
1190 __ mov(r8, Operand::Zero());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001191 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001192 __ mov(r7, Operand(Smi::FromInt(marker)));
1193 __ mov(r6, Operand(Smi::FromInt(marker)));
Steve Block44f0eee2011-05-26 01:26:41 +01001194 __ mov(r5,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001195 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001196 __ ldr(r5, MemOperand(r5));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001197 __ mov(ip, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1198 __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() |
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001199 (FLAG_enable_embedded_constant_pool ? r8.bit() : 0) |
1200 ip.bit());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001201
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001202 // Set up frame pointer for the frame to be pushed.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001203 __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1204
Ben Murdochb0fe1622011-05-05 13:52:32 +01001205 // If this is the outermost JS call, set js_entry_sp value.
Steve Block053d10c2011-06-13 19:13:29 +01001206 Label non_outermost_js;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001207 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
Ben Murdochb0fe1622011-05-05 13:52:32 +01001208 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1209 __ ldr(r6, MemOperand(r5));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001210 __ cmp(r6, Operand::Zero());
Steve Block053d10c2011-06-13 19:13:29 +01001211 __ b(ne, &non_outermost_js);
1212 __ str(fp, MemOperand(r5));
1213 __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1214 Label cont;
1215 __ b(&cont);
1216 __ bind(&non_outermost_js);
1217 __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1218 __ bind(&cont);
1219 __ push(ip);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001220
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001221 // Jump to a faked try block that does the invoke, with a faked catch
1222 // block that sets the pending exception.
1223 __ jmp(&invoke);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001224
1225 // Block literal pool emission whilst taking the position of the handler
1226 // entry. This avoids making the assumption that literal pools are always
1227 // emitted after an instruction is emitted, rather than before.
1228 {
1229 Assembler::BlockConstPoolScope block_const_pool(masm);
1230 __ bind(&handler_entry);
1231 handler_offset_ = handler_entry.pos();
1232 // Caught exception: Store result (exception) in the pending exception
1233 // field in the JSEnv and return a failure sentinel. Coming in here the
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001234 // fp will be invalid because the PushStackHandler below sets it to 0 to
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001235 // signal the existence of the JSEntry frame.
1236 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1237 isolate())));
1238 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001239 __ str(r0, MemOperand(ip));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001240 __ LoadRoot(r0, Heap::kExceptionRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001241 __ b(&exit);
1242
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001243 // Invoke: Link this frame into the handler chain.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001244 __ bind(&invoke);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001245 // Must preserve r0-r4, r5-r6 are available.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001246 __ PushStackHandler();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001247 // If an exception not caught by another handler occurs, this handler
1248 // returns control to the code after the bl(&invoke) above, which
1249 // restores all kCalleeSaved registers (including cp and fp) to their
1250 // saved values before returning a failure to C.
1251
1252 // Clear any pending exceptions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001253 __ mov(r5, Operand(isolate()->factory()->the_hole_value()));
Ben Murdoch589d6972011-11-30 16:04:58 +00001254 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001255 isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001256 __ str(r5, MemOperand(ip));
1257
1258 // Invoke the function by calling through JS entry trampoline builtin.
1259 // Notice that we cannot store a reference to the trampoline code directly in
1260 // this stub, because runtime stubs are not traversed when doing GC.
1261
1262 // Expected registers by Builtins::JSEntryTrampoline
1263 // r0: code entry
1264 // r1: function
1265 // r2: receiver
1266 // r3: argc
1267 // r4: argv
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001268 if (type() == StackFrame::ENTRY_CONSTRUCT) {
Steve Block44f0eee2011-05-26 01:26:41 +01001269 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001270 isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001271 __ mov(ip, Operand(construct_entry));
1272 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001273 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001274 __ mov(ip, Operand(entry));
1275 }
1276 __ ldr(ip, MemOperand(ip)); // deref address
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001277 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001278
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001279 // Branch and link to JSEntryTrampoline.
1280 __ Call(ip);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001281
Steve Block053d10c2011-06-13 19:13:29 +01001282 // Unlink this frame from the handler chain.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001283 __ PopStackHandler();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001284
1285 __ bind(&exit); // r0 holds result
Steve Block053d10c2011-06-13 19:13:29 +01001286 // Check if the current stack frame is marked as the outermost JS frame.
1287 Label non_outermost_js_2;
1288 __ pop(r5);
1289 __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1290 __ b(ne, &non_outermost_js_2);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001291 __ mov(r6, Operand::Zero());
Steve Block053d10c2011-06-13 19:13:29 +01001292 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1293 __ str(r6, MemOperand(r5));
1294 __ bind(&non_outermost_js_2);
Steve Block053d10c2011-06-13 19:13:29 +01001295
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001296 // Restore the top frame descriptors from the stack.
1297 __ pop(r3);
Steve Block44f0eee2011-05-26 01:26:41 +01001298 __ mov(ip,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001299 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001300 __ str(r3, MemOperand(ip));
1301
1302 // Reset the stack to the callee saved registers.
1303 __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1304
1305 // Restore callee-saved registers and return.
1306#ifdef DEBUG
1307 if (FLAG_debug_code) {
1308 __ mov(lr, Operand(pc));
1309 }
1310#endif
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001311
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001312 // Restore callee-saved vfp registers.
1313 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001314
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001315 __ ldm(ia_w, sp, kCalleeSaved | pc.bit());
1316}
1317
1318
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001319void InstanceOfStub::Generate(MacroAssembler* masm) {
1320 Register const object = r1; // Object (lhs).
1321 Register const function = r0; // Function (rhs).
1322 Register const object_map = r2; // Map of {object}.
1323 Register const function_map = r3; // Map of {function}.
1324 Register const function_prototype = r4; // Prototype of {function}.
1325 Register const scratch = r5;
Steve Block1e0659c2011-05-24 12:43:12 +01001326
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001327 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1328 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
Steve Block1e0659c2011-05-24 12:43:12 +01001329
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001330 // Check if {object} is a smi.
1331 Label object_is_smi;
1332 __ JumpIfSmi(object, &object_is_smi);
Steve Block1e0659c2011-05-24 12:43:12 +01001333
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001334 // Lookup the {function} and the {object} map in the global instanceof cache.
1335 // Note: This is safe because we clear the global instanceof cache whenever
1336 // we change the prototype of any object.
1337 Label fast_case, slow_case;
1338 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1339 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1340 __ b(ne, &fast_case);
1341 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1342 __ b(ne, &fast_case);
1343 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1344 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001345
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001346 // If {object} is a smi we can safely return false if {function} is a JS
1347 // function, otherwise we have to miss to the runtime and throw an exception.
1348 __ bind(&object_is_smi);
1349 __ JumpIfSmi(function, &slow_case);
1350 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1351 __ b(ne, &slow_case);
1352 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
1353 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001354
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001355 // Fast-case: The {function} must be a valid JSFunction.
1356 __ bind(&fast_case);
1357 __ JumpIfSmi(function, &slow_case);
1358 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
1359 __ b(ne, &slow_case);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001360
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001361 // Ensure that {function} has an instance prototype.
1362 __ ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1363 __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
1364 __ b(ne, &slow_case);
Steve Block1e0659c2011-05-24 12:43:12 +01001365
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001366 // Get the "prototype" (or initial map) of the {function}.
1367 __ ldr(function_prototype,
1368 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1369 __ AssertNotSmi(function_prototype);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001370
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001371 // Resolve the prototype if the {function} has an initial map. Afterwards the
1372 // {function_prototype} will be either the JSReceiver prototype object or the
1373 // hole value, which means that no instances of the {function} were created so
1374 // far and hence we should return false.
1375 Label function_prototype_valid;
1376 __ CompareObjectType(function_prototype, scratch, scratch, MAP_TYPE);
1377 __ b(ne, &function_prototype_valid);
1378 __ ldr(function_prototype,
1379 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1380 __ bind(&function_prototype_valid);
1381 __ AssertNotSmi(function_prototype);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001382
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001383 // Update the global instanceof cache with the current {object} map and
1384 // {function}. The cached answer will be set when it is known below.
1385 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1386 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
Steve Block1e0659c2011-05-24 12:43:12 +01001387
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001388 // Loop through the prototype chain looking for the {function} prototype.
1389 // Assume true, and change to false if not found.
1390 Register const object_instance_type = function_map;
1391 Register const map_bit_field = function_map;
1392 Register const null = scratch;
1393 Register const result = r0;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001394
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001395 Label done, loop, fast_runtime_fallback;
1396 __ LoadRoot(result, Heap::kTrueValueRootIndex);
1397 __ LoadRoot(null, Heap::kNullValueRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001398 __ bind(&loop);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001399
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001400 // Check if the object needs to be access checked.
1401 __ ldrb(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset));
1402 __ tst(map_bit_field, Operand(1 << Map::kIsAccessCheckNeeded));
1403 __ b(ne, &fast_runtime_fallback);
1404 // Check if the current object is a Proxy.
1405 __ CompareInstanceType(object_map, object_instance_type, JS_PROXY_TYPE);
1406 __ b(eq, &fast_runtime_fallback);
Steve Block1e0659c2011-05-24 12:43:12 +01001407
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001408 __ ldr(object, FieldMemOperand(object_map, Map::kPrototypeOffset));
1409 __ cmp(object, function_prototype);
1410 __ b(eq, &done);
1411 __ cmp(object, null);
1412 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1413 __ b(ne, &loop);
1414 __ LoadRoot(result, Heap::kFalseValueRootIndex);
1415 __ bind(&done);
1416 __ StoreRoot(result, Heap::kInstanceofCacheAnswerRootIndex);
1417 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001418
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001419 // Found Proxy or access check needed: Call the runtime
1420 __ bind(&fast_runtime_fallback);
1421 __ Push(object, function_prototype);
1422 // Invalidate the instanceof cache.
1423 __ Move(scratch, Smi::FromInt(0));
1424 __ StoreRoot(scratch, Heap::kInstanceofCacheFunctionRootIndex);
1425 __ TailCallRuntime(Runtime::kHasInPrototypeChain);
Steve Block1e0659c2011-05-24 12:43:12 +01001426
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001427 // Slow-case: Call the %InstanceOf runtime function.
1428 __ bind(&slow_case);
1429 __ Push(object, function);
1430 __ TailCallRuntime(Runtime::kInstanceOf);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001431}
1432
1433
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001434void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1435 Label miss;
1436 Register receiver = LoadDescriptor::ReceiverRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001437 // Ensure that the vector and slot registers won't be clobbered before
1438 // calling the miss handler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001439 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(),
1440 LoadWithVectorDescriptor::SlotRegister()));
Steve Block1e0659c2011-05-24 12:43:12 +01001441
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001442 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4,
1443 r5, &miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001444 __ bind(&miss);
1445 PropertyAccessCompiler::TailCallBuiltin(
1446 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1447}
Steve Block1e0659c2011-05-24 12:43:12 +01001448
1449
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001450void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1451 // Return address is in lr.
1452 Label miss;
1453
1454 Register receiver = LoadDescriptor::ReceiverRegister();
1455 Register index = LoadDescriptor::NameRegister();
1456 Register scratch = r5;
1457 Register result = r0;
1458 DCHECK(!scratch.is(receiver) && !scratch.is(index));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001459 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1460 result.is(LoadWithVectorDescriptor::SlotRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001461
1462 // StringCharAtGenerator doesn't use the result register until it's passed
1463 // the different miss possibilities. If it did, we would have a conflict
1464 // when FLAG_vector_ics is true.
1465 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1466 &miss, // When not a string.
1467 &miss, // When not a number.
1468 &miss, // When index out of range.
1469 STRING_INDEX_IS_ARRAY_INDEX,
1470 RECEIVER_IS_STRING);
1471 char_at_generator.GenerateFast(masm);
1472 __ Ret();
1473
1474 StubRuntimeCallHelper call_helper;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001475 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001476
1477 __ bind(&miss);
1478 PropertyAccessCompiler::TailCallBuiltin(
1479 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1480}
1481
1482
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001483void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1484 // Return address is in lr.
1485 Label slow;
1486
1487 Register receiver = LoadDescriptor::ReceiverRegister();
1488 Register key = LoadDescriptor::NameRegister();
1489
1490 // Check that the key is an array index, that is Uint32.
1491 __ NonNegativeSmiTst(key);
1492 __ b(ne, &slow);
1493
1494 // Everything is fine, call runtime.
1495 __ Push(receiver, key); // Receiver, key.
1496
1497 // Perform tail call to the entry.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001498 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001499
1500 __ bind(&slow);
1501 PropertyAccessCompiler::TailCallBuiltin(
1502 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001503}
1504
1505
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001506void RegExpExecStub::Generate(MacroAssembler* masm) {
1507 // Just jump directly to runtime if native RegExp is not selected at compile
1508 // time or if regexp entry in generated code is turned off runtime switch or
1509 // at compilation.
1510#ifdef V8_INTERPRETED_REGEXP
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001511 __ TailCallRuntime(Runtime::kRegExpExec);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001512#else // V8_INTERPRETED_REGEXP
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001513
1514 // Stack frame on entry.
1515 // sp[0]: last_match_info (expected JSArray)
1516 // sp[4]: previous index
1517 // sp[8]: subject string
1518 // sp[12]: JSRegExp object
1519
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001520 const int kLastMatchInfoOffset = 0 * kPointerSize;
1521 const int kPreviousIndexOffset = 1 * kPointerSize;
1522 const int kSubjectOffset = 2 * kPointerSize;
1523 const int kJSRegExpOffset = 3 * kPointerSize;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001524
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001525 Label runtime;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001526 // Allocation of registers for this function. These are in callee save
1527 // registers and will be preserved by the call to the native RegExp code, as
1528 // this code is called using the normal C calling convention. When calling
1529 // directly from generated code the native RegExp code will not do a GC and
1530 // therefore the content of these registers are safe to use after the call.
1531 Register subject = r4;
1532 Register regexp_data = r5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001533 Register last_match_info_elements = no_reg; // will be r6;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001534
1535 // Ensure that a RegExp stack is allocated.
1536 ExternalReference address_of_regexp_stack_memory_address =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001537 ExternalReference::address_of_regexp_stack_memory_address(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001538 ExternalReference address_of_regexp_stack_memory_size =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001539 ExternalReference::address_of_regexp_stack_memory_size(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001540 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
1541 __ ldr(r0, MemOperand(r0, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001542 __ cmp(r0, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001543 __ b(eq, &runtime);
1544
1545 // Check that the first argument is a JSRegExp object.
1546 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001547 __ JumpIfSmi(r0, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001548 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
1549 __ b(ne, &runtime);
1550
1551 // Check that the RegExp has been compiled (data contains a fixed array).
1552 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
1553 if (FLAG_debug_code) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001554 __ SmiTst(regexp_data);
1555 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001556 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001557 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001558 }
1559
1560 // regexp_data: RegExp data (FixedArray)
1561 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1562 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1563 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
1564 __ b(ne, &runtime);
1565
1566 // regexp_data: RegExp data (FixedArray)
1567 // Check that the number of captures fit in the static offsets vector buffer.
1568 __ ldr(r2,
1569 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001570 // Check (number_of_captures + 1) * 2 <= offsets vector size
1571 // Or number_of_captures * 2 <= offsets vector size - 2
1572 // Multiplying by 2 comes for free since r2 is smi-tagged.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001573 STATIC_ASSERT(kSmiTag == 0);
1574 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001575 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1576 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001577 __ b(hi, &runtime);
1578
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001579 // Reset offset for possibly sliced string.
1580 __ mov(r9, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001581 __ ldr(subject, MemOperand(sp, kSubjectOffset));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001582 __ JumpIfSmi(subject, &runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001583 __ mov(r3, subject); // Make a copy of the original subject string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001584 // subject: subject string
1585 // r3: subject string
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001586 // regexp_data: RegExp data (FixedArray)
1587 // Handle subject string according to its encoding and representation:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001588 // (1) Sequential string? If yes, go to (4).
1589 // (2) Sequential or cons? If not, go to (5).
1590 // (3) Cons string. If the string is flat, replace subject with first string
1591 // and go to (1). Otherwise bail out to runtime.
1592 // (4) Sequential string. Load regexp code according to encoding.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001593 // (E) Carry on.
1594 /// [...]
1595
1596 // Deferred code at the end of the stub:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001597 // (5) Long external string? If not, go to (7).
1598 // (6) External string. Make it, offset-wise, look like a sequential string.
1599 // Go to (4).
1600 // (7) Short external string or not a string? If yes, bail out to runtime.
1601 // (8) Sliced string. Replace subject with parent. Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001602
Ben Murdoch097c5b22016-05-18 11:27:45 +01001603 Label seq_string /* 4 */, external_string /* 6 */, check_underlying /* 1 */,
1604 not_seq_nor_cons /* 5 */, not_long_external /* 7 */;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001605
Ben Murdoch097c5b22016-05-18 11:27:45 +01001606 __ bind(&check_underlying);
1607 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1608 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1609
1610 // (1) Sequential string? If yes, go to (4).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001611 __ and_(r1,
1612 r0,
1613 Operand(kIsNotStringMask |
1614 kStringRepresentationMask |
1615 kShortExternalStringMask),
1616 SetCC);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001617 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001618 __ b(eq, &seq_string); // Go to (4).
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001619
Ben Murdoch097c5b22016-05-18 11:27:45 +01001620 // (2) Sequential or cons? If not, go to (5).
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001621 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1622 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001623 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1624 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001625 __ cmp(r1, Operand(kExternalStringTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001626 __ b(ge, &not_seq_nor_cons); // Go to (5).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001627
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001628 // (3) Cons string. Check that it's flat.
1629 // Replace subject with first string and reload instance type.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001630 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001631 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001632 __ b(ne, &runtime);
1633 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001634 __ jmp(&check_underlying);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001635
Ben Murdoch097c5b22016-05-18 11:27:45 +01001636 // (4) Sequential string. Load regexp code according to encoding.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001637 __ bind(&seq_string);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001638 // subject: sequential subject string (or look-alike, external string)
1639 // r3: original subject string
1640 // Load previous index and check range before r3 is overwritten. We have to
1641 // use r3 instead of subject here because subject might have been only made
1642 // to look like a sequential string when it actually is an external string.
1643 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
1644 __ JumpIfNotSmi(r1, &runtime);
1645 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
1646 __ cmp(r3, Operand(r1));
1647 __ b(ls, &runtime);
1648 __ SmiUntag(r1);
1649
1650 STATIC_ASSERT(4 == kOneByteStringTag);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001651 STATIC_ASSERT(kTwoByteStringTag == 0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001652 __ and_(r0, r0, Operand(kStringEncodingMask));
1653 __ mov(r3, Operand(r0, ASR, 2), SetCC);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001654 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
1655 ne);
1656 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001657
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001658 // (E) Carry on. String handling is done.
1659 // r6: irregexp code
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001660 // Check that the irregexp code has been generated for the actual string
1661 // encoding. If it has, the field contains a code object otherwise it contains
Ben Murdoch257744e2011-11-30 15:57:28 +00001662 // a smi (code flushing support).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001663 __ JumpIfSmi(r6, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001664
1665 // r1: previous index
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001666 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
1667 // r6: code
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001668 // subject: Subject string
1669 // regexp_data: RegExp data (FixedArray)
1670 // All checks done. Now push arguments for native regexp code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001671 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001672
Steve Block44f0eee2011-05-26 01:26:41 +01001673 // Isolates: note we add an additional parameter here (isolate pointer).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001674 const int kRegExpExecuteArguments = 9;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001675 const int kParameterRegisters = 4;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001676 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001677
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001678 // Stack pointer now points to cell where return address is to be written.
1679 // Arguments are before that on the stack or in registers.
1680
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001681 // Argument 9 (sp[20]): Pass current isolate address.
1682 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
1683 __ str(r0, MemOperand(sp, 5 * kPointerSize));
1684
1685 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
1686 __ mov(r0, Operand(1));
Steve Block44f0eee2011-05-26 01:26:41 +01001687 __ str(r0, MemOperand(sp, 4 * kPointerSize));
1688
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001689 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001690 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
1691 __ ldr(r0, MemOperand(r0, 0));
1692 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
1693 __ ldr(r2, MemOperand(r2, 0));
1694 __ add(r0, r0, Operand(r2));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001695 __ str(r0, MemOperand(sp, 3 * kPointerSize));
1696
1697 // Argument 6: Set the number of capture registers to zero to force global
1698 // regexps to behave as non-global. This does not affect non-global regexps.
1699 __ mov(r0, Operand::Zero());
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001700 __ str(r0, MemOperand(sp, 2 * kPointerSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001701
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001702 // Argument 5 (sp[4]): static offsets vector buffer.
Steve Block44f0eee2011-05-26 01:26:41 +01001703 __ mov(r0,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001704 Operand(ExternalReference::address_of_static_offsets_vector(
1705 isolate())));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001706 __ str(r0, MemOperand(sp, 1 * kPointerSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001707
1708 // For arguments 4 and 3 get string length, calculate start of string data and
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001709 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
1710 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001711 __ eor(r3, r3, Operand(1));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001712 // Load the length from the original subject string from the previous stack
1713 // frame. Therefore we have to use fp, which points exactly to two pointer
1714 // sizes below the previous sp. (Because creating a new stack frame pushes
1715 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
Ben Murdoch589d6972011-11-30 16:04:58 +00001716 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001717 // If slice offset is not 0, load the length from the original sliced string.
1718 // Argument 4, r3: End of string data
1719 // Argument 3, r2: Start of string data
1720 // Prepare start and end index of the input.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001721 __ add(r9, r7, Operand(r9, LSL, r3));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001722 __ add(r2, r9, Operand(r1, LSL, r3));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001723
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001724 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
1725 __ SmiUntag(r7);
1726 __ add(r3, r9, Operand(r7, LSL, r3));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001727
1728 // Argument 2 (r1): Previous index.
1729 // Already there
1730
1731 // Argument 1 (r0): Subject string.
Ben Murdoch589d6972011-11-30 16:04:58 +00001732 __ mov(r0, subject);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001733
1734 // Locate the code entry and call it.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001735 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
1736 DirectCEntryStub stub(isolate());
1737 stub.GenerateCall(masm, r6);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001738
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001739 __ LeaveExitFrame(false, no_reg, true);
1740
1741 last_match_info_elements = r6;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001742
1743 // r0: result
1744 // subject: subject string (callee saved)
1745 // regexp_data: RegExp data (callee saved)
1746 // last_match_info_elements: Last match info elements (callee saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001747 // Check the result.
1748 Label success;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001749 __ cmp(r0, Operand(1));
1750 // We expect exactly one result since we force the called regexp to behave
1751 // as non-global.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001752 __ b(eq, &success);
1753 Label failure;
Ben Murdoch589d6972011-11-30 16:04:58 +00001754 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001755 __ b(eq, &failure);
Ben Murdoch589d6972011-11-30 16:04:58 +00001756 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001757 // If not exception it can only be retry. Handle that in the runtime system.
1758 __ b(ne, &runtime);
1759 // Result must now be exception. If there is no pending exception already a
1760 // stack overflow (on the backtrack stack) was detected in RegExp code but
1761 // haven't created the exception yet. Handle that in the runtime system.
1762 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001763 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
Ben Murdoch589d6972011-11-30 16:04:58 +00001764 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001765 isolate())));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001766 __ ldr(r0, MemOperand(r2, 0));
Ben Murdoch589d6972011-11-30 16:04:58 +00001767 __ cmp(r0, r1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001768 __ b(eq, &runtime);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001769
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001770 // For exception, throw the exception again.
1771 __ TailCallRuntime(Runtime::kRegExpExecReThrow);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001772
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001773 __ bind(&failure);
1774 // For failure and exception return null.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001775 __ mov(r0, Operand(isolate()->factory()->null_value()));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001776 __ add(sp, sp, Operand(4 * kPointerSize));
1777 __ Ret();
1778
1779 // Process the result from the native regexp code.
1780 __ bind(&success);
1781 __ ldr(r1,
1782 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1783 // Calculate number of capture registers (number_of_captures + 1) * 2.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001784 // Multiplying by 2 comes for free since r1 is smi-tagged.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001785 STATIC_ASSERT(kSmiTag == 0);
1786 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
1787 __ add(r1, r1, Operand(2)); // r1 was a smi.
1788
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001789 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
1790 __ JumpIfSmi(r0, &runtime);
1791 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
1792 __ b(ne, &runtime);
1793 // Check that the JSArray is in fast case.
1794 __ ldr(last_match_info_elements,
1795 FieldMemOperand(r0, JSArray::kElementsOffset));
1796 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
1797 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
1798 __ b(ne, &runtime);
1799 // Check that the last match info has space for the capture registers and the
1800 // additional information.
1801 __ ldr(r0,
1802 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
1803 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
1804 __ cmp(r2, Operand::SmiUntag(r0));
1805 __ b(gt, &runtime);
1806
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001807 // r1: number of capture registers
1808 // r4: subject string
1809 // Store the capture count.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001810 __ SmiTag(r2, r1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001811 __ str(r2, FieldMemOperand(last_match_info_elements,
1812 RegExpImpl::kLastCaptureCountOffset));
1813 // Store last subject and last input.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001814 __ str(subject,
1815 FieldMemOperand(last_match_info_elements,
1816 RegExpImpl::kLastSubjectOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001817 __ mov(r2, subject);
1818 __ RecordWriteField(last_match_info_elements,
1819 RegExpImpl::kLastSubjectOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001820 subject,
1821 r3,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001822 kLRHasNotBeenSaved,
1823 kDontSaveFPRegs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001824 __ mov(subject, r2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001825 __ str(subject,
1826 FieldMemOperand(last_match_info_elements,
1827 RegExpImpl::kLastInputOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001828 __ RecordWriteField(last_match_info_elements,
1829 RegExpImpl::kLastInputOffset,
1830 subject,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001831 r3,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001832 kLRHasNotBeenSaved,
1833 kDontSaveFPRegs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001834
1835 // Get the static offsets vector filled by the native regexp code.
1836 ExternalReference address_of_static_offsets_vector =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001837 ExternalReference::address_of_static_offsets_vector(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001838 __ mov(r2, Operand(address_of_static_offsets_vector));
1839
1840 // r1: number of capture registers
1841 // r2: offsets vector
1842 Label next_capture, done;
1843 // Capture register counter starts from number of capture registers and
1844 // counts down until wraping after zero.
1845 __ add(r0,
1846 last_match_info_elements,
1847 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
1848 __ bind(&next_capture);
1849 __ sub(r1, r1, Operand(1), SetCC);
1850 __ b(mi, &done);
1851 // Read the value from the static offsets vector buffer.
1852 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
1853 // Store the smi value in the last match info.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001854 __ SmiTag(r3);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001855 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
1856 __ jmp(&next_capture);
1857 __ bind(&done);
1858
1859 // Return last match info.
1860 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
1861 __ add(sp, sp, Operand(4 * kPointerSize));
1862 __ Ret();
1863
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001864 // Do the runtime call to execute the regexp.
1865 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001866 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001867
1868 // Deferred code for string handling.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001869 // (5) Long external string? If not, go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001870 __ bind(&not_seq_nor_cons);
1871 // Compare flags are still set.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001872 __ b(gt, &not_long_external); // Go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001873
Ben Murdoch097c5b22016-05-18 11:27:45 +01001874 // (6) External string. Make it, offset-wise, look like a sequential string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001875 __ bind(&external_string);
1876 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1877 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
1878 if (FLAG_debug_code) {
1879 // Assert that we do not have a cons or slice (indirect strings) here.
1880 // Sequential strings have already been ruled out.
1881 __ tst(r0, Operand(kIsIndirectStringMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001882 __ Assert(eq, kExternalStringExpectedButNotFound);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001883 }
1884 __ ldr(subject,
1885 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
1886 // Move the pointer so that offset-wise, it looks like a sequential string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001887 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001888 __ sub(subject,
1889 subject,
1890 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001891 __ jmp(&seq_string); // Go to (4).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001892
Ben Murdoch097c5b22016-05-18 11:27:45 +01001893 // (7) Short external string or not a string? If yes, bail out to runtime.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001894 __ bind(&not_long_external);
1895 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
1896 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
1897 __ b(ne, &runtime);
1898
Ben Murdoch097c5b22016-05-18 11:27:45 +01001899 // (8) Sliced string. Replace subject with parent. Go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001900 // Load offset into r9 and replace subject string with parent.
1901 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
1902 __ SmiUntag(r9);
1903 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
1904 __ jmp(&check_underlying); // Go to (4).
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001905#endif // V8_INTERPRETED_REGEXP
1906}
1907
1908
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001909static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
1910 // r0 : number of arguments to the construct function
1911 // r1 : the function to call
1912 // r2 : feedback vector
1913 // r3 : slot in feedback vector (Smi)
1914 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
1915
1916 // Number-of-arguments register must be smi-tagged to call out.
1917 __ SmiTag(r0);
1918 __ Push(r3, r2, r1, r0);
1919
1920 __ CallStub(stub);
1921
1922 __ Pop(r3, r2, r1, r0);
1923 __ SmiUntag(r0);
1924}
1925
1926
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001927static void GenerateRecordCallTarget(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001928 // Cache the called function in a feedback vector slot. Cache states
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001929 // are uninitialized, monomorphic (indicated by a JSFunction), and
1930 // megamorphic.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001931 // r0 : number of arguments to the construct function
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001932 // r1 : the function to call
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001933 // r2 : feedback vector
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001934 // r3 : slot in feedback vector (Smi)
1935 Label initialize, done, miss, megamorphic, not_array_function;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001936
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001937 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
1938 masm->isolate()->heap()->megamorphic_symbol());
1939 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
1940 masm->isolate()->heap()->uninitialized_symbol());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001941
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001942 // Load the cache state into r5.
1943 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
1944 __ ldr(r5, FieldMemOperand(r5, FixedArray::kHeaderSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001945
1946 // A monomorphic cache hit or an already megamorphic state: invoke the
1947 // function without changing the state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001948 // We don't know if r5 is a WeakCell or a Symbol, but it's harmless to read at
1949 // this position in a symbol (see static asserts in type-feedback-vector.h).
1950 Label check_allocation_site;
1951 Register feedback_map = r6;
1952 Register weak_value = r9;
1953 __ ldr(weak_value, FieldMemOperand(r5, WeakCell::kValueOffset));
1954 __ cmp(r1, weak_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001955 __ b(eq, &done);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001956 __ CompareRoot(r5, Heap::kmegamorphic_symbolRootIndex);
1957 __ b(eq, &done);
1958 __ ldr(feedback_map, FieldMemOperand(r5, HeapObject::kMapOffset));
1959 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
1960 __ b(ne, &check_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001961
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001962 // If the weak cell is cleared, we have a new chance to become monomorphic.
1963 __ JumpIfSmi(weak_value, &initialize);
1964 __ jmp(&megamorphic);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001965
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001966 __ bind(&check_allocation_site);
1967 // If we came here, we need to see if we are the array function.
1968 // If we didn't have a matching function, and we didn't find the megamorph
1969 // sentinel, then we have in the slot either some other function or an
1970 // AllocationSite.
1971 __ CompareRoot(feedback_map, Heap::kAllocationSiteMapRootIndex);
1972 __ b(ne, &miss);
1973
1974 // Make sure the function is the Array() function
1975 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r5);
1976 __ cmp(r1, r5);
1977 __ b(ne, &megamorphic);
1978 __ jmp(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001979
1980 __ bind(&miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001981
1982 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
1983 // megamorphic.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001984 __ CompareRoot(r5, Heap::kuninitialized_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001985 __ b(eq, &initialize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001986 // MegamorphicSentinel is an immortal immovable object (undefined) so no
1987 // write-barrier is needed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001988 __ bind(&megamorphic);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001989 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001990 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001991 __ str(ip, FieldMemOperand(r5, FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001992 __ jmp(&done);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001993
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001994 // An uninitialized cache is patched with the function
1995 __ bind(&initialize);
1996
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001997 // Make sure the function is the Array() function
1998 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r5);
1999 __ cmp(r1, r5);
2000 __ b(ne, &not_array_function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002001
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002002 // The target function is the Array constructor,
2003 // Create an AllocationSite if we don't already have it, store it in the
2004 // slot.
2005 CreateAllocationSiteStub create_stub(masm->isolate());
2006 CallStubInRecordCallTarget(masm, &create_stub);
2007 __ b(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002008
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002009 __ bind(&not_array_function);
2010 CreateWeakCellStub weak_cell_stub(masm->isolate());
2011 CallStubInRecordCallTarget(masm, &weak_cell_stub);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002012 __ bind(&done);
2013}
2014
2015
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002016void CallConstructStub::Generate(MacroAssembler* masm) {
2017 // r0 : number of arguments
2018 // r1 : the function to call
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002019 // r2 : feedback vector
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002020 // r3 : slot in feedback vector (Smi, for RecordCallTarget)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002021
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002022 Label non_function;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002023 // Check that the function is not a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002024 __ JumpIfSmi(r1, &non_function);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002025 // Check that the function is a JSFunction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002026 __ CompareObjectType(r1, r5, r5, JS_FUNCTION_TYPE);
2027 __ b(ne, &non_function);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002028
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002029 GenerateRecordCallTarget(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002030
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002031 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2032 Label feedback_register_initialized;
2033 // Put the AllocationSite from the feedback vector into r2, or undefined.
2034 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2035 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2036 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2037 __ b(eq, &feedback_register_initialized);
2038 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2039 __ bind(&feedback_register_initialized);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002040
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002041 __ AssertUndefinedOrAllocationSite(r2, r5);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002042
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002043 // Pass function as new target.
2044 __ mov(r3, r1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002045
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002046 // Tail call to the function-specific construct stub (still in the caller
2047 // context at this point).
2048 __ ldr(r4, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2049 __ ldr(r4, FieldMemOperand(r4, SharedFunctionInfo::kConstructStubOffset));
2050 __ add(pc, r4, Operand(Code::kHeaderSize - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002051
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002052 __ bind(&non_function);
2053 __ mov(r3, r1);
2054 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002055}
2056
2057
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002058void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002059 // r1 - function
2060 // r3 - slot id
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002061 // r2 - vector
2062 // r4 - allocation site (loaded from vector[slot])
2063 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r5);
2064 __ cmp(r1, r5);
2065 __ b(ne, miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002066
2067 __ mov(r0, Operand(arg_count()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002068
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002069 // Increment the call count for monomorphic function calls.
2070 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2071 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2072 __ ldr(r3, FieldMemOperand(r2, 0));
2073 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2074 __ str(r3, FieldMemOperand(r2, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002075
2076 __ mov(r2, r4);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002077 __ mov(r3, r1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002078 ArrayConstructorStub stub(masm->isolate(), arg_count());
2079 __ TailCallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002080}
2081
2082
2083void CallICStub::Generate(MacroAssembler* masm) {
2084 // r1 - function
2085 // r3 - slot id (Smi)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002086 // r2 - vector
2087 Label extra_checks_or_miss, call, call_function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002088 int argc = arg_count();
2089 ParameterCount actual(argc);
2090
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002091 // The checks. First, does r1 match the recorded monomorphic target?
2092 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2093 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002094
2095 // We don't know that we have a weak cell. We might have a private symbol
2096 // or an AllocationSite, but the memory is safe to examine.
2097 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2098 // FixedArray.
2099 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2100 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2101 // computed, meaning that it can't appear to be a pointer. If the low bit is
2102 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2103 // to be a pointer.
2104 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2105 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2106 WeakCell::kValueOffset &&
2107 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2108
2109 __ ldr(r5, FieldMemOperand(r4, WeakCell::kValueOffset));
2110 __ cmp(r1, r5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002111 __ b(ne, &extra_checks_or_miss);
2112
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002113 // The compare above could have been a SMI/SMI comparison. Guard against this
2114 // convincing us that we have a monomorphic JSFunction.
2115 __ JumpIfSmi(r1, &extra_checks_or_miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002116
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002117 // Increment the call count for monomorphic function calls.
2118 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3));
2119 __ add(r2, r2, Operand(FixedArray::kHeaderSize + kPointerSize));
2120 __ ldr(r3, FieldMemOperand(r2, 0));
2121 __ add(r3, r3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2122 __ str(r3, FieldMemOperand(r2, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002123
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002124 __ bind(&call_function);
2125 __ mov(r0, Operand(argc));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002126 __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(),
2127 tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002128 RelocInfo::CODE_TARGET);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002129
2130 __ bind(&extra_checks_or_miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002131 Label uninitialized, miss, not_allocation_site;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002132
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002133 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002134 __ b(eq, &call);
2135
2136 // Verify that r4 contains an AllocationSite
2137 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2138 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2139 __ b(ne, &not_allocation_site);
2140
2141 // We have an allocation site.
2142 HandleArrayCase(masm, &miss);
2143
2144 __ bind(&not_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002145
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002146 // The following cases attempt to handle MISS cases without going to the
2147 // runtime.
2148 if (FLAG_trace_ic) {
2149 __ jmp(&miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002150 }
2151
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002152 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2153 __ b(eq, &uninitialized);
2154
2155 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2156 // to handle it here. More complex cases are dealt with in the runtime.
2157 __ AssertNotSmi(r4);
2158 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2159 __ b(ne, &miss);
2160 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2161 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2162 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002163
2164 __ bind(&call);
2165 __ mov(r0, Operand(argc));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002166 __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002167 RelocInfo::CODE_TARGET);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002168
2169 __ bind(&uninitialized);
2170
2171 // We are going monomorphic, provided we actually have a JSFunction.
2172 __ JumpIfSmi(r1, &miss);
2173
2174 // Goto miss case if we do not have a function.
2175 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2176 __ b(ne, &miss);
2177
2178 // Make sure the function is not the Array() function, which requires special
2179 // behavior on MISS.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002180 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r4);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002181 __ cmp(r1, r4);
2182 __ b(eq, &miss);
2183
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002184 // Make sure the function belongs to the same native context.
2185 __ ldr(r4, FieldMemOperand(r1, JSFunction::kContextOffset));
2186 __ ldr(r4, ContextMemOperand(r4, Context::NATIVE_CONTEXT_INDEX));
2187 __ ldr(ip, NativeContextMemOperand());
2188 __ cmp(r4, ip);
2189 __ b(ne, &miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002190
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002191 // Initialize the call counter.
2192 __ Move(r5, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002193 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002194 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + kPointerSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002195
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002196 // Store the function. Use a stub since we need a frame for allocation.
2197 // r2 - vector
2198 // r3 - slot
2199 // r1 - function
2200 {
2201 FrameScope scope(masm, StackFrame::INTERNAL);
2202 CreateWeakCellStub create_stub(masm->isolate());
2203 __ Push(r1);
2204 __ CallStub(&create_stub);
2205 __ Pop(r1);
2206 }
2207
2208 __ jmp(&call_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002209
2210 // We are here because tracing is on or we encountered a MISS case we can't
2211 // handle here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002212 __ bind(&miss);
2213 GenerateMiss(masm);
2214
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002215 __ jmp(&call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002216}
2217
2218
2219void CallICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002220 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002221
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002222 // Push the receiver and the function and feedback info.
2223 __ Push(r1, r2, r3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002224
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002225 // Call the entry.
2226 __ CallRuntime(Runtime::kCallIC_Miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002227
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002228 // Move result to edi and exit the internal frame.
2229 __ mov(r1, r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002230}
2231
2232
2233// StringCharCodeAtGenerator
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002234void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002235 // If the receiver is a smi trigger the non-string case.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002236 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2237 __ JumpIfSmi(object_, receiver_not_string_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002238
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002239 // Fetch the instance type of the receiver into result register.
2240 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2241 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2242 // If the receiver is not a string trigger the non-string case.
2243 __ tst(result_, Operand(kIsNotStringMask));
2244 __ b(ne, receiver_not_string_);
2245 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002246
2247 // If the index is non-smi trigger the non-smi case.
Steve Block1e0659c2011-05-24 12:43:12 +01002248 __ JumpIfNotSmi(index_, &index_not_smi_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002249 __ bind(&got_smi_index_);
2250
2251 // Check for index out of range.
2252 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002253 __ cmp(ip, Operand(index_));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002254 __ b(ls, index_out_of_range_);
2255
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002256 __ SmiUntag(index_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002257
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002258 StringCharLoadGenerator::Generate(masm,
2259 object_,
2260 index_,
2261 result_,
2262 &call_runtime_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002263
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002264 __ SmiTag(result_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002265 __ bind(&exit_);
2266}
2267
2268
2269void StringCharCodeAtGenerator::GenerateSlow(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002270 MacroAssembler* masm, EmbedMode embed_mode,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002271 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002272 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002273
2274 // Index is not a smi.
2275 __ bind(&index_not_smi_);
2276 // If index is a heap number, try converting it to an integer.
2277 __ CheckMap(index_,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002278 result_,
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002279 Heap::kHeapNumberMapRootIndex,
2280 index_not_number_,
Ben Murdoch257744e2011-11-30 15:57:28 +00002281 DONT_DO_SMI_CHECK);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002282 call_helper.BeforeCall(masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002283 if (embed_mode == PART_OF_IC_HANDLER) {
2284 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2285 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2286 } else {
2287 // index_ is consumed by runtime conversion function.
2288 __ Push(object_, index_);
2289 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002290 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002291 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002292 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002293 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002294 // NumberToSmi discards numbers that are not exact integers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002295 __ CallRuntime(Runtime::kNumberToSmi);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002296 }
2297 // Save the conversion result before the pop instructions below
2298 // have a chance to overwrite it.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002299 __ Move(index_, r0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002300 if (embed_mode == PART_OF_IC_HANDLER) {
2301 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2302 LoadWithVectorDescriptor::SlotRegister(), object_);
2303 } else {
2304 __ pop(object_);
2305 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002306 // Reload the instance type.
2307 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2308 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2309 call_helper.AfterCall(masm);
2310 // If index is still not a smi, it must be out of range.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002311 __ JumpIfNotSmi(index_, index_out_of_range_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002312 // Otherwise, return to the fast path.
2313 __ jmp(&got_smi_index_);
2314
2315 // Call runtime. We get here when the receiver is a string and the
2316 // index is a number, but the code of getting the actual character
2317 // is too complex (e.g., when the string needs to be flattened).
2318 __ bind(&call_runtime_);
2319 call_helper.BeforeCall(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002320 __ SmiTag(index_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002321 __ Push(object_, index_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002322 __ CallRuntime(Runtime::kStringCharCodeAtRT);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002323 __ Move(result_, r0);
2324 call_helper.AfterCall(masm);
2325 __ jmp(&exit_);
2326
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002327 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002328}
2329
2330
2331// -------------------------------------------------------------------------
2332// StringCharFromCodeGenerator
2333
2334void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2335 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2336 STATIC_ASSERT(kSmiTag == 0);
2337 STATIC_ASSERT(kSmiShiftSize == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002338 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2339 __ tst(code_, Operand(kSmiTagMask |
2340 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
Steve Block1e0659c2011-05-24 12:43:12 +01002341 __ b(ne, &slow_case_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002342
2343 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002344 // At this point code register contains smi tagged one-byte char code.
2345 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002346 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002347 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002348 __ b(eq, &slow_case_);
2349 __ bind(&exit_);
2350}
2351
2352
2353void StringCharFromCodeGenerator::GenerateSlow(
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002354 MacroAssembler* masm,
2355 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002356 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002357
2358 __ bind(&slow_case_);
2359 call_helper.BeforeCall(masm);
2360 __ push(code_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002361 __ CallRuntime(Runtime::kStringCharFromCode);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002362 __ Move(result_, r0);
2363 call_helper.AfterCall(masm);
2364 __ jmp(&exit_);
2365
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002366 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002367}
2368
2369
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002370enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002371
2372
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002373void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2374 Register dest,
2375 Register src,
2376 Register count,
2377 Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002378 String::Encoding encoding) {
2379 if (FLAG_debug_code) {
2380 // Check that destination is word aligned.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002381 __ tst(dest, Operand(kPointerAlignmentMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002382 __ Check(eq, kDestinationOfCopyNotAligned);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002383 }
2384
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002385 // Assumes word reads and writes are little endian.
2386 // Nothing to do for zero characters.
2387 Label done;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002388 if (encoding == String::TWO_BYTE_ENCODING) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002389 __ add(count, count, Operand(count), SetCC);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002390 }
2391
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002392 Register limit = count; // Read until dest equals this.
2393 __ add(limit, dest, Operand(count));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002394
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002395 Label loop_entry, loop;
2396 // Copy bytes from src to dest until dest hits limit.
2397 __ b(&loop_entry);
2398 __ bind(&loop);
2399 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
2400 __ strb(scratch, MemOperand(dest, 1, PostIndex));
2401 __ bind(&loop_entry);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002402 __ cmp(dest, Operand(limit));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002403 __ b(lt, &loop);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002404
2405 __ bind(&done);
2406}
2407
2408
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002409void SubStringStub::Generate(MacroAssembler* masm) {
2410 Label runtime;
2411
2412 // Stack frame on entry.
2413 // lr: return address
2414 // sp[0]: to
2415 // sp[4]: from
2416 // sp[8]: string
2417
2418 // This stub is called from the native-call %_SubString(...), so
2419 // nothing can be assumed about the arguments. It is tested that:
2420 // "string" is a sequential string,
2421 // both "from" and "to" are smis, and
2422 // 0 <= from <= to <= string.length.
2423 // If any of these assumptions fail, we call the runtime system.
2424
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002425 const int kToOffset = 0 * kPointerSize;
2426 const int kFromOffset = 1 * kPointerSize;
2427 const int kStringOffset = 2 * kPointerSize;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002428
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002429 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002430 STATIC_ASSERT(kFromOffset == kToOffset + 4);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002431 STATIC_ASSERT(kSmiTag == 0);
2432 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002433
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002434 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
2435 // instead because we bail out on non-smi values: ROR and ASR are equivalent
2436 // for smis but they set the flags in a way that's easier to optimize.
2437 __ mov(r2, Operand(r2, ROR, 1), SetCC);
2438 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
2439 // If either to or from had the smi tag bit set, then C is set now, and N
2440 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002441 // We want to bailout to runtime here if From is negative. In that case, the
2442 // next instruction is not executed and we fall through to bailing out to
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002443 // runtime.
2444 // Executed if both r2 and r3 are untagged integers.
2445 __ sub(r2, r2, Operand(r3), SetCC, cc);
2446 // One of the above un-smis or the above SUB could have set N==1.
2447 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
Ben Murdoch85b71792012-04-11 18:30:58 +01002448
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002449 // Make sure first argument is a string.
Ben Murdoch589d6972011-11-30 16:04:58 +00002450 __ ldr(r0, MemOperand(sp, kStringOffset));
Ben Murdoch589d6972011-11-30 16:04:58 +00002451 __ JumpIfSmi(r0, &runtime);
2452 Condition is_string = masm->IsObjectStringType(r0, r1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002453 __ b(NegateCondition(is_string), &runtime);
2454
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002455 Label single_char;
2456 __ cmp(r2, Operand(1));
2457 __ b(eq, &single_char);
2458
Ben Murdoch589d6972011-11-30 16:04:58 +00002459 // Short-cut for the case of trivial substring.
2460 Label return_r0;
2461 // r0: original string
2462 // r2: result string length
2463 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
2464 __ cmp(r2, Operand(r4, ASR, 1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002465 // Return original string.
Ben Murdoch589d6972011-11-30 16:04:58 +00002466 __ b(eq, &return_r0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002467 // Longer than original string's length or negative: unsafe arguments.
2468 __ b(hi, &runtime);
2469 // Shorter than original string's length: an actual substring.
Ben Murdoch589d6972011-11-30 16:04:58 +00002470
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002471 // Deal with different string types: update the index if necessary
2472 // and put the underlying string into r5.
2473 // r0: original string
2474 // r1: instance type
2475 // r2: length
2476 // r3: from index (untagged)
2477 Label underlying_unpacked, sliced_string, seq_or_external_string;
2478 // If the string is not indirect, it can only be sequential or external.
2479 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2480 STATIC_ASSERT(kIsIndirectStringMask != 0);
2481 __ tst(r1, Operand(kIsIndirectStringMask));
2482 __ b(eq, &seq_or_external_string);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002483
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002484 __ tst(r1, Operand(kSlicedNotConsMask));
2485 __ b(ne, &sliced_string);
2486 // Cons string. Check whether it is flat, then fetch first part.
2487 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002488 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002489 __ b(ne, &runtime);
2490 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
2491 // Update instance type.
2492 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
2493 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
2494 __ jmp(&underlying_unpacked);
Ben Murdoch589d6972011-11-30 16:04:58 +00002495
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002496 __ bind(&sliced_string);
2497 // Sliced string. Fetch parent and correct start index by offset.
2498 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
2499 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
2500 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
2501 // Update instance type.
2502 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
2503 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
2504 __ jmp(&underlying_unpacked);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002505
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002506 __ bind(&seq_or_external_string);
2507 // Sequential or external string. Just move string to the expected register.
2508 __ mov(r5, r0);
2509
2510 __ bind(&underlying_unpacked);
2511
2512 if (FLAG_string_slices) {
2513 Label copy_routine;
2514 // r5: underlying subject string
2515 // r1: instance type of underlying subject string
2516 // r2: length
2517 // r3: adjusted start index (untagged)
2518 __ cmp(r2, Operand(SlicedString::kMinLength));
2519 // Short slice. Copy instead of slicing.
2520 __ b(lt, &copy_routine);
2521 // Allocate new sliced string. At this point we do not reload the instance
2522 // type including the string encoding because we simply rely on the info
2523 // provided by the original string. It does not matter if the original
2524 // string's encoding is wrong because we always have to recheck encoding of
2525 // the newly created string's parent anyways due to externalized strings.
2526 Label two_byte_slice, set_slice_header;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002527 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002528 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2529 __ tst(r1, Operand(kStringEncodingMask));
2530 __ b(eq, &two_byte_slice);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002531 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002532 __ jmp(&set_slice_header);
2533 __ bind(&two_byte_slice);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002534 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002535 __ bind(&set_slice_header);
2536 __ mov(r3, Operand(r3, LSL, 1));
2537 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
2538 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
2539 __ jmp(&return_r0);
2540
2541 __ bind(&copy_routine);
2542 }
2543
2544 // r5: underlying subject string
2545 // r1: instance type of underlying subject string
2546 // r2: length
2547 // r3: adjusted start index (untagged)
2548 Label two_byte_sequential, sequential_string, allocate_result;
2549 STATIC_ASSERT(kExternalStringTag != 0);
2550 STATIC_ASSERT(kSeqStringTag == 0);
2551 __ tst(r1, Operand(kExternalStringTag));
2552 __ b(eq, &sequential_string);
2553
2554 // Handle external string.
2555 // Rule out short external strings.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002556 STATIC_ASSERT(kShortExternalStringTag != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002557 __ tst(r1, Operand(kShortExternalStringTag));
2558 __ b(ne, &runtime);
2559 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
2560 // r5 already points to the first character of underlying string.
2561 __ jmp(&allocate_result);
2562
2563 __ bind(&sequential_string);
2564 // Locate first character of underlying subject string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002565 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2566 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002567
2568 __ bind(&allocate_result);
2569 // Sequential acii string. Allocate the result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002570 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002571 __ tst(r1, Operand(kStringEncodingMask));
2572 __ b(eq, &two_byte_sequential);
2573
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002574 // Allocate and copy the resulting one-byte string.
2575 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002576
2577 // Locate first character of substring to copy.
2578 __ add(r5, r5, r3);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002579 // Locate first character of result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002580 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002581
Ben Murdoch589d6972011-11-30 16:04:58 +00002582 // r0: result string
2583 // r1: first character of result string
2584 // r2: result string length
2585 // r5: first character of substring to copy
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002586 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2587 StringHelper::GenerateCopyCharacters(
2588 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
Ben Murdoch589d6972011-11-30 16:04:58 +00002589 __ jmp(&return_r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002590
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002591 // Allocate and copy the resulting two-byte string.
2592 __ bind(&two_byte_sequential);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002593 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002594
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002595 // Locate first character of substring to copy.
Ben Murdoch589d6972011-11-30 16:04:58 +00002596 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002597 __ add(r5, r5, Operand(r3, LSL, 1));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002598 // Locate first character of result.
2599 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch589d6972011-11-30 16:04:58 +00002600
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002601 // r0: result string.
2602 // r1: first character of result.
2603 // r2: result length.
Ben Murdoch589d6972011-11-30 16:04:58 +00002604 // r5: first character of substring to copy.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002605 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002606 StringHelper::GenerateCopyCharacters(
2607 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
Ben Murdoch589d6972011-11-30 16:04:58 +00002608
2609 __ bind(&return_r0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002610 Counters* counters = isolate()->counters();
Steve Block44f0eee2011-05-26 01:26:41 +01002611 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002612 __ Drop(3);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002613 __ Ret();
2614
2615 // Just jump to runtime to create the sub string.
2616 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002617 __ TailCallRuntime(Runtime::kSubString);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002618
2619 __ bind(&single_char);
2620 // r0: original string
2621 // r1: instance type
2622 // r2: length
2623 // r3: from index (untagged)
2624 __ SmiTag(r3, r3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002625 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
2626 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002627 generator.GenerateFast(masm);
2628 __ Drop(3);
2629 __ Ret();
2630 generator.SkipSlow(masm, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002631}
2632
2633
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002634void ToNumberStub::Generate(MacroAssembler* masm) {
2635 // The ToNumber stub takes one argument in r0.
2636 Label not_smi;
2637 __ JumpIfNotSmi(r0, &not_smi);
2638 __ Ret();
2639 __ bind(&not_smi);
2640
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002641 __ CompareObjectType(r0, r1, r1, HEAP_NUMBER_TYPE);
2642 // r0: receiver
2643 // r1: receiver instance type
2644 __ Ret(eq);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002645
2646 Label not_string, slow_string;
2647 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
2648 __ b(hs, &not_string);
2649 // Check if string has a cached array index.
2650 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
2651 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
2652 __ b(ne, &slow_string);
2653 __ IndexFromHash(r2, r0);
2654 __ Ret();
2655 __ bind(&slow_string);
2656 __ push(r0); // Push argument.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002657 __ TailCallRuntime(Runtime::kStringToNumber);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002658 __ bind(&not_string);
2659
2660 Label not_oddball;
2661 __ cmp(r1, Operand(ODDBALL_TYPE));
2662 __ b(ne, &not_oddball);
2663 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
2664 __ Ret();
2665 __ bind(&not_oddball);
2666
2667 __ push(r0); // Push argument.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002668 __ TailCallRuntime(Runtime::kToNumber);
2669}
2670
2671
2672void ToLengthStub::Generate(MacroAssembler* masm) {
2673 // The ToLength stub takes one argument in r0.
2674 Label not_smi;
2675 __ JumpIfNotSmi(r0, &not_smi);
2676 STATIC_ASSERT(kSmiTag == 0);
2677 __ tst(r0, r0);
2678 __ mov(r0, Operand(0), LeaveCC, lt);
2679 __ Ret();
2680 __ bind(&not_smi);
2681
2682 __ push(r0); // Push argument.
2683 __ TailCallRuntime(Runtime::kToLength);
2684}
2685
2686
2687void ToStringStub::Generate(MacroAssembler* masm) {
2688 // The ToString stub takes one argument in r0.
2689 Label is_number;
2690 __ JumpIfSmi(r0, &is_number);
2691
2692 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE);
2693 // r0: receiver
2694 // r1: receiver instance type
2695 __ Ret(lo);
2696
2697 Label not_heap_number;
2698 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
2699 __ b(ne, &not_heap_number);
2700 __ bind(&is_number);
2701 NumberToStringStub stub(isolate());
2702 __ TailCallStub(&stub);
2703 __ bind(&not_heap_number);
2704
2705 Label not_oddball;
2706 __ cmp(r1, Operand(ODDBALL_TYPE));
2707 __ b(ne, &not_oddball);
2708 __ ldr(r0, FieldMemOperand(r0, Oddball::kToStringOffset));
2709 __ Ret();
2710 __ bind(&not_oddball);
2711
2712 __ push(r0); // Push argument.
2713 __ TailCallRuntime(Runtime::kToString);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002714}
2715
2716
Ben Murdoch097c5b22016-05-18 11:27:45 +01002717void ToNameStub::Generate(MacroAssembler* masm) {
2718 // The ToName stub takes one argument in r0.
2719 Label is_number;
2720 __ JumpIfSmi(r0, &is_number);
2721
2722 STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
2723 __ CompareObjectType(r0, r1, r1, LAST_NAME_TYPE);
2724 // r0: receiver
2725 // r1: receiver instance type
2726 __ Ret(ls);
2727
2728 Label not_heap_number;
2729 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
2730 __ b(ne, &not_heap_number);
2731 __ bind(&is_number);
2732 NumberToStringStub stub(isolate());
2733 __ TailCallStub(&stub);
2734 __ bind(&not_heap_number);
2735
2736 Label not_oddball;
2737 __ cmp(r1, Operand(ODDBALL_TYPE));
2738 __ b(ne, &not_oddball);
2739 __ ldr(r0, FieldMemOperand(r0, Oddball::kToStringOffset));
2740 __ Ret();
2741 __ bind(&not_oddball);
2742
2743 __ push(r0); // Push argument.
2744 __ TailCallRuntime(Runtime::kToName);
2745}
2746
2747
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002748void StringHelper::GenerateFlatOneByteStringEquals(
2749 MacroAssembler* masm, Register left, Register right, Register scratch1,
2750 Register scratch2, Register scratch3) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002751 Register length = scratch1;
2752
2753 // Compare lengths.
2754 Label strings_not_equal, check_zero_length;
2755 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
2756 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
2757 __ cmp(length, scratch2);
2758 __ b(eq, &check_zero_length);
2759 __ bind(&strings_not_equal);
2760 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
2761 __ Ret();
2762
2763 // Check if the length is zero.
2764 Label compare_chars;
2765 __ bind(&check_zero_length);
2766 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002767 __ cmp(length, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00002768 __ b(ne, &compare_chars);
2769 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
2770 __ Ret();
2771
2772 // Compare characters.
2773 __ bind(&compare_chars);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002774 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
2775 &strings_not_equal);
Ben Murdoch257744e2011-11-30 15:57:28 +00002776
2777 // Characters are equal.
2778 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
2779 __ Ret();
2780}
2781
2782
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002783void StringHelper::GenerateCompareFlatOneByteStrings(
2784 MacroAssembler* masm, Register left, Register right, Register scratch1,
2785 Register scratch2, Register scratch3, Register scratch4) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002786 Label result_not_equal, compare_lengths;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002787 // Find minimum length and length difference.
2788 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
2789 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
2790 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
2791 Register length_delta = scratch3;
2792 __ mov(scratch1, scratch2, LeaveCC, gt);
2793 Register min_length = scratch1;
2794 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002795 __ cmp(min_length, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002796 __ b(eq, &compare_lengths);
2797
Ben Murdoch257744e2011-11-30 15:57:28 +00002798 // Compare loop.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002799 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
2800 scratch4, &result_not_equal);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002801
Ben Murdoch257744e2011-11-30 15:57:28 +00002802 // Compare lengths - strings up to min-length are equal.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002803 __ bind(&compare_lengths);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002804 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
Ben Murdoch257744e2011-11-30 15:57:28 +00002805 // Use length_delta as result if it's zero.
2806 __ mov(r0, Operand(length_delta), SetCC);
2807 __ bind(&result_not_equal);
2808 // Conditionally update the result based either on length_delta or
2809 // the last comparion performed in the loop above.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002810 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
2811 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
2812 __ Ret();
2813}
2814
2815
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002816void StringHelper::GenerateOneByteCharsCompareLoop(
2817 MacroAssembler* masm, Register left, Register right, Register length,
2818 Register scratch1, Register scratch2, Label* chars_not_equal) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002819 // Change index to run from -length to -1 by adding length to string
2820 // start. This means that loop ends when index reaches zero, which
2821 // doesn't need an additional compare.
2822 __ SmiUntag(length);
2823 __ add(scratch1, length,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002824 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch257744e2011-11-30 15:57:28 +00002825 __ add(left, left, Operand(scratch1));
2826 __ add(right, right, Operand(scratch1));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002827 __ rsb(length, length, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00002828 Register index = length; // index = -length;
2829
2830 // Compare loop.
2831 Label loop;
2832 __ bind(&loop);
2833 __ ldrb(scratch1, MemOperand(left, index));
2834 __ ldrb(scratch2, MemOperand(right, index));
2835 __ cmp(scratch1, scratch2);
2836 __ b(ne, chars_not_equal);
2837 __ add(index, index, Operand(1), SetCC);
2838 __ b(ne, &loop);
2839}
2840
2841
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002842void StringCompareStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002843 // ----------- S t a t e -------------
2844 // -- r1 : left
2845 // -- r0 : right
2846 // -- lr : return address
2847 // -----------------------------------
2848 __ AssertString(r1);
2849 __ AssertString(r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002850
2851 Label not_same;
2852 __ cmp(r0, r1);
2853 __ b(ne, &not_same);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002854 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002855 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r1,
2856 r2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002857 __ Ret();
2858
2859 __ bind(&not_same);
2860
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002861 // Check that both objects are sequential one-byte strings.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002862 Label runtime;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002863 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002864
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002865 // Compare flat one-byte strings natively.
2866 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
2867 r3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002868 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002869
2870 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
2871 // tagged as a small integer.
2872 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002873 __ Push(r1, r0);
2874 __ TailCallRuntime(Runtime::kStringCompare);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002875}
2876
2877
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002878void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
2879 // ----------- S t a t e -------------
2880 // -- r1 : left
2881 // -- r0 : right
2882 // -- lr : return address
2883 // -----------------------------------
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002884
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002885 // Load r2 with the allocation site. We stick an undefined dummy value here
2886 // and replace it with the real allocation site later when we instantiate this
2887 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
2888 __ Move(r2, handle(isolate()->heap()->undefined_value()));
Steve Block44f0eee2011-05-26 01:26:41 +01002889
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002890 // Make sure that we actually patched the allocation site.
2891 if (FLAG_debug_code) {
2892 __ tst(r2, Operand(kSmiTagMask));
2893 __ Assert(ne, kExpectedAllocationSite);
2894 __ push(r2);
2895 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
2896 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
2897 __ cmp(r2, ip);
2898 __ pop(r2);
2899 __ Assert(eq, kExpectedAllocationSite);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002900 }
2901
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002902 // Tail call into the stub that handles binary operations with allocation
2903 // sites.
2904 BinaryOpWithAllocationSiteStub stub(isolate(), state());
2905 __ TailCallStub(&stub);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002906}
2907
2908
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002909void CompareICStub::GenerateBooleans(MacroAssembler* masm) {
2910 DCHECK_EQ(CompareICState::BOOLEAN, state());
2911 Label miss;
2912
2913 __ CheckMap(r1, r2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
2914 __ CheckMap(r0, r3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002915 if (!Token::IsEqualityOp(op())) {
2916 __ ldr(r1, FieldMemOperand(r1, Oddball::kToNumberOffset));
2917 __ AssertSmi(r1);
2918 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
2919 __ AssertSmi(r0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002920 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002921 __ sub(r0, r1, r0);
2922 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002923
2924 __ bind(&miss);
2925 GenerateMiss(masm);
2926}
2927
2928
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002929void CompareICStub::GenerateSmis(MacroAssembler* masm) {
2930 DCHECK(state() == CompareICState::SMI);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002931 Label miss;
2932 __ orr(r2, r1, r0);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002933 __ JumpIfNotSmi(r2, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002934
2935 if (GetCondition() == eq) {
2936 // For equality we do not care about the sign of the result.
2937 __ sub(r0, r0, r1, SetCC);
2938 } else {
Steve Block1e0659c2011-05-24 12:43:12 +01002939 // Untag before subtracting to avoid handling overflow.
2940 __ SmiUntag(r1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002941 __ sub(r0, r1, Operand::SmiUntag(r0));
Ben Murdochb0fe1622011-05-05 13:52:32 +01002942 }
2943 __ Ret();
2944
2945 __ bind(&miss);
2946 GenerateMiss(masm);
2947}
2948
2949
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002950void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
2951 DCHECK(state() == CompareICState::NUMBER);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002952
2953 Label generic_stub;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002954 Label unordered, maybe_undefined1, maybe_undefined2;
Ben Murdochb0fe1622011-05-05 13:52:32 +01002955 Label miss;
Ben Murdochb0fe1622011-05-05 13:52:32 +01002956
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002957 if (left() == CompareICState::SMI) {
2958 __ JumpIfNotSmi(r1, &miss);
2959 }
2960 if (right() == CompareICState::SMI) {
2961 __ JumpIfNotSmi(r0, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002962 }
2963
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002964 // Inlining the double comparison and falling back to the general compare
2965 // stub if NaN is involved.
2966 // Load left and right operand.
2967 Label done, left, left_smi, right_smi;
2968 __ JumpIfSmi(r0, &right_smi);
2969 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
2970 DONT_DO_SMI_CHECK);
2971 __ sub(r2, r0, Operand(kHeapObjectTag));
2972 __ vldr(d1, r2, HeapNumber::kValueOffset);
2973 __ b(&left);
2974 __ bind(&right_smi);
2975 __ SmiToDouble(d1, r0);
2976
2977 __ bind(&left);
2978 __ JumpIfSmi(r1, &left_smi);
2979 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
2980 DONT_DO_SMI_CHECK);
2981 __ sub(r2, r1, Operand(kHeapObjectTag));
2982 __ vldr(d0, r2, HeapNumber::kValueOffset);
2983 __ b(&done);
2984 __ bind(&left_smi);
2985 __ SmiToDouble(d0, r1);
2986
2987 __ bind(&done);
2988 // Compare operands.
2989 __ VFPCompareAndSetFlags(d0, d1);
2990
2991 // Don't base result on status bits when a NaN is involved.
2992 __ b(vs, &unordered);
2993
2994 // Return a result of -1, 0, or 1, based on status bits.
2995 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
2996 __ mov(r0, Operand(LESS), LeaveCC, lt);
2997 __ mov(r0, Operand(GREATER), LeaveCC, gt);
2998 __ Ret();
2999
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003000 __ bind(&unordered);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003001 __ bind(&generic_stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003002 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003003 CompareICState::GENERIC, CompareICState::GENERIC);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003004 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3005
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003006 __ bind(&maybe_undefined1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003007 if (Token::IsOrderedRelationalCompareOp(op())) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003008 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3009 __ b(ne, &miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003010 __ JumpIfSmi(r1, &unordered);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003011 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3012 __ b(ne, &maybe_undefined2);
3013 __ jmp(&unordered);
3014 }
3015
3016 __ bind(&maybe_undefined2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003017 if (Token::IsOrderedRelationalCompareOp(op())) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003018 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3019 __ b(eq, &unordered);
3020 }
3021
Ben Murdochb0fe1622011-05-05 13:52:32 +01003022 __ bind(&miss);
3023 GenerateMiss(masm);
3024}
3025
3026
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003027void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3028 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
Ben Murdoch257744e2011-11-30 15:57:28 +00003029 Label miss;
3030
3031 // Registers containing left and right operands respectively.
3032 Register left = r1;
3033 Register right = r0;
3034 Register tmp1 = r2;
3035 Register tmp2 = r3;
3036
3037 // Check that both operands are heap objects.
3038 __ JumpIfEitherSmi(left, right, &miss);
3039
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003040 // Check that both operands are internalized strings.
Ben Murdoch257744e2011-11-30 15:57:28 +00003041 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3042 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3043 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3044 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003045 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3046 __ orr(tmp1, tmp1, Operand(tmp2));
3047 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3048 __ b(ne, &miss);
Ben Murdoch257744e2011-11-30 15:57:28 +00003049
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003050 // Internalized strings are compared by identity.
Ben Murdoch257744e2011-11-30 15:57:28 +00003051 __ cmp(left, right);
3052 // Make sure r0 is non-zero. At this point input operands are
3053 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003054 DCHECK(right.is(r0));
Ben Murdoch257744e2011-11-30 15:57:28 +00003055 STATIC_ASSERT(EQUAL == 0);
3056 STATIC_ASSERT(kSmiTag == 0);
3057 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3058 __ Ret();
3059
3060 __ bind(&miss);
3061 GenerateMiss(masm);
3062}
3063
3064
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003065void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3066 DCHECK(state() == CompareICState::UNIQUE_NAME);
3067 DCHECK(GetCondition() == eq);
Ben Murdoch257744e2011-11-30 15:57:28 +00003068 Label miss;
3069
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003070 // Registers containing left and right operands respectively.
3071 Register left = r1;
3072 Register right = r0;
3073 Register tmp1 = r2;
3074 Register tmp2 = r3;
3075
3076 // Check that both operands are heap objects.
3077 __ JumpIfEitherSmi(left, right, &miss);
3078
3079 // Check that both operands are unique names. This leaves the instance
3080 // types loaded in tmp1 and tmp2.
3081 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3082 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3083 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3084 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3085
3086 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3087 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3088
3089 // Unique names are compared by identity.
3090 __ cmp(left, right);
3091 // Make sure r0 is non-zero. At this point input operands are
3092 // guaranteed to be non-zero.
3093 DCHECK(right.is(r0));
3094 STATIC_ASSERT(EQUAL == 0);
3095 STATIC_ASSERT(kSmiTag == 0);
3096 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3097 __ Ret();
3098
3099 __ bind(&miss);
3100 GenerateMiss(masm);
3101}
3102
3103
3104void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3105 DCHECK(state() == CompareICState::STRING);
3106 Label miss;
3107
3108 bool equality = Token::IsEqualityOp(op());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003109
Ben Murdoch257744e2011-11-30 15:57:28 +00003110 // Registers containing left and right operands respectively.
3111 Register left = r1;
3112 Register right = r0;
3113 Register tmp1 = r2;
3114 Register tmp2 = r3;
3115 Register tmp3 = r4;
3116 Register tmp4 = r5;
3117
3118 // Check that both operands are heap objects.
3119 __ JumpIfEitherSmi(left, right, &miss);
3120
3121 // Check that both operands are strings. This leaves the instance
3122 // types loaded in tmp1 and tmp2.
3123 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3124 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3125 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3126 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3127 STATIC_ASSERT(kNotStringTag != 0);
3128 __ orr(tmp3, tmp1, tmp2);
3129 __ tst(tmp3, Operand(kIsNotStringMask));
3130 __ b(ne, &miss);
3131
3132 // Fast check for identical strings.
3133 __ cmp(left, right);
3134 STATIC_ASSERT(EQUAL == 0);
3135 STATIC_ASSERT(kSmiTag == 0);
3136 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3137 __ Ret(eq);
3138
3139 // Handle not identical strings.
3140
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003141 // Check that both strings are internalized strings. If they are, we're done
3142 // because we already know they are not identical. We know they are both
3143 // strings.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003144 if (equality) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003145 DCHECK(GetCondition() == eq);
3146 STATIC_ASSERT(kInternalizedTag == 0);
3147 __ orr(tmp3, tmp1, Operand(tmp2));
3148 __ tst(tmp3, Operand(kIsNotInternalizedMask));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003149 // Make sure r0 is non-zero. At this point input operands are
3150 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003151 DCHECK(right.is(r0));
3152 __ Ret(eq);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003153 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003154
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003155 // Check that both strings are sequential one-byte.
Ben Murdoch257744e2011-11-30 15:57:28 +00003156 Label runtime;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003157 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3158 &runtime);
Ben Murdoch257744e2011-11-30 15:57:28 +00003159
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003160 // Compare flat one-byte strings. Returns when done.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003161 if (equality) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003162 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3163 tmp3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003164 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003165 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3166 tmp2, tmp3, tmp4);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003167 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003168
3169 // Handle more complex cases in runtime.
3170 __ bind(&runtime);
3171 __ Push(left, right);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003172 if (equality) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003173 __ TailCallRuntime(Runtime::kStringEquals);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003174 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003175 __ TailCallRuntime(Runtime::kStringCompare);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003176 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003177
3178 __ bind(&miss);
3179 GenerateMiss(masm);
3180}
3181
3182
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003183void CompareICStub::GenerateReceivers(MacroAssembler* masm) {
3184 DCHECK_EQ(CompareICState::RECEIVER, state());
Ben Murdochb0fe1622011-05-05 13:52:32 +01003185 Label miss;
3186 __ and_(r2, r1, Operand(r0));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003187 __ JumpIfSmi(r2, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003188
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003189 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
3190 __ CompareObjectType(r0, r2, r2, FIRST_JS_RECEIVER_TYPE);
3191 __ b(lt, &miss);
3192 __ CompareObjectType(r1, r2, r2, FIRST_JS_RECEIVER_TYPE);
3193 __ b(lt, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003194
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003195 DCHECK(GetCondition() == eq);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003196 __ sub(r0, r0, Operand(r1));
3197 __ Ret();
3198
3199 __ bind(&miss);
3200 GenerateMiss(masm);
3201}
3202
3203
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003204void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003205 Label miss;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003206 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003207 __ and_(r2, r1, Operand(r0));
3208 __ JumpIfSmi(r2, &miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003209 __ GetWeakValue(r4, cell);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003210 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3211 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003212 __ cmp(r2, r4);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003213 __ b(ne, &miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003214 __ cmp(r3, r4);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003215 __ b(ne, &miss);
Ben Murdochc7cc0282012-03-05 14:35:55 +00003216
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003217 if (Token::IsEqualityOp(op())) {
3218 __ sub(r0, r0, Operand(r1));
3219 __ Ret();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003220 } else {
3221 if (op() == Token::LT || op() == Token::LTE) {
3222 __ mov(r2, Operand(Smi::FromInt(GREATER)));
3223 } else {
3224 __ mov(r2, Operand(Smi::FromInt(LESS)));
3225 }
3226 __ Push(r1, r0, r2);
3227 __ TailCallRuntime(Runtime::kCompare);
3228 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003229
3230 __ bind(&miss);
3231 GenerateMiss(masm);
3232}
3233
3234
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003235void CompareICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003236 {
3237 // Call the runtime system in a fresh internal frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003238 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003239 __ Push(r1, r0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003240 __ Push(lr, r1, r0);
3241 __ mov(ip, Operand(Smi::FromInt(op())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003242 __ push(ip);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003243 __ CallRuntime(Runtime::kCompareIC_Miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003244 // Compute the entry point of the rewritten stub.
3245 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3246 // Restore registers.
3247 __ pop(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003248 __ Pop(r1, r0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003249 }
3250
Ben Murdochb0fe1622011-05-05 13:52:32 +01003251 __ Jump(r2);
3252}
3253
3254
Steve Block1e0659c2011-05-24 12:43:12 +01003255void DirectCEntryStub::Generate(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003256 // Place the return address on the stack, making the call
3257 // GC safe. The RegExp backend also relies on this.
3258 __ str(lr, MemOperand(sp, 0));
3259 __ blx(ip); // Call the C++ function.
3260 __ VFPEnsureFPSCRState(r2);
Steve Block1e0659c2011-05-24 12:43:12 +01003261 __ ldr(pc, MemOperand(sp, 0));
3262}
3263
3264
3265void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003266 Register target) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003267 intptr_t code =
3268 reinterpret_cast<intptr_t>(GetCode().location());
3269 __ Move(ip, target);
3270 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3271 __ blx(lr); // Call the stub.
Steve Block1e0659c2011-05-24 12:43:12 +01003272}
3273
3274
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003275void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3276 Label* miss,
3277 Label* done,
3278 Register receiver,
3279 Register properties,
3280 Handle<Name> name,
3281 Register scratch0) {
3282 DCHECK(name->IsUniqueName());
Ben Murdoch257744e2011-11-30 15:57:28 +00003283 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3284 // not equal to the name and kProbes-th slot is not used (its name is the
3285 // undefined value), it guarantees the hash table doesn't contain the
3286 // property. It's true even if some slots represent deleted properties
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003287 // (their names are the hole value).
Ben Murdoch257744e2011-11-30 15:57:28 +00003288 for (int i = 0; i < kInlinedProbes; i++) {
3289 // scratch0 points to properties hash.
3290 // Compute the masked index: (hash + i + i * i) & mask.
3291 Register index = scratch0;
3292 // Capacity is smi 2^n.
3293 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3294 __ sub(index, index, Operand(1));
3295 __ and_(index, index, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003296 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
Ben Murdoch257744e2011-11-30 15:57:28 +00003297
3298 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003299 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003300 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3301
3302 Register entity_name = scratch0;
3303 // Having undefined at this place means the name is not contained.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003304 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003305 Register tmp = properties;
3306 __ add(tmp, properties, Operand(index, LSL, 1));
3307 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3308
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003309 DCHECK(!tmp.is(entity_name));
Ben Murdoch257744e2011-11-30 15:57:28 +00003310 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3311 __ cmp(entity_name, tmp);
3312 __ b(eq, done);
3313
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003314 // Load the hole ready for use below:
3315 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003316
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003317 // Stop if found the property.
3318 __ cmp(entity_name, Operand(Handle<Name>(name)));
3319 __ b(eq, miss);
Ben Murdoch257744e2011-11-30 15:57:28 +00003320
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003321 Label good;
3322 __ cmp(entity_name, tmp);
3323 __ b(eq, &good);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003324
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003325 // Check if the entry name is not a unique name.
3326 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3327 __ ldrb(entity_name,
3328 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3329 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3330 __ bind(&good);
Ben Murdoch257744e2011-11-30 15:57:28 +00003331
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003332 // Restore the properties.
3333 __ ldr(properties,
3334 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003335 }
3336
3337 const int spill_mask =
3338 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3339 r2.bit() | r1.bit() | r0.bit());
3340
3341 __ stm(db_w, sp, spill_mask);
3342 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003343 __ mov(r1, Operand(Handle<Name>(name)));
3344 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003345 __ CallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003346 __ cmp(r0, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003347 __ ldm(ia_w, sp, spill_mask);
3348
3349 __ b(eq, done);
3350 __ b(ne, miss);
Ben Murdoch257744e2011-11-30 15:57:28 +00003351}
3352
3353
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003354// Probe the name dictionary in the |elements| register. Jump to the
Ben Murdoch257744e2011-11-30 15:57:28 +00003355// |done| label if a property with the given name is found. Jump to
3356// the |miss| label otherwise.
3357// If lookup was successful |scratch2| will be equal to elements + 4 * index.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003358void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3359 Label* miss,
3360 Label* done,
3361 Register elements,
3362 Register name,
3363 Register scratch1,
3364 Register scratch2) {
3365 DCHECK(!elements.is(scratch1));
3366 DCHECK(!elements.is(scratch2));
3367 DCHECK(!name.is(scratch1));
3368 DCHECK(!name.is(scratch2));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003369
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003370 __ AssertName(name);
Ben Murdoch257744e2011-11-30 15:57:28 +00003371
3372 // Compute the capacity mask.
3373 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003374 __ SmiUntag(scratch1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003375 __ sub(scratch1, scratch1, Operand(1));
3376
3377 // Generate an unrolled loop that performs a few probes before
3378 // giving up. Measurements done on Gmail indicate that 2 probes
3379 // cover ~93% of loads from dictionaries.
3380 for (int i = 0; i < kInlinedProbes; i++) {
3381 // Compute the masked index: (hash + i + i * i) & mask.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003382 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003383 if (i > 0) {
3384 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3385 // the hash in a separate instruction. The value hash + i + i * i is right
3386 // shifted in the following and instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003387 DCHECK(NameDictionary::GetProbeOffset(i) <
3388 1 << (32 - Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003389 __ add(scratch2, scratch2, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003390 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003391 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003392 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003393
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003394 // Scale the index by multiplying by the entry size.
3395 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003396 // scratch2 = scratch2 * 3.
3397 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3398
3399 // Check if the key is identical to the name.
3400 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3401 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3402 __ cmp(name, Operand(ip));
3403 __ b(eq, done);
3404 }
3405
3406 const int spill_mask =
3407 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3408 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3409 ~(scratch1.bit() | scratch2.bit());
3410
3411 __ stm(db_w, sp, spill_mask);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003412 if (name.is(r0)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003413 DCHECK(!elements.is(r1));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003414 __ Move(r1, name);
3415 __ Move(r0, elements);
3416 } else {
3417 __ Move(r0, elements);
3418 __ Move(r1, name);
3419 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003420 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
Ben Murdoch257744e2011-11-30 15:57:28 +00003421 __ CallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003422 __ cmp(r0, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003423 __ mov(scratch2, Operand(r2));
3424 __ ldm(ia_w, sp, spill_mask);
3425
3426 __ b(ne, done);
3427 __ b(eq, miss);
3428}
3429
3430
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003431void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003432 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3433 // we cannot call anything that could cause a GC from this stub.
Ben Murdoch257744e2011-11-30 15:57:28 +00003434 // Registers:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003435 // result: NameDictionary to probe
Ben Murdoch257744e2011-11-30 15:57:28 +00003436 // r1: key
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003437 // dictionary: NameDictionary to probe.
3438 // index: will hold an index of entry if lookup is successful.
3439 // might alias with result_.
Ben Murdoch257744e2011-11-30 15:57:28 +00003440 // Returns:
3441 // result_ is zero if lookup failed, non zero otherwise.
3442
3443 Register result = r0;
3444 Register dictionary = r0;
3445 Register key = r1;
3446 Register index = r2;
3447 Register mask = r3;
3448 Register hash = r4;
3449 Register undefined = r5;
3450 Register entry_key = r6;
3451
3452 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3453
3454 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003455 __ SmiUntag(mask);
Ben Murdoch257744e2011-11-30 15:57:28 +00003456 __ sub(mask, mask, Operand(1));
3457
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003458 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003459
3460 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3461
3462 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3463 // Compute the masked index: (hash + i + i * i) & mask.
3464 // Capacity is smi 2^n.
3465 if (i > 0) {
3466 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3467 // the hash in a separate instruction. The value hash + i + i * i is right
3468 // shifted in the following and instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003469 DCHECK(NameDictionary::GetProbeOffset(i) <
3470 1 << (32 - Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003471 __ add(index, hash, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003472 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003473 } else {
3474 __ mov(index, Operand(hash));
3475 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003476 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003477
3478 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003479 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003480 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3481
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003482 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003483 __ add(index, dictionary, Operand(index, LSL, 2));
3484 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
3485
3486 // Having undefined at this place means the name is not contained.
3487 __ cmp(entry_key, Operand(undefined));
3488 __ b(eq, &not_in_dictionary);
3489
3490 // Stop if found the property.
3491 __ cmp(entry_key, Operand(key));
3492 __ b(eq, &in_dictionary);
3493
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003494 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3495 // Check if the entry name is not a unique name.
Ben Murdoch257744e2011-11-30 15:57:28 +00003496 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3497 __ ldrb(entry_key,
3498 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003499 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
Ben Murdoch257744e2011-11-30 15:57:28 +00003500 }
3501 }
3502
3503 __ bind(&maybe_in_dictionary);
3504 // If we are doing negative lookup then probing failure should be
3505 // treated as a lookup success. For positive lookup probing failure
3506 // should be treated as lookup failure.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003507 if (mode() == POSITIVE_LOOKUP) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003508 __ mov(result, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003509 __ Ret();
3510 }
3511
3512 __ bind(&in_dictionary);
3513 __ mov(result, Operand(1));
3514 __ Ret();
3515
3516 __ bind(&not_in_dictionary);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003517 __ mov(result, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003518 __ Ret();
3519}
3520
3521
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003522void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3523 Isolate* isolate) {
3524 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3525 stub1.GetCode();
3526 // Hydrogen code stubs need stub2 at snapshot time.
3527 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3528 stub2.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003529}
3530
3531
3532// Takes the input in 3 registers: address_ value_ and object_. A pointer to
3533// the value has just been written into the object, now this stub makes sure
3534// we keep the GC informed. The word in the object where the value has been
3535// written is in the address register.
3536void RecordWriteStub::Generate(MacroAssembler* masm) {
3537 Label skip_to_incremental_noncompacting;
3538 Label skip_to_incremental_compacting;
3539
3540 // The first two instructions are generated with labels so as to get the
3541 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3542 // forth between a compare instructions (a nop in this position) and the
3543 // real branch when we start and stop incremental heap marking.
3544 // See RecordWriteStub::Patch for details.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003545 {
3546 // Block literal pool emission, as the position of these two instructions
3547 // is assumed by the patching code.
3548 Assembler::BlockConstPoolScope block_const_pool(masm);
3549 __ b(&skip_to_incremental_noncompacting);
3550 __ b(&skip_to_incremental_compacting);
3551 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003552
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003553 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3554 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003555 MacroAssembler::kReturnAtEnd);
3556 }
3557 __ Ret();
3558
3559 __ bind(&skip_to_incremental_noncompacting);
3560 GenerateIncremental(masm, INCREMENTAL);
3561
3562 __ bind(&skip_to_incremental_compacting);
3563 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3564
3565 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3566 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003567 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
3568 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003569 PatchBranchIntoNop(masm, 0);
3570 PatchBranchIntoNop(masm, Assembler::kInstrSize);
3571}
3572
3573
3574void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3575 regs_.Save(masm);
3576
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003577 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003578 Label dont_need_remembered_set;
3579
3580 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
3581 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
3582 regs_.scratch0(),
3583 &dont_need_remembered_set);
3584
Ben Murdoch097c5b22016-05-18 11:27:45 +01003585 __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(),
3586 &dont_need_remembered_set);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003587
3588 // First notify the incremental marker if necessary, then update the
3589 // remembered set.
3590 CheckNeedsToInformIncrementalMarker(
3591 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003592 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003593 regs_.Restore(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003594 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003595 MacroAssembler::kReturnAtEnd);
3596
3597 __ bind(&dont_need_remembered_set);
3598 }
3599
3600 CheckNeedsToInformIncrementalMarker(
3601 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003602 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003603 regs_.Restore(masm);
3604 __ Ret();
3605}
3606
3607
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003608void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3609 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003610 int argument_count = 3;
3611 __ PrepareCallCFunction(argument_count, regs_.scratch0());
3612 Register address =
3613 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003614 DCHECK(!address.is(regs_.object()));
3615 DCHECK(!address.is(r0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003616 __ Move(address, regs_.address());
3617 __ Move(r0, regs_.object());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003618 __ Move(r1, address);
3619 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003620
3621 AllowExternalCallThatCantCauseGC scope(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003622 __ CallCFunction(
3623 ExternalReference::incremental_marking_record_write_function(isolate()),
3624 argument_count);
3625 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003626}
3627
3628
3629void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
3630 MacroAssembler* masm,
3631 OnNoNeedToInformIncrementalMarker on_no_need,
3632 Mode mode) {
3633 Label on_black;
3634 Label need_incremental;
3635 Label need_incremental_pop_scratch;
3636
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003637 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
3638 __ ldr(regs_.scratch1(),
3639 MemOperand(regs_.scratch0(),
3640 MemoryChunk::kWriteBarrierCounterOffset));
3641 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
3642 __ str(regs_.scratch1(),
3643 MemOperand(regs_.scratch0(),
3644 MemoryChunk::kWriteBarrierCounterOffset));
3645 __ b(mi, &need_incremental);
3646
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003647 // Let's look at the color of the object: If it is not black we don't have
3648 // to inform the incremental marker.
3649 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
3650
3651 regs_.Restore(masm);
3652 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003653 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003654 MacroAssembler::kReturnAtEnd);
3655 } else {
3656 __ Ret();
3657 }
3658
3659 __ bind(&on_black);
3660
3661 // Get the value from the slot.
3662 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
3663
3664 if (mode == INCREMENTAL_COMPACTION) {
3665 Label ensure_not_white;
3666
3667 __ CheckPageFlag(regs_.scratch0(), // Contains value.
3668 regs_.scratch1(), // Scratch.
3669 MemoryChunk::kEvacuationCandidateMask,
3670 eq,
3671 &ensure_not_white);
3672
3673 __ CheckPageFlag(regs_.object(),
3674 regs_.scratch1(), // Scratch.
3675 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
3676 eq,
3677 &need_incremental);
3678
3679 __ bind(&ensure_not_white);
3680 }
3681
3682 // We need extra registers for this, so we push the object and the address
3683 // register temporarily.
3684 __ Push(regs_.object(), regs_.address());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003685 __ JumpIfWhite(regs_.scratch0(), // The value.
3686 regs_.scratch1(), // Scratch.
3687 regs_.object(), // Scratch.
3688 regs_.address(), // Scratch.
3689 &need_incremental_pop_scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003690 __ Pop(regs_.object(), regs_.address());
3691
3692 regs_.Restore(masm);
3693 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003694 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003695 MacroAssembler::kReturnAtEnd);
3696 } else {
3697 __ Ret();
3698 }
3699
3700 __ bind(&need_incremental_pop_scratch);
3701 __ Pop(regs_.object(), regs_.address());
3702
3703 __ bind(&need_incremental);
3704
3705 // Fall through when we need to inform the incremental marker.
3706}
3707
3708
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003709void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
3710 CEntryStub ces(isolate(), 1, kSaveFPRegs);
3711 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
3712 int parameter_count_offset =
3713 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
3714 __ ldr(r1, MemOperand(fp, parameter_count_offset));
3715 if (function_mode() == JS_FUNCTION_STUB_MODE) {
3716 __ add(r1, r1, Operand(1));
3717 }
3718 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
3719 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
3720 __ add(sp, sp, r1);
3721 __ Ret();
3722}
3723
3724
3725void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003726 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3727 LoadICStub stub(isolate(), state());
3728 stub.GenerateForTrampoline(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003729}
3730
3731
3732void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003733 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3734 KeyedLoadICStub stub(isolate(), state());
3735 stub.GenerateForTrampoline(masm);
3736}
3737
3738
3739void CallICTrampolineStub::Generate(MacroAssembler* masm) {
3740 __ EmitLoadTypeFeedbackVector(r2);
3741 CallICStub stub(isolate(), state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003742 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3743}
3744
3745
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003746void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
3747
3748
3749void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3750 GenerateImpl(masm, true);
3751}
3752
3753
3754static void HandleArrayCases(MacroAssembler* masm, Register feedback,
3755 Register receiver_map, Register scratch1,
3756 Register scratch2, bool is_polymorphic,
3757 Label* miss) {
3758 // feedback initially contains the feedback array
3759 Label next_loop, prepare_next;
3760 Label start_polymorphic;
3761
3762 Register cached_map = scratch1;
3763
3764 __ ldr(cached_map,
3765 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
3766 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3767 __ cmp(receiver_map, cached_map);
3768 __ b(ne, &start_polymorphic);
3769 // found, now call handler.
3770 Register handler = feedback;
3771 __ ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
3772 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3773
3774
3775 Register length = scratch2;
3776 __ bind(&start_polymorphic);
3777 __ ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
3778 if (!is_polymorphic) {
3779 // If the IC could be monomorphic we have to make sure we don't go past the
3780 // end of the feedback array.
3781 __ cmp(length, Operand(Smi::FromInt(2)));
3782 __ b(eq, miss);
3783 }
3784
3785 Register too_far = length;
3786 Register pointer_reg = feedback;
3787
3788 // +-----+------+------+-----+-----+ ... ----+
3789 // | map | len | wm0 | h0 | wm1 | hN |
3790 // +-----+------+------+-----+-----+ ... ----+
3791 // 0 1 2 len-1
3792 // ^ ^
3793 // | |
3794 // pointer_reg too_far
3795 // aka feedback scratch2
3796 // also need receiver_map
3797 // use cached_map (scratch1) to look in the weak map values.
3798 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(length));
3799 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3800 __ add(pointer_reg, feedback,
3801 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
3802
3803 __ bind(&next_loop);
3804 __ ldr(cached_map, MemOperand(pointer_reg));
3805 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3806 __ cmp(receiver_map, cached_map);
3807 __ b(ne, &prepare_next);
3808 __ ldr(handler, MemOperand(pointer_reg, kPointerSize));
3809 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3810
3811 __ bind(&prepare_next);
3812 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
3813 __ cmp(pointer_reg, too_far);
3814 __ b(lt, &next_loop);
3815
3816 // We exhausted our array of map handler pairs.
3817 __ jmp(miss);
3818}
3819
3820
3821static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
3822 Register receiver_map, Register feedback,
3823 Register vector, Register slot,
3824 Register scratch, Label* compare_map,
3825 Label* load_smi_map, Label* try_array) {
3826 __ JumpIfSmi(receiver, load_smi_map);
3827 __ ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
3828 __ bind(compare_map);
3829 Register cached_map = scratch;
3830 // Move the weak map into the weak_cell register.
3831 __ ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
3832 __ cmp(cached_map, receiver_map);
3833 __ b(ne, try_array);
3834 Register handler = feedback;
3835 __ add(handler, vector, Operand::PointerOffsetFromSmiKey(slot));
3836 __ ldr(handler,
3837 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
3838 __ add(pc, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3839}
3840
3841
3842void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3843 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
3844 Register name = LoadWithVectorDescriptor::NameRegister(); // r2
3845 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
3846 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
3847 Register feedback = r4;
3848 Register receiver_map = r5;
3849 Register scratch1 = r6;
3850
3851 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
3852 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3853
3854 // Try to quickly handle the monomorphic case without knowing for sure
3855 // if we have a weak cell in feedback. We do know it's safe to look
3856 // at WeakCell::kValueOffset.
3857 Label try_array, load_smi_map, compare_map;
3858 Label not_array, miss;
3859 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3860 scratch1, &compare_map, &load_smi_map, &try_array);
3861
3862 // Is it a fixed array?
3863 __ bind(&try_array);
3864 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3865 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
3866 __ b(ne, &not_array);
3867 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
3868
3869 __ bind(&not_array);
3870 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
3871 __ b(ne, &miss);
3872 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
3873 Code::ComputeHandlerFlags(Code::LOAD_IC));
3874 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
3875 receiver, name, feedback,
3876 receiver_map, scratch1, r9);
3877
3878 __ bind(&miss);
3879 LoadIC::GenerateMiss(masm);
3880
3881 __ bind(&load_smi_map);
3882 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3883 __ jmp(&compare_map);
3884}
3885
3886
3887void KeyedLoadICStub::Generate(MacroAssembler* masm) {
3888 GenerateImpl(masm, false);
3889}
3890
3891
3892void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3893 GenerateImpl(masm, true);
3894}
3895
3896
3897void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3898 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // r1
3899 Register key = LoadWithVectorDescriptor::NameRegister(); // r2
3900 Register vector = LoadWithVectorDescriptor::VectorRegister(); // r3
3901 Register slot = LoadWithVectorDescriptor::SlotRegister(); // r0
3902 Register feedback = r4;
3903 Register receiver_map = r5;
3904 Register scratch1 = r6;
3905
3906 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
3907 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3908
3909 // Try to quickly handle the monomorphic case without knowing for sure
3910 // if we have a weak cell in feedback. We do know it's safe to look
3911 // at WeakCell::kValueOffset.
3912 Label try_array, load_smi_map, compare_map;
3913 Label not_array, miss;
3914 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3915 scratch1, &compare_map, &load_smi_map, &try_array);
3916
3917 __ bind(&try_array);
3918 // Is it a fixed array?
3919 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3920 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
3921 __ b(ne, &not_array);
3922
3923 // We have a polymorphic element handler.
3924 Label polymorphic, try_poly_name;
3925 __ bind(&polymorphic);
3926 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, true, &miss);
3927
3928 __ bind(&not_array);
3929 // Is it generic?
3930 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
3931 __ b(ne, &try_poly_name);
3932 Handle<Code> megamorphic_stub =
3933 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
3934 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
3935
3936 __ bind(&try_poly_name);
3937 // We might have a name in feedback, and a fixed array in the next slot.
3938 __ cmp(key, feedback);
3939 __ b(ne, &miss);
3940 // If the name comparison succeeded, we know we have a fixed array with
3941 // at least one map/handler pair.
3942 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
3943 __ ldr(feedback,
3944 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
3945 HandleArrayCases(masm, feedback, receiver_map, scratch1, r9, false, &miss);
3946
3947 __ bind(&miss);
3948 KeyedLoadIC::GenerateMiss(masm);
3949
3950 __ bind(&load_smi_map);
3951 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3952 __ jmp(&compare_map);
3953}
3954
3955
3956void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3957 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3958 VectorStoreICStub stub(isolate(), state());
3959 stub.GenerateForTrampoline(masm);
3960}
3961
3962
3963void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3964 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3965 VectorKeyedStoreICStub stub(isolate(), state());
3966 stub.GenerateForTrampoline(masm);
3967}
3968
3969
3970void VectorStoreICStub::Generate(MacroAssembler* masm) {
3971 GenerateImpl(masm, false);
3972}
3973
3974
3975void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
3976 GenerateImpl(masm, true);
3977}
3978
3979
3980void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3981 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
3982 Register key = VectorStoreICDescriptor::NameRegister(); // r2
3983 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
3984 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
3985 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
3986 Register feedback = r5;
3987 Register receiver_map = r6;
3988 Register scratch1 = r9;
3989
3990 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
3991 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3992
3993 // Try to quickly handle the monomorphic case without knowing for sure
3994 // if we have a weak cell in feedback. We do know it's safe to look
3995 // at WeakCell::kValueOffset.
3996 Label try_array, load_smi_map, compare_map;
3997 Label not_array, miss;
3998 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3999 scratch1, &compare_map, &load_smi_map, &try_array);
4000
4001 // Is it a fixed array?
4002 __ bind(&try_array);
4003 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4004 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4005 __ b(ne, &not_array);
4006
4007 // We are using register r8, which is used for the embedded constant pool
4008 // when FLAG_enable_embedded_constant_pool is true.
4009 DCHECK(!FLAG_enable_embedded_constant_pool);
4010 Register scratch2 = r8;
4011 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4012 &miss);
4013
4014 __ bind(&not_array);
4015 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4016 __ b(ne, &miss);
4017 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4018 Code::ComputeHandlerFlags(Code::STORE_IC));
4019 masm->isolate()->stub_cache()->GenerateProbe(
4020 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4021 scratch1, scratch2);
4022
4023 __ bind(&miss);
4024 StoreIC::GenerateMiss(masm);
4025
4026 __ bind(&load_smi_map);
4027 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4028 __ jmp(&compare_map);
4029}
4030
4031
4032void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4033 GenerateImpl(masm, false);
4034}
4035
4036
4037void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4038 GenerateImpl(masm, true);
4039}
4040
4041
4042static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4043 Register receiver_map, Register scratch1,
4044 Register scratch2, Label* miss) {
4045 // feedback initially contains the feedback array
4046 Label next_loop, prepare_next;
4047 Label start_polymorphic;
4048 Label transition_call;
4049
4050 Register cached_map = scratch1;
4051 Register too_far = scratch2;
4052 Register pointer_reg = feedback;
4053 __ ldr(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4054
4055 // +-----+------+------+-----+-----+-----+ ... ----+
4056 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4057 // +-----+------+------+-----+-----+ ----+ ... ----+
4058 // 0 1 2 len-1
4059 // ^ ^
4060 // | |
4061 // pointer_reg too_far
4062 // aka feedback scratch2
4063 // also need receiver_map
4064 // use cached_map (scratch1) to look in the weak map values.
4065 __ add(too_far, feedback, Operand::PointerOffsetFromSmiKey(too_far));
4066 __ add(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4067 __ add(pointer_reg, feedback,
4068 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4069
4070 __ bind(&next_loop);
4071 __ ldr(cached_map, MemOperand(pointer_reg));
4072 __ ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4073 __ cmp(receiver_map, cached_map);
4074 __ b(ne, &prepare_next);
4075 // Is it a transitioning store?
4076 __ ldr(too_far, MemOperand(pointer_reg, kPointerSize));
4077 __ CompareRoot(too_far, Heap::kUndefinedValueRootIndex);
4078 __ b(ne, &transition_call);
4079 __ ldr(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4080 __ add(pc, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4081
4082 __ bind(&transition_call);
4083 __ ldr(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4084 __ JumpIfSmi(too_far, miss);
4085
4086 __ ldr(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4087
4088 // Load the map into the correct register.
4089 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4090 __ mov(feedback, too_far);
4091
4092 __ add(pc, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4093
4094 __ bind(&prepare_next);
4095 __ add(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4096 __ cmp(pointer_reg, too_far);
4097 __ b(lt, &next_loop);
4098
4099 // We exhausted our array of map handler pairs.
4100 __ jmp(miss);
4101}
4102
4103
4104void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4105 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // r1
4106 Register key = VectorStoreICDescriptor::NameRegister(); // r2
4107 Register vector = VectorStoreICDescriptor::VectorRegister(); // r3
4108 Register slot = VectorStoreICDescriptor::SlotRegister(); // r4
4109 DCHECK(VectorStoreICDescriptor::ValueRegister().is(r0)); // r0
4110 Register feedback = r5;
4111 Register receiver_map = r6;
4112 Register scratch1 = r9;
4113
4114 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4115 __ ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4116
4117 // Try to quickly handle the monomorphic case without knowing for sure
4118 // if we have a weak cell in feedback. We do know it's safe to look
4119 // at WeakCell::kValueOffset.
4120 Label try_array, load_smi_map, compare_map;
4121 Label not_array, miss;
4122 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4123 scratch1, &compare_map, &load_smi_map, &try_array);
4124
4125 __ bind(&try_array);
4126 // Is it a fixed array?
4127 __ ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4128 __ CompareRoot(scratch1, Heap::kFixedArrayMapRootIndex);
4129 __ b(ne, &not_array);
4130
4131 // We have a polymorphic element handler.
4132 Label polymorphic, try_poly_name;
4133 __ bind(&polymorphic);
4134
4135 // We are using register r8, which is used for the embedded constant pool
4136 // when FLAG_enable_embedded_constant_pool is true.
4137 DCHECK(!FLAG_enable_embedded_constant_pool);
4138 Register scratch2 = r8;
4139
4140 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4141 &miss);
4142
4143 __ bind(&not_array);
4144 // Is it generic?
4145 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4146 __ b(ne, &try_poly_name);
4147 Handle<Code> megamorphic_stub =
4148 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4149 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4150
4151 __ bind(&try_poly_name);
4152 // We might have a name in feedback, and a fixed array in the next slot.
4153 __ cmp(key, feedback);
4154 __ b(ne, &miss);
4155 // If the name comparison succeeded, we know we have a fixed array with
4156 // at least one map/handler pair.
4157 __ add(feedback, vector, Operand::PointerOffsetFromSmiKey(slot));
4158 __ ldr(feedback,
4159 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4160 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4161 &miss);
4162
4163 __ bind(&miss);
4164 KeyedStoreIC::GenerateMiss(masm);
4165
4166 __ bind(&load_smi_map);
4167 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4168 __ jmp(&compare_map);
4169}
4170
4171
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004172void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4173 if (masm->isolate()->function_entry_hook() != NULL) {
4174 ProfileEntryHookStub stub(masm->isolate());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004175 PredictableCodeSizeScope predictable(masm);
4176 predictable.ExpectSize(masm->CallStubSize(&stub) +
4177 2 * Assembler::kInstrSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004178 __ push(lr);
4179 __ CallStub(&stub);
4180 __ pop(lr);
4181 }
4182}
4183
4184
4185void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4186 // The entry hook is a "push lr" instruction, followed by a call.
4187 const int32_t kReturnAddressDistanceFromFunctionStart =
4188 3 * Assembler::kInstrSize;
4189
4190 // This should contain all kCallerSaved registers.
4191 const RegList kSavedRegs =
4192 1 << 0 | // r0
4193 1 << 1 | // r1
4194 1 << 2 | // r2
4195 1 << 3 | // r3
4196 1 << 5 | // r5
4197 1 << 9; // r9
4198 // We also save lr, so the count here is one higher than the mask indicates.
4199 const int32_t kNumSavedRegs = 7;
4200
4201 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4202
4203 // Save all caller-save registers as this may be called from anywhere.
4204 __ stm(db_w, sp, kSavedRegs | lr.bit());
4205
4206 // Compute the function's address for the first argument.
4207 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4208
4209 // The caller's return address is above the saved temporaries.
4210 // Grab that for the second argument to the hook.
4211 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4212
4213 // Align the stack if necessary.
4214 int frame_alignment = masm->ActivationFrameAlignment();
4215 if (frame_alignment > kPointerSize) {
4216 __ mov(r5, sp);
4217 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4218 __ and_(sp, sp, Operand(-frame_alignment));
4219 }
4220
4221#if V8_HOST_ARCH_ARM
4222 int32_t entry_hook =
4223 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4224 __ mov(ip, Operand(entry_hook));
4225#else
4226 // Under the simulator we need to indirect the entry hook through a
4227 // trampoline function at a known address.
4228 // It additionally takes an isolate as a third parameter
4229 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4230
4231 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4232 __ mov(ip, Operand(ExternalReference(&dispatcher,
4233 ExternalReference::BUILTIN_CALL,
4234 isolate())));
4235#endif
4236 __ Call(ip);
4237
4238 // Restore the stack pointer if needed.
4239 if (frame_alignment > kPointerSize) {
4240 __ mov(sp, r5);
4241 }
4242
4243 // Also pop pc to get Ret(0).
4244 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4245}
4246
4247
4248template<class T>
4249static void CreateArrayDispatch(MacroAssembler* masm,
4250 AllocationSiteOverrideMode mode) {
4251 if (mode == DISABLE_ALLOCATION_SITES) {
4252 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4253 __ TailCallStub(&stub);
4254 } else if (mode == DONT_OVERRIDE) {
4255 int last_index = GetSequenceIndexFromFastElementsKind(
4256 TERMINAL_FAST_ELEMENTS_KIND);
4257 for (int i = 0; i <= last_index; ++i) {
4258 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4259 __ cmp(r3, Operand(kind));
4260 T stub(masm->isolate(), kind);
4261 __ TailCallStub(&stub, eq);
4262 }
4263
4264 // If we reached this point there is a problem.
4265 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4266 } else {
4267 UNREACHABLE();
4268 }
4269}
4270
4271
4272static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4273 AllocationSiteOverrideMode mode) {
4274 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4275 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4276 // r0 - number of arguments
4277 // r1 - constructor?
4278 // sp[0] - last argument
4279 Label normal_sequence;
4280 if (mode == DONT_OVERRIDE) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004281 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4282 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4283 STATIC_ASSERT(FAST_ELEMENTS == 2);
4284 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4285 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4286 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004287
4288 // is the low bit set? If so, we are holey and that is good.
4289 __ tst(r3, Operand(1));
4290 __ b(ne, &normal_sequence);
4291 }
4292
4293 // look at the first argument
4294 __ ldr(r5, MemOperand(sp, 0));
4295 __ cmp(r5, Operand::Zero());
4296 __ b(eq, &normal_sequence);
4297
4298 if (mode == DISABLE_ALLOCATION_SITES) {
4299 ElementsKind initial = GetInitialFastElementsKind();
4300 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4301
4302 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4303 holey_initial,
4304 DISABLE_ALLOCATION_SITES);
4305 __ TailCallStub(&stub_holey);
4306
4307 __ bind(&normal_sequence);
4308 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4309 initial,
4310 DISABLE_ALLOCATION_SITES);
4311 __ TailCallStub(&stub);
4312 } else if (mode == DONT_OVERRIDE) {
4313 // We are going to create a holey array, but our kind is non-holey.
4314 // Fix kind and retry (only if we have an allocation site in the slot).
4315 __ add(r3, r3, Operand(1));
4316
4317 if (FLAG_debug_code) {
4318 __ ldr(r5, FieldMemOperand(r2, 0));
4319 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4320 __ Assert(eq, kExpectedAllocationSite);
4321 }
4322
4323 // Save the resulting elements kind in type info. We can't just store r3
4324 // in the AllocationSite::transition_info field because elements kind is
4325 // restricted to a portion of the field...upper bits need to be left alone.
4326 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4327 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4328 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4329 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4330
4331 __ bind(&normal_sequence);
4332 int last_index = GetSequenceIndexFromFastElementsKind(
4333 TERMINAL_FAST_ELEMENTS_KIND);
4334 for (int i = 0; i <= last_index; ++i) {
4335 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4336 __ cmp(r3, Operand(kind));
4337 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4338 __ TailCallStub(&stub, eq);
4339 }
4340
4341 // If we reached this point there is a problem.
4342 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4343 } else {
4344 UNREACHABLE();
4345 }
4346}
4347
4348
4349template<class T>
4350static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4351 int to_index = GetSequenceIndexFromFastElementsKind(
4352 TERMINAL_FAST_ELEMENTS_KIND);
4353 for (int i = 0; i <= to_index; ++i) {
4354 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4355 T stub(isolate, kind);
4356 stub.GetCode();
4357 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4358 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4359 stub1.GetCode();
4360 }
4361 }
4362}
4363
4364
4365void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4366 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4367 isolate);
4368 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4369 isolate);
4370 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4371 isolate);
4372}
4373
4374
4375void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4376 Isolate* isolate) {
4377 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4378 for (int i = 0; i < 2; i++) {
4379 // For internal arrays we only need a few things
4380 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4381 stubh1.GetCode();
4382 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4383 stubh2.GetCode();
4384 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4385 stubh3.GetCode();
4386 }
4387}
4388
4389
4390void ArrayConstructorStub::GenerateDispatchToArrayStub(
4391 MacroAssembler* masm,
4392 AllocationSiteOverrideMode mode) {
4393 if (argument_count() == ANY) {
4394 Label not_zero_case, not_one_case;
4395 __ tst(r0, r0);
4396 __ b(ne, &not_zero_case);
4397 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4398
4399 __ bind(&not_zero_case);
4400 __ cmp(r0, Operand(1));
4401 __ b(gt, &not_one_case);
4402 CreateArrayDispatchOneArgument(masm, mode);
4403
4404 __ bind(&not_one_case);
4405 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4406 } else if (argument_count() == NONE) {
4407 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4408 } else if (argument_count() == ONE) {
4409 CreateArrayDispatchOneArgument(masm, mode);
4410 } else if (argument_count() == MORE_THAN_ONE) {
4411 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4412 } else {
4413 UNREACHABLE();
4414 }
4415}
4416
4417
4418void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4419 // ----------- S t a t e -------------
4420 // -- r0 : argc (only if argument_count() == ANY)
4421 // -- r1 : constructor
4422 // -- r2 : AllocationSite or undefined
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004423 // -- r3 : new target
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004424 // -- sp[0] : return address
4425 // -- sp[4] : last argument
4426 // -----------------------------------
4427
4428 if (FLAG_debug_code) {
4429 // The array construct code is only set for the global and natives
4430 // builtin Array functions which always have maps.
4431
4432 // Initial map for the builtin Array function should be a map.
4433 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4434 // Will both indicate a NULL and a Smi.
4435 __ tst(r4, Operand(kSmiTagMask));
4436 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4437 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4438 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4439
4440 // We should either have undefined in r2 or a valid AllocationSite
4441 __ AssertUndefinedOrAllocationSite(r2, r4);
4442 }
4443
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004444 // Enter the context of the Array function.
4445 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
4446
4447 Label subclassing;
4448 __ cmp(r3, r1);
4449 __ b(ne, &subclassing);
4450
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004451 Label no_info;
4452 // Get the elements kind and case on that.
4453 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4454 __ b(eq, &no_info);
4455
4456 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4457 __ SmiUntag(r3);
4458 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4459 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4460 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4461
4462 __ bind(&no_info);
4463 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004464
4465 __ bind(&subclassing);
4466 switch (argument_count()) {
4467 case ANY:
4468 case MORE_THAN_ONE:
4469 __ str(r1, MemOperand(sp, r0, LSL, kPointerSizeLog2));
4470 __ add(r0, r0, Operand(3));
4471 break;
4472 case NONE:
4473 __ str(r1, MemOperand(sp, 0 * kPointerSize));
4474 __ mov(r0, Operand(3));
4475 break;
4476 case ONE:
4477 __ str(r1, MemOperand(sp, 1 * kPointerSize));
4478 __ mov(r0, Operand(4));
4479 break;
4480 }
4481 __ Push(r3, r2);
4482 __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004483}
4484
4485
4486void InternalArrayConstructorStub::GenerateCase(
4487 MacroAssembler* masm, ElementsKind kind) {
4488 __ cmp(r0, Operand(1));
4489
4490 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4491 __ TailCallStub(&stub0, lo);
4492
4493 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4494 __ TailCallStub(&stubN, hi);
4495
4496 if (IsFastPackedElementsKind(kind)) {
4497 // We might need to create a holey array
4498 // look at the first argument
4499 __ ldr(r3, MemOperand(sp, 0));
4500 __ cmp(r3, Operand::Zero());
4501
4502 InternalArraySingleArgumentConstructorStub
4503 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4504 __ TailCallStub(&stub1_holey, ne);
4505 }
4506
4507 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4508 __ TailCallStub(&stub1);
4509}
4510
4511
4512void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4513 // ----------- S t a t e -------------
4514 // -- r0 : argc
4515 // -- r1 : constructor
4516 // -- sp[0] : return address
4517 // -- sp[4] : last argument
4518 // -----------------------------------
4519
4520 if (FLAG_debug_code) {
4521 // The array construct code is only set for the global and natives
4522 // builtin Array functions which always have maps.
4523
4524 // Initial map for the builtin Array function should be a map.
4525 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4526 // Will both indicate a NULL and a Smi.
4527 __ tst(r3, Operand(kSmiTagMask));
4528 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4529 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
4530 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4531 }
4532
4533 // Figure out the right elements kind
4534 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4535 // Load the map's "bit field 2" into |result|. We only need the first byte,
4536 // but the following bit field extraction takes care of that anyway.
4537 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
4538 // Retrieve elements_kind from bit field 2.
4539 __ DecodeField<Map::ElementsKindBits>(r3);
4540
4541 if (FLAG_debug_code) {
4542 Label done;
4543 __ cmp(r3, Operand(FAST_ELEMENTS));
4544 __ b(eq, &done);
4545 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
4546 __ Assert(eq,
4547 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
4548 __ bind(&done);
4549 }
4550
4551 Label fast_elements_case;
4552 __ cmp(r3, Operand(FAST_ELEMENTS));
4553 __ b(eq, &fast_elements_case);
4554 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4555
4556 __ bind(&fast_elements_case);
4557 GenerateCase(masm, FAST_ELEMENTS);
4558}
4559
4560
Ben Murdoch097c5b22016-05-18 11:27:45 +01004561void FastNewObjectStub::Generate(MacroAssembler* masm) {
4562 // ----------- S t a t e -------------
4563 // -- r1 : target
4564 // -- r3 : new target
4565 // -- cp : context
4566 // -- lr : return address
4567 // -----------------------------------
4568 __ AssertFunction(r1);
4569 __ AssertReceiver(r3);
4570
4571 // Verify that the new target is a JSFunction.
4572 Label new_object;
4573 __ CompareObjectType(r3, r2, r2, JS_FUNCTION_TYPE);
4574 __ b(ne, &new_object);
4575
4576 // Load the initial map and verify that it's in fact a map.
4577 __ ldr(r2, FieldMemOperand(r3, JSFunction::kPrototypeOrInitialMapOffset));
4578 __ JumpIfSmi(r2, &new_object);
4579 __ CompareObjectType(r2, r0, r0, MAP_TYPE);
4580 __ b(ne, &new_object);
4581
4582 // Fall back to runtime if the target differs from the new target's
4583 // initial map constructor.
4584 __ ldr(r0, FieldMemOperand(r2, Map::kConstructorOrBackPointerOffset));
4585 __ cmp(r0, r1);
4586 __ b(ne, &new_object);
4587
4588 // Allocate the JSObject on the heap.
4589 Label allocate, done_allocate;
4590 __ ldrb(r4, FieldMemOperand(r2, Map::kInstanceSizeOffset));
4591 __ Allocate(r4, r0, r5, r6, &allocate, SIZE_IN_WORDS);
4592 __ bind(&done_allocate);
4593
4594 // Initialize the JSObject fields.
4595 __ str(r2, MemOperand(r0, JSObject::kMapOffset));
4596 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
4597 __ str(r3, MemOperand(r0, JSObject::kPropertiesOffset));
4598 __ str(r3, MemOperand(r0, JSObject::kElementsOffset));
4599 STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize);
4600 __ add(r1, r0, Operand(JSObject::kHeaderSize));
4601
4602 // ----------- S t a t e -------------
4603 // -- r0 : result (untagged)
4604 // -- r1 : result fields (untagged)
4605 // -- r5 : result end (untagged)
4606 // -- r2 : initial map
4607 // -- cp : context
4608 // -- lr : return address
4609 // -----------------------------------
4610
4611 // Perform in-object slack tracking if requested.
4612 Label slack_tracking;
4613 STATIC_ASSERT(Map::kNoSlackTracking == 0);
4614 __ LoadRoot(r6, Heap::kUndefinedValueRootIndex);
4615 __ ldr(r3, FieldMemOperand(r2, Map::kBitField3Offset));
4616 __ tst(r3, Operand(Map::ConstructionCounter::kMask));
4617 __ b(ne, &slack_tracking);
4618 {
4619 // Initialize all in-object fields with undefined.
4620 __ InitializeFieldsWithFiller(r1, r5, r6);
4621
4622 // Add the object tag to make the JSObject real.
4623 STATIC_ASSERT(kHeapObjectTag == 1);
4624 __ add(r0, r0, Operand(kHeapObjectTag));
4625 __ Ret();
4626 }
4627 __ bind(&slack_tracking);
4628 {
4629 // Decrease generous allocation count.
4630 STATIC_ASSERT(Map::ConstructionCounter::kNext == 32);
4631 __ sub(r3, r3, Operand(1 << Map::ConstructionCounter::kShift));
4632 __ str(r3, FieldMemOperand(r2, Map::kBitField3Offset));
4633
4634 // Initialize the in-object fields with undefined.
4635 __ ldrb(r4, FieldMemOperand(r2, Map::kUnusedPropertyFieldsOffset));
4636 __ sub(r4, r5, Operand(r4, LSL, kPointerSizeLog2));
4637 __ InitializeFieldsWithFiller(r1, r4, r6);
4638
4639 // Initialize the remaining (reserved) fields with one pointer filler map.
4640 __ LoadRoot(r6, Heap::kOnePointerFillerMapRootIndex);
4641 __ InitializeFieldsWithFiller(r1, r5, r6);
4642
4643 // Add the object tag to make the JSObject real.
4644 STATIC_ASSERT(kHeapObjectTag == 1);
4645 __ add(r0, r0, Operand(kHeapObjectTag));
4646
4647 // Check if we can finalize the instance size.
4648 STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1);
4649 __ tst(r3, Operand(Map::ConstructionCounter::kMask));
4650 __ Ret(ne);
4651
4652 // Finalize the instance size.
4653 {
4654 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4655 __ Push(r0, r2);
4656 __ CallRuntime(Runtime::kFinalizeInstanceSize);
4657 __ Pop(r0);
4658 }
4659 __ Ret();
4660 }
4661
4662 // Fall back to %AllocateInNewSpace.
4663 __ bind(&allocate);
4664 {
4665 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4666 STATIC_ASSERT(kSmiTag == 0);
4667 STATIC_ASSERT(kSmiTagSize == 1);
4668 __ mov(r4, Operand(r4, LSL, kPointerSizeLog2 + 1));
4669 __ Push(r2, r4);
4670 __ CallRuntime(Runtime::kAllocateInNewSpace);
4671 __ Pop(r2);
4672 }
4673 STATIC_ASSERT(kHeapObjectTag == 1);
4674 __ sub(r0, r0, Operand(kHeapObjectTag));
4675 __ ldrb(r5, FieldMemOperand(r2, Map::kInstanceSizeOffset));
4676 __ add(r5, r0, Operand(r5, LSL, kPointerSizeLog2));
4677 __ b(&done_allocate);
4678
4679 // Fall back to %NewObject.
4680 __ bind(&new_object);
4681 __ Push(r1, r3);
4682 __ TailCallRuntime(Runtime::kNewObject);
4683}
4684
4685
4686void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
4687 // ----------- S t a t e -------------
4688 // -- r1 : function
4689 // -- cp : context
4690 // -- fp : frame pointer
4691 // -- lr : return address
4692 // -----------------------------------
4693 __ AssertFunction(r1);
4694
4695 // For Ignition we need to skip all possible handler/stub frames until
4696 // we reach the JavaScript frame for the function (similar to what the
4697 // runtime fallback implementation does). So make r2 point to that
4698 // JavaScript frame.
4699 {
4700 Label loop, loop_entry;
4701 __ mov(r2, fp);
4702 __ b(&loop_entry);
4703 __ bind(&loop);
4704 __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset));
4705 __ bind(&loop_entry);
4706 __ ldr(ip, MemOperand(r2, StandardFrameConstants::kMarkerOffset));
4707 __ cmp(ip, r1);
4708 __ b(ne, &loop);
4709 }
4710
4711 // Check if we have rest parameters (only possible if we have an
4712 // arguments adaptor frame below the function frame).
4713 Label no_rest_parameters;
4714 __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset));
4715 __ ldr(ip, MemOperand(r2, StandardFrameConstants::kContextOffset));
4716 __ cmp(ip, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4717 __ b(ne, &no_rest_parameters);
4718
4719 // Check if the arguments adaptor frame contains more arguments than
4720 // specified by the function's internal formal parameter count.
4721 Label rest_parameters;
4722 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
4723 __ ldr(r1, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
4724 __ ldr(r1,
4725 FieldMemOperand(r1, SharedFunctionInfo::kFormalParameterCountOffset));
4726 __ sub(r0, r0, r1, SetCC);
4727 __ b(gt, &rest_parameters);
4728
4729 // Return an empty rest parameter array.
4730 __ bind(&no_rest_parameters);
4731 {
4732 // ----------- S t a t e -------------
4733 // -- cp : context
4734 // -- lr : return address
4735 // -----------------------------------
4736
4737 // Allocate an empty rest parameter array.
4738 Label allocate, done_allocate;
4739 __ Allocate(JSArray::kSize, r0, r1, r2, &allocate, TAG_OBJECT);
4740 __ bind(&done_allocate);
4741
4742 // Setup the rest parameter array in r0.
4743 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, r1);
4744 __ str(r1, FieldMemOperand(r0, JSArray::kMapOffset));
4745 __ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex);
4746 __ str(r1, FieldMemOperand(r0, JSArray::kPropertiesOffset));
4747 __ str(r1, FieldMemOperand(r0, JSArray::kElementsOffset));
4748 __ mov(r1, Operand(0));
4749 __ str(r1, FieldMemOperand(r0, JSArray::kLengthOffset));
4750 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4751 __ Ret();
4752
4753 // Fall back to %AllocateInNewSpace.
4754 __ bind(&allocate);
4755 {
4756 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4757 __ Push(Smi::FromInt(JSArray::kSize));
4758 __ CallRuntime(Runtime::kAllocateInNewSpace);
4759 }
4760 __ jmp(&done_allocate);
4761 }
4762
4763 __ bind(&rest_parameters);
4764 {
4765 // Compute the pointer to the first rest parameter (skippping the receiver).
4766 __ add(r2, r2, Operand(r0, LSL, kPointerSizeLog2 - 1));
4767 __ add(r2, r2,
4768 Operand(StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize));
4769
4770 // ----------- S t a t e -------------
4771 // -- cp : context
4772 // -- r0 : number of rest parameters (tagged)
4773 // -- r2 : pointer to first rest parameters
4774 // -- lr : return address
4775 // -----------------------------------
4776
4777 // Allocate space for the rest parameter array plus the backing store.
4778 Label allocate, done_allocate;
4779 __ mov(r1, Operand(JSArray::kSize + FixedArray::kHeaderSize));
4780 __ add(r1, r1, Operand(r0, LSL, kPointerSizeLog2 - 1));
4781 __ Allocate(r1, r3, r4, r5, &allocate, TAG_OBJECT);
4782 __ bind(&done_allocate);
4783
4784 // Setup the elements array in r3.
4785 __ LoadRoot(r1, Heap::kFixedArrayMapRootIndex);
4786 __ str(r1, FieldMemOperand(r3, FixedArray::kMapOffset));
4787 __ str(r0, FieldMemOperand(r3, FixedArray::kLengthOffset));
4788 __ add(r4, r3, Operand(FixedArray::kHeaderSize));
4789 {
4790 Label loop, done_loop;
4791 __ add(r1, r4, Operand(r0, LSL, kPointerSizeLog2 - 1));
4792 __ bind(&loop);
4793 __ cmp(r4, r1);
4794 __ b(eq, &done_loop);
4795 __ ldr(ip, MemOperand(r2, 1 * kPointerSize, NegPostIndex));
4796 __ str(ip, FieldMemOperand(r4, 0 * kPointerSize));
4797 __ add(r4, r4, Operand(1 * kPointerSize));
4798 __ b(&loop);
4799 __ bind(&done_loop);
4800 }
4801
4802 // Setup the rest parameter array in r4.
4803 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, r1);
4804 __ str(r1, FieldMemOperand(r4, JSArray::kMapOffset));
4805 __ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex);
4806 __ str(r1, FieldMemOperand(r4, JSArray::kPropertiesOffset));
4807 __ str(r3, FieldMemOperand(r4, JSArray::kElementsOffset));
4808 __ str(r0, FieldMemOperand(r4, JSArray::kLengthOffset));
4809 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4810 __ mov(r0, r4);
4811 __ Ret();
4812
4813 // Fall back to %AllocateInNewSpace.
4814 __ bind(&allocate);
4815 {
4816 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
4817 __ SmiTag(r1);
4818 __ Push(r0, r2, r1);
4819 __ CallRuntime(Runtime::kAllocateInNewSpace);
4820 __ mov(r3, r0);
4821 __ Pop(r0, r2);
4822 }
4823 __ jmp(&done_allocate);
4824 }
4825}
4826
4827
4828void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) {
4829 // ----------- S t a t e -------------
4830 // -- r1 : function
4831 // -- cp : context
4832 // -- fp : frame pointer
4833 // -- lr : return address
4834 // -----------------------------------
4835 __ AssertFunction(r1);
4836
4837 // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub.
4838 __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
4839 __ ldr(r2,
4840 FieldMemOperand(r2, SharedFunctionInfo::kFormalParameterCountOffset));
4841 __ add(r3, fp, Operand(r2, LSL, kPointerSizeLog2 - 1));
4842 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
4843
4844 // r1 : function
4845 // r2 : number of parameters (tagged)
4846 // r3 : parameters pointer
4847 // Registers used over whole function:
4848 // r5 : arguments count (tagged)
4849 // r6 : mapped parameter count (tagged)
4850
4851 // Check if the calling frame is an arguments adaptor frame.
4852 Label adaptor_frame, try_allocate, runtime;
4853 __ ldr(r4, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
4854 __ ldr(r0, MemOperand(r4, StandardFrameConstants::kContextOffset));
4855 __ cmp(r0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4856 __ b(eq, &adaptor_frame);
4857
4858 // No adaptor, parameter count = argument count.
4859 __ mov(r5, r2);
4860 __ mov(r6, r2);
4861 __ b(&try_allocate);
4862
4863 // We have an adaptor frame. Patch the parameters pointer.
4864 __ bind(&adaptor_frame);
4865 __ ldr(r5, MemOperand(r4, ArgumentsAdaptorFrameConstants::kLengthOffset));
4866 __ add(r4, r4, Operand(r5, LSL, 1));
4867 __ add(r3, r4, Operand(StandardFrameConstants::kCallerSPOffset));
4868
4869 // r5 = argument count (tagged)
4870 // r6 = parameter count (tagged)
4871 // Compute the mapped parameter count = min(r6, r5) in r6.
4872 __ mov(r6, r2);
4873 __ cmp(r6, Operand(r5));
4874 __ mov(r6, Operand(r5), LeaveCC, gt);
4875
4876 __ bind(&try_allocate);
4877
4878 // Compute the sizes of backing store, parameter map, and arguments object.
4879 // 1. Parameter map, has 2 extra words containing context and backing store.
4880 const int kParameterMapHeaderSize =
4881 FixedArray::kHeaderSize + 2 * kPointerSize;
4882 // If there are no mapped parameters, we do not need the parameter_map.
4883 __ cmp(r6, Operand(Smi::FromInt(0)));
4884 __ mov(r9, Operand::Zero(), LeaveCC, eq);
4885 __ mov(r9, Operand(r6, LSL, 1), LeaveCC, ne);
4886 __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
4887
4888 // 2. Backing store.
4889 __ add(r9, r9, Operand(r5, LSL, 1));
4890 __ add(r9, r9, Operand(FixedArray::kHeaderSize));
4891
4892 // 3. Arguments object.
4893 __ add(r9, r9, Operand(JSSloppyArgumentsObject::kSize));
4894
4895 // Do the allocation of all three objects in one go.
4896 __ Allocate(r9, r0, r9, r4, &runtime, TAG_OBJECT);
4897
4898 // r0 = address of new object(s) (tagged)
4899 // r2 = argument count (smi-tagged)
4900 // Get the arguments boilerplate from the current native context into r4.
4901 const int kNormalOffset =
4902 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
4903 const int kAliasedOffset =
4904 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
4905
4906 __ ldr(r4, NativeContextMemOperand());
4907 __ cmp(r6, Operand::Zero());
4908 __ ldr(r4, MemOperand(r4, kNormalOffset), eq);
4909 __ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
4910
4911 // r0 = address of new object (tagged)
4912 // r2 = argument count (smi-tagged)
4913 // r4 = address of arguments map (tagged)
4914 // r6 = mapped parameter count (tagged)
4915 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
4916 __ LoadRoot(r9, Heap::kEmptyFixedArrayRootIndex);
4917 __ str(r9, FieldMemOperand(r0, JSObject::kPropertiesOffset));
4918 __ str(r9, FieldMemOperand(r0, JSObject::kElementsOffset));
4919
4920 // Set up the callee in-object property.
4921 __ AssertNotSmi(r1);
4922 __ str(r1, FieldMemOperand(r0, JSSloppyArgumentsObject::kCalleeOffset));
4923
4924 // Use the length (smi tagged) and set that as an in-object property too.
4925 __ AssertSmi(r5);
4926 __ str(r5, FieldMemOperand(r0, JSSloppyArgumentsObject::kLengthOffset));
4927
4928 // Set up the elements pointer in the allocated arguments object.
4929 // If we allocated a parameter map, r4 will point there, otherwise
4930 // it will point to the backing store.
4931 __ add(r4, r0, Operand(JSSloppyArgumentsObject::kSize));
4932 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
4933
4934 // r0 = address of new object (tagged)
4935 // r2 = argument count (tagged)
4936 // r4 = address of parameter map or backing store (tagged)
4937 // r6 = mapped parameter count (tagged)
4938 // Initialize parameter map. If there are no mapped arguments, we're done.
4939 Label skip_parameter_map;
4940 __ cmp(r6, Operand(Smi::FromInt(0)));
4941 // Move backing store address to r1, because it is
4942 // expected there when filling in the unmapped arguments.
4943 __ mov(r1, r4, LeaveCC, eq);
4944 __ b(eq, &skip_parameter_map);
4945
4946 __ LoadRoot(r5, Heap::kSloppyArgumentsElementsMapRootIndex);
4947 __ str(r5, FieldMemOperand(r4, FixedArray::kMapOffset));
4948 __ add(r5, r6, Operand(Smi::FromInt(2)));
4949 __ str(r5, FieldMemOperand(r4, FixedArray::kLengthOffset));
4950 __ str(cp, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
4951 __ add(r5, r4, Operand(r6, LSL, 1));
4952 __ add(r5, r5, Operand(kParameterMapHeaderSize));
4953 __ str(r5, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
4954
4955 // Copy the parameter slots and the holes in the arguments.
4956 // We need to fill in mapped_parameter_count slots. They index the context,
4957 // where parameters are stored in reverse order, at
4958 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
4959 // The mapped parameter thus need to get indices
4960 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
4961 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
4962 // We loop from right to left.
4963 Label parameters_loop, parameters_test;
4964 __ mov(r5, r6);
4965 __ add(r9, r2, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
4966 __ sub(r9, r9, Operand(r6));
4967 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
4968 __ add(r1, r4, Operand(r5, LSL, 1));
4969 __ add(r1, r1, Operand(kParameterMapHeaderSize));
4970
4971 // r1 = address of backing store (tagged)
4972 // r4 = address of parameter map (tagged), which is also the address of new
4973 // object + Heap::kSloppyArgumentsObjectSize (tagged)
4974 // r0 = temporary scratch (a.o., for address calculation)
4975 // r5 = loop variable (tagged)
4976 // ip = the hole value
4977 __ jmp(&parameters_test);
4978
4979 __ bind(&parameters_loop);
4980 __ sub(r5, r5, Operand(Smi::FromInt(1)));
4981 __ mov(r0, Operand(r5, LSL, 1));
4982 __ add(r0, r0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
4983 __ str(r9, MemOperand(r4, r0));
4984 __ sub(r0, r0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
4985 __ str(ip, MemOperand(r1, r0));
4986 __ add(r9, r9, Operand(Smi::FromInt(1)));
4987 __ bind(&parameters_test);
4988 __ cmp(r5, Operand(Smi::FromInt(0)));
4989 __ b(ne, &parameters_loop);
4990
4991 // Restore r0 = new object (tagged) and r5 = argument count (tagged).
4992 __ sub(r0, r4, Operand(JSSloppyArgumentsObject::kSize));
4993 __ ldr(r5, FieldMemOperand(r0, JSSloppyArgumentsObject::kLengthOffset));
4994
4995 __ bind(&skip_parameter_map);
4996 // r0 = address of new object (tagged)
4997 // r1 = address of backing store (tagged)
4998 // r5 = argument count (tagged)
4999 // r6 = mapped parameter count (tagged)
5000 // r9 = scratch
5001 // Copy arguments header and remaining slots (if there are any).
5002 __ LoadRoot(r9, Heap::kFixedArrayMapRootIndex);
5003 __ str(r9, FieldMemOperand(r1, FixedArray::kMapOffset));
5004 __ str(r5, FieldMemOperand(r1, FixedArray::kLengthOffset));
5005
5006 Label arguments_loop, arguments_test;
5007 __ sub(r3, r3, Operand(r6, LSL, 1));
5008 __ jmp(&arguments_test);
5009
5010 __ bind(&arguments_loop);
5011 __ sub(r3, r3, Operand(kPointerSize));
5012 __ ldr(r4, MemOperand(r3, 0));
5013 __ add(r9, r1, Operand(r6, LSL, 1));
5014 __ str(r4, FieldMemOperand(r9, FixedArray::kHeaderSize));
5015 __ add(r6, r6, Operand(Smi::FromInt(1)));
5016
5017 __ bind(&arguments_test);
5018 __ cmp(r6, Operand(r5));
5019 __ b(lt, &arguments_loop);
5020
5021 // Return.
5022 __ Ret();
5023
5024 // Do the runtime call to allocate the arguments object.
5025 // r0 = address of new object (tagged)
5026 // r5 = argument count (tagged)
5027 __ bind(&runtime);
5028 __ Push(r1, r3, r5);
5029 __ TailCallRuntime(Runtime::kNewSloppyArguments);
5030}
5031
5032
5033void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) {
5034 // ----------- S t a t e -------------
5035 // -- r1 : function
5036 // -- cp : context
5037 // -- fp : frame pointer
5038 // -- lr : return address
5039 // -----------------------------------
5040 __ AssertFunction(r1);
5041
5042 // For Ignition we need to skip all possible handler/stub frames until
5043 // we reach the JavaScript frame for the function (similar to what the
5044 // runtime fallback implementation does). So make r2 point to that
5045 // JavaScript frame.
5046 {
5047 Label loop, loop_entry;
5048 __ mov(r2, fp);
5049 __ b(&loop_entry);
5050 __ bind(&loop);
5051 __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset));
5052 __ bind(&loop_entry);
5053 __ ldr(ip, MemOperand(r2, StandardFrameConstants::kMarkerOffset));
5054 __ cmp(ip, r1);
5055 __ b(ne, &loop);
5056 }
5057
5058 // Check if we have an arguments adaptor frame below the function frame.
5059 Label arguments_adaptor, arguments_done;
5060 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kCallerFPOffset));
5061 __ ldr(ip, MemOperand(r3, StandardFrameConstants::kContextOffset));
5062 __ cmp(ip, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5063 __ b(eq, &arguments_adaptor);
5064 {
5065 __ ldr(r1, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
5066 __ ldr(r0, FieldMemOperand(
5067 r1, SharedFunctionInfo::kFormalParameterCountOffset));
5068 __ add(r2, r2, Operand(r0, LSL, kPointerSizeLog2 - 1));
5069 __ add(r2, r2,
5070 Operand(StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize));
5071 }
5072 __ b(&arguments_done);
5073 __ bind(&arguments_adaptor);
5074 {
5075 __ ldr(r0, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
5076 __ add(r2, r3, Operand(r0, LSL, kPointerSizeLog2 - 1));
5077 __ add(r2, r2,
5078 Operand(StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize));
5079 }
5080 __ bind(&arguments_done);
5081
5082 // ----------- S t a t e -------------
5083 // -- cp : context
5084 // -- r0 : number of rest parameters (tagged)
5085 // -- r2 : pointer to first rest parameters
5086 // -- lr : return address
5087 // -----------------------------------
5088
5089 // Allocate space for the strict arguments object plus the backing store.
5090 Label allocate, done_allocate;
5091 __ mov(r1, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize));
5092 __ add(r1, r1, Operand(r0, LSL, kPointerSizeLog2 - 1));
5093 __ Allocate(r1, r3, r4, r5, &allocate, TAG_OBJECT);
5094 __ bind(&done_allocate);
5095
5096 // Setup the elements array in r3.
5097 __ LoadRoot(r1, Heap::kFixedArrayMapRootIndex);
5098 __ str(r1, FieldMemOperand(r3, FixedArray::kMapOffset));
5099 __ str(r0, FieldMemOperand(r3, FixedArray::kLengthOffset));
5100 __ add(r4, r3, Operand(FixedArray::kHeaderSize));
5101 {
5102 Label loop, done_loop;
5103 __ add(r1, r4, Operand(r0, LSL, kPointerSizeLog2 - 1));
5104 __ bind(&loop);
5105 __ cmp(r4, r1);
5106 __ b(eq, &done_loop);
5107 __ ldr(ip, MemOperand(r2, 1 * kPointerSize, NegPostIndex));
5108 __ str(ip, FieldMemOperand(r4, 0 * kPointerSize));
5109 __ add(r4, r4, Operand(1 * kPointerSize));
5110 __ b(&loop);
5111 __ bind(&done_loop);
5112 }
5113
5114 // Setup the strict arguments object in r4.
5115 __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, r1);
5116 __ str(r1, FieldMemOperand(r4, JSStrictArgumentsObject::kMapOffset));
5117 __ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex);
5118 __ str(r1, FieldMemOperand(r4, JSStrictArgumentsObject::kPropertiesOffset));
5119 __ str(r3, FieldMemOperand(r4, JSStrictArgumentsObject::kElementsOffset));
5120 __ str(r0, FieldMemOperand(r4, JSStrictArgumentsObject::kLengthOffset));
5121 STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize);
5122 __ mov(r0, r4);
5123 __ Ret();
5124
5125 // Fall back to %AllocateInNewSpace.
5126 __ bind(&allocate);
5127 {
5128 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
5129 __ SmiTag(r1);
5130 __ Push(r0, r2, r1);
5131 __ CallRuntime(Runtime::kAllocateInNewSpace);
5132 __ mov(r3, r0);
5133 __ Pop(r0, r2);
5134 }
5135 __ b(&done_allocate);
5136}
5137
5138
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005139void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5140 Register context = cp;
5141 Register result = r0;
5142 Register slot = r2;
5143
5144 // Go up the context chain to the script context.
5145 for (int i = 0; i < depth(); ++i) {
5146 __ ldr(result, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5147 context = result;
5148 }
5149
5150 // Load the PropertyCell value at the specified slot.
5151 __ add(result, context, Operand(slot, LSL, kPointerSizeLog2));
5152 __ ldr(result, ContextMemOperand(result));
5153 __ ldr(result, FieldMemOperand(result, PropertyCell::kValueOffset));
5154
5155 // If the result is not the_hole, return. Otherwise, handle in the runtime.
5156 __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
5157 __ Ret(ne);
5158
5159 // Fallback to runtime.
5160 __ SmiTag(slot);
5161 __ push(slot);
5162 __ TailCallRuntime(Runtime::kLoadGlobalViaContext);
5163}
5164
5165
5166void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5167 Register value = r0;
5168 Register slot = r2;
5169
5170 Register cell = r1;
5171 Register cell_details = r4;
5172 Register cell_value = r5;
5173 Register cell_value_map = r6;
5174 Register scratch = r9;
5175
5176 Register context = cp;
5177 Register context_temp = cell;
5178
5179 Label fast_heapobject_case, fast_smi_case, slow_case;
5180
5181 if (FLAG_debug_code) {
5182 __ CompareRoot(value, Heap::kTheHoleValueRootIndex);
5183 __ Check(ne, kUnexpectedValue);
5184 }
5185
5186 // Go up the context chain to the script context.
5187 for (int i = 0; i < depth(); i++) {
5188 __ ldr(context_temp, ContextMemOperand(context, Context::PREVIOUS_INDEX));
5189 context = context_temp;
5190 }
5191
5192 // Load the PropertyCell at the specified slot.
5193 __ add(cell, context, Operand(slot, LSL, kPointerSizeLog2));
5194 __ ldr(cell, ContextMemOperand(cell));
5195
5196 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5197 __ ldr(cell_details, FieldMemOperand(cell, PropertyCell::kDetailsOffset));
5198 __ SmiUntag(cell_details);
5199 __ and_(cell_details, cell_details,
5200 Operand(PropertyDetails::PropertyCellTypeField::kMask |
5201 PropertyDetails::KindField::kMask |
5202 PropertyDetails::kAttributesReadOnlyMask));
5203
5204 // Check if PropertyCell holds mutable data.
5205 Label not_mutable_data;
5206 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5207 PropertyCellType::kMutable) |
5208 PropertyDetails::KindField::encode(kData)));
5209 __ b(ne, &not_mutable_data);
5210 __ JumpIfSmi(value, &fast_smi_case);
5211
5212 __ bind(&fast_heapobject_case);
5213 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5214 // RecordWriteField clobbers the value register, so we copy it before the
5215 // call.
5216 __ mov(r4, Operand(value));
5217 __ RecordWriteField(cell, PropertyCell::kValueOffset, r4, scratch,
5218 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
5219 OMIT_SMI_CHECK);
5220 __ Ret();
5221
5222 __ bind(&not_mutable_data);
5223 // Check if PropertyCell value matches the new value (relevant for Constant,
5224 // ConstantType and Undefined cells).
5225 Label not_same_value;
5226 __ ldr(cell_value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5227 __ cmp(cell_value, value);
5228 __ b(ne, &not_same_value);
5229
5230 // Make sure the PropertyCell is not marked READ_ONLY.
5231 __ tst(cell_details, Operand(PropertyDetails::kAttributesReadOnlyMask));
5232 __ b(ne, &slow_case);
5233
5234 if (FLAG_debug_code) {
5235 Label done;
5236 // This can only be true for Constant, ConstantType and Undefined cells,
5237 // because we never store the_hole via this stub.
5238 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5239 PropertyCellType::kConstant) |
5240 PropertyDetails::KindField::encode(kData)));
5241 __ b(eq, &done);
5242 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5243 PropertyCellType::kConstantType) |
5244 PropertyDetails::KindField::encode(kData)));
5245 __ b(eq, &done);
5246 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5247 PropertyCellType::kUndefined) |
5248 PropertyDetails::KindField::encode(kData)));
5249 __ Check(eq, kUnexpectedValue);
5250 __ bind(&done);
5251 }
5252 __ Ret();
5253 __ bind(&not_same_value);
5254
5255 // Check if PropertyCell contains data with constant type (and is not
5256 // READ_ONLY).
5257 __ cmp(cell_details, Operand(PropertyDetails::PropertyCellTypeField::encode(
5258 PropertyCellType::kConstantType) |
5259 PropertyDetails::KindField::encode(kData)));
5260 __ b(ne, &slow_case);
5261
5262 // Now either both old and new values must be smis or both must be heap
5263 // objects with same map.
5264 Label value_is_heap_object;
5265 __ JumpIfNotSmi(value, &value_is_heap_object);
5266 __ JumpIfNotSmi(cell_value, &slow_case);
5267 // Old and new values are smis, no need for a write barrier here.
5268 __ bind(&fast_smi_case);
5269 __ str(value, FieldMemOperand(cell, PropertyCell::kValueOffset));
5270 __ Ret();
5271
5272 __ bind(&value_is_heap_object);
5273 __ JumpIfSmi(cell_value, &slow_case);
5274
5275 __ ldr(cell_value_map, FieldMemOperand(cell_value, HeapObject::kMapOffset));
5276 __ ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5277 __ cmp(cell_value_map, scratch);
5278 __ b(eq, &fast_heapobject_case);
5279
5280 // Fallback to runtime.
5281 __ bind(&slow_case);
5282 __ SmiTag(slot);
5283 __ Push(slot, value);
5284 __ TailCallRuntime(is_strict(language_mode())
5285 ? Runtime::kStoreGlobalViaContext_Strict
5286 : Runtime::kStoreGlobalViaContext_Sloppy);
5287}
5288
5289
5290static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5291 return ref0.address() - ref1.address();
5292}
5293
5294
5295// Calls an API function. Allocates HandleScope, extracts returned value
5296// from handle and propagates exceptions. Restores context. stack_space
5297// - space to be unwound on exit (includes the call JS arguments space and
5298// the additional space allocated for the fast call).
5299static void CallApiFunctionAndReturn(MacroAssembler* masm,
5300 Register function_address,
5301 ExternalReference thunk_ref,
5302 int stack_space,
5303 MemOperand* stack_space_operand,
5304 MemOperand return_value_operand,
5305 MemOperand* context_restore_operand) {
5306 Isolate* isolate = masm->isolate();
5307 ExternalReference next_address =
5308 ExternalReference::handle_scope_next_address(isolate);
5309 const int kNextOffset = 0;
5310 const int kLimitOffset = AddressOffset(
5311 ExternalReference::handle_scope_limit_address(isolate), next_address);
5312 const int kLevelOffset = AddressOffset(
5313 ExternalReference::handle_scope_level_address(isolate), next_address);
5314
5315 DCHECK(function_address.is(r1) || function_address.is(r2));
5316
5317 Label profiler_disabled;
5318 Label end_profiler_check;
5319 __ mov(r9, Operand(ExternalReference::is_profiling_address(isolate)));
5320 __ ldrb(r9, MemOperand(r9, 0));
5321 __ cmp(r9, Operand(0));
5322 __ b(eq, &profiler_disabled);
5323
5324 // Additional parameter is the address of the actual callback.
5325 __ mov(r3, Operand(thunk_ref));
5326 __ jmp(&end_profiler_check);
5327
5328 __ bind(&profiler_disabled);
5329 __ Move(r3, function_address);
5330 __ bind(&end_profiler_check);
5331
5332 // Allocate HandleScope in callee-save registers.
5333 __ mov(r9, Operand(next_address));
5334 __ ldr(r4, MemOperand(r9, kNextOffset));
5335 __ ldr(r5, MemOperand(r9, kLimitOffset));
5336 __ ldr(r6, MemOperand(r9, kLevelOffset));
5337 __ add(r6, r6, Operand(1));
5338 __ str(r6, MemOperand(r9, kLevelOffset));
5339
5340 if (FLAG_log_timer_events) {
5341 FrameScope frame(masm, StackFrame::MANUAL);
5342 __ PushSafepointRegisters();
5343 __ PrepareCallCFunction(1, r0);
5344 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5345 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5346 1);
5347 __ PopSafepointRegisters();
5348 }
5349
5350 // Native call returns to the DirectCEntry stub which redirects to the
5351 // return address pushed on stack (could have moved after GC).
5352 // DirectCEntry stub itself is generated early and never moves.
5353 DirectCEntryStub stub(isolate);
5354 stub.GenerateCall(masm, r3);
5355
5356 if (FLAG_log_timer_events) {
5357 FrameScope frame(masm, StackFrame::MANUAL);
5358 __ PushSafepointRegisters();
5359 __ PrepareCallCFunction(1, r0);
5360 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5361 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5362 1);
5363 __ PopSafepointRegisters();
5364 }
5365
5366 Label promote_scheduled_exception;
5367 Label delete_allocated_handles;
5368 Label leave_exit_frame;
5369 Label return_value_loaded;
5370
5371 // load value from ReturnValue
5372 __ ldr(r0, return_value_operand);
5373 __ bind(&return_value_loaded);
5374 // No more valid handles (the result handle was the last one). Restore
5375 // previous handle scope.
5376 __ str(r4, MemOperand(r9, kNextOffset));
5377 if (__ emit_debug_code()) {
5378 __ ldr(r1, MemOperand(r9, kLevelOffset));
5379 __ cmp(r1, r6);
5380 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5381 }
5382 __ sub(r6, r6, Operand(1));
5383 __ str(r6, MemOperand(r9, kLevelOffset));
5384 __ ldr(ip, MemOperand(r9, kLimitOffset));
5385 __ cmp(r5, ip);
5386 __ b(ne, &delete_allocated_handles);
5387
5388 // Leave the API exit frame.
5389 __ bind(&leave_exit_frame);
5390 bool restore_context = context_restore_operand != NULL;
5391 if (restore_context) {
5392 __ ldr(cp, *context_restore_operand);
5393 }
5394 // LeaveExitFrame expects unwind space to be in a register.
5395 if (stack_space_operand != NULL) {
5396 __ ldr(r4, *stack_space_operand);
5397 } else {
5398 __ mov(r4, Operand(stack_space));
5399 }
5400 __ LeaveExitFrame(false, r4, !restore_context, stack_space_operand != NULL);
5401
5402 // Check if the function scheduled an exception.
5403 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5404 __ mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate)));
5405 __ ldr(r5, MemOperand(ip));
5406 __ cmp(r4, r5);
5407 __ b(ne, &promote_scheduled_exception);
5408
5409 __ mov(pc, lr);
5410
5411 // Re-throw by promoting a scheduled exception.
5412 __ bind(&promote_scheduled_exception);
5413 __ TailCallRuntime(Runtime::kPromoteScheduledException);
5414
5415 // HandleScope limit has changed. Delete allocated extensions.
5416 __ bind(&delete_allocated_handles);
5417 __ str(r5, MemOperand(r9, kLimitOffset));
5418 __ mov(r4, r0);
5419 __ PrepareCallCFunction(1, r5);
5420 __ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
5421 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5422 1);
5423 __ mov(r0, r4);
5424 __ jmp(&leave_exit_frame);
5425}
5426
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005427static void CallApiFunctionStubHelper(MacroAssembler* masm,
5428 const ParameterCount& argc,
5429 bool return_first_arg,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005430 bool call_data_undefined, bool is_lazy) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005431 // ----------- S t a t e -------------
5432 // -- r0 : callee
5433 // -- r4 : call_data
5434 // -- r2 : holder
5435 // -- r1 : api_function_address
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005436 // -- r3 : number of arguments if argc is a register
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005437 // -- cp : context
5438 // --
5439 // -- sp[0] : last argument
5440 // -- ...
5441 // -- sp[(argc - 1)* 4] : first argument
5442 // -- sp[argc * 4] : receiver
5443 // -----------------------------------
5444
5445 Register callee = r0;
5446 Register call_data = r4;
5447 Register holder = r2;
5448 Register api_function_address = r1;
5449 Register context = cp;
5450
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005451 typedef FunctionCallbackArguments FCA;
5452
5453 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5454 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5455 STATIC_ASSERT(FCA::kDataIndex == 4);
5456 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5457 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5458 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5459 STATIC_ASSERT(FCA::kHolderIndex == 0);
5460 STATIC_ASSERT(FCA::kArgsLength == 7);
5461
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005462 DCHECK(argc.is_immediate() || r3.is(argc.reg()));
5463
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005464 // context save
5465 __ push(context);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005466 if (!is_lazy) {
5467 // load context from callee
5468 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5469 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005470
5471 // callee
5472 __ push(callee);
5473
5474 // call data
5475 __ push(call_data);
5476
5477 Register scratch = call_data;
5478 if (!call_data_undefined) {
5479 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5480 }
5481 // return value
5482 __ push(scratch);
5483 // return value default
5484 __ push(scratch);
5485 // isolate
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005486 __ mov(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005487 __ push(scratch);
5488 // holder
5489 __ push(holder);
5490
5491 // Prepare arguments.
5492 __ mov(scratch, sp);
5493
5494 // Allocate the v8::Arguments structure in the arguments' space since
5495 // it's not controlled by GC.
5496 const int kApiStackSpace = 4;
5497
5498 FrameScope frame_scope(masm, StackFrame::MANUAL);
5499 __ EnterExitFrame(false, kApiStackSpace);
5500
5501 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
5502 // r0 = FunctionCallbackInfo&
5503 // Arguments is after the return address.
5504 __ add(r0, sp, Operand(1 * kPointerSize));
5505 // FunctionCallbackInfo::implicit_args_
5506 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005507 if (argc.is_immediate()) {
5508 // FunctionCallbackInfo::values_
5509 __ add(ip, scratch,
5510 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5511 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5512 // FunctionCallbackInfo::length_ = argc
5513 __ mov(ip, Operand(argc.immediate()));
5514 __ str(ip, MemOperand(r0, 2 * kPointerSize));
5515 // FunctionCallbackInfo::is_construct_call_ = 0
5516 __ mov(ip, Operand::Zero());
5517 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5518 } else {
5519 // FunctionCallbackInfo::values_
5520 __ add(ip, scratch, Operand(argc.reg(), LSL, kPointerSizeLog2));
5521 __ add(ip, ip, Operand((FCA::kArgsLength - 1) * kPointerSize));
5522 __ str(ip, MemOperand(r0, 1 * kPointerSize));
5523 // FunctionCallbackInfo::length_ = argc
5524 __ str(argc.reg(), MemOperand(r0, 2 * kPointerSize));
5525 // FunctionCallbackInfo::is_construct_call_
5526 __ add(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5527 __ mov(ip, Operand(argc.reg(), LSL, kPointerSizeLog2));
5528 __ str(ip, MemOperand(r0, 3 * kPointerSize));
5529 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005530
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005531 ExternalReference thunk_ref =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005532 ExternalReference::invoke_function_callback(masm->isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005533
5534 AllowExternalCallThatCantCauseGC scope(masm);
5535 MemOperand context_restore_operand(
5536 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5537 // Stores return the first js argument
5538 int return_value_offset = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005539 if (return_first_arg) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005540 return_value_offset = 2 + FCA::kArgsLength;
5541 } else {
5542 return_value_offset = 2 + FCA::kReturnValueOffset;
5543 }
5544 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005545 int stack_space = 0;
5546 MemOperand is_construct_call_operand = MemOperand(sp, 4 * kPointerSize);
5547 MemOperand* stack_space_operand = &is_construct_call_operand;
5548 if (argc.is_immediate()) {
5549 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5550 stack_space_operand = NULL;
5551 }
5552 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5553 stack_space_operand, return_value_operand,
5554 &context_restore_operand);
5555}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005556
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005557
5558void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5559 bool call_data_undefined = this->call_data_undefined();
5560 CallApiFunctionStubHelper(masm, ParameterCount(r3), false,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005561 call_data_undefined, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005562}
5563
5564
5565void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5566 bool is_store = this->is_store();
5567 int argc = this->argc();
5568 bool call_data_undefined = this->call_data_undefined();
Ben Murdoch097c5b22016-05-18 11:27:45 +01005569 bool is_lazy = this->is_lazy();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005570 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005571 call_data_undefined, is_lazy);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005572}
5573
5574
5575void CallApiGetterStub::Generate(MacroAssembler* masm) {
5576 // ----------- S t a t e -------------
Ben Murdoch097c5b22016-05-18 11:27:45 +01005577 // -- sp[0] : name
5578 // -- sp[4 .. (4 + kArgsLength*4)] : v8::PropertyCallbackInfo::args_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005579 // -- ...
Ben Murdoch097c5b22016-05-18 11:27:45 +01005580 // -- r2 : api_function_address
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005581 // -----------------------------------
5582
5583 Register api_function_address = ApiGetterDescriptor::function_address();
5584 DCHECK(api_function_address.is(r2));
5585
Ben Murdoch097c5b22016-05-18 11:27:45 +01005586 // v8::PropertyCallbackInfo::args_ array and name handle.
5587 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5588
5589 // Load address of v8::PropertyAccessorInfo::args_ array and name handle.
5590 __ mov(r0, sp); // r0 = Handle<Name>
5591 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = v8::PCI::args_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005592
5593 const int kApiStackSpace = 1;
5594 FrameScope frame_scope(masm, StackFrame::MANUAL);
5595 __ EnterExitFrame(false, kApiStackSpace);
5596
Ben Murdoch097c5b22016-05-18 11:27:45 +01005597 // Create v8::PropertyCallbackInfo object on the stack and initialize
5598 // it's args_ field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005599 __ str(r1, MemOperand(sp, 1 * kPointerSize));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005600 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = v8::PropertyCallbackInfo&
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005601
5602 ExternalReference thunk_ref =
5603 ExternalReference::invoke_accessor_getter_callback(isolate());
Ben Murdoch097c5b22016-05-18 11:27:45 +01005604
5605 // +3 is to skip prolog, return address and name handle.
5606 MemOperand return_value_operand(
5607 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005608 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005609 kStackUnwindSpace, NULL, return_value_operand, NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005610}
5611
5612
Kristian Monsen80d68ea2010-09-08 11:05:35 +01005613#undef __
5614
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005615} // namespace internal
5616} // namespace v8
Kristian Monsen80d68ea2010-09-08 11:05:35 +01005617
5618#endif // V8_TARGET_ARCH_ARM