blob: ef286bbe01585a7a1ad56d3e71c0b5fdc278233f [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#include "src/v8.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +01006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#if V8_TARGET_ARCH_ARM
Kristian Monsen80d68ea2010-09-08 11:05:35 +01008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/base/bits.h"
10#include "src/bootstrapper.h"
11#include "src/code-stubs.h"
12#include "src/codegen.h"
13#include "src/ic/handler-compiler.h"
14#include "src/ic/ic.h"
15#include "src/isolate.h"
16#include "src/jsregexp.h"
17#include "src/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040018#include "src/runtime/runtime.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +010019
20namespace v8 {
21namespace internal {
22
23
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024static void InitializeArrayConstructorDescriptor(
25 Isolate* isolate, CodeStubDescriptor* descriptor,
26 int constant_stack_parameter_count) {
27 Address deopt_handler = Runtime::FunctionForId(
28 Runtime::kArrayConstructor)->entry;
29
30 if (constant_stack_parameter_count == 0) {
31 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
32 JS_FUNCTION_STUB_MODE);
33 } else {
34 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
35 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
36 }
37}
38
39
40static void InitializeInternalArrayConstructorDescriptor(
41 Isolate* isolate, CodeStubDescriptor* descriptor,
42 int constant_stack_parameter_count) {
43 Address deopt_handler = Runtime::FunctionForId(
44 Runtime::kInternalArrayConstructor)->entry;
45
46 if (constant_stack_parameter_count == 0) {
47 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
48 JS_FUNCTION_STUB_MODE);
49 } else {
50 descriptor->Initialize(r0, deopt_handler, constant_stack_parameter_count,
51 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
52 }
53}
54
55
56void ArrayNoArgumentConstructorStub::InitializeDescriptor(
57 CodeStubDescriptor* descriptor) {
58 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
59}
60
61
62void ArraySingleArgumentConstructorStub::InitializeDescriptor(
63 CodeStubDescriptor* descriptor) {
64 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
65}
66
67
68void ArrayNArgumentsConstructorStub::InitializeDescriptor(
69 CodeStubDescriptor* descriptor) {
70 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
71}
72
73
74void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
75 CodeStubDescriptor* descriptor) {
76 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
77}
78
79
80void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
81 CodeStubDescriptor* descriptor) {
82 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
83}
84
85
86void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
87 CodeStubDescriptor* descriptor) {
88 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
89}
90
91
Kristian Monsen80d68ea2010-09-08 11:05:35 +010092#define __ ACCESS_MASM(masm)
93
Ben Murdochb8a8cc12014-11-26 15:28:44 +000094
Kristian Monsen80d68ea2010-09-08 11:05:35 +010095static void EmitIdenticalObjectComparison(MacroAssembler* masm,
96 Label* slow,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097 Condition cond);
Kristian Monsen80d68ea2010-09-08 11:05:35 +010098static void EmitSmiNonsmiComparison(MacroAssembler* masm,
99 Register lhs,
100 Register rhs,
101 Label* lhs_not_nan,
102 Label* slow,
103 bool strict);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100104static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
105 Register lhs,
106 Register rhs);
107
108
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
110 ExternalReference miss) {
111 // Update the static counter each time a new code stub is generated.
112 isolate()->counters()->code_stubs()->Increment();
Ben Murdoch257744e2011-11-30 15:57:28 +0000113
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000114 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
115 int param_count = descriptor.GetEnvironmentParameterCount();
116 {
117 // Call the runtime system in a fresh internal frame.
118 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
119 DCHECK(param_count == 0 ||
120 r0.is(descriptor.GetEnvironmentParameterRegister(param_count - 1)));
121 // Push arguments
122 for (int i = 0; i < param_count; ++i) {
123 __ push(descriptor.GetEnvironmentParameterRegister(i));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100124 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000125 __ CallExternalReference(miss, param_count);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100126 }
127
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 __ Ret();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100129}
130
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100131
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132void DoubleToIStub::Generate(MacroAssembler* masm) {
133 Label out_of_range, only_low, negate, done;
134 Register input_reg = source();
135 Register result_reg = destination();
136 DCHECK(is_truncating());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100137
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 int double_offset = offset();
139 // Account for saved regs if input is sp.
140 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100141
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000142 Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
143 Register scratch_low =
144 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
145 Register scratch_high =
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
147 LowDwVfpRegister double_scratch = kScratchDoubleReg;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100148
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000149 __ Push(scratch_high, scratch_low, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100150
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000151 if (!skip_fastpath()) {
152 // Load double input.
153 __ vldr(double_scratch, MemOperand(input_reg, double_offset));
154 __ vmov(scratch_low, scratch_high, double_scratch);
155
156 // Do fast-path convert from double to int.
157 __ vcvt_s32_f64(double_scratch.low(), double_scratch);
158 __ vmov(result_reg, double_scratch.low());
159
160 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
161 __ sub(scratch, result_reg, Operand(1));
162 __ cmp(scratch, Operand(0x7ffffffe));
163 __ b(lt, &done);
164 } else {
165 // We've already done MacroAssembler::TryFastTruncatedDoubleToILoad, so we
166 // know exponent > 31, so we can skip the vcvt_s32_f64 which will saturate.
167 if (double_offset == 0) {
168 __ ldm(ia, input_reg, scratch_low.bit() | scratch_high.bit());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100169 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170 __ ldr(scratch_low, MemOperand(input_reg, double_offset));
171 __ ldr(scratch_high, MemOperand(input_reg, double_offset + kIntSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100172 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100173 }
174
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000175 __ Ubfx(scratch, scratch_high,
176 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
177 // Load scratch with exponent - 1. This is faster than loading
178 // with exponent because Bias + 1 = 1024 which is an *ARM* immediate value.
179 STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
180 __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
181 // If exponent is greater than or equal to 84, the 32 less significant
182 // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
183 // the result is 0.
184 // Compare exponent with 84 (compare exponent - 1 with 83).
185 __ cmp(scratch, Operand(83));
186 __ b(ge, &out_of_range);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100187
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000188 // If we reach this code, 31 <= exponent <= 83.
189 // So, we don't have to handle cases where 0 <= exponent <= 20 for
190 // which we would need to shift right the high part of the mantissa.
191 // Scratch contains exponent - 1.
192 // Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
193 __ rsb(scratch, scratch, Operand(51), SetCC);
194 __ b(ls, &only_low);
195 // 21 <= exponent <= 51, shift scratch_low and scratch_high
196 // to generate the result.
197 __ mov(scratch_low, Operand(scratch_low, LSR, scratch));
198 // Scratch contains: 52 - exponent.
199 // We needs: exponent - 20.
200 // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
201 __ rsb(scratch, scratch, Operand(32));
202 __ Ubfx(result_reg, scratch_high,
203 0, HeapNumber::kMantissaBitsInTopWord);
204 // Set the implicit 1 before the mantissa part in scratch_high.
205 __ orr(result_reg, result_reg,
206 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
207 __ orr(result_reg, scratch_low, Operand(result_reg, LSL, scratch));
208 __ b(&negate);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100209
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000210 __ bind(&out_of_range);
211 __ mov(result_reg, Operand::Zero());
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100212 __ b(&done);
213
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000214 __ bind(&only_low);
215 // 52 <= exponent <= 83, shift only scratch_low.
216 // On entry, scratch contains: 52 - exponent.
217 __ rsb(scratch, scratch, Operand::Zero());
218 __ mov(result_reg, Operand(scratch_low, LSL, scratch));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100219
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000220 __ bind(&negate);
221 // If input was positive, scratch_high ASR 31 equals 0 and
222 // scratch_high LSR 31 equals zero.
223 // New result = (result eor 0) + 0 = result.
224 // If the input was negative, we have to negate the result.
225 // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
226 // New result = (result eor 0xffffffff) + 1 = 0 - result.
227 __ eor(result_reg, result_reg, Operand(scratch_high, ASR, 31));
228 __ add(result_reg, result_reg, Operand(scratch_high, LSR, 31));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100229
230 __ bind(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000231
232 __ Pop(scratch_high, scratch_low, scratch);
233 __ Ret();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100234}
235
236
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100237// Handle the case where the lhs and rhs are the same object.
238// Equality is almost reflexive (everything but NaN), so this is a test
239// for "identity and not NaN".
240static void EmitIdenticalObjectComparison(MacroAssembler* masm,
241 Label* slow,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 Condition cond) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100243 Label not_identical;
244 Label heap_number, return_equal;
245 __ cmp(r0, r1);
246 __ b(ne, &not_identical);
247
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000248 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
249 // so we do the second best thing - test it ourselves.
250 // They are both equal and they are not both Smis so both of them are not
251 // Smis. If it's not a heap number, then return equal.
252 if (cond == lt || cond == gt) {
253 __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
254 __ b(ge, slow);
255 } else {
256 __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
257 __ b(eq, &heap_number);
258 // Comparing JS objects with <=, >= is complicated.
259 if (cond != eq) {
260 __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100261 __ b(ge, slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000262 // Normally here we fall through to return_equal, but undefined is
263 // special: (undefined == undefined) == true, but
264 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
265 if (cond == le || cond == ge) {
266 __ cmp(r4, Operand(ODDBALL_TYPE));
267 __ b(ne, &return_equal);
268 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
269 __ cmp(r0, r2);
270 __ b(ne, &return_equal);
271 if (cond == le) {
272 // undefined <= undefined should fail.
273 __ mov(r0, Operand(GREATER));
274 } else {
275 // undefined >= undefined should fail.
276 __ mov(r0, Operand(LESS));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100277 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000278 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100279 }
280 }
281 }
282
283 __ bind(&return_equal);
Steve Block1e0659c2011-05-24 12:43:12 +0100284 if (cond == lt) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100285 __ mov(r0, Operand(GREATER)); // Things aren't less than themselves.
Steve Block1e0659c2011-05-24 12:43:12 +0100286 } else if (cond == gt) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100287 __ mov(r0, Operand(LESS)); // Things aren't greater than themselves.
288 } else {
289 __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
290 }
291 __ Ret();
292
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000293 // For less and greater we don't have to check for NaN since the result of
294 // x < x is false regardless. For the others here is some code to check
295 // for NaN.
296 if (cond != lt && cond != gt) {
297 __ bind(&heap_number);
298 // It is a heap number, so return non-equal if it's NaN and equal if it's
299 // not NaN.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100300
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 // The representation of NaN values has all exponent bits (52..62) set,
302 // and not all mantissa bits (0..51) clear.
303 // Read top bits of double representation (second word of value).
304 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
305 // Test that exponent bits are all set.
306 __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits);
307 // NaNs have all-one exponents so they sign extend to -1.
308 __ cmp(r3, Operand(-1));
309 __ b(ne, &return_equal);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100310
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000311 // Shift out flag and all exponent bits, retaining only mantissa.
312 __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord));
313 // Or with all low-bits of mantissa.
314 __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
315 __ orr(r0, r3, Operand(r2), SetCC);
316 // For equal we already have the right value in r0: Return zero (equal)
317 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
318 // not (it's a NaN). For <= and >= we need to load r0 with the failing
319 // value if it's a NaN.
320 if (cond != eq) {
321 // All-zero means Infinity means equal.
322 __ Ret(eq);
323 if (cond == le) {
324 __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail.
325 } else {
326 __ mov(r0, Operand(LESS)); // NaN >= NaN should fail.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100327 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100328 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100330 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000331 // No fall through here.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100332
333 __ bind(&not_identical);
334}
335
336
337// See comment at call site.
338static void EmitSmiNonsmiComparison(MacroAssembler* masm,
339 Register lhs,
340 Register rhs,
341 Label* lhs_not_nan,
342 Label* slow,
343 bool strict) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000344 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100345 (lhs.is(r1) && rhs.is(r0)));
346
347 Label rhs_is_smi;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000348 __ JumpIfSmi(rhs, &rhs_is_smi);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100349
350 // Lhs is a Smi. Check whether the rhs is a heap number.
351 __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE);
352 if (strict) {
353 // If rhs is not a number and lhs is a Smi then strict equality cannot
354 // succeed. Return non-equal
355 // If rhs is r0 then there is already a non zero value in it.
356 if (!rhs.is(r0)) {
357 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
358 }
359 __ Ret(ne);
360 } else {
361 // Smi compared non-strictly with a non-Smi non-heap-number. Call
362 // the runtime.
363 __ b(ne, slow);
364 }
365
366 // Lhs is a smi, rhs is a number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000367 // Convert lhs to a double in d7.
368 __ SmiToDouble(d7, lhs);
369 // Load the double from rhs, tagged HeapNumber r0, to d6.
370 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100371
372 // We now have both loaded as doubles but we can skip the lhs nan check
373 // since it's a smi.
374 __ jmp(lhs_not_nan);
375
376 __ bind(&rhs_is_smi);
377 // Rhs is a smi. Check whether the non-smi lhs is a heap number.
378 __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE);
379 if (strict) {
380 // If lhs is not a number and rhs is a smi then strict equality cannot
381 // succeed. Return non-equal.
382 // If lhs is r0 then there is already a non zero value in it.
383 if (!lhs.is(r0)) {
384 __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
385 }
386 __ Ret(ne);
387 } else {
388 // Smi compared non-strictly with a non-smi non-heap-number. Call
389 // the runtime.
390 __ b(ne, slow);
391 }
392
393 // Rhs is a smi, lhs is a heap number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000394 // Load the double from lhs, tagged HeapNumber r1, to d7.
395 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
396 // Convert rhs to a double in d6 .
397 __ SmiToDouble(d6, rhs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100398 // Fall through to both_loaded_as_doubles.
399}
400
401
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100402// See comment at call site.
403static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
404 Register lhs,
405 Register rhs) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000406 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100407 (lhs.is(r1) && rhs.is(r0)));
408
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000409 // If either operand is a JS object or an oddball value, then they are
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100410 // not equal since their pointers are different.
411 // There is no test for undetectability in strict equality.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100412 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100413 Label first_non_object;
414 // Get the type of the first operand into r2 and compare it with
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000415 // FIRST_SPEC_OBJECT_TYPE.
416 __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100417 __ b(lt, &first_non_object);
418
419 // Return non-zero (r0 is not zero)
420 Label return_not_equal;
421 __ bind(&return_not_equal);
422 __ Ret();
423
424 __ bind(&first_non_object);
425 // Check for oddballs: true, false, null, undefined.
426 __ cmp(r2, Operand(ODDBALL_TYPE));
427 __ b(eq, &return_not_equal);
428
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000429 __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100430 __ b(ge, &return_not_equal);
431
432 // Check for oddballs: true, false, null, undefined.
433 __ cmp(r3, Operand(ODDBALL_TYPE));
434 __ b(eq, &return_not_equal);
435
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000436 // Now that we have the types we might as well check for
437 // internalized-internalized.
438 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
439 __ orr(r2, r2, Operand(r3));
440 __ tst(r2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
441 __ b(eq, &return_not_equal);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100442}
443
444
445// See comment at call site.
446static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
447 Register lhs,
448 Register rhs,
449 Label* both_loaded_as_doubles,
450 Label* not_heap_numbers,
451 Label* slow) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000452 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100453 (lhs.is(r1) && rhs.is(r0)));
454
455 __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE);
456 __ b(ne, not_heap_numbers);
457 __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
458 __ cmp(r2, r3);
459 __ b(ne, slow); // First was a heap number, second wasn't. Go slow case.
460
461 // Both are heap numbers. Load them up then jump to the code we have
462 // for that.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000463 __ vldr(d6, rhs, HeapNumber::kValueOffset - kHeapObjectTag);
464 __ vldr(d7, lhs, HeapNumber::kValueOffset - kHeapObjectTag);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100465 __ jmp(both_loaded_as_doubles);
466}
467
468
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000469// Fast negative check for internalized-to-internalized equality.
470static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
471 Register lhs,
472 Register rhs,
473 Label* possible_strings,
474 Label* not_both_strings) {
475 DCHECK((lhs.is(r0) && rhs.is(r1)) ||
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100476 (lhs.is(r1) && rhs.is(r0)));
477
478 // r2 is object type of rhs.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100479 Label object_test;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000480 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100481 __ tst(r2, Operand(kIsNotStringMask));
482 __ b(ne, &object_test);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000483 __ tst(r2, Operand(kIsNotInternalizedMask));
484 __ b(ne, possible_strings);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100485 __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE);
486 __ b(ge, not_both_strings);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000487 __ tst(r3, Operand(kIsNotInternalizedMask));
488 __ b(ne, possible_strings);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100489
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000490 // Both are internalized. We already checked they weren't the same pointer
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100491 // so they are not equal.
492 __ mov(r0, Operand(NOT_EQUAL));
493 __ Ret();
494
495 __ bind(&object_test);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000496 __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100497 __ b(lt, not_both_strings);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000498 __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100499 __ b(lt, not_both_strings);
500 // If both objects are undetectable, they are equal. Otherwise, they
501 // are not equal, since they are different objects and an object is not
502 // equal to undefined.
503 __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset));
504 __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset));
505 __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset));
506 __ and_(r0, r2, Operand(r3));
507 __ and_(r0, r0, Operand(1 << Map::kIsUndetectable));
508 __ eor(r0, r0, Operand(1 << Map::kIsUndetectable));
509 __ Ret();
510}
511
512
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000513static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
514 Register scratch,
515 CompareICState::State expected,
516 Label* fail) {
517 Label ok;
518 if (expected == CompareICState::SMI) {
519 __ JumpIfNotSmi(input, fail);
520 } else if (expected == CompareICState::NUMBER) {
521 __ JumpIfSmi(input, &ok);
522 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
523 DONT_DO_SMI_CHECK);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100524 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000525 // We could be strict about internalized/non-internalized here, but as long as
526 // hydrogen doesn't care, the stub doesn't have to care either.
527 __ bind(&ok);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100528}
529
530
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000531// On entry r1 and r2 are the values to be compared.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100532// On exit r0 is 0, positive or negative to indicate the result of
533// the comparison.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000534void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
535 Register lhs = r1;
536 Register rhs = r0;
537 Condition cc = GetCondition();
538
539 Label miss;
540 CompareICStub_CheckInputType(masm, lhs, r2, left(), &miss);
541 CompareICStub_CheckInputType(masm, rhs, r3, right(), &miss);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100542
543 Label slow; // Call builtin.
544 Label not_smis, both_loaded_as_doubles, lhs_not_nan;
545
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000546 Label not_two_smis, smi_done;
547 __ orr(r2, r1, r0);
548 __ JumpIfNotSmi(r2, &not_two_smis);
549 __ mov(r1, Operand(r1, ASR, 1));
550 __ sub(r0, r1, Operand(r0, ASR, 1));
551 __ Ret();
552 __ bind(&not_two_smis);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100553
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100554 // NOTICE! This code is only reached after a smi-fast-case check, so
555 // it is certain that at least one operand isn't a smi.
556
557 // Handle the case where the objects are identical. Either returns the answer
558 // or goes to slow. Only falls through if the objects were not identical.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000559 EmitIdenticalObjectComparison(masm, &slow, cc);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100560
561 // If either is a Smi (we know that not both are), then they can only
562 // be strictly equal if the other is a HeapNumber.
563 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000564 DCHECK_EQ(0, Smi::FromInt(0));
565 __ and_(r2, lhs, Operand(rhs));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000566 __ JumpIfNotSmi(r2, &not_smis);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100567 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
568 // 1) Return the answer.
569 // 2) Go to slow.
570 // 3) Fall through to both_loaded_as_doubles.
571 // 4) Jump to lhs_not_nan.
572 // In cases 3 and 4 we have found out we were dealing with a number-number
573 // comparison. If VFP3 is supported the double values of the numbers have
574 // been loaded into d7 and d6. Otherwise, the double values have been loaded
575 // into r0, r1, r2, and r3.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000576 EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100577
578 __ bind(&both_loaded_as_doubles);
579 // The arguments have been converted to doubles and stored in d6 and d7, if
580 // VFP3 is supported, or in r0, r1, r2, and r3.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000581 __ bind(&lhs_not_nan);
582 Label no_nan;
583 // ARMv7 VFP3 instructions to implement double precision comparison.
584 __ VFPCompareAndSetFlags(d7, d6);
585 Label nan;
586 __ b(vs, &nan);
587 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
588 __ mov(r0, Operand(LESS), LeaveCC, lt);
589 __ mov(r0, Operand(GREATER), LeaveCC, gt);
590 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100591
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000592 __ bind(&nan);
593 // If one of the sides was a NaN then the v flag is set. Load r0 with
594 // whatever it takes to make the comparison fail, since comparisons with NaN
595 // always fail.
596 if (cc == lt || cc == le) {
597 __ mov(r0, Operand(GREATER));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100598 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000599 __ mov(r0, Operand(LESS));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100600 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000601 __ Ret();
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100602
603 __ bind(&not_smis);
604 // At this point we know we are dealing with two different objects,
605 // and neither of them is a Smi. The objects are in rhs_ and lhs_.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000606 if (strict()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100607 // This returns non-equal for some object types, or falls through if it
608 // was not lucky.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000609 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100610 }
611
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000612 Label check_for_internalized_strings;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100613 Label flat_string_check;
614 // Check for heap-number-heap-number comparison. Can jump to slow case,
615 // or load both doubles into r0, r1, r2, r3 and jump to the code that handles
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000616 // that case. If the inputs are not doubles then jumps to
617 // check_for_internalized_strings.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100618 // In this case r2 will contain the type of rhs_. Never falls through.
619 EmitCheckForTwoHeapNumbers(masm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000620 lhs,
621 rhs,
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100622 &both_loaded_as_doubles,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000623 &check_for_internalized_strings,
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100624 &flat_string_check);
625
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000626 __ bind(&check_for_internalized_strings);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100627 // In the strict case the EmitStrictTwoHeapObjectCompare already took care of
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000628 // internalized strings.
629 if (cc == eq && !strict()) {
630 // Returns an answer for two internalized strings or two detectable objects.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100631 // Otherwise jumps to string case or not both strings case.
632 // Assumes that r2 is the type of rhs_ on entry.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000633 EmitCheckForInternalizedStringsOrObjects(
634 masm, lhs, rhs, &flat_string_check, &slow);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100635 }
636
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000637 // Check for both being sequential one-byte strings,
638 // and inline if that is the case.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100639 __ bind(&flat_string_check);
640
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000641 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r2, r3, &slow);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100642
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000643 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2,
644 r3);
645 if (cc == eq) {
646 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r2, r3, r4);
Ben Murdoch257744e2011-11-30 15:57:28 +0000647 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000648 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r2, r3, r4,
649 r5);
Ben Murdoch257744e2011-11-30 15:57:28 +0000650 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100651 // Never falls through to here.
652
653 __ bind(&slow);
654
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000655 __ Push(lhs, rhs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100656 // Figure out which native to call and setup the arguments.
657 Builtins::JavaScript native;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000658 if (cc == eq) {
659 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100660 } else {
661 native = Builtins::COMPARE;
662 int ncr; // NaN compare result
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000663 if (cc == lt || cc == le) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100664 ncr = GREATER;
665 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000666 DCHECK(cc == gt || cc == ge); // remaining cases
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100667 ncr = LESS;
668 }
669 __ mov(r0, Operand(Smi::FromInt(ncr)));
670 __ push(r0);
671 }
672
673 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
674 // tagged as a small integer.
Ben Murdoch257744e2011-11-30 15:57:28 +0000675 __ InvokeBuiltin(native, JUMP_FUNCTION);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100676
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000677 __ bind(&miss);
678 GenerateMiss(masm);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100679}
680
681
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100682void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
683 // We don't allow a GC during a store buffer overflow so there is no need to
684 // store the registers in any particular way, but we do have to store and
685 // restore them.
686 __ stm(db_w, sp, kCallerSaved | lr.bit());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000687
688 const Register scratch = r1;
689
690 if (save_doubles()) {
691 __ SaveFPRegs(sp, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100692 }
693 const int argument_count = 1;
694 const int fp_argument_count = 0;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100695
696 AllowExternalCallThatCantCauseGC scope(masm);
697 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000698 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100699 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000700 ExternalReference::store_buffer_overflow_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100701 argument_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000702 if (save_doubles()) {
703 __ RestoreFPRegs(sp, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100704 }
705 __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
706}
707
708
Steve Block44f0eee2011-05-26 01:26:41 +0100709void MathPowStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100710 const Register base = r1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000711 const Register exponent = MathPowTaggedDescriptor::exponent();
712 DCHECK(exponent.is(r2));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100713 const Register heapnumbermap = r5;
714 const Register heapnumber = r0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000715 const DwVfpRegister double_base = d0;
716 const DwVfpRegister double_exponent = d1;
717 const DwVfpRegister double_result = d2;
718 const DwVfpRegister double_scratch = d3;
719 const SwVfpRegister single_scratch = s6;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100720 const Register scratch = r9;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000721 const Register scratch2 = r4;
Steve Block44f0eee2011-05-26 01:26:41 +0100722
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100723 Label call_runtime, done, int_exponent;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000724 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100725 Label base_is_smi, unpack_exponent;
726 // The exponent and base are supplied as arguments on the stack.
727 // This can only happen if the stub is called from non-optimized code.
728 // Load input parameters from stack to double registers.
Steve Block44f0eee2011-05-26 01:26:41 +0100729 __ ldr(base, MemOperand(sp, 1 * kPointerSize));
730 __ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
731
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100732 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
Steve Block44f0eee2011-05-26 01:26:41 +0100733
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100734 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
Steve Block44f0eee2011-05-26 01:26:41 +0100735 __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
736 __ cmp(scratch, heapnumbermap);
737 __ b(ne, &call_runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100738
Ben Murdochc7cc0282012-03-05 14:35:55 +0000739 __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100740 __ jmp(&unpack_exponent);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000741
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100742 __ bind(&base_is_smi);
743 __ vmov(single_scratch, scratch);
744 __ vcvt_f64_s32(double_base, single_scratch);
745 __ bind(&unpack_exponent);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000746
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100747 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
Steve Block44f0eee2011-05-26 01:26:41 +0100748
Steve Block44f0eee2011-05-26 01:26:41 +0100749 __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
750 __ cmp(scratch, heapnumbermap);
751 __ b(ne, &call_runtime);
Steve Block44f0eee2011-05-26 01:26:41 +0100752 __ vldr(double_exponent,
753 FieldMemOperand(exponent, HeapNumber::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000754 } else if (exponent_type() == TAGGED) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100755 // Base is already in double_base.
756 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
Steve Block44f0eee2011-05-26 01:26:41 +0100757
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100758 __ vldr(double_exponent,
759 FieldMemOperand(exponent, HeapNumber::kValueOffset));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000760 }
Ben Murdoch85b71792012-04-11 18:30:58 +0100761
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000762 if (exponent_type() != INTEGER) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100763 Label int_exponent_convert;
764 // Detect integer exponents stored as double.
765 __ vcvt_u32_f64(single_scratch, double_exponent);
766 // We do not check for NaN or Infinity here because comparing numbers on
767 // ARM correctly distinguishes NaNs. We end up calling the built-in.
768 __ vcvt_f64_u32(double_scratch, single_scratch);
769 __ VFPCompareAndSetFlags(double_scratch, double_exponent);
770 __ b(eq, &int_exponent_convert);
771
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000772 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100773 // Detect square root case. Crankshaft detects constant +/-0.5 at
774 // compile time and uses DoMathPowHalf instead. We then skip this check
775 // for non-constant cases of +/-0.5 as these hardly occur.
776 Label not_plus_half;
777
778 // Test for 0.5.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000779 __ vmov(double_scratch, 0.5, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100780 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
781 __ b(ne, &not_plus_half);
782
783 // Calculates square root of base. Check for the special case of
784 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000785 __ vmov(double_scratch, -V8_INFINITY, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100786 __ VFPCompareAndSetFlags(double_base, double_scratch);
787 __ vneg(double_result, double_scratch, eq);
788 __ b(eq, &done);
789
790 // Add +0 to convert -0 to +0.
791 __ vadd(double_scratch, double_base, kDoubleRegZero);
792 __ vsqrt(double_result, double_scratch);
793 __ jmp(&done);
794
795 __ bind(&not_plus_half);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000796 __ vmov(double_scratch, -0.5, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100797 __ VFPCompareAndSetFlags(double_exponent, double_scratch);
798 __ b(ne, &call_runtime);
799
800 // Calculates square root of base. Check for the special case of
801 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000802 __ vmov(double_scratch, -V8_INFINITY, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100803 __ VFPCompareAndSetFlags(double_base, double_scratch);
804 __ vmov(double_result, kDoubleRegZero, eq);
805 __ b(eq, &done);
806
807 // Add +0 to convert -0 to +0.
808 __ vadd(double_scratch, double_base, kDoubleRegZero);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000809 __ vmov(double_result, 1.0, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100810 __ vsqrt(double_scratch, double_scratch);
811 __ vdiv(double_result, double_result, double_scratch);
812 __ jmp(&done);
813 }
814
815 __ push(lr);
816 {
817 AllowExternalCallThatCantCauseGC scope(masm);
818 __ PrepareCallCFunction(0, 2, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000819 __ MovToFloatParameters(double_base, double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100820 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000821 ExternalReference::power_double_double_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100822 0, 2);
823 }
824 __ pop(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000825 __ MovFromFloatResult(double_result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100826 __ jmp(&done);
827
828 __ bind(&int_exponent_convert);
829 __ vcvt_u32_f64(single_scratch, double_exponent);
830 __ vmov(scratch, single_scratch);
831 }
832
833 // Calculate power with integer exponent.
834 __ bind(&int_exponent);
835
836 // Get two copies of exponent in the registers scratch and exponent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000837 if (exponent_type() == INTEGER) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100838 __ mov(scratch, exponent);
839 } else {
840 // Exponent has previously been stored into scratch as untagged integer.
841 __ mov(exponent, scratch);
842 }
843 __ vmov(double_scratch, double_base); // Back up base.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000844 __ vmov(double_result, 1.0, scratch2);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100845
846 // Get absolute value of exponent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000847 __ cmp(scratch, Operand::Zero());
848 __ mov(scratch2, Operand::Zero(), LeaveCC, mi);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100849 __ sub(scratch, scratch2, scratch, LeaveCC, mi);
850
851 Label while_true;
852 __ bind(&while_true);
853 __ mov(scratch, Operand(scratch, ASR, 1), SetCC);
854 __ vmul(double_result, double_result, double_scratch, cs);
855 __ vmul(double_scratch, double_scratch, double_scratch, ne);
856 __ b(ne, &while_true);
857
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000858 __ cmp(exponent, Operand::Zero());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100859 __ b(ge, &done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000860 __ vmov(double_scratch, 1.0, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100861 __ vdiv(double_result, double_scratch, double_result);
862 // Test whether result is zero. Bail out to check for subnormal result.
863 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
864 __ VFPCompareAndSetFlags(double_result, 0.0);
865 __ b(ne, &done);
866 // double_exponent may not containe the exponent value if the input was a
867 // smi. We set it with exponent value before bailing out.
868 __ vmov(single_scratch, exponent);
869 __ vcvt_f64_s32(double_exponent, single_scratch);
870
871 // Returning or bailing out.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000872 Counters* counters = isolate()->counters();
873 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100874 // The arguments are still on the stack.
875 __ bind(&call_runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000876 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100877
878 // The stub is called from non-optimized code, which expects the result
879 // as heap number in exponent.
880 __ bind(&done);
881 __ AllocateHeapNumber(
882 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
883 __ vstr(double_result,
884 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000885 DCHECK(heapnumber.is(r0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100886 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
887 __ Ret(2);
888 } else {
889 __ push(lr);
890 {
891 AllowExternalCallThatCantCauseGC scope(masm);
892 __ PrepareCallCFunction(0, 2, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000893 __ MovToFloatParameters(double_base, double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100894 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000895 ExternalReference::power_double_double_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100896 0, 2);
897 }
898 __ pop(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000899 __ MovFromFloatResult(double_result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100900
901 __ bind(&done);
902 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
903 __ Ret();
904 }
Steve Block44f0eee2011-05-26 01:26:41 +0100905}
906
907
908bool CEntryStub::NeedsImmovableCode() {
909 return true;
910}
911
912
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000913void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
914 CEntryStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000915 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
916 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
917 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
918 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
919 BinaryOpICStub::GenerateAheadOfTime(isolate);
920 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000921}
922
923
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000924void CodeStub::GenerateFPStubs(Isolate* isolate) {
925 // Generate if not already in cache.
926 SaveFPRegsMode mode = kSaveFPRegs;
927 CEntryStub(isolate, 1, mode).GetCode();
928 StoreBufferOverflowStub(isolate, mode).GetCode();
929 isolate->set_fp_stubs_generated(true);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100930}
931
932
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000933void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
934 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
935 stub.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100936}
937
938
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000939void CEntryStub::Generate(MacroAssembler* masm) {
940 // Called from JavaScript; parameters are on stack as if calling JS function.
941 // r0: number of arguments including receiver
942 // r1: pointer to builtin function
943 // fp: frame pointer (restored after C call)
944 // sp: stack pointer (restored as callee's sp after C call)
945 // cp: current context (C callee-saved)
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000946
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000947 ProfileEntryHookStub::MaybeCallEntryHook(masm);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000948
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000949 __ mov(r5, Operand(r1));
950
951 // Compute the argv pointer in a callee-saved register.
952 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2));
953 __ sub(r1, r1, Operand(kPointerSize));
954
955 // Enter the exit frame that transitions from JavaScript to C++.
956 FrameScope scope(masm, StackFrame::MANUAL);
957 __ EnterExitFrame(save_doubles());
958
959 // Store a copy of argc in callee-saved registers for later.
960 __ mov(r4, Operand(r0));
961
962 // r0, r4: number of arguments including receiver (C callee-saved)
963 // r1: pointer to the first argument (C callee-saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100964 // r5: pointer to builtin function (C callee-saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100965
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000966 // Result returned in r0 or r0+r1 by default.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100967
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000968#if V8_HOST_ARCH_ARM
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100969 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
970 int frame_alignment_mask = frame_alignment - 1;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100971 if (FLAG_debug_code) {
972 if (frame_alignment > kPointerSize) {
973 Label alignment_as_expected;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000974 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
Steve Block1e0659c2011-05-24 12:43:12 +0100975 __ tst(sp, Operand(frame_alignment_mask));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100976 __ b(eq, &alignment_as_expected);
977 // Don't use Check here, as it will call Runtime_Abort re-entering here.
978 __ stop("Unexpected alignment");
979 __ bind(&alignment_as_expected);
980 }
981 }
982#endif
983
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000984 // Call C built-in.
985 // r0 = argc, r1 = argv
986 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
Steve Block44f0eee2011-05-26 01:26:41 +0100987
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000988 // To let the GC traverse the return address of the exit frames, we need to
989 // know where the return address is. The CEntryStub is unmovable, so
990 // we can store the address on the stack to be able to find it again and
991 // we never have to restore it, because it will not change.
Steve Block1e0659c2011-05-24 12:43:12 +0100992 // Compute the return address in lr to return to after the jump below. Pc is
993 // already at '+ 8' from the current instruction but return is after three
994 // instructions so add another 4 to pc to get the return address.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000995 {
996 // Prevent literal pool emission before return address.
997 Assembler::BlockConstPoolScope block_const_pool(masm);
998 __ add(lr, pc, Operand(4));
999 __ str(lr, MemOperand(sp, 0));
1000 __ Call(r5);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001001 }
1002
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001003 __ VFPEnsureFPSCRState(r2);
1004
1005 // Runtime functions should not return 'the hole'. Allowing it to escape may
1006 // lead to crashes in the IC code later.
1007 if (FLAG_debug_code) {
1008 Label okay;
1009 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex);
1010 __ b(ne, &okay);
1011 __ stop("The hole escaped");
1012 __ bind(&okay);
1013 }
1014
1015 // Check result for exception sentinel.
1016 Label exception_returned;
1017 __ CompareRoot(r0, Heap::kExceptionRootIndex);
1018 __ b(eq, &exception_returned);
1019
1020 ExternalReference pending_exception_address(
1021 Isolate::kPendingExceptionAddress, isolate());
1022
1023 // Check that there is no pending exception, otherwise we
1024 // should have returned the exception sentinel.
1025 if (FLAG_debug_code) {
1026 Label okay;
1027 __ mov(r2, Operand(pending_exception_address));
1028 __ ldr(r2, MemOperand(r2));
1029 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
1030 // Cannot use check here as it attempts to generate call into runtime.
1031 __ b(eq, &okay);
1032 __ stop("Unexpected pending exception");
1033 __ bind(&okay);
1034 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001035
1036 // Exit C frame and return.
1037 // r0:r1: result
1038 // sp: stack pointer
1039 // fp: frame pointer
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001040 // Callee-saved register r4 still holds argc.
1041 __ LeaveExitFrame(save_doubles(), r4, true);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001042 __ mov(pc, lr);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001043
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001044 // Handling of exception.
1045 __ bind(&exception_returned);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001046
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001047 // Retrieve the pending exception.
1048 __ mov(r2, Operand(pending_exception_address));
1049 __ ldr(r0, MemOperand(r2));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001050
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001051 // Clear the pending exception.
1052 __ LoadRoot(r3, Heap::kTheHoleValueRootIndex);
1053 __ str(r3, MemOperand(r2));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001054
1055 // Special handling of termination exceptions which are uncatchable
1056 // by javascript code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001057 Label throw_termination_exception;
1058 __ CompareRoot(r0, Heap::kTerminationExceptionRootIndex);
1059 __ b(eq, &throw_termination_exception);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001060
1061 // Handle normal exception.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001062 __ Throw(r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001063
1064 __ bind(&throw_termination_exception);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001065 __ ThrowUncatchable(r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001066}
1067
1068
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001069void JSEntryStub::Generate(MacroAssembler* masm) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001070 // r0: code entry
1071 // r1: function
1072 // r2: receiver
1073 // r3: argc
1074 // [sp+0]: argv
1075
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001076 Label invoke, handler_entry, exit;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001077
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001078 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1079
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001080 // Called from C, so do not pop argc and args on exit (preserve sp)
1081 // No need to save register-passed args
1082 // Save callee-saved registers (incl. cp and fp), sp, and lr
1083 __ stm(db_w, sp, kCalleeSaved | lr.bit());
1084
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001085 // Save callee-saved vfp registers.
1086 __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
1087 // Set up the reserved register for 0.0.
1088 __ vmov(kDoubleRegZero, 0.0);
1089 __ VFPEnsureFPSCRState(r4);
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001090
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001091 // Get address of argv, see stm above.
1092 // r0: code entry
1093 // r1: function
1094 // r2: receiver
1095 // r3: argc
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001096
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001097 // Set up argv in r4.
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001098 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001099 offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001100 __ ldr(r4, MemOperand(sp, offset_to_argv));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001101
1102 // Push a frame with special values setup to mark it as an entry frame.
1103 // r0: code entry
1104 // r1: function
1105 // r2: receiver
1106 // r3: argc
1107 // r4: argv
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001108 int marker = type();
1109 if (FLAG_enable_ool_constant_pool) {
1110 __ mov(r8, Operand(isolate()->factory()->empty_constant_pool_array()));
1111 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001112 __ mov(r7, Operand(Smi::FromInt(marker)));
1113 __ mov(r6, Operand(Smi::FromInt(marker)));
Steve Block44f0eee2011-05-26 01:26:41 +01001114 __ mov(r5,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001115 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001116 __ ldr(r5, MemOperand(r5));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001117 __ mov(ip, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1118 __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() |
1119 (FLAG_enable_ool_constant_pool ? r8.bit() : 0) |
1120 ip.bit());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001121
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001122 // Set up frame pointer for the frame to be pushed.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001123 __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1124
Ben Murdochb0fe1622011-05-05 13:52:32 +01001125 // If this is the outermost JS call, set js_entry_sp value.
Steve Block053d10c2011-06-13 19:13:29 +01001126 Label non_outermost_js;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001127 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
Ben Murdochb0fe1622011-05-05 13:52:32 +01001128 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1129 __ ldr(r6, MemOperand(r5));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001130 __ cmp(r6, Operand::Zero());
Steve Block053d10c2011-06-13 19:13:29 +01001131 __ b(ne, &non_outermost_js);
1132 __ str(fp, MemOperand(r5));
1133 __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1134 Label cont;
1135 __ b(&cont);
1136 __ bind(&non_outermost_js);
1137 __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1138 __ bind(&cont);
1139 __ push(ip);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001140
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001141 // Jump to a faked try block that does the invoke, with a faked catch
1142 // block that sets the pending exception.
1143 __ jmp(&invoke);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001144
1145 // Block literal pool emission whilst taking the position of the handler
1146 // entry. This avoids making the assumption that literal pools are always
1147 // emitted after an instruction is emitted, rather than before.
1148 {
1149 Assembler::BlockConstPoolScope block_const_pool(masm);
1150 __ bind(&handler_entry);
1151 handler_offset_ = handler_entry.pos();
1152 // Caught exception: Store result (exception) in the pending exception
1153 // field in the JSEnv and return a failure sentinel. Coming in here the
1154 // fp will be invalid because the PushTryHandler below sets it to 0 to
1155 // signal the existence of the JSEntry frame.
1156 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1157 isolate())));
1158 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001159 __ str(r0, MemOperand(ip));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001160 __ LoadRoot(r0, Heap::kExceptionRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001161 __ b(&exit);
1162
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001163 // Invoke: Link this frame into the handler chain. There's only one
1164 // handler block in this code object, so its index is 0.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001165 __ bind(&invoke);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001166 // Must preserve r0-r4, r5-r6 are available.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001167 __ PushTryHandler(StackHandler::JS_ENTRY, 0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001168 // If an exception not caught by another handler occurs, this handler
1169 // returns control to the code after the bl(&invoke) above, which
1170 // restores all kCalleeSaved registers (including cp and fp) to their
1171 // saved values before returning a failure to C.
1172
1173 // Clear any pending exceptions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001174 __ mov(r5, Operand(isolate()->factory()->the_hole_value()));
Ben Murdoch589d6972011-11-30 16:04:58 +00001175 __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001176 isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001177 __ str(r5, MemOperand(ip));
1178
1179 // Invoke the function by calling through JS entry trampoline builtin.
1180 // Notice that we cannot store a reference to the trampoline code directly in
1181 // this stub, because runtime stubs are not traversed when doing GC.
1182
1183 // Expected registers by Builtins::JSEntryTrampoline
1184 // r0: code entry
1185 // r1: function
1186 // r2: receiver
1187 // r3: argc
1188 // r4: argv
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001189 if (type() == StackFrame::ENTRY_CONSTRUCT) {
Steve Block44f0eee2011-05-26 01:26:41 +01001190 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001191 isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001192 __ mov(ip, Operand(construct_entry));
1193 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001194 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001195 __ mov(ip, Operand(entry));
1196 }
1197 __ ldr(ip, MemOperand(ip)); // deref address
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001198 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001199
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001200 // Branch and link to JSEntryTrampoline.
1201 __ Call(ip);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001202
Steve Block053d10c2011-06-13 19:13:29 +01001203 // Unlink this frame from the handler chain.
1204 __ PopTryHandler();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001205
1206 __ bind(&exit); // r0 holds result
Steve Block053d10c2011-06-13 19:13:29 +01001207 // Check if the current stack frame is marked as the outermost JS frame.
1208 Label non_outermost_js_2;
1209 __ pop(r5);
1210 __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1211 __ b(ne, &non_outermost_js_2);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001212 __ mov(r6, Operand::Zero());
Steve Block053d10c2011-06-13 19:13:29 +01001213 __ mov(r5, Operand(ExternalReference(js_entry_sp)));
1214 __ str(r6, MemOperand(r5));
1215 __ bind(&non_outermost_js_2);
Steve Block053d10c2011-06-13 19:13:29 +01001216
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001217 // Restore the top frame descriptors from the stack.
1218 __ pop(r3);
Steve Block44f0eee2011-05-26 01:26:41 +01001219 __ mov(ip,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001220 Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001221 __ str(r3, MemOperand(ip));
1222
1223 // Reset the stack to the callee saved registers.
1224 __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
1225
1226 // Restore callee-saved registers and return.
1227#ifdef DEBUG
1228 if (FLAG_debug_code) {
1229 __ mov(lr, Operand(pc));
1230 }
1231#endif
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001232
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001233 // Restore callee-saved vfp registers.
1234 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +01001235
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001236 __ ldm(ia_w, sp, kCalleeSaved | pc.bit());
1237}
1238
1239
Steve Block1e0659c2011-05-24 12:43:12 +01001240// Uses registers r0 to r4.
1241// Expected input (depending on whether args are in registers or on the stack):
1242// * object: r0 or at sp + 1 * kPointerSize.
1243// * function: r1 or at sp.
1244//
1245// An inlined call site may have been generated before calling this stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001246// In this case the offset to the inline sites to patch are passed in r5 and r6.
Steve Block1e0659c2011-05-24 12:43:12 +01001247// (See LCodeGen::DoInstanceOfKnownGlobal)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001248void InstanceofStub::Generate(MacroAssembler* masm) {
Steve Block1e0659c2011-05-24 12:43:12 +01001249 // Call site inlining and patching implies arguments in registers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001250 DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
Steve Block1e0659c2011-05-24 12:43:12 +01001251
Ben Murdochb0fe1622011-05-05 13:52:32 +01001252 // Fixed register usage throughout the stub:
Steve Block9fac8402011-05-12 15:51:54 +01001253 const Register object = r0; // Object (lhs).
Steve Block1e0659c2011-05-24 12:43:12 +01001254 Register map = r3; // Map of the object.
Steve Block9fac8402011-05-12 15:51:54 +01001255 const Register function = r1; // Function (rhs).
Ben Murdochb0fe1622011-05-05 13:52:32 +01001256 const Register prototype = r4; // Prototype of the function.
1257 const Register scratch = r2;
Steve Block1e0659c2011-05-24 12:43:12 +01001258
Ben Murdochb0fe1622011-05-05 13:52:32 +01001259 Label slow, loop, is_instance, is_not_instance, not_js_object;
Steve Block1e0659c2011-05-24 12:43:12 +01001260
Ben Murdoch086aeea2011-05-13 15:57:08 +01001261 if (!HasArgsInRegisters()) {
Steve Block9fac8402011-05-12 15:51:54 +01001262 __ ldr(object, MemOperand(sp, 1 * kPointerSize));
1263 __ ldr(function, MemOperand(sp, 0));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001264 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001265
Ben Murdochb0fe1622011-05-05 13:52:32 +01001266 // Check that the left hand is a JS object and load map.
Steve Block1e0659c2011-05-24 12:43:12 +01001267 __ JumpIfSmi(object, &not_js_object);
Steve Block9fac8402011-05-12 15:51:54 +01001268 __ IsObjectJSObjectType(object, map, scratch, &not_js_object);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001269
Steve Block1e0659c2011-05-24 12:43:12 +01001270 // If there is a call site cache don't look in the global cache, but do the
1271 // real lookup and update the call site cache.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001272 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
Steve Block1e0659c2011-05-24 12:43:12 +01001273 Label miss;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001274 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
Steve Block1e0659c2011-05-24 12:43:12 +01001275 __ b(ne, &miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001276 __ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex);
Steve Block1e0659c2011-05-24 12:43:12 +01001277 __ b(ne, &miss);
1278 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
1279 __ Ret(HasArgsInRegisters() ? 0 : 2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001280
Steve Block1e0659c2011-05-24 12:43:12 +01001281 __ bind(&miss);
1282 }
1283
1284 // Get the prototype of the function.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001285 __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001286
1287 // Check that the function prototype is a JS object.
Steve Block1e0659c2011-05-24 12:43:12 +01001288 __ JumpIfSmi(prototype, &slow);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001289 __ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001290
Steve Block1e0659c2011-05-24 12:43:12 +01001291 // Update the global instanceof or call site inlined cache with the current
1292 // map and function. The cached answer will be set when it is known below.
1293 if (!HasCallSiteInlineCheck()) {
1294 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1295 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1296 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001297 DCHECK(HasArgsInRegisters());
Steve Block1e0659c2011-05-24 12:43:12 +01001298 // Patch the (relocated) inlined map check.
1299
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001300 // The map_load_offset was stored in r5
1301 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1302 const Register map_load_offset = r5;
1303 __ sub(r9, lr, map_load_offset);
1304 // Get the map location in r5 and patch it.
1305 __ GetRelocatedValueLocation(r9, map_load_offset, scratch);
1306 __ ldr(map_load_offset, MemOperand(map_load_offset));
1307 __ str(map, FieldMemOperand(map_load_offset, Cell::kValueOffset));
Steve Block1e0659c2011-05-24 12:43:12 +01001308 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001309
1310 // Register mapping: r3 is object map and r4 is function prototype.
1311 // Get prototype of object into r2.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001312 __ ldr(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001313
Steve Block1e0659c2011-05-24 12:43:12 +01001314 // We don't need map any more. Use it as a scratch register.
1315 Register scratch2 = map;
1316 map = no_reg;
1317
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001318 // Loop through the prototype chain looking for the function prototype.
Steve Block1e0659c2011-05-24 12:43:12 +01001319 __ LoadRoot(scratch2, Heap::kNullValueRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001320 __ bind(&loop);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001321 __ cmp(scratch, Operand(prototype));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001322 __ b(eq, &is_instance);
Steve Block1e0659c2011-05-24 12:43:12 +01001323 __ cmp(scratch, scratch2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001324 __ b(eq, &is_not_instance);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001325 __ ldr(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
1326 __ ldr(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001327 __ jmp(&loop);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001328 Factory* factory = isolate()->factory();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001329
1330 __ bind(&is_instance);
Steve Block1e0659c2011-05-24 12:43:12 +01001331 if (!HasCallSiteInlineCheck()) {
1332 __ mov(r0, Operand(Smi::FromInt(0)));
1333 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001334 if (ReturnTrueFalseObject()) {
1335 __ Move(r0, factory->true_value());
1336 }
Steve Block1e0659c2011-05-24 12:43:12 +01001337 } else {
1338 // Patch the call site to return true.
1339 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001340 // The bool_load_offset was stored in r6
1341 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1342 const Register bool_load_offset = r6;
1343 __ sub(r9, lr, bool_load_offset);
Steve Block1e0659c2011-05-24 12:43:12 +01001344 // Get the boolean result location in scratch and patch it.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001345 __ GetRelocatedValueLocation(r9, scratch, scratch2);
Steve Block1e0659c2011-05-24 12:43:12 +01001346 __ str(r0, MemOperand(scratch));
1347
1348 if (!ReturnTrueFalseObject()) {
1349 __ mov(r0, Operand(Smi::FromInt(0)));
1350 }
1351 }
Ben Murdoch086aeea2011-05-13 15:57:08 +01001352 __ Ret(HasArgsInRegisters() ? 0 : 2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001353
1354 __ bind(&is_not_instance);
Steve Block1e0659c2011-05-24 12:43:12 +01001355 if (!HasCallSiteInlineCheck()) {
1356 __ mov(r0, Operand(Smi::FromInt(1)));
1357 __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001358 if (ReturnTrueFalseObject()) {
1359 __ Move(r0, factory->false_value());
1360 }
Steve Block1e0659c2011-05-24 12:43:12 +01001361 } else {
1362 // Patch the call site to return false.
1363 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001364 // The bool_load_offset was stored in r6
1365 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1366 const Register bool_load_offset = r6;
1367 __ sub(r9, lr, bool_load_offset);
1368 ;
Steve Block1e0659c2011-05-24 12:43:12 +01001369 // Get the boolean result location in scratch and patch it.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001370 __ GetRelocatedValueLocation(r9, scratch, scratch2);
Steve Block1e0659c2011-05-24 12:43:12 +01001371 __ str(r0, MemOperand(scratch));
1372
1373 if (!ReturnTrueFalseObject()) {
1374 __ mov(r0, Operand(Smi::FromInt(1)));
1375 }
1376 }
Ben Murdoch086aeea2011-05-13 15:57:08 +01001377 __ Ret(HasArgsInRegisters() ? 0 : 2);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001378
1379 Label object_not_null, object_not_null_or_smi;
1380 __ bind(&not_js_object);
1381 // Before null, smi and string value checks, check that the rhs is a function
1382 // as for a non-function rhs an exception needs to be thrown.
Steve Block1e0659c2011-05-24 12:43:12 +01001383 __ JumpIfSmi(function, &slow);
1384 __ CompareObjectType(function, scratch2, scratch, JS_FUNCTION_TYPE);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001385 __ b(ne, &slow);
1386
1387 // Null is not instance of anything.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001388 __ cmp(object, Operand(isolate()->factory()->null_value()));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001389 __ b(ne, &object_not_null);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001390 if (ReturnTrueFalseObject()) {
1391 __ Move(r0, factory->false_value());
1392 } else {
1393 __ mov(r0, Operand(Smi::FromInt(1)));
1394 }
Ben Murdoch086aeea2011-05-13 15:57:08 +01001395 __ Ret(HasArgsInRegisters() ? 0 : 2);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001396
1397 __ bind(&object_not_null);
1398 // Smi values are not instances of anything.
Steve Block1e0659c2011-05-24 12:43:12 +01001399 __ JumpIfNotSmi(object, &object_not_null_or_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001400 if (ReturnTrueFalseObject()) {
1401 __ Move(r0, factory->false_value());
1402 } else {
1403 __ mov(r0, Operand(Smi::FromInt(1)));
1404 }
Ben Murdoch086aeea2011-05-13 15:57:08 +01001405 __ Ret(HasArgsInRegisters() ? 0 : 2);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001406
1407 __ bind(&object_not_null_or_smi);
1408 // String values are not instances of anything.
1409 __ IsObjectJSStringType(object, scratch, &slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001410 if (ReturnTrueFalseObject()) {
1411 __ Move(r0, factory->false_value());
1412 } else {
1413 __ mov(r0, Operand(Smi::FromInt(1)));
1414 }
Ben Murdoch086aeea2011-05-13 15:57:08 +01001415 __ Ret(HasArgsInRegisters() ? 0 : 2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001416
1417 // Slow-case. Tail call builtin.
Ben Murdoch086aeea2011-05-13 15:57:08 +01001418 __ bind(&slow);
Steve Block1e0659c2011-05-24 12:43:12 +01001419 if (!ReturnTrueFalseObject()) {
1420 if (HasArgsInRegisters()) {
1421 __ Push(r0, r1);
1422 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001423 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
Steve Block1e0659c2011-05-24 12:43:12 +01001424 } else {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001425 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001426 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001427 __ Push(r0, r1);
1428 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1429 }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001430 __ cmp(r0, Operand::Zero());
Steve Block1e0659c2011-05-24 12:43:12 +01001431 __ LoadRoot(r0, Heap::kTrueValueRootIndex, eq);
1432 __ LoadRoot(r0, Heap::kFalseValueRootIndex, ne);
1433 __ Ret(HasArgsInRegisters() ? 0 : 2);
1434 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001435}
1436
1437
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001438void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1439 Label miss;
1440 Register receiver = LoadDescriptor::ReceiverRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001441 // Ensure that the vector and slot registers won't be clobbered before
1442 // calling the miss handler.
1443 DCHECK(!FLAG_vector_ics ||
1444 !AreAliased(r4, r5, VectorLoadICDescriptor::VectorRegister(),
1445 VectorLoadICDescriptor::SlotRegister()));
Steve Block1e0659c2011-05-24 12:43:12 +01001446
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001447 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4,
1448 r5, &miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001449 __ bind(&miss);
1450 PropertyAccessCompiler::TailCallBuiltin(
1451 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1452}
Steve Block1e0659c2011-05-24 12:43:12 +01001453
1454
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001455void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1456 // Return address is in lr.
1457 Label miss;
1458
1459 Register receiver = LoadDescriptor::ReceiverRegister();
1460 Register index = LoadDescriptor::NameRegister();
1461 Register scratch = r5;
1462 Register result = r0;
1463 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1464 DCHECK(!FLAG_vector_ics ||
1465 (!scratch.is(VectorLoadICDescriptor::VectorRegister()) &&
1466 result.is(VectorLoadICDescriptor::SlotRegister())));
1467
1468 // StringCharAtGenerator doesn't use the result register until it's passed
1469 // the different miss possibilities. If it did, we would have a conflict
1470 // when FLAG_vector_ics is true.
1471 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1472 &miss, // When not a string.
1473 &miss, // When not a number.
1474 &miss, // When index out of range.
1475 STRING_INDEX_IS_ARRAY_INDEX,
1476 RECEIVER_IS_STRING);
1477 char_at_generator.GenerateFast(masm);
1478 __ Ret();
1479
1480 StubRuntimeCallHelper call_helper;
1481 char_at_generator.GenerateSlow(masm, call_helper);
1482
1483 __ bind(&miss);
1484 PropertyAccessCompiler::TailCallBuiltin(
1485 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1486}
1487
1488
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001489void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1490 // The displacement is the offset of the last parameter (if any)
1491 // relative to the frame pointer.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001492 const int kDisplacement =
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001493 StandardFrameConstants::kCallerSPOffset - kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001494 DCHECK(r1.is(ArgumentsAccessReadDescriptor::index()));
1495 DCHECK(r0.is(ArgumentsAccessReadDescriptor::parameter_count()));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001496
1497 // Check that the key is a smi.
1498 Label slow;
Steve Block1e0659c2011-05-24 12:43:12 +01001499 __ JumpIfNotSmi(r1, &slow);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001500
1501 // Check if the calling frame is an arguments adaptor frame.
1502 Label adaptor;
1503 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1504 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1505 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1506 __ b(eq, &adaptor);
1507
1508 // Check index against formal parameters count limit passed in
1509 // through register r0. Use unsigned comparison to get negative
1510 // check for free.
1511 __ cmp(r1, r0);
Ben Murdoch086aeea2011-05-13 15:57:08 +01001512 __ b(hs, &slow);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001513
1514 // Read the argument from the stack and return it.
1515 __ sub(r3, r0, r1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001516 __ add(r3, fp, Operand::PointerOffsetFromSmiKey(r3));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001517 __ ldr(r0, MemOperand(r3, kDisplacement));
1518 __ Jump(lr);
1519
1520 // Arguments adaptor case: Check index against actual arguments
1521 // limit found in the arguments adaptor frame. Use unsigned
1522 // comparison to get negative check for free.
1523 __ bind(&adaptor);
1524 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1525 __ cmp(r1, r0);
1526 __ b(cs, &slow);
1527
1528 // Read the argument from the adaptor frame and return it.
1529 __ sub(r3, r0, r1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001530 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r3));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001531 __ ldr(r0, MemOperand(r3, kDisplacement));
1532 __ Jump(lr);
1533
1534 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1535 // by calling the runtime system.
1536 __ bind(&slow);
1537 __ push(r1);
1538 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1539}
1540
1541
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001542void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001543 // sp[0] : number of parameters
1544 // sp[4] : receiver displacement
1545 // sp[8] : function
1546
1547 // Check if the calling frame is an arguments adaptor frame.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001548 Label runtime;
1549 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1550 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1551 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1552 __ b(ne, &runtime);
1553
1554 // Patch the arguments.length and the parameters pointer in the current frame.
1555 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1556 __ str(r2, MemOperand(sp, 0 * kPointerSize));
1557 __ add(r3, r3, Operand(r2, LSL, 1));
1558 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1559 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1560
1561 __ bind(&runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001562 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001563}
1564
1565
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001566void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001567 // Stack layout:
1568 // sp[0] : number of parameters (tagged)
1569 // sp[4] : address of receiver argument
1570 // sp[8] : function
1571 // Registers used over whole function:
1572 // r6 : allocated object (tagged)
1573 // r9 : mapped parameter count (tagged)
1574
1575 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
1576 // r1 = parameter count (tagged)
1577
1578 // Check if the calling frame is an arguments adaptor frame.
1579 Label runtime;
1580 Label adaptor_frame, try_allocate;
1581 __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1582 __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
1583 __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1584 __ b(eq, &adaptor_frame);
1585
1586 // No adaptor, parameter count = argument count.
1587 __ mov(r2, r1);
1588 __ b(&try_allocate);
1589
1590 // We have an adaptor frame. Patch the parameters pointer.
1591 __ bind(&adaptor_frame);
1592 __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1593 __ add(r3, r3, Operand(r2, LSL, 1));
1594 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1595 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1596
1597 // r1 = parameter count (tagged)
1598 // r2 = argument count (tagged)
1599 // Compute the mapped parameter count = min(r1, r2) in r1.
1600 __ cmp(r1, Operand(r2));
1601 __ mov(r1, Operand(r2), LeaveCC, gt);
1602
1603 __ bind(&try_allocate);
1604
1605 // Compute the sizes of backing store, parameter map, and arguments object.
1606 // 1. Parameter map, has 2 extra words containing context and backing store.
1607 const int kParameterMapHeaderSize =
1608 FixedArray::kHeaderSize + 2 * kPointerSize;
1609 // If there are no mapped parameters, we do not need the parameter_map.
1610 __ cmp(r1, Operand(Smi::FromInt(0)));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001611 __ mov(r9, Operand::Zero(), LeaveCC, eq);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001612 __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne);
1613 __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
1614
1615 // 2. Backing store.
1616 __ add(r9, r9, Operand(r2, LSL, 1));
1617 __ add(r9, r9, Operand(FixedArray::kHeaderSize));
1618
1619 // 3. Arguments object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001620 __ add(r9, r9, Operand(Heap::kSloppyArgumentsObjectSize));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001621
1622 // Do the allocation of all three objects in one go.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001623 __ Allocate(r9, r0, r3, r4, &runtime, TAG_OBJECT);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001624
1625 // r0 = address of new object(s) (tagged)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001626 // r2 = argument count (smi-tagged)
1627 // Get the arguments boilerplate from the current native context into r4.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001628 const int kNormalOffset =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001629 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001630 const int kAliasedOffset =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001631 Context::SlotOffset(Context::ALIASED_ARGUMENTS_MAP_INDEX);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001632
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001633 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1634 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001635 __ cmp(r1, Operand::Zero());
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001636 __ ldr(r4, MemOperand(r4, kNormalOffset), eq);
1637 __ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
1638
1639 // r0 = address of new object (tagged)
1640 // r1 = mapped parameter count (tagged)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001641 // r2 = argument count (smi-tagged)
1642 // r4 = address of arguments map (tagged)
1643 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1644 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1645 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1646 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001647
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001648 // Set up the callee in-object property.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001649 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1650 __ ldr(r3, MemOperand(sp, 2 * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001651 __ AssertNotSmi(r3);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001652 const int kCalleeOffset = JSObject::kHeaderSize +
1653 Heap::kArgumentsCalleeIndex * kPointerSize;
1654 __ str(r3, FieldMemOperand(r0, kCalleeOffset));
1655
1656 // Use the length (smi tagged) and set that as an in-object property too.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001657 __ AssertSmi(r2);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001658 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1659 const int kLengthOffset = JSObject::kHeaderSize +
1660 Heap::kArgumentsLengthIndex * kPointerSize;
1661 __ str(r2, FieldMemOperand(r0, kLengthOffset));
1662
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001663 // Set up the elements pointer in the allocated arguments object.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001664 // If we allocated a parameter map, r4 will point there, otherwise
1665 // it will point to the backing store.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001666 __ add(r4, r0, Operand(Heap::kSloppyArgumentsObjectSize));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001667 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1668
1669 // r0 = address of new object (tagged)
1670 // r1 = mapped parameter count (tagged)
1671 // r2 = argument count (tagged)
1672 // r4 = address of parameter map or backing store (tagged)
1673 // Initialize parameter map. If there are no mapped arguments, we're done.
1674 Label skip_parameter_map;
1675 __ cmp(r1, Operand(Smi::FromInt(0)));
1676 // Move backing store address to r3, because it is
1677 // expected there when filling in the unmapped arguments.
1678 __ mov(r3, r4, LeaveCC, eq);
1679 __ b(eq, &skip_parameter_map);
1680
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001681 __ LoadRoot(r6, Heap::kSloppyArgumentsElementsMapRootIndex);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001682 __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset));
1683 __ add(r6, r1, Operand(Smi::FromInt(2)));
1684 __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001685 __ str(cp, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001686 __ add(r6, r4, Operand(r1, LSL, 1));
1687 __ add(r6, r6, Operand(kParameterMapHeaderSize));
1688 __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
1689
1690 // Copy the parameter slots and the holes in the arguments.
1691 // We need to fill in mapped_parameter_count slots. They index the context,
1692 // where parameters are stored in reverse order, at
1693 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1694 // The mapped parameter thus need to get indices
1695 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1696 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1697 // We loop from right to left.
1698 Label parameters_loop, parameters_test;
1699 __ mov(r6, r1);
1700 __ ldr(r9, MemOperand(sp, 0 * kPointerSize));
1701 __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1702 __ sub(r9, r9, Operand(r1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001703 __ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001704 __ add(r3, r4, Operand(r6, LSL, 1));
1705 __ add(r3, r3, Operand(kParameterMapHeaderSize));
1706
1707 // r6 = loop variable (tagged)
1708 // r1 = mapping index (tagged)
1709 // r3 = address of backing store (tagged)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001710 // r4 = address of parameter map (tagged), which is also the address of new
1711 // object + Heap::kSloppyArgumentsObjectSize (tagged)
1712 // r0 = temporary scratch (a.o., for address calculation)
1713 // r5 = the hole value
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001714 __ jmp(&parameters_test);
1715
1716 __ bind(&parameters_loop);
1717 __ sub(r6, r6, Operand(Smi::FromInt(1)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001718 __ mov(r0, Operand(r6, LSL, 1));
1719 __ add(r0, r0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1720 __ str(r9, MemOperand(r4, r0));
1721 __ sub(r0, r0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1722 __ str(r5, MemOperand(r3, r0));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001723 __ add(r9, r9, Operand(Smi::FromInt(1)));
1724 __ bind(&parameters_test);
1725 __ cmp(r6, Operand(Smi::FromInt(0)));
1726 __ b(ne, &parameters_loop);
1727
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001728 // Restore r0 = new object (tagged)
1729 __ sub(r0, r4, Operand(Heap::kSloppyArgumentsObjectSize));
1730
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001731 __ bind(&skip_parameter_map);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001732 // r0 = address of new object (tagged)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001733 // r2 = argument count (tagged)
1734 // r3 = address of backing store (tagged)
1735 // r5 = scratch
1736 // Copy arguments header and remaining slots (if there are any).
1737 __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex);
1738 __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset));
1739 __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset));
1740
1741 Label arguments_loop, arguments_test;
1742 __ mov(r9, r1);
1743 __ ldr(r4, MemOperand(sp, 1 * kPointerSize));
1744 __ sub(r4, r4, Operand(r9, LSL, 1));
1745 __ jmp(&arguments_test);
1746
1747 __ bind(&arguments_loop);
1748 __ sub(r4, r4, Operand(kPointerSize));
1749 __ ldr(r6, MemOperand(r4, 0));
1750 __ add(r5, r3, Operand(r9, LSL, 1));
1751 __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize));
1752 __ add(r9, r9, Operand(Smi::FromInt(1)));
1753
1754 __ bind(&arguments_test);
1755 __ cmp(r9, Operand(r2));
1756 __ b(lt, &arguments_loop);
1757
1758 // Return and remove the on-stack parameters.
1759 __ add(sp, sp, Operand(3 * kPointerSize));
1760 __ Ret();
1761
1762 // Do the runtime call to allocate the arguments object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001763 // r0 = address of new object (tagged)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001764 // r2 = argument count (tagged)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001765 __ bind(&runtime);
1766 __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001767 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1768}
1769
1770
1771void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1772 // Return address is in lr.
1773 Label slow;
1774
1775 Register receiver = LoadDescriptor::ReceiverRegister();
1776 Register key = LoadDescriptor::NameRegister();
1777
1778 // Check that the key is an array index, that is Uint32.
1779 __ NonNegativeSmiTst(key);
1780 __ b(ne, &slow);
1781
1782 // Everything is fine, call runtime.
1783 __ Push(receiver, key); // Receiver, key.
1784
1785 // Perform tail call to the entry.
1786 __ TailCallExternalReference(
1787 ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
1788 masm->isolate()),
1789 2, 1);
1790
1791 __ bind(&slow);
1792 PropertyAccessCompiler::TailCallBuiltin(
1793 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001794}
1795
1796
1797void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1798 // sp[0] : number of parameters
1799 // sp[4] : receiver displacement
1800 // sp[8] : function
1801 // Check if the calling frame is an arguments adaptor frame.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001802 Label adaptor_frame, try_allocate, runtime;
1803 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1804 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
1805 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1806 __ b(eq, &adaptor_frame);
1807
1808 // Get the length from the frame.
1809 __ ldr(r1, MemOperand(sp, 0));
1810 __ b(&try_allocate);
1811
1812 // Patch the arguments.length and the parameters pointer.
1813 __ bind(&adaptor_frame);
1814 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1815 __ str(r1, MemOperand(sp, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001816 __ add(r3, r2, Operand::PointerOffsetFromSmiKey(r1));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001817 __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
1818 __ str(r3, MemOperand(sp, 1 * kPointerSize));
1819
1820 // Try the new space allocation. Start out with computing the size
1821 // of the arguments object and the elements array in words.
1822 Label add_arguments_object;
1823 __ bind(&try_allocate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001824 __ SmiUntag(r1, SetCC);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001825 __ b(eq, &add_arguments_object);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001826 __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
1827 __ bind(&add_arguments_object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001828 __ add(r1, r1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001829
1830 // Do the allocation of both objects in one go.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001831 __ Allocate(r1, r0, r2, r3, &runtime,
1832 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001833
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001834 // Get the arguments boilerplate from the current native context.
1835 __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1836 __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
1837 __ ldr(r4, MemOperand(
1838 r4, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001839
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001840 __ str(r4, FieldMemOperand(r0, JSObject::kMapOffset));
1841 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
1842 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
1843 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001844
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001845 // Get the length (smi tagged) and set that as an in-object property too.
Steve Block44f0eee2011-05-26 01:26:41 +01001846 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001847 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001848 __ AssertSmi(r1);
Steve Block44f0eee2011-05-26 01:26:41 +01001849 __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001850 Heap::kArgumentsLengthIndex * kPointerSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001851
1852 // If there are no actual arguments, we're done.
1853 Label done;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001854 __ cmp(r1, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001855 __ b(eq, &done);
1856
1857 // Get the parameters pointer from the stack.
1858 __ ldr(r2, MemOperand(sp, 1 * kPointerSize));
1859
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001860 // Set up the elements pointer in the allocated arguments object and
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001861 // initialize the header in the elements fixed array.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001862 __ add(r4, r0, Operand(Heap::kStrictArgumentsObjectSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001863 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
1864 __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
1865 __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
1866 __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001867 __ SmiUntag(r1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001868
1869 // Copy the fixed array slots.
1870 Label loop;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001871 // Set up r4 to point to the first array slot.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001872 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1873 __ bind(&loop);
1874 // Pre-decrement r2 with kPointerSize on each iteration.
1875 // Pre-decrement in order to skip receiver.
1876 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
1877 // Post-increment r4 with kPointerSize on each iteration.
1878 __ str(r3, MemOperand(r4, kPointerSize, PostIndex));
1879 __ sub(r1, r1, Operand(1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001880 __ cmp(r1, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001881 __ b(ne, &loop);
1882
1883 // Return and remove the on-stack parameters.
1884 __ bind(&done);
1885 __ add(sp, sp, Operand(3 * kPointerSize));
1886 __ Ret();
1887
1888 // Do the runtime call to allocate the arguments object.
1889 __ bind(&runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001890 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001891}
1892
1893
1894void RegExpExecStub::Generate(MacroAssembler* masm) {
1895 // Just jump directly to runtime if native RegExp is not selected at compile
1896 // time or if regexp entry in generated code is turned off runtime switch or
1897 // at compilation.
1898#ifdef V8_INTERPRETED_REGEXP
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001899 __ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001900#else // V8_INTERPRETED_REGEXP
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001901
1902 // Stack frame on entry.
1903 // sp[0]: last_match_info (expected JSArray)
1904 // sp[4]: previous index
1905 // sp[8]: subject string
1906 // sp[12]: JSRegExp object
1907
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001908 const int kLastMatchInfoOffset = 0 * kPointerSize;
1909 const int kPreviousIndexOffset = 1 * kPointerSize;
1910 const int kSubjectOffset = 2 * kPointerSize;
1911 const int kJSRegExpOffset = 3 * kPointerSize;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001912
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001913 Label runtime;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001914 // Allocation of registers for this function. These are in callee save
1915 // registers and will be preserved by the call to the native RegExp code, as
1916 // this code is called using the normal C calling convention. When calling
1917 // directly from generated code the native RegExp code will not do a GC and
1918 // therefore the content of these registers are safe to use after the call.
1919 Register subject = r4;
1920 Register regexp_data = r5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001921 Register last_match_info_elements = no_reg; // will be r6;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001922
1923 // Ensure that a RegExp stack is allocated.
1924 ExternalReference address_of_regexp_stack_memory_address =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001925 ExternalReference::address_of_regexp_stack_memory_address(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001926 ExternalReference address_of_regexp_stack_memory_size =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001927 ExternalReference::address_of_regexp_stack_memory_size(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001928 __ mov(r0, Operand(address_of_regexp_stack_memory_size));
1929 __ ldr(r0, MemOperand(r0, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001930 __ cmp(r0, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001931 __ b(eq, &runtime);
1932
1933 // Check that the first argument is a JSRegExp object.
1934 __ ldr(r0, MemOperand(sp, kJSRegExpOffset));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001935 __ JumpIfSmi(r0, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001936 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
1937 __ b(ne, &runtime);
1938
1939 // Check that the RegExp has been compiled (data contains a fixed array).
1940 __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
1941 if (FLAG_debug_code) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001942 __ SmiTst(regexp_data);
1943 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001944 __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001945 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001946 }
1947
1948 // regexp_data: RegExp data (FixedArray)
1949 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1950 __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1951 __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
1952 __ b(ne, &runtime);
1953
1954 // regexp_data: RegExp data (FixedArray)
1955 // Check that the number of captures fit in the static offsets vector buffer.
1956 __ ldr(r2,
1957 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001958 // Check (number_of_captures + 1) * 2 <= offsets vector size
1959 // Or number_of_captures * 2 <= offsets vector size - 2
1960 // Multiplying by 2 comes for free since r2 is smi-tagged.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001961 STATIC_ASSERT(kSmiTag == 0);
1962 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001963 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1964 __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001965 __ b(hi, &runtime);
1966
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001967 // Reset offset for possibly sliced string.
1968 __ mov(r9, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001969 __ ldr(subject, MemOperand(sp, kSubjectOffset));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001970 __ JumpIfSmi(subject, &runtime);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001971 __ mov(r3, subject); // Make a copy of the original subject string.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001972 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
1973 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001974 // subject: subject string
1975 // r3: subject string
1976 // r0: subject string instance type
1977 // regexp_data: RegExp data (FixedArray)
1978 // Handle subject string according to its encoding and representation:
1979 // (1) Sequential string? If yes, go to (5).
1980 // (2) Anything but sequential or cons? If yes, go to (6).
1981 // (3) Cons string. If the string is flat, replace subject with first string.
1982 // Otherwise bailout.
1983 // (4) Is subject external? If yes, go to (7).
1984 // (5) Sequential string. Load regexp code according to encoding.
1985 // (E) Carry on.
1986 /// [...]
1987
1988 // Deferred code at the end of the stub:
1989 // (6) Not a long external string? If yes, go to (8).
1990 // (7) External string. Make it, offset-wise, look like a sequential string.
1991 // Go to (5).
1992 // (8) Short external string or not a string? If yes, bail out to runtime.
1993 // (9) Sliced string. Replace subject with parent. Go to (4).
1994
1995 Label seq_string /* 5 */, external_string /* 7 */,
1996 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
1997 not_long_external /* 8 */;
1998
1999 // (1) Sequential string? If yes, go to (5).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002000 __ and_(r1,
2001 r0,
2002 Operand(kIsNotStringMask |
2003 kStringRepresentationMask |
2004 kShortExternalStringMask),
2005 SetCC);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002006 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002007 __ b(eq, &seq_string); // Go to (5).
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002009 // (2) Anything but sequential or cons? If yes, go to (6).
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002010 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2011 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002012 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2013 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002014 __ cmp(r1, Operand(kExternalStringTag));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002015 __ b(ge, &not_seq_nor_cons); // Go to (6).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002016
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002017 // (3) Cons string. Check that it's flat.
2018 // Replace subject with first string and reload instance type.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002019 __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002020 __ CompareRoot(r0, Heap::kempty_stringRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002021 __ b(ne, &runtime);
2022 __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002023
2024 // (4) Is subject external? If yes, go to (7).
2025 __ bind(&check_underlying);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002026 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2027 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002028 STATIC_ASSERT(kSeqStringTag == 0);
2029 __ tst(r0, Operand(kStringRepresentationMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002030 // The underlying external string is never a short external string.
2031 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2032 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2033 __ b(ne, &external_string); // Go to (7).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002034
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002035 // (5) Sequential string. Load regexp code according to encoding.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002036 __ bind(&seq_string);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002037 // subject: sequential subject string (or look-alike, external string)
2038 // r3: original subject string
2039 // Load previous index and check range before r3 is overwritten. We have to
2040 // use r3 instead of subject here because subject might have been only made
2041 // to look like a sequential string when it actually is an external string.
2042 __ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
2043 __ JumpIfNotSmi(r1, &runtime);
2044 __ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
2045 __ cmp(r3, Operand(r1));
2046 __ b(ls, &runtime);
2047 __ SmiUntag(r1);
2048
2049 STATIC_ASSERT(4 == kOneByteStringTag);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002050 STATIC_ASSERT(kTwoByteStringTag == 0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002051 __ and_(r0, r0, Operand(kStringEncodingMask));
2052 __ mov(r3, Operand(r0, ASR, 2), SetCC);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002053 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset),
2054 ne);
2055 __ ldr(r6, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002056
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002057 // (E) Carry on. String handling is done.
2058 // r6: irregexp code
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002059 // Check that the irregexp code has been generated for the actual string
2060 // encoding. If it has, the field contains a code object otherwise it contains
Ben Murdoch257744e2011-11-30 15:57:28 +00002061 // a smi (code flushing support).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002062 __ JumpIfSmi(r6, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002063
2064 // r1: previous index
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002065 // r3: encoding of subject string (1 if one_byte, 0 if two_byte);
2066 // r6: code
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002067 // subject: Subject string
2068 // regexp_data: RegExp data (FixedArray)
2069 // All checks done. Now push arguments for native regexp code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002070 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r0, r2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002071
Steve Block44f0eee2011-05-26 01:26:41 +01002072 // Isolates: note we add an additional parameter here (isolate pointer).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002073 const int kRegExpExecuteArguments = 9;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002074 const int kParameterRegisters = 4;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002075 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002076
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002077 // Stack pointer now points to cell where return address is to be written.
2078 // Arguments are before that on the stack or in registers.
2079
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002080 // Argument 9 (sp[20]): Pass current isolate address.
2081 __ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2082 __ str(r0, MemOperand(sp, 5 * kPointerSize));
2083
2084 // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
2085 __ mov(r0, Operand(1));
Steve Block44f0eee2011-05-26 01:26:41 +01002086 __ str(r0, MemOperand(sp, 4 * kPointerSize));
2087
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002088 // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002089 __ mov(r0, Operand(address_of_regexp_stack_memory_address));
2090 __ ldr(r0, MemOperand(r0, 0));
2091 __ mov(r2, Operand(address_of_regexp_stack_memory_size));
2092 __ ldr(r2, MemOperand(r2, 0));
2093 __ add(r0, r0, Operand(r2));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002094 __ str(r0, MemOperand(sp, 3 * kPointerSize));
2095
2096 // Argument 6: Set the number of capture registers to zero to force global
2097 // regexps to behave as non-global. This does not affect non-global regexps.
2098 __ mov(r0, Operand::Zero());
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002099 __ str(r0, MemOperand(sp, 2 * kPointerSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002100
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002101 // Argument 5 (sp[4]): static offsets vector buffer.
Steve Block44f0eee2011-05-26 01:26:41 +01002102 __ mov(r0,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002103 Operand(ExternalReference::address_of_static_offsets_vector(
2104 isolate())));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002105 __ str(r0, MemOperand(sp, 1 * kPointerSize));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002106
2107 // For arguments 4 and 3 get string length, calculate start of string data and
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002108 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2109 __ add(r7, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002110 __ eor(r3, r3, Operand(1));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002111 // Load the length from the original subject string from the previous stack
2112 // frame. Therefore we have to use fp, which points exactly to two pointer
2113 // sizes below the previous sp. (Because creating a new stack frame pushes
2114 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
Ben Murdoch589d6972011-11-30 16:04:58 +00002115 __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002116 // If slice offset is not 0, load the length from the original sliced string.
2117 // Argument 4, r3: End of string data
2118 // Argument 3, r2: Start of string data
2119 // Prepare start and end index of the input.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002120 __ add(r9, r7, Operand(r9, LSL, r3));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002121 __ add(r2, r9, Operand(r1, LSL, r3));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002122
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002123 __ ldr(r7, FieldMemOperand(subject, String::kLengthOffset));
2124 __ SmiUntag(r7);
2125 __ add(r3, r9, Operand(r7, LSL, r3));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002126
2127 // Argument 2 (r1): Previous index.
2128 // Already there
2129
2130 // Argument 1 (r0): Subject string.
Ben Murdoch589d6972011-11-30 16:04:58 +00002131 __ mov(r0, subject);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002132
2133 // Locate the code entry and call it.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002134 __ add(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
2135 DirectCEntryStub stub(isolate());
2136 stub.GenerateCall(masm, r6);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002137
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002138 __ LeaveExitFrame(false, no_reg, true);
2139
2140 last_match_info_elements = r6;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002141
2142 // r0: result
2143 // subject: subject string (callee saved)
2144 // regexp_data: RegExp data (callee saved)
2145 // last_match_info_elements: Last match info elements (callee saved)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002146 // Check the result.
2147 Label success;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002148 __ cmp(r0, Operand(1));
2149 // We expect exactly one result since we force the called regexp to behave
2150 // as non-global.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002151 __ b(eq, &success);
2152 Label failure;
Ben Murdoch589d6972011-11-30 16:04:58 +00002153 __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002154 __ b(eq, &failure);
Ben Murdoch589d6972011-11-30 16:04:58 +00002155 __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002156 // If not exception it can only be retry. Handle that in the runtime system.
2157 __ b(ne, &runtime);
2158 // Result must now be exception. If there is no pending exception already a
2159 // stack overflow (on the backtrack stack) was detected in RegExp code but
2160 // haven't created the exception yet. Handle that in the runtime system.
2161 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002162 __ mov(r1, Operand(isolate()->factory()->the_hole_value()));
Ben Murdoch589d6972011-11-30 16:04:58 +00002163 __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002164 isolate())));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002165 __ ldr(r0, MemOperand(r2, 0));
Ben Murdoch589d6972011-11-30 16:04:58 +00002166 __ cmp(r0, r1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002167 __ b(eq, &runtime);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002168
2169 __ str(r1, MemOperand(r2, 0)); // Clear pending exception.
2170
2171 // Check if the exception is a termination. If so, throw as uncatchable.
Ben Murdoch589d6972011-11-30 16:04:58 +00002172 __ CompareRoot(r0, Heap::kTerminationExceptionRootIndex);
2173
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002174 Label termination_exception;
2175 __ b(eq, &termination_exception);
2176
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002177 __ Throw(r0);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002178
2179 __ bind(&termination_exception);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002180 __ ThrowUncatchable(r0);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002181
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002182 __ bind(&failure);
2183 // For failure and exception return null.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002184 __ mov(r0, Operand(isolate()->factory()->null_value()));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002185 __ add(sp, sp, Operand(4 * kPointerSize));
2186 __ Ret();
2187
2188 // Process the result from the native regexp code.
2189 __ bind(&success);
2190 __ ldr(r1,
2191 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2192 // Calculate number of capture registers (number_of_captures + 1) * 2.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002193 // Multiplying by 2 comes for free since r1 is smi-tagged.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002194 STATIC_ASSERT(kSmiTag == 0);
2195 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2196 __ add(r1, r1, Operand(2)); // r1 was a smi.
2197
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002198 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2199 __ JumpIfSmi(r0, &runtime);
2200 __ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
2201 __ b(ne, &runtime);
2202 // Check that the JSArray is in fast case.
2203 __ ldr(last_match_info_elements,
2204 FieldMemOperand(r0, JSArray::kElementsOffset));
2205 __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2206 __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
2207 __ b(ne, &runtime);
2208 // Check that the last match info has space for the capture registers and the
2209 // additional information.
2210 __ ldr(r0,
2211 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2212 __ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
2213 __ cmp(r2, Operand::SmiUntag(r0));
2214 __ b(gt, &runtime);
2215
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002216 // r1: number of capture registers
2217 // r4: subject string
2218 // Store the capture count.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002219 __ SmiTag(r2, r1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002220 __ str(r2, FieldMemOperand(last_match_info_elements,
2221 RegExpImpl::kLastCaptureCountOffset));
2222 // Store last subject and last input.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002223 __ str(subject,
2224 FieldMemOperand(last_match_info_elements,
2225 RegExpImpl::kLastSubjectOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002226 __ mov(r2, subject);
2227 __ RecordWriteField(last_match_info_elements,
2228 RegExpImpl::kLastSubjectOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002229 subject,
2230 r3,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002231 kLRHasNotBeenSaved,
2232 kDontSaveFPRegs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002233 __ mov(subject, r2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002234 __ str(subject,
2235 FieldMemOperand(last_match_info_elements,
2236 RegExpImpl::kLastInputOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002237 __ RecordWriteField(last_match_info_elements,
2238 RegExpImpl::kLastInputOffset,
2239 subject,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002240 r3,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002241 kLRHasNotBeenSaved,
2242 kDontSaveFPRegs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002243
2244 // Get the static offsets vector filled by the native regexp code.
2245 ExternalReference address_of_static_offsets_vector =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002246 ExternalReference::address_of_static_offsets_vector(isolate());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002247 __ mov(r2, Operand(address_of_static_offsets_vector));
2248
2249 // r1: number of capture registers
2250 // r2: offsets vector
2251 Label next_capture, done;
2252 // Capture register counter starts from number of capture registers and
2253 // counts down until wraping after zero.
2254 __ add(r0,
2255 last_match_info_elements,
2256 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2257 __ bind(&next_capture);
2258 __ sub(r1, r1, Operand(1), SetCC);
2259 __ b(mi, &done);
2260 // Read the value from the static offsets vector buffer.
2261 __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
2262 // Store the smi value in the last match info.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002263 __ SmiTag(r3);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002264 __ str(r3, MemOperand(r0, kPointerSize, PostIndex));
2265 __ jmp(&next_capture);
2266 __ bind(&done);
2267
2268 // Return last match info.
2269 __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
2270 __ add(sp, sp, Operand(4 * kPointerSize));
2271 __ Ret();
2272
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002273 // Do the runtime call to execute the regexp.
2274 __ bind(&runtime);
2275 __ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1);
2276
2277 // Deferred code for string handling.
2278 // (6) Not a long external string? If yes, go to (8).
2279 __ bind(&not_seq_nor_cons);
2280 // Compare flags are still set.
2281 __ b(gt, &not_long_external); // Go to (8).
2282
2283 // (7) External string. Make it, offset-wise, look like a sequential string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002284 __ bind(&external_string);
2285 __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
2286 __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
2287 if (FLAG_debug_code) {
2288 // Assert that we do not have a cons or slice (indirect strings) here.
2289 // Sequential strings have already been ruled out.
2290 __ tst(r0, Operand(kIsIndirectStringMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002291 __ Assert(eq, kExternalStringExpectedButNotFound);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002292 }
2293 __ ldr(subject,
2294 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2295 // Move the pointer so that offset-wise, it looks like a sequential string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002296 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002297 __ sub(subject,
2298 subject,
2299 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002300 __ jmp(&seq_string); // Go to (5).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002301
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002302 // (8) Short external string or not a string? If yes, bail out to runtime.
2303 __ bind(&not_long_external);
2304 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2305 __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
2306 __ b(ne, &runtime);
2307
2308 // (9) Sliced string. Replace subject with parent. Go to (4).
2309 // Load offset into r9 and replace subject string with parent.
2310 __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2311 __ SmiUntag(r9);
2312 __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2313 __ jmp(&check_underlying); // Go to (4).
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002314#endif // V8_INTERPRETED_REGEXP
2315}
2316
2317
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002318static void GenerateRecordCallTarget(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002319 // Cache the called function in a feedback vector slot. Cache states
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002320 // are uninitialized, monomorphic (indicated by a JSFunction), and
2321 // megamorphic.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002322 // r0 : number of arguments to the construct function
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002323 // r1 : the function to call
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002324 // r2 : Feedback vector
2325 // r3 : slot in feedback vector (Smi)
2326 Label initialize, done, miss, megamorphic, not_array_function;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002327
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002328 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2329 masm->isolate()->heap()->megamorphic_symbol());
2330 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2331 masm->isolate()->heap()->uninitialized_symbol());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002332
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002333 // Load the cache state into r4.
2334 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2335 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002336
2337 // A monomorphic cache hit or an already megamorphic state: invoke the
2338 // function without changing the state.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002339 __ cmp(r4, r1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002340 __ b(eq, &done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002341
2342 if (!FLAG_pretenuring_call_new) {
2343 // If we came here, we need to see if we are the array function.
2344 // If we didn't have a matching function, and we didn't find the megamorph
2345 // sentinel, then we have in the slot either some other function or an
2346 // AllocationSite. Do a map check on the object in ecx.
2347 __ ldr(r5, FieldMemOperand(r4, 0));
2348 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2349 __ b(ne, &miss);
2350
2351 // Make sure the function is the Array() function
2352 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2353 __ cmp(r1, r4);
2354 __ b(ne, &megamorphic);
2355 __ jmp(&done);
2356 }
2357
2358 __ bind(&miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002359
2360 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2361 // megamorphic.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002362 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002363 __ b(eq, &initialize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002364 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2365 // write-barrier is needed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002366 __ bind(&megamorphic);
2367 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002368 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002369 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2370 __ jmp(&done);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002371
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002372 // An uninitialized cache is patched with the function
2373 __ bind(&initialize);
2374
2375 if (!FLAG_pretenuring_call_new) {
2376 // Make sure the function is the Array() function
2377 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2378 __ cmp(r1, r4);
2379 __ b(ne, &not_array_function);
2380
2381 // The target function is the Array constructor,
2382 // Create an AllocationSite if we don't already have it, store it in the
2383 // slot.
2384 {
2385 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2386
2387 // Arguments register must be smi-tagged to call out.
2388 __ SmiTag(r0);
2389 __ Push(r3, r2, r1, r0);
2390
2391 CreateAllocationSiteStub create_stub(masm->isolate());
2392 __ CallStub(&create_stub);
2393
2394 __ Pop(r3, r2, r1, r0);
2395 __ SmiUntag(r0);
2396 }
2397 __ b(&done);
2398
2399 __ bind(&not_array_function);
2400 }
2401
2402 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2403 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2404 __ str(r1, MemOperand(r4, 0));
2405
2406 __ Push(r4, r2, r1);
2407 __ RecordWrite(r2, r4, r1, kLRHasNotBeenSaved, kDontSaveFPRegs,
2408 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
2409 __ Pop(r4, r2, r1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002410
2411 __ bind(&done);
2412}
2413
2414
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002415static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2416 // Do not transform the receiver for strict mode functions.
2417 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2418 __ ldr(r4, FieldMemOperand(r3, SharedFunctionInfo::kCompilerHintsOffset));
2419 __ tst(r4, Operand(1 << (SharedFunctionInfo::kStrictModeFunction +
2420 kSmiTagSize)));
2421 __ b(ne, cont);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002422
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002423 // Do not transform the receiver for native (Compilerhints already in r3).
2424 __ tst(r4, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
2425 __ b(ne, cont);
2426}
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002427
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002428
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002429static void EmitSlowCase(MacroAssembler* masm,
2430 int argc,
2431 Label* non_function) {
Ben Murdoch589d6972011-11-30 16:04:58 +00002432 // Check for function proxy.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002433 __ cmp(r4, Operand(JS_FUNCTION_PROXY_TYPE));
2434 __ b(ne, non_function);
Ben Murdoch589d6972011-11-30 16:04:58 +00002435 __ push(r1); // put proxy as additional argument
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002436 __ mov(r0, Operand(argc + 1, RelocInfo::NONE32));
2437 __ mov(r2, Operand::Zero());
2438 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY);
Ben Murdoch589d6972011-11-30 16:04:58 +00002439 {
2440 Handle<Code> adaptor =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002441 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
Ben Murdoch589d6972011-11-30 16:04:58 +00002442 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2443 }
2444
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002445 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2446 // of the original receiver from the call site).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002447 __ bind(non_function);
2448 __ str(r1, MemOperand(sp, argc * kPointerSize));
2449 __ mov(r0, Operand(argc)); // Set up the number of arguments.
2450 __ mov(r2, Operand::Zero());
2451 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION);
Steve Block44f0eee2011-05-26 01:26:41 +01002452 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002453 RelocInfo::CODE_TARGET);
2454}
2455
2456
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002457static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2458 // Wrap the receiver and patch it back onto the stack.
2459 { FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
2460 __ Push(r1, r3);
2461 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2462 __ pop(r1);
2463 }
2464 __ str(r0, MemOperand(sp, argc * kPointerSize));
2465 __ jmp(cont);
2466}
2467
2468
2469static void CallFunctionNoFeedback(MacroAssembler* masm,
2470 int argc, bool needs_checks,
2471 bool call_as_method) {
2472 // r1 : the function to call
2473 Label slow, non_function, wrap, cont;
2474
2475 if (needs_checks) {
2476 // Check that the function is really a JavaScript function.
2477 // r1: pushed function (to be verified)
2478 __ JumpIfSmi(r1, &non_function);
2479
2480 // Goto slow case if we do not have a function.
2481 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2482 __ b(ne, &slow);
2483 }
2484
2485 // Fast-case: Invoke the function now.
2486 // r1: pushed function
2487 ParameterCount actual(argc);
2488
2489 if (call_as_method) {
2490 if (needs_checks) {
2491 EmitContinueIfStrictOrNative(masm, &cont);
2492 }
2493
2494 // Compute the receiver in sloppy mode.
2495 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2496
2497 if (needs_checks) {
2498 __ JumpIfSmi(r3, &wrap);
2499 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2500 __ b(lt, &wrap);
2501 } else {
2502 __ jmp(&wrap);
2503 }
2504
2505 __ bind(&cont);
2506 }
2507
2508 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2509
2510 if (needs_checks) {
2511 // Slow-case: Non-function called.
2512 __ bind(&slow);
2513 EmitSlowCase(masm, argc, &non_function);
2514 }
2515
2516 if (call_as_method) {
2517 __ bind(&wrap);
2518 EmitWrapCase(masm, argc, &cont);
2519 }
2520}
2521
2522
2523void CallFunctionStub::Generate(MacroAssembler* masm) {
2524 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2525}
2526
2527
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002528void CallConstructStub::Generate(MacroAssembler* masm) {
2529 // r0 : number of arguments
2530 // r1 : the function to call
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002531 // r2 : feedback vector
2532 // r3 : (only if r2 is not the megamorphic symbol) slot in feedback
2533 // vector (Smi)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002534 Label slow, non_function_call;
2535
2536 // Check that the function is not a smi.
2537 __ JumpIfSmi(r1, &non_function_call);
2538 // Check that the function is a JSFunction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002539 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002540 __ b(ne, &slow);
2541
2542 if (RecordCallTarget()) {
2543 GenerateRecordCallTarget(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002544
2545 __ add(r5, r2, Operand::PointerOffsetFromSmiKey(r3));
2546 if (FLAG_pretenuring_call_new) {
2547 // Put the AllocationSite from the feedback vector into r2.
2548 // By adding kPointerSize we encode that we know the AllocationSite
2549 // entry is at the feedback vector slot given by r3 + 1.
2550 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize + kPointerSize));
2551 } else {
2552 Label feedback_register_initialized;
2553 // Put the AllocationSite from the feedback vector into r2, or undefined.
2554 __ ldr(r2, FieldMemOperand(r5, FixedArray::kHeaderSize));
2555 __ ldr(r5, FieldMemOperand(r2, AllocationSite::kMapOffset));
2556 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2557 __ b(eq, &feedback_register_initialized);
2558 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2559 __ bind(&feedback_register_initialized);
2560 }
2561
2562 __ AssertUndefinedOrAllocationSite(r2, r5);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002563 }
2564
2565 // Jump to the function-specific construct stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002566 Register jmp_reg = r4;
2567 __ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
2568 __ ldr(jmp_reg, FieldMemOperand(jmp_reg,
2569 SharedFunctionInfo::kConstructStubOffset));
2570 __ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002571
2572 // r0: number of arguments
2573 // r1: called object
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002574 // r4: object type
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002575 Label do_call;
2576 __ bind(&slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002577 __ cmp(r4, Operand(JS_FUNCTION_PROXY_TYPE));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002578 __ b(ne, &non_function_call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002579 __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002580 __ jmp(&do_call);
2581
2582 __ bind(&non_function_call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002583 __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002584 __ bind(&do_call);
2585 // Set expected number of arguments to zero (not changing r0).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002586 __ mov(r2, Operand::Zero());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002587 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2588 RelocInfo::CODE_TARGET);
2589}
2590
2591
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002592static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2593 __ ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2594 __ ldr(vector, FieldMemOperand(vector,
2595 JSFunction::kSharedFunctionInfoOffset));
2596 __ ldr(vector, FieldMemOperand(vector,
2597 SharedFunctionInfo::kFeedbackVectorOffset));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002598}
2599
2600
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002601void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2602 // r1 - function
2603 // r3 - slot id
2604 Label miss;
2605 int argc = arg_count();
2606 ParameterCount actual(argc);
2607
2608 EmitLoadTypeFeedbackVector(masm, r2);
2609
2610 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2611 __ cmp(r1, r4);
2612 __ b(ne, &miss);
2613
2614 __ mov(r0, Operand(arg_count()));
2615 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2616 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2617
2618 // Verify that r4 contains an AllocationSite
2619 __ ldr(r5, FieldMemOperand(r4, HeapObject::kMapOffset));
2620 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
2621 __ b(ne, &miss);
2622
2623 __ mov(r2, r4);
2624 ArrayConstructorStub stub(masm->isolate(), arg_count());
2625 __ TailCallStub(&stub);
2626
2627 __ bind(&miss);
2628 GenerateMiss(masm);
2629
2630 // The slow case, we need this no matter what to complete a call after a miss.
2631 CallFunctionNoFeedback(masm,
2632 arg_count(),
2633 true,
2634 CallAsMethod());
2635
2636 // Unreachable.
2637 __ stop("Unexpected code address");
2638}
2639
2640
2641void CallICStub::Generate(MacroAssembler* masm) {
2642 // r1 - function
2643 // r3 - slot id (Smi)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002644 const int with_types_offset =
2645 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2646 const int generic_offset =
2647 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002648 Label extra_checks_or_miss, slow_start;
2649 Label slow, non_function, wrap, cont;
2650 Label have_js_function;
2651 int argc = arg_count();
2652 ParameterCount actual(argc);
2653
2654 EmitLoadTypeFeedbackVector(masm, r2);
2655
2656 // The checks. First, does r1 match the recorded monomorphic target?
2657 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2658 __ ldr(r4, FieldMemOperand(r4, FixedArray::kHeaderSize));
2659 __ cmp(r1, r4);
2660 __ b(ne, &extra_checks_or_miss);
2661
2662 __ bind(&have_js_function);
2663 if (CallAsMethod()) {
2664 EmitContinueIfStrictOrNative(masm, &cont);
2665 // Compute the receiver in sloppy mode.
2666 __ ldr(r3, MemOperand(sp, argc * kPointerSize));
2667
2668 __ JumpIfSmi(r3, &wrap);
2669 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
2670 __ b(lt, &wrap);
2671
2672 __ bind(&cont);
2673 }
2674
2675 __ InvokeFunction(r1, actual, JUMP_FUNCTION, NullCallWrapper());
2676
2677 __ bind(&slow);
2678 EmitSlowCase(masm, argc, &non_function);
2679
2680 if (CallAsMethod()) {
2681 __ bind(&wrap);
2682 EmitWrapCase(masm, argc, &cont);
2683 }
2684
2685 __ bind(&extra_checks_or_miss);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002686 Label uninitialized, miss;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002687
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002688 __ CompareRoot(r4, Heap::kmegamorphic_symbolRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002689 __ b(eq, &slow_start);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002690
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002691 // The following cases attempt to handle MISS cases without going to the
2692 // runtime.
2693 if (FLAG_trace_ic) {
2694 __ jmp(&miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002695 }
2696
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002697 __ CompareRoot(r4, Heap::kuninitialized_symbolRootIndex);
2698 __ b(eq, &uninitialized);
2699
2700 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2701 // to handle it here. More complex cases are dealt with in the runtime.
2702 __ AssertNotSmi(r4);
2703 __ CompareObjectType(r4, r5, r5, JS_FUNCTION_TYPE);
2704 __ b(ne, &miss);
2705 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2706 __ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
2707 __ str(ip, FieldMemOperand(r4, FixedArray::kHeaderSize));
2708 // We have to update statistics for runtime profiling.
2709 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2710 __ sub(r4, r4, Operand(Smi::FromInt(1)));
2711 __ str(r4, FieldMemOperand(r2, with_types_offset));
2712 __ ldr(r4, FieldMemOperand(r2, generic_offset));
2713 __ add(r4, r4, Operand(Smi::FromInt(1)));
2714 __ str(r4, FieldMemOperand(r2, generic_offset));
2715 __ jmp(&slow_start);
2716
2717 __ bind(&uninitialized);
2718
2719 // We are going monomorphic, provided we actually have a JSFunction.
2720 __ JumpIfSmi(r1, &miss);
2721
2722 // Goto miss case if we do not have a function.
2723 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2724 __ b(ne, &miss);
2725
2726 // Make sure the function is not the Array() function, which requires special
2727 // behavior on MISS.
2728 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r4);
2729 __ cmp(r1, r4);
2730 __ b(eq, &miss);
2731
2732 // Update stats.
2733 __ ldr(r4, FieldMemOperand(r2, with_types_offset));
2734 __ add(r4, r4, Operand(Smi::FromInt(1)));
2735 __ str(r4, FieldMemOperand(r2, with_types_offset));
2736
2737 // Store the function.
2738 __ add(r4, r2, Operand::PointerOffsetFromSmiKey(r3));
2739 __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2740 __ str(r1, MemOperand(r4, 0));
2741
2742 // Update the write barrier.
2743 __ mov(r5, r1);
2744 __ RecordWrite(r2, r4, r5, kLRHasNotBeenSaved, kDontSaveFPRegs,
2745 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
2746 __ jmp(&have_js_function);
2747
2748 // We are here because tracing is on or we encountered a MISS case we can't
2749 // handle here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002750 __ bind(&miss);
2751 GenerateMiss(masm);
2752
2753 // the slow case
2754 __ bind(&slow_start);
2755 // Check that the function is really a JavaScript function.
2756 // r1: pushed function (to be verified)
2757 __ JumpIfSmi(r1, &non_function);
2758
2759 // Goto slow case if we do not have a function.
2760 __ CompareObjectType(r1, r4, r4, JS_FUNCTION_TYPE);
2761 __ b(ne, &slow);
2762 __ jmp(&have_js_function);
2763}
2764
2765
2766void CallICStub::GenerateMiss(MacroAssembler* masm) {
2767 // Get the receiver of the function from the stack; 1 ~ return address.
2768 __ ldr(r4, MemOperand(sp, (arg_count() + 1) * kPointerSize));
2769
2770 {
2771 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
2772
2773 // Push the receiver and the function and feedback info.
2774 __ Push(r4, r1, r2, r3);
2775
2776 // Call the entry.
2777 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
2778 : IC::kCallIC_Customization_Miss;
2779
2780 ExternalReference miss = ExternalReference(IC_Utility(id),
2781 masm->isolate());
2782 __ CallExternalReference(miss, 4);
2783
2784 // Move result to edi and exit the internal frame.
2785 __ mov(r1, r0);
2786 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002787}
2788
2789
2790// StringCharCodeAtGenerator
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002791void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002792 // If the receiver is a smi trigger the non-string case.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002793 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2794 __ JumpIfSmi(object_, receiver_not_string_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002795
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002796 // Fetch the instance type of the receiver into result register.
2797 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2798 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2799 // If the receiver is not a string trigger the non-string case.
2800 __ tst(result_, Operand(kIsNotStringMask));
2801 __ b(ne, receiver_not_string_);
2802 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002803
2804 // If the index is non-smi trigger the non-smi case.
Steve Block1e0659c2011-05-24 12:43:12 +01002805 __ JumpIfNotSmi(index_, &index_not_smi_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002806 __ bind(&got_smi_index_);
2807
2808 // Check for index out of range.
2809 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002810 __ cmp(ip, Operand(index_));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002811 __ b(ls, index_out_of_range_);
2812
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002813 __ SmiUntag(index_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002814
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002815 StringCharLoadGenerator::Generate(masm,
2816 object_,
2817 index_,
2818 result_,
2819 &call_runtime_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002820
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002821 __ SmiTag(result_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002822 __ bind(&exit_);
2823}
2824
2825
2826void StringCharCodeAtGenerator::GenerateSlow(
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002827 MacroAssembler* masm,
2828 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002829 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002830
2831 // Index is not a smi.
2832 __ bind(&index_not_smi_);
2833 // If index is a heap number, try converting it to an integer.
2834 __ CheckMap(index_,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002835 result_,
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002836 Heap::kHeapNumberMapRootIndex,
2837 index_not_number_,
Ben Murdoch257744e2011-11-30 15:57:28 +00002838 DONT_DO_SMI_CHECK);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002839 call_helper.BeforeCall(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002840 __ push(object_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002841 __ push(index_); // Consumed by runtime conversion function.
2842 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2843 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2844 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002845 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002846 // NumberToSmi discards numbers that are not exact integers.
2847 __ CallRuntime(Runtime::kNumberToSmi, 1);
2848 }
2849 // Save the conversion result before the pop instructions below
2850 // have a chance to overwrite it.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002851 __ Move(index_, r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002852 __ pop(object_);
2853 // Reload the instance type.
2854 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2855 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2856 call_helper.AfterCall(masm);
2857 // If index is still not a smi, it must be out of range.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002858 __ JumpIfNotSmi(index_, index_out_of_range_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002859 // Otherwise, return to the fast path.
2860 __ jmp(&got_smi_index_);
2861
2862 // Call runtime. We get here when the receiver is a string and the
2863 // index is a number, but the code of getting the actual character
2864 // is too complex (e.g., when the string needs to be flattened).
2865 __ bind(&call_runtime_);
2866 call_helper.BeforeCall(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002867 __ SmiTag(index_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002868 __ Push(object_, index_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002869 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002870 __ Move(result_, r0);
2871 call_helper.AfterCall(masm);
2872 __ jmp(&exit_);
2873
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002874 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002875}
2876
2877
2878// -------------------------------------------------------------------------
2879// StringCharFromCodeGenerator
2880
2881void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2882 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2883 STATIC_ASSERT(kSmiTag == 0);
2884 STATIC_ASSERT(kSmiShiftSize == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002885 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCode + 1));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002886 __ tst(code_,
2887 Operand(kSmiTagMask |
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002888 ((~String::kMaxOneByteCharCode) << kSmiTagSize)));
Steve Block1e0659c2011-05-24 12:43:12 +01002889 __ b(ne, &slow_case_);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002890
2891 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002892 // At this point code register contains smi tagged one-byte char code.
2893 __ add(result_, result_, Operand::PointerOffsetFromSmiKey(code_));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002894 __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002895 __ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002896 __ b(eq, &slow_case_);
2897 __ bind(&exit_);
2898}
2899
2900
2901void StringCharFromCodeGenerator::GenerateSlow(
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002902 MacroAssembler* masm,
2903 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002904 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002905
2906 __ bind(&slow_case_);
2907 call_helper.BeforeCall(masm);
2908 __ push(code_);
2909 __ CallRuntime(Runtime::kCharFromCode, 1);
2910 __ Move(result_, r0);
2911 call_helper.AfterCall(masm);
2912 __ jmp(&exit_);
2913
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002914 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002915}
2916
2917
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002918enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002919
2920
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002921void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2922 Register dest,
2923 Register src,
2924 Register count,
2925 Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002926 String::Encoding encoding) {
2927 if (FLAG_debug_code) {
2928 // Check that destination is word aligned.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002929 __ tst(dest, Operand(kPointerAlignmentMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002930 __ Check(eq, kDestinationOfCopyNotAligned);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002931 }
2932
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002933 // Assumes word reads and writes are little endian.
2934 // Nothing to do for zero characters.
2935 Label done;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002936 if (encoding == String::TWO_BYTE_ENCODING) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002937 __ add(count, count, Operand(count), SetCC);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002938 }
2939
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002940 Register limit = count; // Read until dest equals this.
2941 __ add(limit, dest, Operand(count));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002942
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002943 Label loop_entry, loop;
2944 // Copy bytes from src to dest until dest hits limit.
2945 __ b(&loop_entry);
2946 __ bind(&loop);
2947 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt);
2948 __ strb(scratch, MemOperand(dest, 1, PostIndex));
2949 __ bind(&loop_entry);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002950 __ cmp(dest, Operand(limit));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002951 __ b(lt, &loop);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002952
2953 __ bind(&done);
2954}
2955
2956
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002957void SubStringStub::Generate(MacroAssembler* masm) {
2958 Label runtime;
2959
2960 // Stack frame on entry.
2961 // lr: return address
2962 // sp[0]: to
2963 // sp[4]: from
2964 // sp[8]: string
2965
2966 // This stub is called from the native-call %_SubString(...), so
2967 // nothing can be assumed about the arguments. It is tested that:
2968 // "string" is a sequential string,
2969 // both "from" and "to" are smis, and
2970 // 0 <= from <= to <= string.length.
2971 // If any of these assumptions fail, we call the runtime system.
2972
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002973 const int kToOffset = 0 * kPointerSize;
2974 const int kFromOffset = 1 * kPointerSize;
2975 const int kStringOffset = 2 * kPointerSize;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002976
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002977 __ Ldrd(r2, r3, MemOperand(sp, kToOffset));
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002978 STATIC_ASSERT(kFromOffset == kToOffset + 4);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002979 STATIC_ASSERT(kSmiTag == 0);
2980 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002981
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002982 // Arithmetic shift right by one un-smi-tags. In this case we rotate right
2983 // instead because we bail out on non-smi values: ROR and ASR are equivalent
2984 // for smis but they set the flags in a way that's easier to optimize.
2985 __ mov(r2, Operand(r2, ROR, 1), SetCC);
2986 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
2987 // If either to or from had the smi tag bit set, then C is set now, and N
2988 // has the same value: we rotated by 1, so the bottom bit is now the top bit.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002989 // We want to bailout to runtime here if From is negative. In that case, the
2990 // next instruction is not executed and we fall through to bailing out to
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002991 // runtime.
2992 // Executed if both r2 and r3 are untagged integers.
2993 __ sub(r2, r2, Operand(r3), SetCC, cc);
2994 // One of the above un-smis or the above SUB could have set N==1.
2995 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
Ben Murdoch85b71792012-04-11 18:30:58 +01002996
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002997 // Make sure first argument is a string.
Ben Murdoch589d6972011-11-30 16:04:58 +00002998 __ ldr(r0, MemOperand(sp, kStringOffset));
Ben Murdoch589d6972011-11-30 16:04:58 +00002999 __ JumpIfSmi(r0, &runtime);
3000 Condition is_string = masm->IsObjectStringType(r0, r1);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003001 __ b(NegateCondition(is_string), &runtime);
3002
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003003 Label single_char;
3004 __ cmp(r2, Operand(1));
3005 __ b(eq, &single_char);
3006
Ben Murdoch589d6972011-11-30 16:04:58 +00003007 // Short-cut for the case of trivial substring.
3008 Label return_r0;
3009 // r0: original string
3010 // r2: result string length
3011 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
3012 __ cmp(r2, Operand(r4, ASR, 1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003013 // Return original string.
Ben Murdoch589d6972011-11-30 16:04:58 +00003014 __ b(eq, &return_r0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003015 // Longer than original string's length or negative: unsafe arguments.
3016 __ b(hi, &runtime);
3017 // Shorter than original string's length: an actual substring.
Ben Murdoch589d6972011-11-30 16:04:58 +00003018
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003019 // Deal with different string types: update the index if necessary
3020 // and put the underlying string into r5.
3021 // r0: original string
3022 // r1: instance type
3023 // r2: length
3024 // r3: from index (untagged)
3025 Label underlying_unpacked, sliced_string, seq_or_external_string;
3026 // If the string is not indirect, it can only be sequential or external.
3027 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3028 STATIC_ASSERT(kIsIndirectStringMask != 0);
3029 __ tst(r1, Operand(kIsIndirectStringMask));
3030 __ b(eq, &seq_or_external_string);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003031
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003032 __ tst(r1, Operand(kSlicedNotConsMask));
3033 __ b(ne, &sliced_string);
3034 // Cons string. Check whether it is flat, then fetch first part.
3035 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003036 __ CompareRoot(r5, Heap::kempty_stringRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003037 __ b(ne, &runtime);
3038 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
3039 // Update instance type.
3040 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3041 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3042 __ jmp(&underlying_unpacked);
Ben Murdoch589d6972011-11-30 16:04:58 +00003043
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003044 __ bind(&sliced_string);
3045 // Sliced string. Fetch parent and correct start index by offset.
3046 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3047 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3048 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
3049 // Update instance type.
3050 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
3051 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3052 __ jmp(&underlying_unpacked);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003053
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003054 __ bind(&seq_or_external_string);
3055 // Sequential or external string. Just move string to the expected register.
3056 __ mov(r5, r0);
3057
3058 __ bind(&underlying_unpacked);
3059
3060 if (FLAG_string_slices) {
3061 Label copy_routine;
3062 // r5: underlying subject string
3063 // r1: instance type of underlying subject string
3064 // r2: length
3065 // r3: adjusted start index (untagged)
3066 __ cmp(r2, Operand(SlicedString::kMinLength));
3067 // Short slice. Copy instead of slicing.
3068 __ b(lt, &copy_routine);
3069 // Allocate new sliced string. At this point we do not reload the instance
3070 // type including the string encoding because we simply rely on the info
3071 // provided by the original string. It does not matter if the original
3072 // string's encoding is wrong because we always have to recheck encoding of
3073 // the newly created string's parent anyways due to externalized strings.
3074 Label two_byte_slice, set_slice_header;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003075 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003076 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3077 __ tst(r1, Operand(kStringEncodingMask));
3078 __ b(eq, &two_byte_slice);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003079 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003080 __ jmp(&set_slice_header);
3081 __ bind(&two_byte_slice);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003082 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003083 __ bind(&set_slice_header);
3084 __ mov(r3, Operand(r3, LSL, 1));
3085 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
3086 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
3087 __ jmp(&return_r0);
3088
3089 __ bind(&copy_routine);
3090 }
3091
3092 // r5: underlying subject string
3093 // r1: instance type of underlying subject string
3094 // r2: length
3095 // r3: adjusted start index (untagged)
3096 Label two_byte_sequential, sequential_string, allocate_result;
3097 STATIC_ASSERT(kExternalStringTag != 0);
3098 STATIC_ASSERT(kSeqStringTag == 0);
3099 __ tst(r1, Operand(kExternalStringTag));
3100 __ b(eq, &sequential_string);
3101
3102 // Handle external string.
3103 // Rule out short external strings.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003104 STATIC_ASSERT(kShortExternalStringTag != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003105 __ tst(r1, Operand(kShortExternalStringTag));
3106 __ b(ne, &runtime);
3107 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
3108 // r5 already points to the first character of underlying string.
3109 __ jmp(&allocate_result);
3110
3111 __ bind(&sequential_string);
3112 // Locate first character of underlying subject string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003113 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3114 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003115
3116 __ bind(&allocate_result);
3117 // Sequential acii string. Allocate the result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003118 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003119 __ tst(r1, Operand(kStringEncodingMask));
3120 __ b(eq, &two_byte_sequential);
3121
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003122 // Allocate and copy the resulting one-byte string.
3123 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003124
3125 // Locate first character of substring to copy.
3126 __ add(r5, r5, r3);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003127 // Locate first character of result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003128 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003129
Ben Murdoch589d6972011-11-30 16:04:58 +00003130 // r0: result string
3131 // r1: first character of result string
3132 // r2: result string length
3133 // r5: first character of substring to copy
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003134 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3135 StringHelper::GenerateCopyCharacters(
3136 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING);
Ben Murdoch589d6972011-11-30 16:04:58 +00003137 __ jmp(&return_r0);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003138
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003139 // Allocate and copy the resulting two-byte string.
3140 __ bind(&two_byte_sequential);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003141 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003142
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003143 // Locate first character of substring to copy.
Ben Murdoch589d6972011-11-30 16:04:58 +00003144 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003145 __ add(r5, r5, Operand(r3, LSL, 1));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003146 // Locate first character of result.
3147 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch589d6972011-11-30 16:04:58 +00003148
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003149 // r0: result string.
3150 // r1: first character of result.
3151 // r2: result length.
Ben Murdoch589d6972011-11-30 16:04:58 +00003152 // r5: first character of substring to copy.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003153 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003154 StringHelper::GenerateCopyCharacters(
3155 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING);
Ben Murdoch589d6972011-11-30 16:04:58 +00003156
3157 __ bind(&return_r0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003158 Counters* counters = isolate()->counters();
Steve Block44f0eee2011-05-26 01:26:41 +01003159 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003160 __ Drop(3);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003161 __ Ret();
3162
3163 // Just jump to runtime to create the sub string.
3164 __ bind(&runtime);
3165 __ TailCallRuntime(Runtime::kSubString, 3, 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003166
3167 __ bind(&single_char);
3168 // r0: original string
3169 // r1: instance type
3170 // r2: length
3171 // r3: from index (untagged)
3172 __ SmiTag(r3, r3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003173 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime,
3174 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003175 generator.GenerateFast(masm);
3176 __ Drop(3);
3177 __ Ret();
3178 generator.SkipSlow(masm, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003179}
3180
3181
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003182void ToNumberStub::Generate(MacroAssembler* masm) {
3183 // The ToNumber stub takes one argument in r0.
3184 Label not_smi;
3185 __ JumpIfNotSmi(r0, &not_smi);
3186 __ Ret();
3187 __ bind(&not_smi);
3188
3189 Label not_heap_number;
3190 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
3191 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
3192 // r0: object
3193 // r1: instance type.
3194 __ cmp(r1, Operand(HEAP_NUMBER_TYPE));
3195 __ b(ne, &not_heap_number);
3196 __ Ret();
3197 __ bind(&not_heap_number);
3198
3199 Label not_string, slow_string;
3200 __ cmp(r1, Operand(FIRST_NONSTRING_TYPE));
3201 __ b(hs, &not_string);
3202 // Check if string has a cached array index.
3203 __ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
3204 __ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
3205 __ b(ne, &slow_string);
3206 __ IndexFromHash(r2, r0);
3207 __ Ret();
3208 __ bind(&slow_string);
3209 __ push(r0); // Push argument.
3210 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3211 __ bind(&not_string);
3212
3213 Label not_oddball;
3214 __ cmp(r1, Operand(ODDBALL_TYPE));
3215 __ b(ne, &not_oddball);
3216 __ ldr(r0, FieldMemOperand(r0, Oddball::kToNumberOffset));
3217 __ Ret();
3218 __ bind(&not_oddball);
3219
3220 __ push(r0); // Push argument.
3221 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3222}
3223
3224
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003225void StringHelper::GenerateFlatOneByteStringEquals(
3226 MacroAssembler* masm, Register left, Register right, Register scratch1,
3227 Register scratch2, Register scratch3) {
Ben Murdoch257744e2011-11-30 15:57:28 +00003228 Register length = scratch1;
3229
3230 // Compare lengths.
3231 Label strings_not_equal, check_zero_length;
3232 __ ldr(length, FieldMemOperand(left, String::kLengthOffset));
3233 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3234 __ cmp(length, scratch2);
3235 __ b(eq, &check_zero_length);
3236 __ bind(&strings_not_equal);
3237 __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
3238 __ Ret();
3239
3240 // Check if the length is zero.
3241 Label compare_chars;
3242 __ bind(&check_zero_length);
3243 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003244 __ cmp(length, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003245 __ b(ne, &compare_chars);
3246 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3247 __ Ret();
3248
3249 // Compare characters.
3250 __ bind(&compare_chars);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003251 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3252 &strings_not_equal);
Ben Murdoch257744e2011-11-30 15:57:28 +00003253
3254 // Characters are equal.
3255 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
3256 __ Ret();
3257}
3258
3259
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003260void StringHelper::GenerateCompareFlatOneByteStrings(
3261 MacroAssembler* masm, Register left, Register right, Register scratch1,
3262 Register scratch2, Register scratch3, Register scratch4) {
Ben Murdoch257744e2011-11-30 15:57:28 +00003263 Label result_not_equal, compare_lengths;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003264 // Find minimum length and length difference.
3265 __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
3266 __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
3267 __ sub(scratch3, scratch1, Operand(scratch2), SetCC);
3268 Register length_delta = scratch3;
3269 __ mov(scratch1, scratch2, LeaveCC, gt);
3270 Register min_length = scratch1;
3271 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003272 __ cmp(min_length, Operand::Zero());
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003273 __ b(eq, &compare_lengths);
3274
Ben Murdoch257744e2011-11-30 15:57:28 +00003275 // Compare loop.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003276 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3277 scratch4, &result_not_equal);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003278
Ben Murdoch257744e2011-11-30 15:57:28 +00003279 // Compare lengths - strings up to min-length are equal.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003280 __ bind(&compare_lengths);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003281 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
Ben Murdoch257744e2011-11-30 15:57:28 +00003282 // Use length_delta as result if it's zero.
3283 __ mov(r0, Operand(length_delta), SetCC);
3284 __ bind(&result_not_equal);
3285 // Conditionally update the result based either on length_delta or
3286 // the last comparion performed in the loop above.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003287 __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
3288 __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
3289 __ Ret();
3290}
3291
3292
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003293void StringHelper::GenerateOneByteCharsCompareLoop(
3294 MacroAssembler* masm, Register left, Register right, Register length,
3295 Register scratch1, Register scratch2, Label* chars_not_equal) {
Ben Murdoch257744e2011-11-30 15:57:28 +00003296 // Change index to run from -length to -1 by adding length to string
3297 // start. This means that loop ends when index reaches zero, which
3298 // doesn't need an additional compare.
3299 __ SmiUntag(length);
3300 __ add(scratch1, length,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003301 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch257744e2011-11-30 15:57:28 +00003302 __ add(left, left, Operand(scratch1));
3303 __ add(right, right, Operand(scratch1));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003304 __ rsb(length, length, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003305 Register index = length; // index = -length;
3306
3307 // Compare loop.
3308 Label loop;
3309 __ bind(&loop);
3310 __ ldrb(scratch1, MemOperand(left, index));
3311 __ ldrb(scratch2, MemOperand(right, index));
3312 __ cmp(scratch1, scratch2);
3313 __ b(ne, chars_not_equal);
3314 __ add(index, index, Operand(1), SetCC);
3315 __ b(ne, &loop);
3316}
3317
3318
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003319void StringCompareStub::Generate(MacroAssembler* masm) {
3320 Label runtime;
3321
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003322 Counters* counters = isolate()->counters();
Steve Block44f0eee2011-05-26 01:26:41 +01003323
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003324 // Stack frame on entry.
3325 // sp[0]: right string
3326 // sp[4]: left string
Kristian Monsen0d5e1162010-09-30 15:31:59 +01003327 __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003328
3329 Label not_same;
3330 __ cmp(r0, r1);
3331 __ b(ne, &not_same);
3332 STATIC_ASSERT(EQUAL == 0);
3333 STATIC_ASSERT(kSmiTag == 0);
3334 __ mov(r0, Operand(Smi::FromInt(EQUAL)));
Steve Block44f0eee2011-05-26 01:26:41 +01003335 __ IncrementCounter(counters->string_compare_native(), 1, r1, r2);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003336 __ add(sp, sp, Operand(2 * kPointerSize));
3337 __ Ret();
3338
3339 __ bind(&not_same);
3340
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003341 // Check that both objects are sequential one-byte strings.
3342 __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003343
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003344 // Compare flat one-byte strings natively. Remove arguments from stack first.
Steve Block44f0eee2011-05-26 01:26:41 +01003345 __ IncrementCounter(counters->string_compare_native(), 1, r2, r3);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003346 __ add(sp, sp, Operand(2 * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003347 StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003348
3349 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3350 // tagged as a small integer.
3351 __ bind(&runtime);
3352 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3353}
3354
3355
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003356void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3357 // ----------- S t a t e -------------
3358 // -- r1 : left
3359 // -- r0 : right
3360 // -- lr : return address
3361 // -----------------------------------
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003362
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003363 // Load r2 with the allocation site. We stick an undefined dummy value here
3364 // and replace it with the real allocation site later when we instantiate this
3365 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3366 __ Move(r2, handle(isolate()->heap()->undefined_value()));
Steve Block44f0eee2011-05-26 01:26:41 +01003367
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003368 // Make sure that we actually patched the allocation site.
3369 if (FLAG_debug_code) {
3370 __ tst(r2, Operand(kSmiTagMask));
3371 __ Assert(ne, kExpectedAllocationSite);
3372 __ push(r2);
3373 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3374 __ LoadRoot(ip, Heap::kAllocationSiteMapRootIndex);
3375 __ cmp(r2, ip);
3376 __ pop(r2);
3377 __ Assert(eq, kExpectedAllocationSite);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003378 }
3379
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003380 // Tail call into the stub that handles binary operations with allocation
3381 // sites.
3382 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3383 __ TailCallStub(&stub);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003384}
3385
3386
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003387void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3388 DCHECK(state() == CompareICState::SMI);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003389 Label miss;
3390 __ orr(r2, r1, r0);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003391 __ JumpIfNotSmi(r2, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003392
3393 if (GetCondition() == eq) {
3394 // For equality we do not care about the sign of the result.
3395 __ sub(r0, r0, r1, SetCC);
3396 } else {
Steve Block1e0659c2011-05-24 12:43:12 +01003397 // Untag before subtracting to avoid handling overflow.
3398 __ SmiUntag(r1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003399 __ sub(r0, r1, Operand::SmiUntag(r0));
Ben Murdochb0fe1622011-05-05 13:52:32 +01003400 }
3401 __ Ret();
3402
3403 __ bind(&miss);
3404 GenerateMiss(masm);
3405}
3406
3407
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003408void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3409 DCHECK(state() == CompareICState::NUMBER);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003410
3411 Label generic_stub;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003412 Label unordered, maybe_undefined1, maybe_undefined2;
Ben Murdochb0fe1622011-05-05 13:52:32 +01003413 Label miss;
Ben Murdochb0fe1622011-05-05 13:52:32 +01003414
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003415 if (left() == CompareICState::SMI) {
3416 __ JumpIfNotSmi(r1, &miss);
3417 }
3418 if (right() == CompareICState::SMI) {
3419 __ JumpIfNotSmi(r0, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003420 }
3421
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003422 // Inlining the double comparison and falling back to the general compare
3423 // stub if NaN is involved.
3424 // Load left and right operand.
3425 Label done, left, left_smi, right_smi;
3426 __ JumpIfSmi(r0, &right_smi);
3427 __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3428 DONT_DO_SMI_CHECK);
3429 __ sub(r2, r0, Operand(kHeapObjectTag));
3430 __ vldr(d1, r2, HeapNumber::kValueOffset);
3431 __ b(&left);
3432 __ bind(&right_smi);
3433 __ SmiToDouble(d1, r0);
3434
3435 __ bind(&left);
3436 __ JumpIfSmi(r1, &left_smi);
3437 __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3438 DONT_DO_SMI_CHECK);
3439 __ sub(r2, r1, Operand(kHeapObjectTag));
3440 __ vldr(d0, r2, HeapNumber::kValueOffset);
3441 __ b(&done);
3442 __ bind(&left_smi);
3443 __ SmiToDouble(d0, r1);
3444
3445 __ bind(&done);
3446 // Compare operands.
3447 __ VFPCompareAndSetFlags(d0, d1);
3448
3449 // Don't base result on status bits when a NaN is involved.
3450 __ b(vs, &unordered);
3451
3452 // Return a result of -1, 0, or 1, based on status bits.
3453 __ mov(r0, Operand(EQUAL), LeaveCC, eq);
3454 __ mov(r0, Operand(LESS), LeaveCC, lt);
3455 __ mov(r0, Operand(GREATER), LeaveCC, gt);
3456 __ Ret();
3457
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003458 __ bind(&unordered);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003459 __ bind(&generic_stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003460 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
3461 CompareICState::GENERIC, CompareICState::GENERIC);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003462 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3463
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003464 __ bind(&maybe_undefined1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003465 if (Token::IsOrderedRelationalCompareOp(op())) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003466 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
3467 __ b(ne, &miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003468 __ JumpIfSmi(r1, &unordered);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003469 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
3470 __ b(ne, &maybe_undefined2);
3471 __ jmp(&unordered);
3472 }
3473
3474 __ bind(&maybe_undefined2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003475 if (Token::IsOrderedRelationalCompareOp(op())) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003476 __ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
3477 __ b(eq, &unordered);
3478 }
3479
Ben Murdochb0fe1622011-05-05 13:52:32 +01003480 __ bind(&miss);
3481 GenerateMiss(masm);
3482}
3483
3484
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003485void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3486 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
Ben Murdoch257744e2011-11-30 15:57:28 +00003487 Label miss;
3488
3489 // Registers containing left and right operands respectively.
3490 Register left = r1;
3491 Register right = r0;
3492 Register tmp1 = r2;
3493 Register tmp2 = r3;
3494
3495 // Check that both operands are heap objects.
3496 __ JumpIfEitherSmi(left, right, &miss);
3497
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003498 // Check that both operands are internalized strings.
Ben Murdoch257744e2011-11-30 15:57:28 +00003499 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3500 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3501 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3502 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003503 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3504 __ orr(tmp1, tmp1, Operand(tmp2));
3505 __ tst(tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3506 __ b(ne, &miss);
Ben Murdoch257744e2011-11-30 15:57:28 +00003507
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003508 // Internalized strings are compared by identity.
Ben Murdoch257744e2011-11-30 15:57:28 +00003509 __ cmp(left, right);
3510 // Make sure r0 is non-zero. At this point input operands are
3511 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003512 DCHECK(right.is(r0));
Ben Murdoch257744e2011-11-30 15:57:28 +00003513 STATIC_ASSERT(EQUAL == 0);
3514 STATIC_ASSERT(kSmiTag == 0);
3515 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3516 __ Ret();
3517
3518 __ bind(&miss);
3519 GenerateMiss(masm);
3520}
3521
3522
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003523void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3524 DCHECK(state() == CompareICState::UNIQUE_NAME);
3525 DCHECK(GetCondition() == eq);
Ben Murdoch257744e2011-11-30 15:57:28 +00003526 Label miss;
3527
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003528 // Registers containing left and right operands respectively.
3529 Register left = r1;
3530 Register right = r0;
3531 Register tmp1 = r2;
3532 Register tmp2 = r3;
3533
3534 // Check that both operands are heap objects.
3535 __ JumpIfEitherSmi(left, right, &miss);
3536
3537 // Check that both operands are unique names. This leaves the instance
3538 // types loaded in tmp1 and tmp2.
3539 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3540 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3541 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3542 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3543
3544 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3545 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3546
3547 // Unique names are compared by identity.
3548 __ cmp(left, right);
3549 // Make sure r0 is non-zero. At this point input operands are
3550 // guaranteed to be non-zero.
3551 DCHECK(right.is(r0));
3552 STATIC_ASSERT(EQUAL == 0);
3553 STATIC_ASSERT(kSmiTag == 0);
3554 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3555 __ Ret();
3556
3557 __ bind(&miss);
3558 GenerateMiss(masm);
3559}
3560
3561
3562void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3563 DCHECK(state() == CompareICState::STRING);
3564 Label miss;
3565
3566 bool equality = Token::IsEqualityOp(op());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003567
Ben Murdoch257744e2011-11-30 15:57:28 +00003568 // Registers containing left and right operands respectively.
3569 Register left = r1;
3570 Register right = r0;
3571 Register tmp1 = r2;
3572 Register tmp2 = r3;
3573 Register tmp3 = r4;
3574 Register tmp4 = r5;
3575
3576 // Check that both operands are heap objects.
3577 __ JumpIfEitherSmi(left, right, &miss);
3578
3579 // Check that both operands are strings. This leaves the instance
3580 // types loaded in tmp1 and tmp2.
3581 __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3582 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3583 __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3584 __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3585 STATIC_ASSERT(kNotStringTag != 0);
3586 __ orr(tmp3, tmp1, tmp2);
3587 __ tst(tmp3, Operand(kIsNotStringMask));
3588 __ b(ne, &miss);
3589
3590 // Fast check for identical strings.
3591 __ cmp(left, right);
3592 STATIC_ASSERT(EQUAL == 0);
3593 STATIC_ASSERT(kSmiTag == 0);
3594 __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
3595 __ Ret(eq);
3596
3597 // Handle not identical strings.
3598
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003599 // Check that both strings are internalized strings. If they are, we're done
3600 // because we already know they are not identical. We know they are both
3601 // strings.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003602 if (equality) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003603 DCHECK(GetCondition() == eq);
3604 STATIC_ASSERT(kInternalizedTag == 0);
3605 __ orr(tmp3, tmp1, Operand(tmp2));
3606 __ tst(tmp3, Operand(kIsNotInternalizedMask));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003607 // Make sure r0 is non-zero. At this point input operands are
3608 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003609 DCHECK(right.is(r0));
3610 __ Ret(eq);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003611 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003612
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003613 // Check that both strings are sequential one-byte.
Ben Murdoch257744e2011-11-30 15:57:28 +00003614 Label runtime;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003615 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3616 &runtime);
Ben Murdoch257744e2011-11-30 15:57:28 +00003617
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003618 // Compare flat one-byte strings. Returns when done.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003619 if (equality) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003620 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3621 tmp3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003622 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003623 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3624 tmp2, tmp3, tmp4);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003625 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003626
3627 // Handle more complex cases in runtime.
3628 __ bind(&runtime);
3629 __ Push(left, right);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003630 if (equality) {
3631 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3632 } else {
3633 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3634 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003635
3636 __ bind(&miss);
3637 GenerateMiss(masm);
3638}
3639
3640
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003641void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3642 DCHECK(state() == CompareICState::OBJECT);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003643 Label miss;
3644 __ and_(r2, r1, Operand(r0));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003645 __ JumpIfSmi(r2, &miss);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003646
3647 __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
3648 __ b(ne, &miss);
3649 __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
3650 __ b(ne, &miss);
3651
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003652 DCHECK(GetCondition() == eq);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003653 __ sub(r0, r0, Operand(r1));
3654 __ Ret();
3655
3656 __ bind(&miss);
3657 GenerateMiss(masm);
3658}
3659
3660
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003661void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003662 Label miss;
3663 __ and_(r2, r1, Operand(r0));
3664 __ JumpIfSmi(r2, &miss);
3665 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3666 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
3667 __ cmp(r2, Operand(known_map_));
3668 __ b(ne, &miss);
3669 __ cmp(r3, Operand(known_map_));
3670 __ b(ne, &miss);
Ben Murdochc7cc0282012-03-05 14:35:55 +00003671
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003672 __ sub(r0, r0, Operand(r1));
3673 __ Ret();
3674
3675 __ bind(&miss);
3676 GenerateMiss(masm);
3677}
3678
3679
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003680void CompareICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003681 {
3682 // Call the runtime system in a fresh internal frame.
3683 ExternalReference miss =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003684 ExternalReference(IC_Utility(IC::kCompareIC_Miss), isolate());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003685
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003686 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003687 __ Push(r1, r0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003688 __ Push(lr, r1, r0);
3689 __ mov(ip, Operand(Smi::FromInt(op())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003690 __ push(ip);
3691 __ CallExternalReference(miss, 3);
3692 // Compute the entry point of the rewritten stub.
3693 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
3694 // Restore registers.
3695 __ pop(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003696 __ Pop(r1, r0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003697 }
3698
Ben Murdochb0fe1622011-05-05 13:52:32 +01003699 __ Jump(r2);
3700}
3701
3702
Steve Block1e0659c2011-05-24 12:43:12 +01003703void DirectCEntryStub::Generate(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003704 // Place the return address on the stack, making the call
3705 // GC safe. The RegExp backend also relies on this.
3706 __ str(lr, MemOperand(sp, 0));
3707 __ blx(ip); // Call the C++ function.
3708 __ VFPEnsureFPSCRState(r2);
Steve Block1e0659c2011-05-24 12:43:12 +01003709 __ ldr(pc, MemOperand(sp, 0));
3710}
3711
3712
3713void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003714 Register target) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003715 intptr_t code =
3716 reinterpret_cast<intptr_t>(GetCode().location());
3717 __ Move(ip, target);
3718 __ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
3719 __ blx(lr); // Call the stub.
Steve Block1e0659c2011-05-24 12:43:12 +01003720}
3721
3722
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003723void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3724 Label* miss,
3725 Label* done,
3726 Register receiver,
3727 Register properties,
3728 Handle<Name> name,
3729 Register scratch0) {
3730 DCHECK(name->IsUniqueName());
Ben Murdoch257744e2011-11-30 15:57:28 +00003731 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3732 // not equal to the name and kProbes-th slot is not used (its name is the
3733 // undefined value), it guarantees the hash table doesn't contain the
3734 // property. It's true even if some slots represent deleted properties
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003735 // (their names are the hole value).
Ben Murdoch257744e2011-11-30 15:57:28 +00003736 for (int i = 0; i < kInlinedProbes; i++) {
3737 // scratch0 points to properties hash.
3738 // Compute the masked index: (hash + i + i * i) & mask.
3739 Register index = scratch0;
3740 // Capacity is smi 2^n.
3741 __ ldr(index, FieldMemOperand(properties, kCapacityOffset));
3742 __ sub(index, index, Operand(1));
3743 __ and_(index, index, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003744 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
Ben Murdoch257744e2011-11-30 15:57:28 +00003745
3746 // Scale the index by multiplying by the entry size.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003747 DCHECK(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003748 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3749
3750 Register entity_name = scratch0;
3751 // Having undefined at this place means the name is not contained.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003752 DCHECK_EQ(kSmiTagSize, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003753 Register tmp = properties;
3754 __ add(tmp, properties, Operand(index, LSL, 1));
3755 __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3756
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003757 DCHECK(!tmp.is(entity_name));
Ben Murdoch257744e2011-11-30 15:57:28 +00003758 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3759 __ cmp(entity_name, tmp);
3760 __ b(eq, done);
3761
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003762 // Load the hole ready for use below:
3763 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003764
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003765 // Stop if found the property.
3766 __ cmp(entity_name, Operand(Handle<Name>(name)));
3767 __ b(eq, miss);
Ben Murdoch257744e2011-11-30 15:57:28 +00003768
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003769 Label good;
3770 __ cmp(entity_name, tmp);
3771 __ b(eq, &good);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003772
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003773 // Check if the entry name is not a unique name.
3774 __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3775 __ ldrb(entity_name,
3776 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3777 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3778 __ bind(&good);
Ben Murdoch257744e2011-11-30 15:57:28 +00003779
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003780 // Restore the properties.
3781 __ ldr(properties,
3782 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003783 }
3784
3785 const int spill_mask =
3786 (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
3787 r2.bit() | r1.bit() | r0.bit());
3788
3789 __ stm(db_w, sp, spill_mask);
3790 __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003791 __ mov(r1, Operand(Handle<Name>(name)));
3792 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003793 __ CallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003794 __ cmp(r0, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003795 __ ldm(ia_w, sp, spill_mask);
3796
3797 __ b(eq, done);
3798 __ b(ne, miss);
Ben Murdoch257744e2011-11-30 15:57:28 +00003799}
3800
3801
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003802// Probe the name dictionary in the |elements| register. Jump to the
Ben Murdoch257744e2011-11-30 15:57:28 +00003803// |done| label if a property with the given name is found. Jump to
3804// the |miss| label otherwise.
3805// If lookup was successful |scratch2| will be equal to elements + 4 * index.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003806void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3807 Label* miss,
3808 Label* done,
3809 Register elements,
3810 Register name,
3811 Register scratch1,
3812 Register scratch2) {
3813 DCHECK(!elements.is(scratch1));
3814 DCHECK(!elements.is(scratch2));
3815 DCHECK(!name.is(scratch1));
3816 DCHECK(!name.is(scratch2));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003817
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003818 __ AssertName(name);
Ben Murdoch257744e2011-11-30 15:57:28 +00003819
3820 // Compute the capacity mask.
3821 __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003822 __ SmiUntag(scratch1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003823 __ sub(scratch1, scratch1, Operand(1));
3824
3825 // Generate an unrolled loop that performs a few probes before
3826 // giving up. Measurements done on Gmail indicate that 2 probes
3827 // cover ~93% of loads from dictionaries.
3828 for (int i = 0; i < kInlinedProbes; i++) {
3829 // Compute the masked index: (hash + i + i * i) & mask.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003830 __ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003831 if (i > 0) {
3832 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3833 // the hash in a separate instruction. The value hash + i + i * i is right
3834 // shifted in the following and instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003835 DCHECK(NameDictionary::GetProbeOffset(i) <
3836 1 << (32 - Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003837 __ add(scratch2, scratch2, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003838 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003839 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003840 __ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003841
3842 // Scale the index by multiplying by the element size.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003843 DCHECK(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003844 // scratch2 = scratch2 * 3.
3845 __ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
3846
3847 // Check if the key is identical to the name.
3848 __ add(scratch2, elements, Operand(scratch2, LSL, 2));
3849 __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
3850 __ cmp(name, Operand(ip));
3851 __ b(eq, done);
3852 }
3853
3854 const int spill_mask =
3855 (lr.bit() | r6.bit() | r5.bit() | r4.bit() |
3856 r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
3857 ~(scratch1.bit() | scratch2.bit());
3858
3859 __ stm(db_w, sp, spill_mask);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003860 if (name.is(r0)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003861 DCHECK(!elements.is(r1));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003862 __ Move(r1, name);
3863 __ Move(r0, elements);
3864 } else {
3865 __ Move(r0, elements);
3866 __ Move(r1, name);
3867 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003868 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
Ben Murdoch257744e2011-11-30 15:57:28 +00003869 __ CallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003870 __ cmp(r0, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003871 __ mov(scratch2, Operand(r2));
3872 __ ldm(ia_w, sp, spill_mask);
3873
3874 __ b(ne, done);
3875 __ b(eq, miss);
3876}
3877
3878
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003879void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003880 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3881 // we cannot call anything that could cause a GC from this stub.
Ben Murdoch257744e2011-11-30 15:57:28 +00003882 // Registers:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003883 // result: NameDictionary to probe
Ben Murdoch257744e2011-11-30 15:57:28 +00003884 // r1: key
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003885 // dictionary: NameDictionary to probe.
3886 // index: will hold an index of entry if lookup is successful.
3887 // might alias with result_.
Ben Murdoch257744e2011-11-30 15:57:28 +00003888 // Returns:
3889 // result_ is zero if lookup failed, non zero otherwise.
3890
3891 Register result = r0;
3892 Register dictionary = r0;
3893 Register key = r1;
3894 Register index = r2;
3895 Register mask = r3;
3896 Register hash = r4;
3897 Register undefined = r5;
3898 Register entry_key = r6;
3899
3900 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3901
3902 __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003903 __ SmiUntag(mask);
Ben Murdoch257744e2011-11-30 15:57:28 +00003904 __ sub(mask, mask, Operand(1));
3905
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003906 __ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003907
3908 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3909
3910 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3911 // Compute the masked index: (hash + i + i * i) & mask.
3912 // Capacity is smi 2^n.
3913 if (i > 0) {
3914 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3915 // the hash in a separate instruction. The value hash + i + i * i is right
3916 // shifted in the following and instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003917 DCHECK(NameDictionary::GetProbeOffset(i) <
3918 1 << (32 - Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003919 __ add(index, hash, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003920 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003921 } else {
3922 __ mov(index, Operand(hash));
3923 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003924 __ and_(index, mask, Operand(index, LSR, Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003925
3926 // Scale the index by multiplying by the entry size.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003927 DCHECK(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003928 __ add(index, index, Operand(index, LSL, 1)); // index *= 3.
3929
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003930 DCHECK_EQ(kSmiTagSize, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003931 __ add(index, dictionary, Operand(index, LSL, 2));
3932 __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
3933
3934 // Having undefined at this place means the name is not contained.
3935 __ cmp(entry_key, Operand(undefined));
3936 __ b(eq, &not_in_dictionary);
3937
3938 // Stop if found the property.
3939 __ cmp(entry_key, Operand(key));
3940 __ b(eq, &in_dictionary);
3941
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003942 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3943 // Check if the entry name is not a unique name.
Ben Murdoch257744e2011-11-30 15:57:28 +00003944 __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3945 __ ldrb(entry_key,
3946 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003947 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
Ben Murdoch257744e2011-11-30 15:57:28 +00003948 }
3949 }
3950
3951 __ bind(&maybe_in_dictionary);
3952 // If we are doing negative lookup then probing failure should be
3953 // treated as a lookup success. For positive lookup probing failure
3954 // should be treated as lookup failure.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003955 if (mode() == POSITIVE_LOOKUP) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003956 __ mov(result, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003957 __ Ret();
3958 }
3959
3960 __ bind(&in_dictionary);
3961 __ mov(result, Operand(1));
3962 __ Ret();
3963
3964 __ bind(&not_in_dictionary);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003965 __ mov(result, Operand::Zero());
Ben Murdoch257744e2011-11-30 15:57:28 +00003966 __ Ret();
3967}
3968
3969
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003970void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3971 Isolate* isolate) {
3972 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3973 stub1.GetCode();
3974 // Hydrogen code stubs need stub2 at snapshot time.
3975 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3976 stub2.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003977}
3978
3979
3980// Takes the input in 3 registers: address_ value_ and object_. A pointer to
3981// the value has just been written into the object, now this stub makes sure
3982// we keep the GC informed. The word in the object where the value has been
3983// written is in the address register.
3984void RecordWriteStub::Generate(MacroAssembler* masm) {
3985 Label skip_to_incremental_noncompacting;
3986 Label skip_to_incremental_compacting;
3987
3988 // The first two instructions are generated with labels so as to get the
3989 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3990 // forth between a compare instructions (a nop in this position) and the
3991 // real branch when we start and stop incremental heap marking.
3992 // See RecordWriteStub::Patch for details.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003993 {
3994 // Block literal pool emission, as the position of these two instructions
3995 // is assumed by the patching code.
3996 Assembler::BlockConstPoolScope block_const_pool(masm);
3997 __ b(&skip_to_incremental_noncompacting);
3998 __ b(&skip_to_incremental_compacting);
3999 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004000
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004001 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4002 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004003 MacroAssembler::kReturnAtEnd);
4004 }
4005 __ Ret();
4006
4007 __ bind(&skip_to_incremental_noncompacting);
4008 GenerateIncremental(masm, INCREMENTAL);
4009
4010 __ bind(&skip_to_incremental_compacting);
4011 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4012
4013 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4014 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004015 DCHECK(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
4016 DCHECK(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004017 PatchBranchIntoNop(masm, 0);
4018 PatchBranchIntoNop(masm, Assembler::kInstrSize);
4019}
4020
4021
4022void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4023 regs_.Save(masm);
4024
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004025 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004026 Label dont_need_remembered_set;
4027
4028 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4029 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4030 regs_.scratch0(),
4031 &dont_need_remembered_set);
4032
4033 __ CheckPageFlag(regs_.object(),
4034 regs_.scratch0(),
4035 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4036 ne,
4037 &dont_need_remembered_set);
4038
4039 // First notify the incremental marker if necessary, then update the
4040 // remembered set.
4041 CheckNeedsToInformIncrementalMarker(
4042 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004043 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004044 regs_.Restore(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004045 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004046 MacroAssembler::kReturnAtEnd);
4047
4048 __ bind(&dont_need_remembered_set);
4049 }
4050
4051 CheckNeedsToInformIncrementalMarker(
4052 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004053 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004054 regs_.Restore(masm);
4055 __ Ret();
4056}
4057
4058
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004059void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4060 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004061 int argument_count = 3;
4062 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4063 Register address =
4064 r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004065 DCHECK(!address.is(regs_.object()));
4066 DCHECK(!address.is(r0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004067 __ Move(address, regs_.address());
4068 __ Move(r0, regs_.object());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004069 __ Move(r1, address);
4070 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004071
4072 AllowExternalCallThatCantCauseGC scope(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004073 __ CallCFunction(
4074 ExternalReference::incremental_marking_record_write_function(isolate()),
4075 argument_count);
4076 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004077}
4078
4079
4080void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4081 MacroAssembler* masm,
4082 OnNoNeedToInformIncrementalMarker on_no_need,
4083 Mode mode) {
4084 Label on_black;
4085 Label need_incremental;
4086 Label need_incremental_pop_scratch;
4087
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004088 __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4089 __ ldr(regs_.scratch1(),
4090 MemOperand(regs_.scratch0(),
4091 MemoryChunk::kWriteBarrierCounterOffset));
4092 __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
4093 __ str(regs_.scratch1(),
4094 MemOperand(regs_.scratch0(),
4095 MemoryChunk::kWriteBarrierCounterOffset));
4096 __ b(mi, &need_incremental);
4097
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004098 // Let's look at the color of the object: If it is not black we don't have
4099 // to inform the incremental marker.
4100 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4101
4102 regs_.Restore(masm);
4103 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004104 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004105 MacroAssembler::kReturnAtEnd);
4106 } else {
4107 __ Ret();
4108 }
4109
4110 __ bind(&on_black);
4111
4112 // Get the value from the slot.
4113 __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
4114
4115 if (mode == INCREMENTAL_COMPACTION) {
4116 Label ensure_not_white;
4117
4118 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4119 regs_.scratch1(), // Scratch.
4120 MemoryChunk::kEvacuationCandidateMask,
4121 eq,
4122 &ensure_not_white);
4123
4124 __ CheckPageFlag(regs_.object(),
4125 regs_.scratch1(), // Scratch.
4126 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4127 eq,
4128 &need_incremental);
4129
4130 __ bind(&ensure_not_white);
4131 }
4132
4133 // We need extra registers for this, so we push the object and the address
4134 // register temporarily.
4135 __ Push(regs_.object(), regs_.address());
4136 __ EnsureNotWhite(regs_.scratch0(), // The value.
4137 regs_.scratch1(), // Scratch.
4138 regs_.object(), // Scratch.
4139 regs_.address(), // Scratch.
4140 &need_incremental_pop_scratch);
4141 __ Pop(regs_.object(), regs_.address());
4142
4143 regs_.Restore(masm);
4144 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004145 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004146 MacroAssembler::kReturnAtEnd);
4147 } else {
4148 __ Ret();
4149 }
4150
4151 __ bind(&need_incremental_pop_scratch);
4152 __ Pop(regs_.object(), regs_.address());
4153
4154 __ bind(&need_incremental);
4155
4156 // Fall through when we need to inform the incremental marker.
4157}
4158
4159
4160void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4161 // ----------- S t a t e -------------
4162 // -- r0 : element value to store
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004163 // -- r3 : element index as smi
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004164 // -- sp[0] : array literal index in function as smi
4165 // -- sp[4] : array literal
4166 // clobbers r1, r2, r4
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004167 // -----------------------------------
4168
4169 Label element_done;
4170 Label double_elements;
4171 Label smi_element;
4172 Label slow_elements;
4173 Label fast_elements;
4174
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004175 // Get array literal index, array literal and its map.
4176 __ ldr(r4, MemOperand(sp, 0 * kPointerSize));
4177 __ ldr(r1, MemOperand(sp, 1 * kPointerSize));
4178 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset));
4179
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004180 __ CheckFastElements(r2, r5, &double_elements);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004181 // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004182 __ JumpIfSmi(r0, &smi_element);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004183 __ CheckFastSmiElements(r2, r5, &fast_elements);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004184
4185 // Store into the array literal requires a elements transition. Call into
4186 // the runtime.
4187 __ bind(&slow_elements);
4188 // call.
4189 __ Push(r1, r3, r0);
4190 __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4191 __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
4192 __ Push(r5, r4);
4193 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4194
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004195 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004196 __ bind(&fast_elements);
4197 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004198 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004199 __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4200 __ str(r0, MemOperand(r6, 0));
4201 // Update the write barrier for the array store.
4202 __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
4203 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4204 __ Ret();
4205
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004206 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4207 // and value is Smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004208 __ bind(&smi_element);
4209 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004210 __ add(r6, r5, Operand::PointerOffsetFromSmiKey(r3));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004211 __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
4212 __ Ret();
4213
4214 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
4215 __ bind(&double_elements);
4216 __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004217 __ StoreNumberToDoubleElements(r0, r3, r5, r6, d0, &slow_elements);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004218 __ Ret();
4219}
4220
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004221
4222void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4223 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4224 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4225 int parameter_count_offset =
4226 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4227 __ ldr(r1, MemOperand(fp, parameter_count_offset));
4228 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4229 __ add(r1, r1, Operand(1));
4230 }
4231 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4232 __ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
4233 __ add(sp, sp, r1);
4234 __ Ret();
4235}
4236
4237
4238void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4239 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister());
4240 VectorLoadStub stub(isolate(), state());
4241 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4242}
4243
4244
4245void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4246 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister());
4247 VectorKeyedLoadStub stub(isolate());
4248 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4249}
4250
4251
4252void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4253 if (masm->isolate()->function_entry_hook() != NULL) {
4254 ProfileEntryHookStub stub(masm->isolate());
4255 int code_size = masm->CallStubSize(&stub) + 2 * Assembler::kInstrSize;
4256 PredictableCodeSizeScope predictable(masm, code_size);
4257 __ push(lr);
4258 __ CallStub(&stub);
4259 __ pop(lr);
4260 }
4261}
4262
4263
4264void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4265 // The entry hook is a "push lr" instruction, followed by a call.
4266 const int32_t kReturnAddressDistanceFromFunctionStart =
4267 3 * Assembler::kInstrSize;
4268
4269 // This should contain all kCallerSaved registers.
4270 const RegList kSavedRegs =
4271 1 << 0 | // r0
4272 1 << 1 | // r1
4273 1 << 2 | // r2
4274 1 << 3 | // r3
4275 1 << 5 | // r5
4276 1 << 9; // r9
4277 // We also save lr, so the count here is one higher than the mask indicates.
4278 const int32_t kNumSavedRegs = 7;
4279
4280 DCHECK((kCallerSaved & kSavedRegs) == kCallerSaved);
4281
4282 // Save all caller-save registers as this may be called from anywhere.
4283 __ stm(db_w, sp, kSavedRegs | lr.bit());
4284
4285 // Compute the function's address for the first argument.
4286 __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
4287
4288 // The caller's return address is above the saved temporaries.
4289 // Grab that for the second argument to the hook.
4290 __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
4291
4292 // Align the stack if necessary.
4293 int frame_alignment = masm->ActivationFrameAlignment();
4294 if (frame_alignment > kPointerSize) {
4295 __ mov(r5, sp);
4296 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4297 __ and_(sp, sp, Operand(-frame_alignment));
4298 }
4299
4300#if V8_HOST_ARCH_ARM
4301 int32_t entry_hook =
4302 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4303 __ mov(ip, Operand(entry_hook));
4304#else
4305 // Under the simulator we need to indirect the entry hook through a
4306 // trampoline function at a known address.
4307 // It additionally takes an isolate as a third parameter
4308 __ mov(r2, Operand(ExternalReference::isolate_address(isolate())));
4309
4310 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4311 __ mov(ip, Operand(ExternalReference(&dispatcher,
4312 ExternalReference::BUILTIN_CALL,
4313 isolate())));
4314#endif
4315 __ Call(ip);
4316
4317 // Restore the stack pointer if needed.
4318 if (frame_alignment > kPointerSize) {
4319 __ mov(sp, r5);
4320 }
4321
4322 // Also pop pc to get Ret(0).
4323 __ ldm(ia_w, sp, kSavedRegs | pc.bit());
4324}
4325
4326
4327template<class T>
4328static void CreateArrayDispatch(MacroAssembler* masm,
4329 AllocationSiteOverrideMode mode) {
4330 if (mode == DISABLE_ALLOCATION_SITES) {
4331 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4332 __ TailCallStub(&stub);
4333 } else if (mode == DONT_OVERRIDE) {
4334 int last_index = GetSequenceIndexFromFastElementsKind(
4335 TERMINAL_FAST_ELEMENTS_KIND);
4336 for (int i = 0; i <= last_index; ++i) {
4337 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4338 __ cmp(r3, Operand(kind));
4339 T stub(masm->isolate(), kind);
4340 __ TailCallStub(&stub, eq);
4341 }
4342
4343 // If we reached this point there is a problem.
4344 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4345 } else {
4346 UNREACHABLE();
4347 }
4348}
4349
4350
4351static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4352 AllocationSiteOverrideMode mode) {
4353 // r2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4354 // r3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4355 // r0 - number of arguments
4356 // r1 - constructor?
4357 // sp[0] - last argument
4358 Label normal_sequence;
4359 if (mode == DONT_OVERRIDE) {
4360 DCHECK(FAST_SMI_ELEMENTS == 0);
4361 DCHECK(FAST_HOLEY_SMI_ELEMENTS == 1);
4362 DCHECK(FAST_ELEMENTS == 2);
4363 DCHECK(FAST_HOLEY_ELEMENTS == 3);
4364 DCHECK(FAST_DOUBLE_ELEMENTS == 4);
4365 DCHECK(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4366
4367 // is the low bit set? If so, we are holey and that is good.
4368 __ tst(r3, Operand(1));
4369 __ b(ne, &normal_sequence);
4370 }
4371
4372 // look at the first argument
4373 __ ldr(r5, MemOperand(sp, 0));
4374 __ cmp(r5, Operand::Zero());
4375 __ b(eq, &normal_sequence);
4376
4377 if (mode == DISABLE_ALLOCATION_SITES) {
4378 ElementsKind initial = GetInitialFastElementsKind();
4379 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4380
4381 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4382 holey_initial,
4383 DISABLE_ALLOCATION_SITES);
4384 __ TailCallStub(&stub_holey);
4385
4386 __ bind(&normal_sequence);
4387 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4388 initial,
4389 DISABLE_ALLOCATION_SITES);
4390 __ TailCallStub(&stub);
4391 } else if (mode == DONT_OVERRIDE) {
4392 // We are going to create a holey array, but our kind is non-holey.
4393 // Fix kind and retry (only if we have an allocation site in the slot).
4394 __ add(r3, r3, Operand(1));
4395
4396 if (FLAG_debug_code) {
4397 __ ldr(r5, FieldMemOperand(r2, 0));
4398 __ CompareRoot(r5, Heap::kAllocationSiteMapRootIndex);
4399 __ Assert(eq, kExpectedAllocationSite);
4400 }
4401
4402 // Save the resulting elements kind in type info. We can't just store r3
4403 // in the AllocationSite::transition_info field because elements kind is
4404 // restricted to a portion of the field...upper bits need to be left alone.
4405 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4406 __ ldr(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4407 __ add(r4, r4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4408 __ str(r4, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4409
4410 __ bind(&normal_sequence);
4411 int last_index = GetSequenceIndexFromFastElementsKind(
4412 TERMINAL_FAST_ELEMENTS_KIND);
4413 for (int i = 0; i <= last_index; ++i) {
4414 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4415 __ cmp(r3, Operand(kind));
4416 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4417 __ TailCallStub(&stub, eq);
4418 }
4419
4420 // If we reached this point there is a problem.
4421 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4422 } else {
4423 UNREACHABLE();
4424 }
4425}
4426
4427
4428template<class T>
4429static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4430 int to_index = GetSequenceIndexFromFastElementsKind(
4431 TERMINAL_FAST_ELEMENTS_KIND);
4432 for (int i = 0; i <= to_index; ++i) {
4433 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4434 T stub(isolate, kind);
4435 stub.GetCode();
4436 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4437 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4438 stub1.GetCode();
4439 }
4440 }
4441}
4442
4443
4444void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4445 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4446 isolate);
4447 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4448 isolate);
4449 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4450 isolate);
4451}
4452
4453
4454void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4455 Isolate* isolate) {
4456 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4457 for (int i = 0; i < 2; i++) {
4458 // For internal arrays we only need a few things
4459 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4460 stubh1.GetCode();
4461 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4462 stubh2.GetCode();
4463 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4464 stubh3.GetCode();
4465 }
4466}
4467
4468
4469void ArrayConstructorStub::GenerateDispatchToArrayStub(
4470 MacroAssembler* masm,
4471 AllocationSiteOverrideMode mode) {
4472 if (argument_count() == ANY) {
4473 Label not_zero_case, not_one_case;
4474 __ tst(r0, r0);
4475 __ b(ne, &not_zero_case);
4476 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4477
4478 __ bind(&not_zero_case);
4479 __ cmp(r0, Operand(1));
4480 __ b(gt, &not_one_case);
4481 CreateArrayDispatchOneArgument(masm, mode);
4482
4483 __ bind(&not_one_case);
4484 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4485 } else if (argument_count() == NONE) {
4486 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4487 } else if (argument_count() == ONE) {
4488 CreateArrayDispatchOneArgument(masm, mode);
4489 } else if (argument_count() == MORE_THAN_ONE) {
4490 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4491 } else {
4492 UNREACHABLE();
4493 }
4494}
4495
4496
4497void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4498 // ----------- S t a t e -------------
4499 // -- r0 : argc (only if argument_count() == ANY)
4500 // -- r1 : constructor
4501 // -- r2 : AllocationSite or undefined
4502 // -- sp[0] : return address
4503 // -- sp[4] : last argument
4504 // -----------------------------------
4505
4506 if (FLAG_debug_code) {
4507 // The array construct code is only set for the global and natives
4508 // builtin Array functions which always have maps.
4509
4510 // Initial map for the builtin Array function should be a map.
4511 __ ldr(r4, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4512 // Will both indicate a NULL and a Smi.
4513 __ tst(r4, Operand(kSmiTagMask));
4514 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4515 __ CompareObjectType(r4, r4, r5, MAP_TYPE);
4516 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4517
4518 // We should either have undefined in r2 or a valid AllocationSite
4519 __ AssertUndefinedOrAllocationSite(r2, r4);
4520 }
4521
4522 Label no_info;
4523 // Get the elements kind and case on that.
4524 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
4525 __ b(eq, &no_info);
4526
4527 __ ldr(r3, FieldMemOperand(r2, AllocationSite::kTransitionInfoOffset));
4528 __ SmiUntag(r3);
4529 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4530 __ and_(r3, r3, Operand(AllocationSite::ElementsKindBits::kMask));
4531 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4532
4533 __ bind(&no_info);
4534 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4535}
4536
4537
4538void InternalArrayConstructorStub::GenerateCase(
4539 MacroAssembler* masm, ElementsKind kind) {
4540 __ cmp(r0, Operand(1));
4541
4542 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4543 __ TailCallStub(&stub0, lo);
4544
4545 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4546 __ TailCallStub(&stubN, hi);
4547
4548 if (IsFastPackedElementsKind(kind)) {
4549 // We might need to create a holey array
4550 // look at the first argument
4551 __ ldr(r3, MemOperand(sp, 0));
4552 __ cmp(r3, Operand::Zero());
4553
4554 InternalArraySingleArgumentConstructorStub
4555 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4556 __ TailCallStub(&stub1_holey, ne);
4557 }
4558
4559 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4560 __ TailCallStub(&stub1);
4561}
4562
4563
4564void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4565 // ----------- S t a t e -------------
4566 // -- r0 : argc
4567 // -- r1 : constructor
4568 // -- sp[0] : return address
4569 // -- sp[4] : last argument
4570 // -----------------------------------
4571
4572 if (FLAG_debug_code) {
4573 // The array construct code is only set for the global and natives
4574 // builtin Array functions which always have maps.
4575
4576 // Initial map for the builtin Array function should be a map.
4577 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4578 // Will both indicate a NULL and a Smi.
4579 __ tst(r3, Operand(kSmiTagMask));
4580 __ Assert(ne, kUnexpectedInitialMapForArrayFunction);
4581 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
4582 __ Assert(eq, kUnexpectedInitialMapForArrayFunction);
4583 }
4584
4585 // Figure out the right elements kind
4586 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
4587 // Load the map's "bit field 2" into |result|. We only need the first byte,
4588 // but the following bit field extraction takes care of that anyway.
4589 __ ldr(r3, FieldMemOperand(r3, Map::kBitField2Offset));
4590 // Retrieve elements_kind from bit field 2.
4591 __ DecodeField<Map::ElementsKindBits>(r3);
4592
4593 if (FLAG_debug_code) {
4594 Label done;
4595 __ cmp(r3, Operand(FAST_ELEMENTS));
4596 __ b(eq, &done);
4597 __ cmp(r3, Operand(FAST_HOLEY_ELEMENTS));
4598 __ Assert(eq,
4599 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
4600 __ bind(&done);
4601 }
4602
4603 Label fast_elements_case;
4604 __ cmp(r3, Operand(FAST_ELEMENTS));
4605 __ b(eq, &fast_elements_case);
4606 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4607
4608 __ bind(&fast_elements_case);
4609 GenerateCase(masm, FAST_ELEMENTS);
4610}
4611
4612
4613void CallApiFunctionStub::Generate(MacroAssembler* masm) {
4614 // ----------- S t a t e -------------
4615 // -- r0 : callee
4616 // -- r4 : call_data
4617 // -- r2 : holder
4618 // -- r1 : api_function_address
4619 // -- cp : context
4620 // --
4621 // -- sp[0] : last argument
4622 // -- ...
4623 // -- sp[(argc - 1)* 4] : first argument
4624 // -- sp[argc * 4] : receiver
4625 // -----------------------------------
4626
4627 Register callee = r0;
4628 Register call_data = r4;
4629 Register holder = r2;
4630 Register api_function_address = r1;
4631 Register context = cp;
4632
4633 int argc = this->argc();
4634 bool is_store = this->is_store();
4635 bool call_data_undefined = this->call_data_undefined();
4636
4637 typedef FunctionCallbackArguments FCA;
4638
4639 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
4640 STATIC_ASSERT(FCA::kCalleeIndex == 5);
4641 STATIC_ASSERT(FCA::kDataIndex == 4);
4642 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
4643 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
4644 STATIC_ASSERT(FCA::kIsolateIndex == 1);
4645 STATIC_ASSERT(FCA::kHolderIndex == 0);
4646 STATIC_ASSERT(FCA::kArgsLength == 7);
4647
4648 // context save
4649 __ push(context);
4650 // load context from callee
4651 __ ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
4652
4653 // callee
4654 __ push(callee);
4655
4656 // call data
4657 __ push(call_data);
4658
4659 Register scratch = call_data;
4660 if (!call_data_undefined) {
4661 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
4662 }
4663 // return value
4664 __ push(scratch);
4665 // return value default
4666 __ push(scratch);
4667 // isolate
4668 __ mov(scratch,
4669 Operand(ExternalReference::isolate_address(isolate())));
4670 __ push(scratch);
4671 // holder
4672 __ push(holder);
4673
4674 // Prepare arguments.
4675 __ mov(scratch, sp);
4676
4677 // Allocate the v8::Arguments structure in the arguments' space since
4678 // it's not controlled by GC.
4679 const int kApiStackSpace = 4;
4680
4681 FrameScope frame_scope(masm, StackFrame::MANUAL);
4682 __ EnterExitFrame(false, kApiStackSpace);
4683
4684 DCHECK(!api_function_address.is(r0) && !scratch.is(r0));
4685 // r0 = FunctionCallbackInfo&
4686 // Arguments is after the return address.
4687 __ add(r0, sp, Operand(1 * kPointerSize));
4688 // FunctionCallbackInfo::implicit_args_
4689 __ str(scratch, MemOperand(r0, 0 * kPointerSize));
4690 // FunctionCallbackInfo::values_
4691 __ add(ip, scratch, Operand((FCA::kArgsLength - 1 + argc) * kPointerSize));
4692 __ str(ip, MemOperand(r0, 1 * kPointerSize));
4693 // FunctionCallbackInfo::length_ = argc
4694 __ mov(ip, Operand(argc));
4695 __ str(ip, MemOperand(r0, 2 * kPointerSize));
4696 // FunctionCallbackInfo::is_construct_call = 0
4697 __ mov(ip, Operand::Zero());
4698 __ str(ip, MemOperand(r0, 3 * kPointerSize));
4699
4700 const int kStackUnwindSpace = argc + FCA::kArgsLength + 1;
4701 ExternalReference thunk_ref =
4702 ExternalReference::invoke_function_callback(isolate());
4703
4704 AllowExternalCallThatCantCauseGC scope(masm);
4705 MemOperand context_restore_operand(
4706 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
4707 // Stores return the first js argument
4708 int return_value_offset = 0;
4709 if (is_store) {
4710 return_value_offset = 2 + FCA::kArgsLength;
4711 } else {
4712 return_value_offset = 2 + FCA::kReturnValueOffset;
4713 }
4714 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
4715
4716 __ CallApiFunctionAndReturn(api_function_address,
4717 thunk_ref,
4718 kStackUnwindSpace,
4719 return_value_operand,
4720 &context_restore_operand);
4721}
4722
4723
4724void CallApiGetterStub::Generate(MacroAssembler* masm) {
4725 // ----------- S t a t e -------------
4726 // -- sp[0] : name
4727 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
4728 // -- ...
4729 // -- r2 : api_function_address
4730 // -----------------------------------
4731
4732 Register api_function_address = ApiGetterDescriptor::function_address();
4733 DCHECK(api_function_address.is(r2));
4734
4735 __ mov(r0, sp); // r0 = Handle<Name>
4736 __ add(r1, r0, Operand(1 * kPointerSize)); // r1 = PCA
4737
4738 const int kApiStackSpace = 1;
4739 FrameScope frame_scope(masm, StackFrame::MANUAL);
4740 __ EnterExitFrame(false, kApiStackSpace);
4741
4742 // Create PropertyAccessorInfo instance on the stack above the exit frame with
4743 // r1 (internal::Object** args_) as the data.
4744 __ str(r1, MemOperand(sp, 1 * kPointerSize));
4745 __ add(r1, sp, Operand(1 * kPointerSize)); // r1 = AccessorInfo&
4746
4747 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
4748
4749 ExternalReference thunk_ref =
4750 ExternalReference::invoke_accessor_getter_callback(isolate());
4751 __ CallApiFunctionAndReturn(api_function_address,
4752 thunk_ref,
4753 kStackUnwindSpace,
4754 MemOperand(fp, 6 * kPointerSize),
4755 NULL);
4756}
4757
4758
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004759#undef __
4760
4761} } // namespace v8::internal
4762
4763#endif // V8_TARGET_ARCH_ARM