blob: 3213677f6209a1251c8c3c23b921ef4bb4224eb7 [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.
Steve Block44f0eee2011-05-26 01:26:41 +01004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_MIPS
Steve Block44f0eee2011-05-26 01:26:41 +01006
Ben Murdochda12d292016-06-02 14:46:10 +01007#include "src/code-stubs.h"
8#include "src/api-arguments.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/base/bits.h"
10#include "src/bootstrapper.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/codegen.h"
12#include "src/ic/handler-compiler.h"
13#include "src/ic/ic.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014#include "src/ic/stub-cache.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000015#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016#include "src/mips/code-stubs-mips.h"
17#include "src/regexp/jsregexp.h"
18#include "src/regexp/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040019#include "src/runtime/runtime.h"
Steve Block44f0eee2011-05-26 01:26:41 +010020
21namespace v8 {
22namespace internal {
23
Ben Murdoch61f157c2016-09-16 13:49:30 +010024#define __ ACCESS_MASM(masm)
Steve Block44f0eee2011-05-26 01:26:41 +010025
Ben Murdoch61f157c2016-09-16 13:49:30 +010026void ArrayNArgumentsConstructorStub::Generate(MacroAssembler* masm) {
27 __ sll(t9, a0, kPointerSizeLog2);
28 __ Addu(t9, sp, t9);
29 __ sw(a1, MemOperand(t9, 0));
30 __ Push(a1);
31 __ Push(a2);
32 __ Addu(a0, a0, Operand(3));
33 __ TailCallRuntime(Runtime::kNewArray);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034}
35
Ben Murdochda12d292016-06-02 14:46:10 +010036void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) {
37 Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry;
38 descriptor->Initialize(a0, deopt_handler, -1, JS_FUNCTION_STUB_MODE);
39}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040
Ben Murdoch61f157c2016-09-16 13:49:30 +010041void FastFunctionBindStub::InitializeDescriptor(
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 CodeStubDescriptor* descriptor) {
Ben Murdoch61f157c2016-09-16 13:49:30 +010043 Address deopt_handler = Runtime::FunctionForId(Runtime::kFunctionBind)->entry;
44 descriptor->Initialize(a0, deopt_handler, -1, JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045}
46
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000047static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +010048 Condition cc);
Ben Murdoch257744e2011-11-30 15:57:28 +000049static void EmitSmiNonsmiComparison(MacroAssembler* masm,
50 Register lhs,
51 Register rhs,
52 Label* rhs_not_nan,
53 Label* slow,
54 bool strict);
Ben Murdoch257744e2011-11-30 15:57:28 +000055static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
56 Register lhs,
57 Register rhs);
58
59
Ben Murdochb8a8cc12014-11-26 15:28:44 +000060void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
61 ExternalReference miss) {
62 // Update the static counter each time a new code stub is generated.
63 isolate()->counters()->code_stubs()->Increment();
Ben Murdoch257744e2011-11-30 15:57:28 +000064
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000066 int param_count = descriptor.GetRegisterParameterCount();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067 {
68 // Call the runtime system in a fresh internal frame.
69 FrameScope scope(masm, StackFrame::INTERNAL);
70 DCHECK(param_count == 0 ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072 // Push arguments, adjust sp.
73 __ Subu(sp, sp, Operand(param_count * kPointerSize));
74 for (int i = 0; i < param_count; ++i) {
75 // Store argument to stack.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000076 __ sw(descriptor.GetRegisterParameter(i),
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
78 }
79 __ CallExternalReference(miss, param_count);
80 }
Steve Block44f0eee2011-05-26 01:26:41 +010081
Ben Murdoch257744e2011-11-30 15:57:28 +000082 __ Ret();
Steve Block44f0eee2011-05-26 01:26:41 +010083}
84
85
Ben Murdochb8a8cc12014-11-26 15:28:44 +000086void DoubleToIStub::Generate(MacroAssembler* masm) {
87 Label out_of_range, only_low, negate, done;
88 Register input_reg = source();
89 Register result_reg = destination();
Ben Murdoch257744e2011-11-30 15:57:28 +000090
Ben Murdochb8a8cc12014-11-26 15:28:44 +000091 int double_offset = offset();
92 // Account for saved regs if input is sp.
93 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
Ben Murdoch257744e2011-11-30 15:57:28 +000094
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095 Register scratch =
96 GetRegisterThatIsNotOneOf(input_reg, result_reg);
97 Register scratch2 =
98 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
99 Register scratch3 =
100 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
101 DoubleRegister double_scratch = kLithiumScratchDouble;
Ben Murdoch257744e2011-11-30 15:57:28 +0000102
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103 __ Push(scratch, scratch2, scratch3);
Ben Murdoch257744e2011-11-30 15:57:28 +0000104
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105 if (!skip_fastpath()) {
106 // Load double input.
107 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000108
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109 // Clear cumulative exception flags and save the FCSR.
110 __ cfc1(scratch2, FCSR);
111 __ ctc1(zero_reg, FCSR);
Ben Murdoch257744e2011-11-30 15:57:28 +0000112
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113 // Try a conversion to a signed integer.
114 __ Trunc_w_d(double_scratch, double_scratch);
115 // Move the converted value into the result register.
116 __ mfc1(scratch3, double_scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +0000117
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118 // Retrieve and restore the FCSR.
119 __ cfc1(scratch, FCSR);
120 __ ctc1(scratch2, FCSR);
Steve Block44f0eee2011-05-26 01:26:41 +0100121
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000122 // Check for overflow and NaNs.
123 __ And(
124 scratch, scratch,
125 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
126 | kFCSRInvalidOpFlagMask);
127 // If we had no exceptions then set result_reg and we are done.
128 Label error;
129 __ Branch(&error, ne, scratch, Operand(zero_reg));
130 __ Move(result_reg, scratch3);
Ben Murdoch257744e2011-11-30 15:57:28 +0000131 __ Branch(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132 __ bind(&error);
Ben Murdoch257744e2011-11-30 15:57:28 +0000133 }
134
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000135 // Load the double value and perform a manual truncation.
136 Register input_high = scratch2;
137 Register input_low = scratch3;
Ben Murdoch257744e2011-11-30 15:57:28 +0000138
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000139 __ lw(input_low,
140 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
141 __ lw(input_high,
142 MemOperand(input_reg, double_offset + Register::kExponentOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000143
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000144 Label normal_exponent, restore_sign;
145 // Extract the biased exponent in result.
146 __ Ext(result_reg,
147 input_high,
Ben Murdoch257744e2011-11-30 15:57:28 +0000148 HeapNumber::kExponentShift,
149 HeapNumber::kExponentBits);
150
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000151 // Check for Infinity and NaNs, which should return 0.
152 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
153 __ Movz(result_reg, zero_reg, scratch);
154 __ Branch(&done, eq, scratch, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000155
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000156 // Express exponent as delta to (number of mantissa bits + 31).
157 __ Subu(result_reg,
158 result_reg,
159 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
Ben Murdoch257744e2011-11-30 15:57:28 +0000160
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000161 // If the delta is strictly positive, all bits would be shifted away,
162 // which means that we can return 0.
163 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
164 __ mov(result_reg, zero_reg);
165 __ Branch(&done);
Ben Murdoch257744e2011-11-30 15:57:28 +0000166
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000167 __ bind(&normal_exponent);
168 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
169 // Calculate shift.
170 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
Ben Murdoch257744e2011-11-30 15:57:28 +0000171
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172 // Save the sign.
173 Register sign = result_reg;
174 result_reg = no_reg;
175 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
Ben Murdoch257744e2011-11-30 15:57:28 +0000176
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000177 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
178 // to check for this specific case.
179 Label high_shift_needed, high_shift_done;
180 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
181 __ mov(input_high, zero_reg);
182 __ Branch(&high_shift_done);
183 __ bind(&high_shift_needed);
184
185 // Set the implicit 1 before the mantissa part in input_high.
186 __ Or(input_high,
187 input_high,
188 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
189 // Shift the mantissa bits to the correct position.
190 // We don't need to clear non-mantissa bits as they will be shifted away.
191 // If they weren't, it would mean that the answer is in the 32bit range.
192 __ sllv(input_high, input_high, scratch);
193
194 __ bind(&high_shift_done);
195
196 // Replace the shifted bits with bits from the lower mantissa word.
197 Label pos_shift, shift_done;
Ben Murdoch257744e2011-11-30 15:57:28 +0000198 __ li(at, 32);
199 __ subu(scratch, at, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000200 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
201
202 // Negate scratch.
203 __ Subu(scratch, zero_reg, scratch);
204 __ sllv(input_low, input_low, scratch);
205 __ Branch(&shift_done);
206
207 __ bind(&pos_shift);
208 __ srlv(input_low, input_low, scratch);
209
210 __ bind(&shift_done);
211 __ Or(input_high, input_high, Operand(input_low));
212 // Restore sign if necessary.
213 __ mov(scratch, sign);
214 result_reg = sign;
215 sign = no_reg;
216 __ Subu(result_reg, zero_reg, input_high);
217 __ Movz(result_reg, input_high, scratch);
218
219 __ bind(&done);
220
221 __ Pop(scratch, scratch2, scratch3);
222 __ Ret();
Ben Murdoch257744e2011-11-30 15:57:28 +0000223}
224
225
Ben Murdoch257744e2011-11-30 15:57:28 +0000226// Handle the case where the lhs and rhs are the same object.
227// Equality is almost reflexive (everything but NaN), so this is a test
228// for "identity and not NaN".
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000229static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100230 Condition cc) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000231 Label not_identical;
232 Label heap_number, return_equal;
233 Register exp_mask_reg = t5;
234
235 __ Branch(&not_identical, ne, a0, Operand(a1));
236
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
Ben Murdoch257744e2011-11-30 15:57:28 +0000238
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
240 // so we do the second best thing - test it ourselves.
241 // They are both equal and they are not both Smis so both of them are not
242 // Smis. If it's not a heap number, then return equal.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000243 __ GetObjectType(a0, t4, t4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000244 if (cc == less || cc == greater) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000245 // Call runtime on identical JSObjects.
246 __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE));
247 // Call runtime on identical symbols since we need to throw a TypeError.
248 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
249 // Call runtime on identical SIMD values since we must throw a TypeError.
250 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000251 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000252 __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE));
253 // Comparing JS objects with <=, >= is complicated.
254 if (cc != eq) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100255 __ Branch(slow, greater, t4, Operand(FIRST_JS_RECEIVER_TYPE));
256 // Call runtime on identical symbols since we need to throw a TypeError.
257 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
258 // Call runtime on identical SIMD values since we must throw a TypeError.
259 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260 // Normally here we fall through to return_equal, but undefined is
261 // special: (undefined == undefined) == true, but
262 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
263 if (cc == less_equal || cc == greater_equal) {
264 __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE));
265 __ LoadRoot(t2, Heap::kUndefinedValueRootIndex);
266 __ Branch(&return_equal, ne, a0, Operand(t2));
267 DCHECK(is_int16(GREATER) && is_int16(LESS));
268 __ Ret(USE_DELAY_SLOT);
269 if (cc == le) {
270 // undefined <= undefined should fail.
271 __ li(v0, Operand(GREATER));
272 } else {
273 // undefined >= undefined should fail.
274 __ li(v0, Operand(LESS));
Ben Murdoch257744e2011-11-30 15:57:28 +0000275 }
276 }
277 }
278 }
279
280 __ bind(&return_equal);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000281 DCHECK(is_int16(GREATER) && is_int16(LESS));
282 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +0000283 if (cc == less) {
284 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
285 } else if (cc == greater) {
286 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
287 } else {
288 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
289 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000290
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000291 // For less and greater we don't have to check for NaN since the result of
292 // x < x is false regardless. For the others here is some code to check
293 // for NaN.
294 if (cc != lt && cc != gt) {
295 __ bind(&heap_number);
296 // It is a heap number, so return non-equal if it's NaN and equal if it's
297 // not NaN.
Ben Murdoch257744e2011-11-30 15:57:28 +0000298
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000299 // The representation of NaN values has all exponent bits (52..62) set,
300 // and not all mantissa bits (0..51) clear.
301 // Read top bits of double representation (second word of value).
302 __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset));
303 // Test that exponent bits are all set.
304 __ And(t3, t2, Operand(exp_mask_reg));
305 // If all bits not set (ne cond), then not a NaN, objects are equal.
306 __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000307
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000308 // Shift out flag and all exponent bits, retaining only mantissa.
309 __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord);
310 // Or with all low-bits of mantissa.
311 __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
312 __ Or(v0, t3, Operand(t2));
313 // For equal we already have the right value in v0: Return zero (equal)
314 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
315 // not (it's a NaN). For <= and >= we need to load v0 with the failing
316 // value if it's a NaN.
317 if (cc != eq) {
318 // All-zero means Infinity means equal.
319 __ Ret(eq, v0, Operand(zero_reg));
320 DCHECK(is_int16(GREATER) && is_int16(LESS));
321 __ Ret(USE_DELAY_SLOT);
322 if (cc == le) {
323 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
324 } else {
325 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
Ben Murdoch257744e2011-11-30 15:57:28 +0000326 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000327 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000328 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329 // No fall through here.
Ben Murdoch257744e2011-11-30 15:57:28 +0000330
331 __ bind(&not_identical);
332}
333
334
335static void EmitSmiNonsmiComparison(MacroAssembler* masm,
336 Register lhs,
337 Register rhs,
338 Label* both_loaded_as_doubles,
339 Label* slow,
340 bool strict) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000341 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
Ben Murdoch257744e2011-11-30 15:57:28 +0000342 (lhs.is(a1) && rhs.is(a0)));
343
344 Label lhs_is_smi;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100345 __ JumpIfSmi(lhs, &lhs_is_smi);
Ben Murdoch257744e2011-11-30 15:57:28 +0000346 // Rhs is a Smi.
347 // Check whether the non-smi is a heap number.
348 __ GetObjectType(lhs, t4, t4);
349 if (strict) {
350 // If lhs was not a number and rhs was a Smi then strict equality cannot
351 // succeed. Return non-equal (lhs is already not zero).
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100352 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
Ben Murdoch257744e2011-11-30 15:57:28 +0000353 __ mov(v0, lhs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000354 } else {
355 // Smi compared non-strictly with a non-Smi non-heap-number. Call
356 // the runtime.
357 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
358 }
359
360 // Rhs is a smi, lhs is a number.
361 // Convert smi rhs to double.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000362 __ sra(at, rhs, kSmiTagSize);
363 __ mtc1(at, f14);
364 __ cvt_d_w(f14, f14);
365 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000366
367 // We now have both loaded as doubles.
368 __ jmp(both_loaded_as_doubles);
369
370 __ bind(&lhs_is_smi);
371 // Lhs is a Smi. Check whether the non-smi is a heap number.
372 __ GetObjectType(rhs, t4, t4);
373 if (strict) {
374 // If lhs was not a number and rhs was a Smi then strict equality cannot
375 // succeed. Return non-equal.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100376 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
Ben Murdoch257744e2011-11-30 15:57:28 +0000377 __ li(v0, Operand(1));
Ben Murdoch257744e2011-11-30 15:57:28 +0000378 } else {
379 // Smi compared non-strictly with a non-Smi non-heap-number. Call
380 // the runtime.
381 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
382 }
383
384 // Lhs is a smi, rhs is a number.
385 // Convert smi lhs to double.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386 __ sra(at, lhs, kSmiTagSize);
387 __ mtc1(at, f12);
388 __ cvt_d_w(f12, f12);
389 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000390 // Fall through to both_loaded_as_doubles.
Steve Block44f0eee2011-05-26 01:26:41 +0100391}
392
393
Ben Murdoch257744e2011-11-30 15:57:28 +0000394static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
395 Register lhs,
396 Register rhs) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000397 // If either operand is a JS object or an oddball value, then they are
Ben Murdoch257744e2011-11-30 15:57:28 +0000398 // not equal since their pointers are different.
399 // There is no test for undetectability in strict equality.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000400 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Ben Murdoch257744e2011-11-30 15:57:28 +0000401 Label first_non_object;
402 // Get the type of the first operand into a2 and compare it with
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000403 // FIRST_JS_RECEIVER_TYPE.
Ben Murdoch257744e2011-11-30 15:57:28 +0000404 __ GetObjectType(lhs, a2, a2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000405 __ Branch(&first_non_object, less, a2, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdoch257744e2011-11-30 15:57:28 +0000406
407 // Return non-zero.
408 Label return_not_equal;
409 __ bind(&return_not_equal);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100410 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +0000411 __ li(v0, Operand(1));
Ben Murdoch257744e2011-11-30 15:57:28 +0000412
413 __ bind(&first_non_object);
414 // Check for oddballs: true, false, null, undefined.
415 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
416
417 __ GetObjectType(rhs, a3, a3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000418 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdoch257744e2011-11-30 15:57:28 +0000419
420 // Check for oddballs: true, false, null, undefined.
421 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
422
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000423 // Now that we have the types we might as well check for
424 // internalized-internalized.
425 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
426 __ Or(a2, a2, Operand(a3));
427 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
428 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000429}
430
431
432static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
433 Register lhs,
434 Register rhs,
435 Label* both_loaded_as_doubles,
436 Label* not_heap_numbers,
437 Label* slow) {
438 __ GetObjectType(lhs, a3, a2);
439 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
440 __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
441 // If first was a heap number & second wasn't, go to slow case.
442 __ Branch(slow, ne, a3, Operand(a2));
443
444 // Both are heap numbers. Load them up then jump to the code we have
445 // for that.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000446 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
447 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
448
Ben Murdoch257744e2011-11-30 15:57:28 +0000449 __ jmp(both_loaded_as_doubles);
450}
451
452
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000453// Fast negative check for internalized-to-internalized equality.
454static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100455 Register lhs, Register rhs,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000456 Label* possible_strings,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100457 Label* runtime_call) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000458 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
Ben Murdoch257744e2011-11-30 15:57:28 +0000459 (lhs.is(a1) && rhs.is(a0)));
460
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461 // a2 is object type of rhs.
Ben Murdochda12d292016-06-02 14:46:10 +0100462 Label object_test, return_equal, return_unequal, undetectable;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000463 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
Ben Murdoch257744e2011-11-30 15:57:28 +0000464 __ And(at, a2, Operand(kIsNotStringMask));
465 __ Branch(&object_test, ne, at, Operand(zero_reg));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000466 __ And(at, a2, Operand(kIsNotInternalizedMask));
467 __ Branch(possible_strings, ne, at, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000468 __ GetObjectType(rhs, a3, a3);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100469 __ Branch(runtime_call, ge, a3, Operand(FIRST_NONSTRING_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000470 __ And(at, a3, Operand(kIsNotInternalizedMask));
471 __ Branch(possible_strings, ne, at, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000472
Ben Murdoch097c5b22016-05-18 11:27:45 +0100473 // Both are internalized. We already checked they weren't the same pointer so
474 // they are not equal. Return non-equal by returning the non-zero object
475 // pointer in v0.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100476 __ Ret(USE_DELAY_SLOT);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100477 __ mov(v0, a0); // In delay slot.
Ben Murdoch257744e2011-11-30 15:57:28 +0000478
479 __ bind(&object_test);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100480 __ lw(a2, FieldMemOperand(lhs, HeapObject::kMapOffset));
481 __ lw(a3, FieldMemOperand(rhs, HeapObject::kMapOffset));
482 __ lbu(t0, FieldMemOperand(a2, Map::kBitFieldOffset));
483 __ lbu(t1, FieldMemOperand(a3, Map::kBitFieldOffset));
484 __ And(at, t0, Operand(1 << Map::kIsUndetectable));
485 __ Branch(&undetectable, ne, at, Operand(zero_reg));
486 __ And(at, t1, Operand(1 << Map::kIsUndetectable));
487 __ Branch(&return_unequal, ne, at, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000488
Ben Murdoch097c5b22016-05-18 11:27:45 +0100489 __ GetInstanceType(a2, a2);
490 __ Branch(runtime_call, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE));
491 __ GetInstanceType(a3, a3);
492 __ Branch(runtime_call, lt, a3, Operand(FIRST_JS_RECEIVER_TYPE));
493
494 __ bind(&return_unequal);
495 // Return non-equal by returning the non-zero object pointer in v0.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100496 __ Ret(USE_DELAY_SLOT);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100497 __ mov(v0, a0); // In delay slot.
498
499 __ bind(&undetectable);
500 __ And(at, t1, Operand(1 << Map::kIsUndetectable));
501 __ Branch(&return_unequal, eq, at, Operand(zero_reg));
Ben Murdochda12d292016-06-02 14:46:10 +0100502
503 // If both sides are JSReceivers, then the result is false according to
504 // the HTML specification, which says that only comparisons with null or
505 // undefined are affected by special casing for document.all.
506 __ GetInstanceType(a2, a2);
507 __ Branch(&return_equal, eq, a2, Operand(ODDBALL_TYPE));
508 __ GetInstanceType(a3, a3);
509 __ Branch(&return_unequal, ne, a3, Operand(ODDBALL_TYPE));
510
511 __ bind(&return_equal);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100512 __ Ret(USE_DELAY_SLOT);
513 __ li(v0, Operand(EQUAL)); // In delay slot.
Steve Block44f0eee2011-05-26 01:26:41 +0100514}
515
516
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000517static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
518 Register scratch,
519 CompareICState::State expected,
520 Label* fail) {
521 Label ok;
522 if (expected == CompareICState::SMI) {
523 __ JumpIfNotSmi(input, fail);
524 } else if (expected == CompareICState::NUMBER) {
525 __ JumpIfSmi(input, &ok);
526 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
527 DONT_DO_SMI_CHECK);
Ben Murdoch257744e2011-11-30 15:57:28 +0000528 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000529 // We could be strict about internalized/string here, but as long as
530 // hydrogen doesn't care, the stub doesn't have to care either.
531 __ bind(&ok);
Steve Block44f0eee2011-05-26 01:26:41 +0100532}
533
534
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000535// On entry a1 and a2 are the values to be compared.
536// On exit a0 is 0, positive or negative to indicate the result of
537// the comparison.
538void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
539 Register lhs = a1;
540 Register rhs = a0;
541 Condition cc = GetCondition();
Ben Murdoch257744e2011-11-30 15:57:28 +0000542
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000543 Label miss;
544 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
545 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
Ben Murdoch257744e2011-11-30 15:57:28 +0000546
Ben Murdoch257744e2011-11-30 15:57:28 +0000547 Label slow; // Call builtin.
548 Label not_smis, both_loaded_as_doubles;
549
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000550 Label not_two_smis, smi_done;
551 __ Or(a2, a1, a0);
552 __ JumpIfNotSmi(a2, &not_two_smis);
553 __ sra(a1, a1, 1);
554 __ sra(a0, a0, 1);
555 __ Ret(USE_DELAY_SLOT);
556 __ subu(v0, a1, a0);
557 __ bind(&not_two_smis);
Ben Murdoch257744e2011-11-30 15:57:28 +0000558
559 // NOTICE! This code is only reached after a smi-fast-case check, so
560 // it is certain that at least one operand isn't a smi.
561
562 // Handle the case where the objects are identical. Either returns the answer
563 // or goes to slow. Only falls through if the objects were not identical.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100564 EmitIdenticalObjectComparison(masm, &slow, cc);
Ben Murdoch257744e2011-11-30 15:57:28 +0000565
566 // If either is a Smi (we know that not both are), then they can only
567 // be strictly equal if the other is a HeapNumber.
568 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000569 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000570 __ And(t2, lhs, Operand(rhs));
Ben Murdoch257744e2011-11-30 15:57:28 +0000571 __ JumpIfNotSmi(t2, &not_smis, t0);
572 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
573 // 1) Return the answer.
574 // 2) Go to slow.
575 // 3) Fall through to both_loaded_as_doubles.
576 // 4) Jump to rhs_not_nan.
577 // In cases 3 and 4 we have found out we were dealing with a number-number
578 // comparison and the numbers have been loaded into f12 and f14 as doubles,
579 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000580 EmitSmiNonsmiComparison(masm, lhs, rhs,
581 &both_loaded_as_doubles, &slow, strict());
Ben Murdoch257744e2011-11-30 15:57:28 +0000582
583 __ bind(&both_loaded_as_doubles);
584 // f12, f14 are the double representations of the left hand side
585 // and the right hand side if we have FPU. Otherwise a2, a3 represent
586 // left hand side and a0, a1 represent right hand side.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000587 Label nan;
588 __ li(t0, Operand(LESS));
589 __ li(t1, Operand(GREATER));
590 __ li(t2, Operand(EQUAL));
Ben Murdoch257744e2011-11-30 15:57:28 +0000591
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000592 // Check if either rhs or lhs is NaN.
593 __ BranchF(NULL, &nan, eq, f12, f14);
Ben Murdoch257744e2011-11-30 15:57:28 +0000594
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000595 // Check if LESS condition is satisfied. If true, move conditionally
596 // result to v0.
597 if (!IsMipsArchVariant(kMips32r6)) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000598 __ c(OLT, D, f12, f14);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100599 __ Movt(v0, t0);
Ben Murdoch257744e2011-11-30 15:57:28 +0000600 // Use previous check to store conditionally to v0 oposite condition
601 // (GREATER). If rhs is equal to lhs, this will be corrected in next
602 // check.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100603 __ Movf(v0, t1);
Ben Murdoch257744e2011-11-30 15:57:28 +0000604 // Check if EQUAL condition is satisfied. If true, move conditionally
605 // result to v0.
606 __ c(EQ, D, f12, f14);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100607 __ Movt(v0, t2);
Ben Murdoch257744e2011-11-30 15:57:28 +0000608 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000609 Label skip;
610 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
611 __ mov(v0, t0); // Return LESS as result.
Ben Murdoch257744e2011-11-30 15:57:28 +0000612
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000613 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
614 __ mov(v0, t2); // Return EQUAL as result.
615
616 __ mov(v0, t1); // Return GREATER as result.
617 __ bind(&skip);
Ben Murdoch257744e2011-11-30 15:57:28 +0000618 }
619
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000620 __ Ret();
621
622 __ bind(&nan);
623 // NaN comparisons always fail.
624 // Load whatever we need in v0 to make the comparison fail.
625 DCHECK(is_int16(GREATER) && is_int16(LESS));
626 __ Ret(USE_DELAY_SLOT);
627 if (cc == lt || cc == le) {
628 __ li(v0, Operand(GREATER));
629 } else {
630 __ li(v0, Operand(LESS));
631 }
632
633
Ben Murdoch257744e2011-11-30 15:57:28 +0000634 __ bind(&not_smis);
635 // At this point we know we are dealing with two different objects,
636 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000637 if (strict()) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000638 // This returns non-equal for some object types, or falls through if it
639 // was not lucky.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000640 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000641 }
642
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000643 Label check_for_internalized_strings;
Ben Murdoch257744e2011-11-30 15:57:28 +0000644 Label flat_string_check;
645 // Check for heap-number-heap-number comparison. Can jump to slow case,
646 // or load both doubles and jump to the code that handles
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000647 // that case. If the inputs are not doubles then jumps to
648 // check_for_internalized_strings.
Ben Murdoch257744e2011-11-30 15:57:28 +0000649 // In this case a2 will contain the type of lhs_.
650 EmitCheckForTwoHeapNumbers(masm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000651 lhs,
652 rhs,
Ben Murdoch257744e2011-11-30 15:57:28 +0000653 &both_loaded_as_doubles,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000654 &check_for_internalized_strings,
Ben Murdoch257744e2011-11-30 15:57:28 +0000655 &flat_string_check);
656
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000657 __ bind(&check_for_internalized_strings);
658 if (cc == eq && !strict()) {
659 // Returns an answer for two internalized strings or two
660 // detectable objects.
Ben Murdoch257744e2011-11-30 15:57:28 +0000661 // Otherwise jumps to string case or not both strings case.
662 // Assumes that a2 is the type of lhs_ on entry.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000663 EmitCheckForInternalizedStringsOrObjects(
664 masm, lhs, rhs, &flat_string_check, &slow);
Ben Murdoch257744e2011-11-30 15:57:28 +0000665 }
666
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000667 // Check for both being sequential one-byte strings,
668 // and inline if that is the case.
Ben Murdoch257744e2011-11-30 15:57:28 +0000669 __ bind(&flat_string_check);
670
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000671 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
Ben Murdoch257744e2011-11-30 15:57:28 +0000672
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000673 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
674 a3);
675 if (cc == eq) {
676 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0);
Ben Murdoch257744e2011-11-30 15:57:28 +0000677 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000678 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0,
679 t1);
Ben Murdoch257744e2011-11-30 15:57:28 +0000680 }
681 // Never falls through to here.
682
683 __ bind(&slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000684 if (cc == eq) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100685 {
686 FrameScope scope(masm, StackFrame::INTERNAL);
687 __ Push(lhs, rhs);
688 __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual);
689 }
690 // Turn true into 0 and false into some non-zero value.
691 STATIC_ASSERT(EQUAL == 0);
692 __ LoadRoot(a0, Heap::kTrueValueRootIndex);
693 __ Ret(USE_DELAY_SLOT);
694 __ subu(v0, v0, a0); // In delay slot.
Ben Murdoch257744e2011-11-30 15:57:28 +0000695 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100696 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
697 // a1 (rhs) second.
698 __ Push(lhs, rhs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000699 int ncr; // NaN compare result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000700 if (cc == lt || cc == le) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000701 ncr = GREATER;
702 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000703 DCHECK(cc == gt || cc == ge); // Remaining cases.
Ben Murdoch257744e2011-11-30 15:57:28 +0000704 ncr = LESS;
705 }
706 __ li(a0, Operand(Smi::FromInt(ncr)));
707 __ push(a0);
Ben Murdoch257744e2011-11-30 15:57:28 +0000708
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000709 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
710 // tagged as a small integer.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100711 __ TailCallRuntime(Runtime::kCompare);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000712 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000713
714 __ bind(&miss);
715 GenerateMiss(masm);
Steve Block44f0eee2011-05-26 01:26:41 +0100716}
717
718
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000719void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
720 __ mov(t9, ra);
721 __ pop(ra);
722 __ PushSafepointRegisters();
723 __ Jump(t9);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100724}
Ben Murdoch257744e2011-11-30 15:57:28 +0000725
Ben Murdoch257744e2011-11-30 15:57:28 +0000726
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000727void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
728 __ mov(t9, ra);
729 __ pop(ra);
730 __ PopSafepointRegisters();
731 __ Jump(t9);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100732}
733
734
735void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
736 // We don't allow a GC during a store buffer overflow so there is no need to
737 // store the registers in any particular way, but we do have to store and
738 // restore them.
739 __ MultiPush(kJSCallerSaved | ra.bit());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000740 if (save_doubles()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100741 __ MultiPushFPU(kCallerSavedFPU);
742 }
743 const int argument_count = 1;
744 const int fp_argument_count = 0;
745 const Register scratch = a1;
746
747 AllowExternalCallThatCantCauseGC scope(masm);
748 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000749 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100750 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000751 ExternalReference::store_buffer_overflow_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100752 argument_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000753 if (save_doubles()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100754 __ MultiPopFPU(kCallerSavedFPU);
755 }
756
757 __ MultiPop(kJSCallerSaved | ra.bit());
Ben Murdoch257744e2011-11-30 15:57:28 +0000758 __ Ret();
Steve Block44f0eee2011-05-26 01:26:41 +0100759}
760
761
Ben Murdoch257744e2011-11-30 15:57:28 +0000762void MathPowStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100763 const Register base = a1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000764 const Register exponent = MathPowTaggedDescriptor::exponent();
765 DCHECK(exponent.is(a2));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100766 const Register heapnumbermap = t1;
767 const Register heapnumber = v0;
768 const DoubleRegister double_base = f2;
769 const DoubleRegister double_exponent = f4;
770 const DoubleRegister double_result = f0;
771 const DoubleRegister double_scratch = f6;
772 const FPURegister single_scratch = f8;
773 const Register scratch = t5;
774 const Register scratch2 = t3;
Ben Murdoch257744e2011-11-30 15:57:28 +0000775
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100776 Label call_runtime, done, int_exponent;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000777 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100778 Label base_is_smi, unpack_exponent;
779 // The exponent and base are supplied as arguments on the stack.
780 // This can only happen if the stub is called from non-optimized code.
781 // Load input parameters from stack to double registers.
Ben Murdoch257744e2011-11-30 15:57:28 +0000782 __ lw(base, MemOperand(sp, 1 * kPointerSize));
783 __ lw(exponent, MemOperand(sp, 0 * kPointerSize));
784
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100785 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
Ben Murdoch257744e2011-11-30 15:57:28 +0000786
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100787 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
Ben Murdoch257744e2011-11-30 15:57:28 +0000788 __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset));
789 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100790
Ben Murdochc7cc0282012-03-05 14:35:55 +0000791 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100792 __ jmp(&unpack_exponent);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000793
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100794 __ bind(&base_is_smi);
795 __ mtc1(scratch, single_scratch);
796 __ cvt_d_w(double_base, single_scratch);
797 __ bind(&unpack_exponent);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000798
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100799 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
Ben Murdoch85b71792012-04-11 18:30:58 +0100800
Ben Murdoch85b71792012-04-11 18:30:58 +0100801 __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
802 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
Ben Murdoch85b71792012-04-11 18:30:58 +0100803 __ ldc1(double_exponent,
804 FieldMemOperand(exponent, HeapNumber::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000805 } else if (exponent_type() == TAGGED) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100806 // Base is already in double_base.
807 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
Ben Murdoch85b71792012-04-11 18:30:58 +0100808
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100809 __ ldc1(double_exponent,
810 FieldMemOperand(exponent, HeapNumber::kValueOffset));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000811 }
Ben Murdoch85b71792012-04-11 18:30:58 +0100812
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000813 if (exponent_type() != INTEGER) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100814 Label int_exponent_convert;
815 // Detect integer exponents stored as double.
816 __ EmitFPUTruncate(kRoundToMinusInf,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100817 scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000818 double_exponent,
819 at,
820 double_scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100821 scratch2,
822 kCheckForInexactConversion);
823 // scratch2 == 0 means there was no conversion error.
824 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
825
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000826 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100827 // Detect square root case. Crankshaft detects constant +/-0.5 at
828 // compile time and uses DoMathPowHalf instead. We then skip this check
829 // for non-constant cases of +/-0.5 as these hardly occur.
830 Label not_plus_half;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100831 // Test for 0.5.
832 __ Move(double_scratch, 0.5);
833 __ BranchF(USE_DELAY_SLOT,
834 &not_plus_half,
835 NULL,
836 ne,
837 double_exponent,
838 double_scratch);
839 // double_scratch can be overwritten in the delay slot.
840 // Calculates square root of base. Check for the special case of
841 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400842 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100843 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
844 __ neg_d(double_result, double_scratch);
845
846 // Add +0 to convert -0 to +0.
847 __ add_d(double_scratch, double_base, kDoubleRegZero);
848 __ sqrt_d(double_result, double_scratch);
849 __ jmp(&done);
850
851 __ bind(&not_plus_half);
852 __ Move(double_scratch, -0.5);
853 __ BranchF(USE_DELAY_SLOT,
854 &call_runtime,
855 NULL,
856 ne,
857 double_exponent,
858 double_scratch);
859 // double_scratch can be overwritten in the delay slot.
860 // Calculates square root of base. Check for the special case of
861 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400862 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100863 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
864 __ Move(double_result, kDoubleRegZero);
865
866 // Add +0 to convert -0 to +0.
867 __ add_d(double_scratch, double_base, kDoubleRegZero);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400868 __ Move(double_result, 1.);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100869 __ sqrt_d(double_scratch, double_scratch);
870 __ div_d(double_result, double_result, double_scratch);
871 __ jmp(&done);
872 }
873
874 __ push(ra);
875 {
876 AllowExternalCallThatCantCauseGC scope(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000877 __ PrepareCallCFunction(0, 2, scratch2);
878 __ MovToFloatParameters(double_base, double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100879 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000880 ExternalReference::power_double_double_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100881 0, 2);
882 }
883 __ pop(ra);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000884 __ MovFromFloatResult(double_result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100885 __ jmp(&done);
886
887 __ bind(&int_exponent_convert);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100888 }
889
890 // Calculate power with integer exponent.
891 __ bind(&int_exponent);
892
893 // Get two copies of exponent in the registers scratch and exponent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000894 if (exponent_type() == INTEGER) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100895 __ mov(scratch, exponent);
896 } else {
897 // Exponent has previously been stored into scratch as untagged integer.
898 __ mov(exponent, scratch);
899 }
900
901 __ mov_d(double_scratch, double_base); // Back up base.
902 __ Move(double_result, 1.0);
903
904 // Get absolute value of exponent.
905 Label positive_exponent;
906 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
907 __ Subu(scratch, zero_reg, scratch);
908 __ bind(&positive_exponent);
909
910 Label while_true, no_carry, loop_end;
911 __ bind(&while_true);
912
913 __ And(scratch2, scratch, 1);
914
915 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
916 __ mul_d(double_result, double_result, double_scratch);
917 __ bind(&no_carry);
918
919 __ sra(scratch, scratch, 1);
920
921 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
922 __ mul_d(double_scratch, double_scratch, double_scratch);
923
924 __ Branch(&while_true);
925
926 __ bind(&loop_end);
927
928 __ Branch(&done, ge, exponent, Operand(zero_reg));
929 __ Move(double_scratch, 1.0);
930 __ div_d(double_result, double_scratch, double_result);
931 // Test whether result is zero. Bail out to check for subnormal result.
932 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
933 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
934
935 // double_exponent may not contain the exponent value if the input was a
936 // smi. We set it with exponent value before bailing out.
937 __ mtc1(exponent, single_scratch);
938 __ cvt_d_w(double_exponent, single_scratch);
939
940 // Returning or bailing out.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000941 if (exponent_type() == ON_STACK) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100942 // The arguments are still on the stack.
943 __ bind(&call_runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000944 __ TailCallRuntime(Runtime::kMathPowRT);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100945
946 // The stub is called from non-optimized code, which expects the result
947 // as heap number in exponent.
948 __ bind(&done);
949 __ AllocateHeapNumber(
950 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
951 __ sdc1(double_result,
952 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000953 DCHECK(heapnumber.is(v0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100954 __ DropAndRet(2);
955 } else {
956 __ push(ra);
957 {
958 AllowExternalCallThatCantCauseGC scope(masm);
959 __ PrepareCallCFunction(0, 2, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000960 __ MovToFloatParameters(double_base, double_exponent);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100961 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000962 ExternalReference::power_double_double_function(isolate()),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100963 0, 2);
964 }
965 __ pop(ra);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000966 __ MovFromFloatResult(double_result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100967
968 __ bind(&done);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100969 __ Ret();
970 }
Steve Block44f0eee2011-05-26 01:26:41 +0100971}
972
973
974bool CEntryStub::NeedsImmovableCode() {
975 return true;
976}
977
978
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000979void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
980 CEntryStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000981 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
982 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100983 CommonArrayConstructorStub::GenerateStubsAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000984 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000985 CreateWeakCellStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000986 BinaryOpICStub::GenerateAheadOfTime(isolate);
987 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
988 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
989 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000990 StoreFastElementStub::GenerateAheadOfTime(isolate);
991 TypeofStub::GenerateAheadOfTime(isolate);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000992}
993
994
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000995void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
996 StoreRegistersStateStub stub(isolate);
997 stub.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100998}
999
1000
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001001void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1002 RestoreRegistersStateStub stub(isolate);
1003 stub.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001004}
1005
1006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001007void CodeStub::GenerateFPStubs(Isolate* isolate) {
1008 // Generate if not already in cache.
1009 SaveFPRegsMode mode = kSaveFPRegs;
1010 CEntryStub(isolate, 1, mode).GetCode();
1011 StoreBufferOverflowStub(isolate, mode).GetCode();
1012 isolate->set_fp_stubs_generated(true);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001013}
1014
1015
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1017 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1018 stub.GetCode();
1019}
Ben Murdoch257744e2011-11-30 15:57:28 +00001020
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001021
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001022void CEntryStub::Generate(MacroAssembler* masm) {
1023 // Called from JavaScript; parameters are on stack as if calling JS function
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001024 // a0: number of arguments including receiver
1025 // a1: pointer to builtin function
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001026 // fp: frame pointer (restored after C call)
1027 // sp: stack pointer (restored as callee's sp after C call)
1028 // cp: current context (C callee-saved)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001029 //
1030 // If argv_in_register():
1031 // a2: pointer to the first argument
Ben Murdoch257744e2011-11-30 15:57:28 +00001032
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001033 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1034
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001035 if (argv_in_register()) {
1036 // Move argv into the correct register.
1037 __ mov(s1, a2);
1038 } else {
1039 // Compute the argv pointer in a callee-saved register.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001040 __ Lsa(s1, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001041 __ Subu(s1, s1, kPointerSize);
1042 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001043
1044 // Enter the exit frame that transitions from JavaScript to C++.
1045 FrameScope scope(masm, StackFrame::MANUAL);
1046 __ EnterExitFrame(save_doubles());
1047
1048 // s0: number of arguments including receiver (C callee-saved)
1049 // s1: pointer to first argument (C callee-saved)
1050 // s2: pointer to builtin function (C callee-saved)
Ben Murdoch257744e2011-11-30 15:57:28 +00001051
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001052 // Prepare arguments for C routine.
1053 // a0 = argc
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001054 __ mov(s0, a0);
1055 __ mov(s2, a1);
Ben Murdoch257744e2011-11-30 15:57:28 +00001056
1057 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1058 // also need to reserve the 4 argument slots on the stack.
1059
1060 __ AssertStackIsAligned();
1061
Ben Murdoch097c5b22016-05-18 11:27:45 +01001062 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1063 int frame_alignment_mask = frame_alignment - 1;
1064 int result_stack_size;
1065 if (result_size() <= 2) {
1066 // a0 = argc, a1 = argv, a2 = isolate
1067 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1068 __ mov(a1, s1);
1069 result_stack_size = 0;
1070 } else {
1071 DCHECK_EQ(3, result_size());
1072 // Allocate additional space for the result.
1073 result_stack_size =
1074 ((result_size() * kPointerSize) + frame_alignment_mask) &
1075 ~frame_alignment_mask;
1076 __ Subu(sp, sp, Operand(result_stack_size));
1077
1078 // a0 = hidden result argument, a1 = argc, a2 = argv, a3 = isolate.
1079 __ li(a3, Operand(ExternalReference::isolate_address(isolate())));
1080 __ mov(a2, s1);
1081 __ mov(a1, a0);
1082 __ mov(a0, sp);
1083 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001084
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001085 // To let the GC traverse the return address of the exit frames, we need to
1086 // know where the return address is. The CEntryStub is unmovable, so
1087 // we can store the address on the stack to be able to find it again and
1088 // we never have to restore it, because it will not change.
Ben Murdoch257744e2011-11-30 15:57:28 +00001089 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001090 int kNumInstructionsToJump = 4;
Ben Murdoch257744e2011-11-30 15:57:28 +00001091 Label find_ra;
Ben Murdoch257744e2011-11-30 15:57:28 +00001092 // Adjust the value in ra to point to the correct return location, 2nd
1093 // instruction past the real call into C code (the jalr(t9)), and push it.
1094 // This is the return address of the exit frame.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001095 if (kArchVariant >= kMips32r6) {
1096 __ addiupc(ra, kNumInstructionsToJump + 1);
1097 } else {
1098 // This branch-and-link sequence is needed to find the current PC on mips
1099 // before r6, saved to the ra register.
1100 __ bal(&find_ra); // bal exposes branch delay slot.
1101 __ Addu(ra, ra, kNumInstructionsToJump * Instruction::kInstrSize);
1102 }
1103 __ bind(&find_ra);
1104
1105 // This spot was reserved in EnterExitFrame.
1106 __ sw(ra, MemOperand(sp, result_stack_size));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001107 // Stack space reservation moved to the branch delay slot below.
Ben Murdoch257744e2011-11-30 15:57:28 +00001108 // Stack is still aligned.
1109
1110 // Call the C routine.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001111 __ mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1112 __ jalr(t9);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001113 // Set up sp in the delay slot.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001114 __ addiu(sp, sp, -kCArgsSlotsSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00001115 // Make sure the stored 'ra' points to this position.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001116 DCHECK_EQ(kNumInstructionsToJump,
Ben Murdoch257744e2011-11-30 15:57:28 +00001117 masm->InstructionsGeneratedSince(&find_ra));
1118 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001119 if (result_size() > 2) {
1120 DCHECK_EQ(3, result_size());
1121 // Read result values stored on stack.
1122 __ lw(a0, MemOperand(v0, 2 * kPointerSize));
1123 __ lw(v1, MemOperand(v0, 1 * kPointerSize));
1124 __ lw(v0, MemOperand(v0, 0 * kPointerSize));
1125 }
1126 // Result returned in v0, v1:v0 or a0:v1:v0 - do not destroy these registers!
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001127
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001128 // Check result for exception sentinel.
1129 Label exception_returned;
1130 __ LoadRoot(t0, Heap::kExceptionRootIndex);
1131 __ Branch(&exception_returned, eq, t0, Operand(v0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001132
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001133 // Check that there is no pending exception, otherwise we
1134 // should have returned the exception sentinel.
1135 if (FLAG_debug_code) {
1136 Label okay;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001137 ExternalReference pending_exception_address(
1138 Isolate::kPendingExceptionAddress, isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001139 __ li(a2, Operand(pending_exception_address));
1140 __ lw(a2, MemOperand(a2));
1141 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1142 // Cannot use check here as it attempts to generate call into runtime.
1143 __ Branch(&okay, eq, t0, Operand(a2));
1144 __ stop("Unexpected pending exception");
1145 __ bind(&okay);
1146 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001147
1148 // Exit C frame and return.
1149 // v0:v1: result
1150 // sp: stack pointer
1151 // fp: frame pointer
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001152 Register argc;
1153 if (argv_in_register()) {
1154 // We don't want to pop arguments so set argc to no_reg.
1155 argc = no_reg;
1156 } else {
1157 // s0: still holds argc (callee-saved).
1158 argc = s0;
1159 }
1160 __ LeaveExitFrame(save_doubles(), argc, true, EMIT_RETURN);
Ben Murdoch257744e2011-11-30 15:57:28 +00001161
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001162 // Handling of exception.
1163 __ bind(&exception_returned);
Ben Murdoch257744e2011-11-30 15:57:28 +00001164
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001165 ExternalReference pending_handler_context_address(
1166 Isolate::kPendingHandlerContextAddress, isolate());
1167 ExternalReference pending_handler_code_address(
1168 Isolate::kPendingHandlerCodeAddress, isolate());
1169 ExternalReference pending_handler_offset_address(
1170 Isolate::kPendingHandlerOffsetAddress, isolate());
1171 ExternalReference pending_handler_fp_address(
1172 Isolate::kPendingHandlerFPAddress, isolate());
1173 ExternalReference pending_handler_sp_address(
1174 Isolate::kPendingHandlerSPAddress, isolate());
Ben Murdoch257744e2011-11-30 15:57:28 +00001175
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001176 // Ask the runtime for help to determine the handler. This will set v0 to
1177 // contain the current pending exception, don't clobber it.
1178 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1179 isolate());
1180 {
1181 FrameScope scope(masm, StackFrame::MANUAL);
1182 __ PrepareCallCFunction(3, 0, a0);
1183 __ mov(a0, zero_reg);
1184 __ mov(a1, zero_reg);
1185 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1186 __ CallCFunction(find_handler, 3);
1187 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001188
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001189 // Retrieve the handler context, SP and FP.
1190 __ li(cp, Operand(pending_handler_context_address));
1191 __ lw(cp, MemOperand(cp));
1192 __ li(sp, Operand(pending_handler_sp_address));
1193 __ lw(sp, MemOperand(sp));
1194 __ li(fp, Operand(pending_handler_fp_address));
1195 __ lw(fp, MemOperand(fp));
Ben Murdoch257744e2011-11-30 15:57:28 +00001196
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001197 // If the handler is a JS frame, restore the context to the frame. Note that
1198 // the context will be set to (cp == 0) for non-JS frames.
1199 Label zero;
1200 __ Branch(&zero, eq, cp, Operand(zero_reg));
1201 __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1202 __ bind(&zero);
Ben Murdoch257744e2011-11-30 15:57:28 +00001203
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001204 // Compute the handler entry address and jump to it.
1205 __ li(a1, Operand(pending_handler_code_address));
1206 __ lw(a1, MemOperand(a1));
1207 __ li(a2, Operand(pending_handler_offset_address));
1208 __ lw(a2, MemOperand(a2));
1209 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1210 __ Addu(t9, a1, a2);
1211 __ Jump(t9);
Steve Block44f0eee2011-05-26 01:26:41 +01001212}
1213
1214
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001215void JSEntryStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001216 Label invoke, handler_entry, exit;
1217 Isolate* isolate = masm->isolate();
Ben Murdoch257744e2011-11-30 15:57:28 +00001218
1219 // Registers:
1220 // a0: entry address
1221 // a1: function
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001222 // a2: receiver
Ben Murdoch257744e2011-11-30 15:57:28 +00001223 // a3: argc
1224 //
1225 // Stack:
1226 // 4 args slots
1227 // args
1228
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001229 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1230
Ben Murdoch257744e2011-11-30 15:57:28 +00001231 // Save callee saved registers on the stack.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001232 __ MultiPush(kCalleeSaved | ra.bit());
Ben Murdoch257744e2011-11-30 15:57:28 +00001233
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001234 // Save callee-saved FPU registers.
1235 __ MultiPushFPU(kCalleeSavedFPU);
1236 // Set up the reserved register for 0.0.
1237 __ Move(kDoubleRegZero, 0.0);
Ben Murdoch589d6972011-11-30 16:04:58 +00001238
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001239
Ben Murdoch257744e2011-11-30 15:57:28 +00001240 // Load argv in s0 register.
Ben Murdoch589d6972011-11-30 16:04:58 +00001241 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001242 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
Ben Murdoch589d6972011-11-30 16:04:58 +00001243
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001244 __ InitializeRootRegister();
Ben Murdoch589d6972011-11-30 16:04:58 +00001245 __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
Ben Murdoch257744e2011-11-30 15:57:28 +00001246
1247 // We build an EntryFrame.
1248 __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001249 int marker = type();
Ben Murdoch257744e2011-11-30 15:57:28 +00001250 __ li(t2, Operand(Smi::FromInt(marker)));
1251 __ li(t1, Operand(Smi::FromInt(marker)));
Ben Murdoch589d6972011-11-30 16:04:58 +00001252 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001253 isolate)));
Ben Murdoch257744e2011-11-30 15:57:28 +00001254 __ lw(t0, MemOperand(t0));
1255 __ Push(t3, t2, t1, t0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001256 // Set up frame pointer for the frame to be pushed.
Ben Murdoch257744e2011-11-30 15:57:28 +00001257 __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1258
1259 // Registers:
1260 // a0: entry_address
1261 // a1: function
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001262 // a2: receiver_pointer
Ben Murdoch257744e2011-11-30 15:57:28 +00001263 // a3: argc
1264 // s0: argv
1265 //
1266 // Stack:
1267 // caller fp |
1268 // function slot | entry frame
1269 // context slot |
1270 // bad fp (0xff...f) |
1271 // callee saved registers + ra
1272 // 4 args slots
1273 // args
1274
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001275 // If this is the outermost JS call, set js_entry_sp value.
1276 Label non_outermost_js;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001277 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001278 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1279 __ lw(t2, MemOperand(t1));
1280 __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
1281 __ sw(fp, MemOperand(t1));
1282 __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1283 Label cont;
1284 __ b(&cont);
1285 __ nop(); // Branch delay slot nop.
1286 __ bind(&non_outermost_js);
1287 __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1288 __ bind(&cont);
1289 __ push(t0);
Ben Murdoch257744e2011-11-30 15:57:28 +00001290
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001291 // Jump to a faked try block that does the invoke, with a faked catch
1292 // block that sets the pending exception.
1293 __ jmp(&invoke);
1294 __ bind(&handler_entry);
1295 handler_offset_ = handler_entry.pos();
1296 // Caught exception: Store result (exception) in the pending exception
1297 // field in the JSEnv and return a failure sentinel. Coming in here the
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001298 // fp will be invalid because the PushStackHandler below sets it to 0 to
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001299 // signal the existence of the JSEntry frame.
Ben Murdoch589d6972011-11-30 16:04:58 +00001300 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001301 isolate)));
Ben Murdoch257744e2011-11-30 15:57:28 +00001302 __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001303 __ LoadRoot(v0, Heap::kExceptionRootIndex);
Ben Murdoch257744e2011-11-30 15:57:28 +00001304 __ b(&exit); // b exposes branch delay slot.
1305 __ nop(); // Branch delay slot nop.
1306
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001307 // Invoke: Link this frame into the handler chain.
Ben Murdoch257744e2011-11-30 15:57:28 +00001308 __ bind(&invoke);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001309 __ PushStackHandler();
Ben Murdoch257744e2011-11-30 15:57:28 +00001310 // If an exception not caught by another handler occurs, this handler
1311 // returns control to the code after the bal(&invoke) above, which
1312 // restores all kCalleeSaved registers (including cp and fp) to their
1313 // saved values before returning a failure to C.
1314
1315 // Clear any pending exceptions.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001316 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
Ben Murdoch589d6972011-11-30 16:04:58 +00001317 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001318 isolate)));
Ben Murdoch257744e2011-11-30 15:57:28 +00001319 __ sw(t1, MemOperand(t0));
1320
1321 // Invoke the function by calling through JS entry trampoline builtin.
1322 // Notice that we cannot store a reference to the trampoline code directly in
1323 // this stub, because runtime stubs are not traversed when doing GC.
1324
1325 // Registers:
1326 // a0: entry_address
1327 // a1: function
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001328 // a2: receiver_pointer
Ben Murdoch257744e2011-11-30 15:57:28 +00001329 // a3: argc
1330 // s0: argv
1331 //
1332 // Stack:
1333 // handler frame
1334 // entry frame
1335 // callee saved registers + ra
1336 // 4 args slots
1337 // args
1338
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001339 if (type() == StackFrame::ENTRY_CONSTRUCT) {
Ben Murdoch257744e2011-11-30 15:57:28 +00001340 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001341 isolate);
Ben Murdoch257744e2011-11-30 15:57:28 +00001342 __ li(t0, Operand(construct_entry));
1343 } else {
1344 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1345 __ li(t0, Operand(entry));
1346 }
1347 __ lw(t9, MemOperand(t0)); // Deref address.
1348
1349 // Call JSEntryTrampoline.
1350 __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1351 __ Call(t9);
1352
1353 // Unlink this frame from the handler chain.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001354 __ PopStackHandler();
Ben Murdoch257744e2011-11-30 15:57:28 +00001355
1356 __ bind(&exit); // v0 holds result
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001357 // Check if the current stack frame is marked as the outermost JS frame.
1358 Label non_outermost_js_2;
1359 __ pop(t1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001360 __ Branch(&non_outermost_js_2,
1361 ne,
1362 t1,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001363 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1364 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1365 __ sw(zero_reg, MemOperand(t1));
1366 __ bind(&non_outermost_js_2);
Ben Murdoch257744e2011-11-30 15:57:28 +00001367
1368 // Restore the top frame descriptors from the stack.
1369 __ pop(t1);
Ben Murdoch589d6972011-11-30 16:04:58 +00001370 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001371 isolate)));
Ben Murdoch257744e2011-11-30 15:57:28 +00001372 __ sw(t1, MemOperand(t0));
1373
1374 // Reset the stack to the callee saved registers.
1375 __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1376
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001377 // Restore callee-saved fpu registers.
1378 __ MultiPopFPU(kCalleeSavedFPU);
Ben Murdoch589d6972011-11-30 16:04:58 +00001379
Ben Murdoch257744e2011-11-30 15:57:28 +00001380 // Restore callee saved registers from the stack.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001381 __ MultiPop(kCalleeSaved | ra.bit());
Ben Murdoch257744e2011-11-30 15:57:28 +00001382 // Return.
1383 __ Jump(ra);
Steve Block44f0eee2011-05-26 01:26:41 +01001384}
1385
1386
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001387void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1388 // Return address is in ra.
1389 Label miss;
1390
1391 Register receiver = LoadDescriptor::ReceiverRegister();
1392 Register index = LoadDescriptor::NameRegister();
1393 Register scratch = t1;
1394 Register result = v0;
1395 DCHECK(!scratch.is(receiver) && !scratch.is(index));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001396 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001397
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001398 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1399 &miss, // When not a string.
1400 &miss, // When not a number.
1401 &miss, // When index out of range.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001402 RECEIVER_IS_STRING);
1403 char_at_generator.GenerateFast(masm);
1404 __ Ret();
1405
1406 StubRuntimeCallHelper call_helper;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001407 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001408
1409 __ bind(&miss);
1410 PropertyAccessCompiler::TailCallBuiltin(
1411 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1412}
1413
1414
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001415void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1416 Label miss;
1417 Register receiver = LoadDescriptor::ReceiverRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001418 // Ensure that the vector and slot registers won't be clobbered before
1419 // calling the miss handler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001420 DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(),
1421 LoadWithVectorDescriptor::SlotRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001422
1423 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0,
1424 t1, &miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001425 __ bind(&miss);
1426 PropertyAccessCompiler::TailCallBuiltin(
1427 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1428}
Ben Murdoch257744e2011-11-30 15:57:28 +00001429
Steve Block44f0eee2011-05-26 01:26:41 +01001430void RegExpExecStub::Generate(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +00001431 // Just jump directly to runtime if native RegExp is not selected at compile
1432 // time or if regexp entry in generated code is turned off runtime switch or
1433 // at compilation.
1434#ifdef V8_INTERPRETED_REGEXP
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001435 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdoch257744e2011-11-30 15:57:28 +00001436#else // V8_INTERPRETED_REGEXP
Ben Murdoch257744e2011-11-30 15:57:28 +00001437
1438 // Stack frame on entry.
1439 // sp[0]: last_match_info (expected JSArray)
1440 // sp[4]: previous index
1441 // sp[8]: subject string
1442 // sp[12]: JSRegExp object
1443
Ben Murdochdb1b4382012-04-26 19:03:50 +01001444 const int kLastMatchInfoOffset = 0 * kPointerSize;
1445 const int kPreviousIndexOffset = 1 * kPointerSize;
1446 const int kSubjectOffset = 2 * kPointerSize;
1447 const int kJSRegExpOffset = 3 * kPointerSize;
Ben Murdoch257744e2011-11-30 15:57:28 +00001448
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001449 Label runtime;
Ben Murdoch257744e2011-11-30 15:57:28 +00001450 // Allocation of registers for this function. These are in callee save
1451 // registers and will be preserved by the call to the native RegExp code, as
1452 // this code is called using the normal C calling convention. When calling
1453 // directly from generated code the native RegExp code will not do a GC and
1454 // therefore the content of these registers are safe to use after the call.
1455 // MIPS - using s0..s2, since we are not using CEntry Stub.
1456 Register subject = s0;
1457 Register regexp_data = s1;
1458 Register last_match_info_elements = s2;
1459
1460 // Ensure that a RegExp stack is allocated.
1461 ExternalReference address_of_regexp_stack_memory_address =
Ben Murdoch097c5b22016-05-18 11:27:45 +01001462 ExternalReference::address_of_regexp_stack_memory_address(isolate());
Ben Murdoch257744e2011-11-30 15:57:28 +00001463 ExternalReference address_of_regexp_stack_memory_size =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001464 ExternalReference::address_of_regexp_stack_memory_size(isolate());
Ben Murdoch257744e2011-11-30 15:57:28 +00001465 __ li(a0, Operand(address_of_regexp_stack_memory_size));
1466 __ lw(a0, MemOperand(a0, 0));
1467 __ Branch(&runtime, eq, a0, Operand(zero_reg));
1468
1469 // Check that the first argument is a JSRegExp object.
1470 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
1471 STATIC_ASSERT(kSmiTag == 0);
1472 __ JumpIfSmi(a0, &runtime);
1473 __ GetObjectType(a0, a1, a1);
1474 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
1475
1476 // Check that the RegExp has been compiled (data contains a fixed array).
1477 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
1478 if (FLAG_debug_code) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001479 __ SmiTst(regexp_data, t0);
Ben Murdoch257744e2011-11-30 15:57:28 +00001480 __ Check(nz,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001481 kUnexpectedTypeForRegExpDataFixedArrayExpected,
Ben Murdoch257744e2011-11-30 15:57:28 +00001482 t0,
1483 Operand(zero_reg));
1484 __ GetObjectType(regexp_data, a0, a0);
1485 __ Check(eq,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001486 kUnexpectedTypeForRegExpDataFixedArrayExpected,
Ben Murdoch257744e2011-11-30 15:57:28 +00001487 a0,
1488 Operand(FIXED_ARRAY_TYPE));
1489 }
1490
1491 // regexp_data: RegExp data (FixedArray)
1492 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1493 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1494 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
1495
1496 // regexp_data: RegExp data (FixedArray)
1497 // Check that the number of captures fit in the static offsets vector buffer.
1498 __ lw(a2,
1499 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001500 // Check (number_of_captures + 1) * 2 <= offsets vector size
1501 // Or number_of_captures * 2 <= offsets vector size - 2
1502 // Multiplying by 2 comes for free since a2 is smi-tagged.
Ben Murdoch257744e2011-11-30 15:57:28 +00001503 STATIC_ASSERT(kSmiTag == 0);
1504 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001505 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1506 __ Branch(
1507 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001508
1509 // Reset offset for possibly sliced string.
1510 __ mov(t0, zero_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001511 __ lw(subject, MemOperand(sp, kSubjectOffset));
1512 __ JumpIfSmi(subject, &runtime);
1513 __ mov(a3, subject); // Make a copy of the original subject string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001514 // subject: subject string
1515 // a3: subject string
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001516 // regexp_data: RegExp data (FixedArray)
1517 // Handle subject string according to its encoding and representation:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001518 // (1) Sequential string? If yes, go to (4).
1519 // (2) Sequential or cons? If not, go to (5).
1520 // (3) Cons string. If the string is flat, replace subject with first string
1521 // and go to (1). Otherwise bail out to runtime.
1522 // (4) Sequential string. Load regexp code according to encoding.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001523 // (E) Carry on.
1524 /// [...]
1525
1526 // Deferred code at the end of the stub:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001527 // (5) Long external string? If not, go to (7).
1528 // (6) External string. Make it, offset-wise, look like a sequential string.
1529 // Go to (4).
1530 // (7) Short external string or not a string? If yes, bail out to runtime.
1531 // (8) Sliced string. Replace subject with parent. Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001532
Ben Murdoch097c5b22016-05-18 11:27:45 +01001533 Label seq_string /* 4 */, external_string /* 6 */, check_underlying /* 1 */,
1534 not_seq_nor_cons /* 5 */, not_long_external /* 7 */;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001535
Ben Murdoch097c5b22016-05-18 11:27:45 +01001536 __ bind(&check_underlying);
1537 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
1538 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
1539
1540 // (1) Sequential string? If yes, go to (4).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001541 __ And(a1,
1542 a0,
1543 Operand(kIsNotStringMask |
1544 kStringRepresentationMask |
1545 kShortExternalStringMask));
Ben Murdoch257744e2011-11-30 15:57:28 +00001546 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001547 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
Ben Murdoch257744e2011-11-30 15:57:28 +00001548
Ben Murdoch097c5b22016-05-18 11:27:45 +01001549 // (2) Sequential or cons? If not, go to (5).
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001550 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1551 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001552 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1553 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001554 // Go to (5).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001555 __ Branch(&not_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001556
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001557 // (3) Cons string. Check that it's flat.
1558 // Replace subject with first string and reload instance type.
Ben Murdoch257744e2011-11-30 15:57:28 +00001559 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001560 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
Ben Murdoch257744e2011-11-30 15:57:28 +00001561 __ Branch(&runtime, ne, a0, Operand(a1));
1562 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001563 __ jmp(&check_underlying);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001564
Ben Murdoch097c5b22016-05-18 11:27:45 +01001565 // (4) Sequential string. Load regexp code according to encoding.
Ben Murdoch257744e2011-11-30 15:57:28 +00001566 __ bind(&seq_string);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001567 // subject: sequential subject string (or look-alike, external string)
1568 // a3: original subject string
1569 // Load previous index and check range before a3 is overwritten. We have to
1570 // use a3 instead of subject here because subject might have been only made
1571 // to look like a sequential string when it actually is an external string.
1572 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
1573 __ JumpIfNotSmi(a1, &runtime);
1574 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
1575 __ Branch(&runtime, ls, a3, Operand(a1));
1576 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
1577
Ben Murdoch257744e2011-11-30 15:57:28 +00001578 STATIC_ASSERT(kStringEncodingMask == 4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001579 STATIC_ASSERT(kOneByteStringTag == 4);
Ben Murdoch257744e2011-11-30 15:57:28 +00001580 STATIC_ASSERT(kTwoByteStringTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001581 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
1582 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001583 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001584 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001585 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
Ben Murdoch257744e2011-11-30 15:57:28 +00001586
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001587 // (E) Carry on. String handling is done.
1588 // t9: irregexp code
Ben Murdoch257744e2011-11-30 15:57:28 +00001589 // Check that the irregexp code has been generated for the actual string
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001590 // encoding. If it has, the field contains a code object otherwise it contains
1591 // a smi (code flushing support).
1592 __ JumpIfSmi(t9, &runtime);
Ben Murdoch257744e2011-11-30 15:57:28 +00001593
Ben Murdoch257744e2011-11-30 15:57:28 +00001594 // a1: previous index
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001595 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
Ben Murdoch257744e2011-11-30 15:57:28 +00001596 // t9: code
1597 // subject: Subject string
1598 // regexp_data: RegExp data (FixedArray)
1599 // All checks done. Now push arguments for native regexp code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001600 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
Ben Murdoch257744e2011-11-30 15:57:28 +00001601 1, a0, a2);
1602
1603 // Isolates: note we add an additional parameter here (isolate pointer).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001604 const int kRegExpExecuteArguments = 9;
Ben Murdochdb1b4382012-04-26 19:03:50 +01001605 const int kParameterRegisters = 4;
Ben Murdoch257744e2011-11-30 15:57:28 +00001606 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
1607
1608 // Stack pointer now points to cell where return address is to be written.
1609 // Arguments are before that on the stack or in registers, meaning we
1610 // treat the return address as argument 5. Thus every argument after that
1611 // needs to be shifted back by 1. Since DirectCEntryStub will handle
1612 // allocating space for the c argument slots, we don't need to calculate
1613 // that into the argument positions on the stack. This is how the stack will
1614 // look (sp meaning the value of sp at this moment):
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001615 // [sp + 5] - Argument 9
Ben Murdoch257744e2011-11-30 15:57:28 +00001616 // [sp + 4] - Argument 8
1617 // [sp + 3] - Argument 7
1618 // [sp + 2] - Argument 6
1619 // [sp + 1] - Argument 5
1620 // [sp + 0] - saved ra
1621
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001622 // Argument 9: Pass current isolate address.
Ben Murdoch257744e2011-11-30 15:57:28 +00001623 // CFunctionArgumentOperand handles MIPS stack argument slots.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001624 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
1625 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
1626
1627 // Argument 8: Indicate that this is a direct call from JavaScript.
1628 __ li(a0, Operand(1));
Ben Murdoch257744e2011-11-30 15:57:28 +00001629 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
1630
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001631 // Argument 7: Start (high end) of backtracking stack memory area.
Ben Murdoch257744e2011-11-30 15:57:28 +00001632 __ li(a0, Operand(address_of_regexp_stack_memory_address));
1633 __ lw(a0, MemOperand(a0, 0));
1634 __ li(a2, Operand(address_of_regexp_stack_memory_size));
1635 __ lw(a2, MemOperand(a2, 0));
1636 __ addu(a0, a0, a2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001637 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
1638
1639 // Argument 6: Set the number of capture registers to zero to force global
1640 // regexps to behave as non-global. This does not affect non-global regexps.
1641 __ mov(a0, zero_reg);
Ben Murdoch257744e2011-11-30 15:57:28 +00001642 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
1643
1644 // Argument 5: static offsets vector buffer.
1645 __ li(a0, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001646 ExternalReference::address_of_static_offsets_vector(isolate())));
Ben Murdoch257744e2011-11-30 15:57:28 +00001647 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
1648
1649 // For arguments 4 and 3 get string length, calculate start of string data
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001650 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001651 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
Ben Murdoch257744e2011-11-30 15:57:28 +00001652 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001653 // Load the length from the original subject string from the previous stack
1654 // frame. Therefore we have to use fp, which points exactly to two pointer
1655 // sizes below the previous sp. (Because creating a new stack frame pushes
1656 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
Ben Murdoch589d6972011-11-30 16:04:58 +00001657 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001658 // If slice offset is not 0, load the length from the original sliced string.
1659 // Argument 4, a3: End of string data
1660 // Argument 3, a2: Start of string data
1661 // Prepare start and end index of the input.
1662 __ sllv(t1, t0, a3);
1663 __ addu(t0, t2, t1);
Ben Murdoch257744e2011-11-30 15:57:28 +00001664 __ sllv(t1, a1, a3);
1665 __ addu(a2, t0, t1);
Ben Murdoch257744e2011-11-30 15:57:28 +00001666
Ben Murdoch589d6972011-11-30 16:04:58 +00001667 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001668 __ sra(t2, t2, kSmiTagSize);
1669 __ sllv(t1, t2, a3);
1670 __ addu(a3, t0, t1);
Ben Murdoch257744e2011-11-30 15:57:28 +00001671 // Argument 2 (a1): Previous index.
1672 // Already there
1673
1674 // Argument 1 (a0): Subject string.
Ben Murdoch589d6972011-11-30 16:04:58 +00001675 __ mov(a0, subject);
Ben Murdoch257744e2011-11-30 15:57:28 +00001676
1677 // Locate the code entry and call it.
1678 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001679 DirectCEntryStub stub(isolate());
Ben Murdoch257744e2011-11-30 15:57:28 +00001680 stub.GenerateCall(masm, t9);
1681
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001682 __ LeaveExitFrame(false, no_reg, true);
Ben Murdoch257744e2011-11-30 15:57:28 +00001683
1684 // v0: result
1685 // subject: subject string (callee saved)
1686 // regexp_data: RegExp data (callee saved)
1687 // last_match_info_elements: Last match info elements (callee saved)
Ben Murdoch257744e2011-11-30 15:57:28 +00001688 // Check the result.
Ben Murdoch257744e2011-11-30 15:57:28 +00001689 Label success;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001690 __ Branch(&success, eq, v0, Operand(1));
1691 // We expect exactly one result since we force the called regexp to behave
1692 // as non-global.
Ben Murdoch257744e2011-11-30 15:57:28 +00001693 Label failure;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001694 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
Ben Murdoch257744e2011-11-30 15:57:28 +00001695 // If not exception it can only be retry. Handle that in the runtime system.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001696 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
Ben Murdoch257744e2011-11-30 15:57:28 +00001697 // Result must now be exception. If there is no pending exception already a
1698 // stack overflow (on the backtrack stack) was detected in RegExp code but
1699 // haven't created the exception yet. Handle that in the runtime system.
1700 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001701 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
Ben Murdoch589d6972011-11-30 16:04:58 +00001702 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001703 isolate())));
Ben Murdoch257744e2011-11-30 15:57:28 +00001704 __ lw(v0, MemOperand(a2, 0));
Ben Murdoch589d6972011-11-30 16:04:58 +00001705 __ Branch(&runtime, eq, v0, Operand(a1));
Ben Murdoch257744e2011-11-30 15:57:28 +00001706
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001707 // For exception, throw the exception again.
1708 __ TailCallRuntime(Runtime::kRegExpExecReThrow);
Ben Murdoch257744e2011-11-30 15:57:28 +00001709
1710 __ bind(&failure);
1711 // For failure and exception return null.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001712 __ li(v0, Operand(isolate()->factory()->null_value()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001713 __ DropAndRet(4);
Ben Murdoch257744e2011-11-30 15:57:28 +00001714
1715 // Process the result from the native regexp code.
1716 __ bind(&success);
1717 __ lw(a1,
1718 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1719 // Calculate number of capture registers (number_of_captures + 1) * 2.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001720 // Multiplying by 2 comes for free since r1 is smi-tagged.
Ben Murdoch257744e2011-11-30 15:57:28 +00001721 STATIC_ASSERT(kSmiTag == 0);
1722 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
1723 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
1724
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001725 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
1726 __ JumpIfSmi(a0, &runtime);
1727 __ GetObjectType(a0, a2, a2);
1728 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
1729 // Check that the JSArray is in fast case.
1730 __ lw(last_match_info_elements,
1731 FieldMemOperand(a0, JSArray::kElementsOffset));
1732 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
1733 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
1734 __ Branch(&runtime, ne, a0, Operand(at));
1735 // Check that the last match info has space for the capture registers and the
1736 // additional information.
1737 __ lw(a0,
1738 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
1739 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
1740 __ sra(at, a0, kSmiTagSize);
1741 __ Branch(&runtime, gt, a2, Operand(at));
1742
Ben Murdoch257744e2011-11-30 15:57:28 +00001743 // a1: number of capture registers
1744 // subject: subject string
1745 // Store the capture count.
1746 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
1747 __ sw(a2, FieldMemOperand(last_match_info_elements,
1748 RegExpImpl::kLastCaptureCountOffset));
1749 // Store last subject and last input.
Ben Murdoch257744e2011-11-30 15:57:28 +00001750 __ sw(subject,
1751 FieldMemOperand(last_match_info_elements,
1752 RegExpImpl::kLastSubjectOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001753 __ mov(a2, subject);
1754 __ RecordWriteField(last_match_info_elements,
1755 RegExpImpl::kLastSubjectOffset,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001756 subject,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001757 t3,
1758 kRAHasNotBeenSaved,
1759 kDontSaveFPRegs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001760 __ mov(subject, a2);
Ben Murdoch257744e2011-11-30 15:57:28 +00001761 __ sw(subject,
1762 FieldMemOperand(last_match_info_elements,
1763 RegExpImpl::kLastInputOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001764 __ RecordWriteField(last_match_info_elements,
1765 RegExpImpl::kLastInputOffset,
1766 subject,
1767 t3,
1768 kRAHasNotBeenSaved,
1769 kDontSaveFPRegs);
Ben Murdoch257744e2011-11-30 15:57:28 +00001770
1771 // Get the static offsets vector filled by the native regexp code.
1772 ExternalReference address_of_static_offsets_vector =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001773 ExternalReference::address_of_static_offsets_vector(isolate());
Ben Murdoch257744e2011-11-30 15:57:28 +00001774 __ li(a2, Operand(address_of_static_offsets_vector));
1775
1776 // a1: number of capture registers
1777 // a2: offsets vector
1778 Label next_capture, done;
1779 // Capture register counter starts from number of capture registers and
1780 // counts down until wrapping after zero.
1781 __ Addu(a0,
1782 last_match_info_elements,
1783 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
1784 __ bind(&next_capture);
1785 __ Subu(a1, a1, Operand(1));
1786 __ Branch(&done, lt, a1, Operand(zero_reg));
1787 // Read the value from the static offsets vector buffer.
1788 __ lw(a3, MemOperand(a2, 0));
1789 __ addiu(a2, a2, kPointerSize);
1790 // Store the smi value in the last match info.
1791 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
1792 __ sw(a3, MemOperand(a0, 0));
1793 __ Branch(&next_capture, USE_DELAY_SLOT);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001794 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
Ben Murdoch257744e2011-11-30 15:57:28 +00001795
1796 __ bind(&done);
1797
1798 // Return last match info.
1799 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001800 __ DropAndRet(4);
1801
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001802 // Do the runtime call to execute the regexp.
1803 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001804 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001805
1806 // Deferred code for string handling.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001807 // (5) Long external string? If not, go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001808 __ bind(&not_seq_nor_cons);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001809 // Go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001810 __ Branch(&not_long_external, gt, a1, Operand(kExternalStringTag));
1811
Ben Murdoch097c5b22016-05-18 11:27:45 +01001812 // (6) External string. Make it, offset-wise, look like a sequential string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001813 __ bind(&external_string);
1814 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
1815 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
1816 if (FLAG_debug_code) {
1817 // Assert that we do not have a cons or slice (indirect strings) here.
1818 // Sequential strings have already been ruled out.
1819 __ And(at, a0, Operand(kIsIndirectStringMask));
1820 __ Assert(eq,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001821 kExternalStringExpectedButNotFound,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001822 at,
1823 Operand(zero_reg));
1824 }
1825 __ lw(subject,
1826 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
1827 // Move the pointer so that offset-wise, it looks like a sequential string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001828 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001829 __ Subu(subject,
1830 subject,
1831 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001832 __ jmp(&seq_string); // Go to (5).
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001833
Ben Murdoch097c5b22016-05-18 11:27:45 +01001834 // (7) Short external string or not a string? If yes, bail out to runtime.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001835 __ bind(&not_long_external);
1836 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
1837 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
1838 __ Branch(&runtime, ne, at, Operand(zero_reg));
1839
Ben Murdoch097c5b22016-05-18 11:27:45 +01001840 // (8) Sliced string. Replace subject with parent. Go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001841 // Load offset into t0 and replace subject string with parent.
1842 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
1843 __ sra(t0, t0, kSmiTagSize);
1844 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
1845 __ jmp(&check_underlying); // Go to (4).
Ben Murdoch257744e2011-11-30 15:57:28 +00001846#endif // V8_INTERPRETED_REGEXP
Steve Block44f0eee2011-05-26 01:26:41 +01001847}
1848
1849
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001850static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
1851 // a0 : number of arguments to the construct function
1852 // a2 : feedback vector
1853 // a3 : slot in feedback vector (Smi)
1854 // a1 : the function to call
1855 FrameScope scope(masm, StackFrame::INTERNAL);
1856 const RegList kSavedRegs = 1 << 4 | // a0
1857 1 << 5 | // a1
1858 1 << 6 | // a2
1859 1 << 7; // a3
1860
1861 // Number-of-arguments register must be smi-tagged to call out.
1862 __ SmiTag(a0);
1863 __ MultiPush(kSavedRegs);
1864
1865 __ CallStub(stub);
1866
1867 __ MultiPop(kSavedRegs);
1868 __ SmiUntag(a0);
1869}
1870
1871
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001872static void GenerateRecordCallTarget(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001873 // Cache the called function in a feedback vector slot. Cache states
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001874 // are uninitialized, monomorphic (indicated by a JSFunction), and
1875 // megamorphic.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001876 // a0 : number of arguments to the construct function
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001877 // a1 : the function to call
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001878 // a2 : feedback vector
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001879 // a3 : slot in feedback vector (Smi)
1880 Label initialize, done, miss, megamorphic, not_array_function;
Ben Murdoch61f157c2016-09-16 13:49:30 +01001881 Label done_initialize_count, done_increment_count;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001882
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001883 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
1884 masm->isolate()->heap()->megamorphic_symbol());
1885 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
1886 masm->isolate()->heap()->uninitialized_symbol());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001887
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001888 // Load the cache state into t2.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001889 __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001890 __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001891
1892 // A monomorphic cache hit or an already megamorphic state: invoke the
1893 // function without changing the state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001894 // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at
1895 // this position in a symbol (see static asserts in type-feedback-vector.h).
1896 Label check_allocation_site;
1897 Register feedback_map = t1;
1898 Register weak_value = t4;
1899 __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset));
Ben Murdoch61f157c2016-09-16 13:49:30 +01001900 __ Branch(&done_increment_count, eq, a1, Operand(weak_value));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001901 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
1902 __ Branch(&done, eq, t2, Operand(at));
1903 __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset));
1904 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
1905 __ Branch(&check_allocation_site, ne, feedback_map, Operand(at));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001906
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001907 // If the weak cell is cleared, we have a new chance to become monomorphic.
1908 __ JumpIfSmi(weak_value, &initialize);
1909 __ jmp(&megamorphic);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001910
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001911 __ bind(&check_allocation_site);
1912 // If we came here, we need to see if we are the array function.
1913 // If we didn't have a matching function, and we didn't find the megamorph
1914 // sentinel, then we have in the slot either some other function or an
1915 // AllocationSite.
1916 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
1917 __ Branch(&miss, ne, feedback_map, Operand(at));
1918
1919 // Make sure the function is the Array() function
1920 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2);
1921 __ Branch(&megamorphic, ne, a1, Operand(t2));
Ben Murdoch61f157c2016-09-16 13:49:30 +01001922 __ jmp(&done_increment_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001923
1924 __ bind(&miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001925
1926 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
1927 // megamorphic.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001928 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001929 __ Branch(&initialize, eq, t2, Operand(at));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001930 // MegamorphicSentinel is an immortal immovable object (undefined) so no
1931 // write-barrier is needed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001932 __ bind(&megamorphic);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001933 __ Lsa(t2, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001934 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001935 __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001936 __ jmp(&done);
1937
1938 // An uninitialized cache is patched with the function.
1939 __ bind(&initialize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001940 // Make sure the function is the Array() function.
1941 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t2);
1942 __ Branch(&not_array_function, ne, a1, Operand(t2));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001943
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001944 // The target function is the Array constructor,
1945 // Create an AllocationSite if we don't already have it, store it in the
1946 // slot.
1947 CreateAllocationSiteStub create_stub(masm->isolate());
1948 CallStubInRecordCallTarget(masm, &create_stub);
Ben Murdoch61f157c2016-09-16 13:49:30 +01001949 __ Branch(&done_initialize_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001950
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001951 __ bind(&not_array_function);
1952 CreateWeakCellStub weak_cell_stub(masm->isolate());
1953 CallStubInRecordCallTarget(masm, &weak_cell_stub);
Ben Murdoch61f157c2016-09-16 13:49:30 +01001954
1955 __ bind(&done_initialize_count);
1956 // Initialize the call counter.
1957 __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize);
1958 __ li(t0, Operand(Smi::FromInt(1)));
1959 __ Branch(USE_DELAY_SLOT, &done);
1960 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
1961
1962 __ bind(&done_increment_count);
1963
1964 // Increment the call count for monomorphic function calls.
1965 __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize);
1966 __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
1967 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
1968 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
1969
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001970 __ bind(&done);
1971}
1972
1973
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001974void CallConstructStub::Generate(MacroAssembler* masm) {
1975 // a0 : number of arguments
1976 // a1 : the function to call
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001977 // a2 : feedback vector
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001978 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001979
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001980 Label non_function;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001981 // Check that the function is not a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001982 __ JumpIfSmi(a1, &non_function);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001983 // Check that the function is a JSFunction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001984 __ GetObjectType(a1, t1, t1);
1985 __ Branch(&non_function, ne, t1, Operand(JS_FUNCTION_TYPE));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001986
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001987 GenerateRecordCallTarget(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001988
Ben Murdoch097c5b22016-05-18 11:27:45 +01001989 __ Lsa(t1, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001990 Label feedback_register_initialized;
1991 // Put the AllocationSite from the feedback vector into a2, or undefined.
1992 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
1993 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
1994 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
1995 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
1996 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
1997 __ bind(&feedback_register_initialized);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001998
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001999 __ AssertUndefinedOrAllocationSite(a2, t1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002000
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002001 // Pass function as new target.
2002 __ mov(a3, a1);
2003
2004 // Tail call to the function-specific construct stub (still in the caller
2005 // context at this point).
2006 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2007 __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset));
2008 __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002009 __ Jump(at);
2010
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002011 __ bind(&non_function);
2012 __ mov(a3, a1);
2013 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002014}
2015
2016
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002017void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002018 // a1 - function
2019 // a3 - slot id
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002020 // a2 - vector
2021 // t0 - loaded from vector[slot]
2022 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, at);
2023 __ Branch(miss, ne, a1, Operand(at));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002024
2025 __ li(a0, Operand(arg_count()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002026
2027 // Increment the call count for monomorphic function calls.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002028 __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002029 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
Ben Murdoch61f157c2016-09-16 13:49:30 +01002030 __ Addu(a3, a3, Operand(Smi::FromInt(1)));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002031 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002032
2033 __ mov(a2, t0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002034 __ mov(a3, a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002035 ArrayConstructorStub stub(masm->isolate(), arg_count());
2036 __ TailCallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002037}
2038
2039
2040void CallICStub::Generate(MacroAssembler* masm) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002041 // a1 - function
2042 // a3 - slot id (Smi)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002043 // a2 - vector
2044 Label extra_checks_or_miss, call, call_function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002045 int argc = arg_count();
2046 ParameterCount actual(argc);
2047
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002048 // The checks. First, does r1 match the recorded monomorphic target?
Ben Murdoch097c5b22016-05-18 11:27:45 +01002049 __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002050 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002051
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002052 // We don't know that we have a weak cell. We might have a private symbol
2053 // or an AllocationSite, but the memory is safe to examine.
2054 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2055 // FixedArray.
2056 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2057 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2058 // computed, meaning that it can't appear to be a pointer. If the low bit is
2059 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2060 // to be a pointer.
2061 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2062 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2063 WeakCell::kValueOffset &&
2064 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002065
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002066 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2067 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002068
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002069 // The compare above could have been a SMI/SMI comparison. Guard against this
2070 // convincing us that we have a monomorphic JSFunction.
2071 __ JumpIfSmi(a1, &extra_checks_or_miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002072
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002073 // Increment the call count for monomorphic function calls.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002074 __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002075 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
Ben Murdoch61f157c2016-09-16 13:49:30 +01002076 __ Addu(a3, a3, Operand(Smi::FromInt(1)));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002077 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002078
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002079 __ bind(&call_function);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002080 __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(),
2081 tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002082 RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg),
2083 USE_DELAY_SLOT);
2084 __ li(a0, Operand(argc)); // In delay slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002085
2086 __ bind(&extra_checks_or_miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002087 Label uninitialized, miss, not_allocation_site;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002088
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002089 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002090 __ Branch(&call, eq, t0, Operand(at));
2091
2092 // Verify that t0 contains an AllocationSite
2093 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2094 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2095 __ Branch(&not_allocation_site, ne, t1, Operand(at));
2096
2097 HandleArrayCase(masm, &miss);
2098
2099 __ bind(&not_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002100
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002101 // The following cases attempt to handle MISS cases without going to the
2102 // runtime.
2103 if (FLAG_trace_ic) {
2104 __ Branch(&miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002105 }
2106
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002107 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2108 __ Branch(&uninitialized, eq, t0, Operand(at));
2109
2110 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2111 // to handle it here. More complex cases are dealt with in the runtime.
2112 __ AssertNotSmi(t0);
2113 __ GetObjectType(t0, t1, t1);
2114 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002115 __ Lsa(t0, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002116 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2117 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002118
2119 __ bind(&call);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002120 __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002121 RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg),
2122 USE_DELAY_SLOT);
2123 __ li(a0, Operand(argc)); // In delay slot.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002124
2125 __ bind(&uninitialized);
2126
2127 // We are going monomorphic, provided we actually have a JSFunction.
2128 __ JumpIfSmi(a1, &miss);
2129
2130 // Goto miss case if we do not have a function.
2131 __ GetObjectType(a1, t0, t0);
2132 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2133
2134 // Make sure the function is not the Array() function, which requires special
2135 // behavior on MISS.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002136 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, t0);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002137 __ Branch(&miss, eq, a1, Operand(t0));
2138
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002139 // Make sure the function belongs to the same native context.
2140 __ lw(t0, FieldMemOperand(a1, JSFunction::kContextOffset));
2141 __ lw(t0, ContextMemOperand(t0, Context::NATIVE_CONTEXT_INDEX));
2142 __ lw(t1, NativeContextMemOperand());
2143 __ Branch(&miss, ne, t0, Operand(t1));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002144
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002145 // Initialize the call counter.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002146 __ Lsa(at, a2, a3, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch61f157c2016-09-16 13:49:30 +01002147 __ li(t0, Operand(Smi::FromInt(1)));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002148 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002149
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002150 // Store the function. Use a stub since we need a frame for allocation.
2151 // a2 - vector
2152 // a3 - slot
2153 // a1 - function
2154 {
2155 FrameScope scope(masm, StackFrame::INTERNAL);
2156 CreateWeakCellStub create_stub(masm->isolate());
2157 __ Push(a1);
2158 __ CallStub(&create_stub);
2159 __ Pop(a1);
2160 }
2161
2162 __ Branch(&call_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002163
2164 // We are here because tracing is on or we encountered a MISS case we can't
2165 // handle here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002166 __ bind(&miss);
2167 GenerateMiss(masm);
2168
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002169 __ Branch(&call);
Steve Block44f0eee2011-05-26 01:26:41 +01002170}
2171
2172
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002173void CallICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002174 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002175
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002176 // Push the receiver and the function and feedback info.
2177 __ Push(a1, a2, a3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002178
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002179 // Call the entry.
2180 __ CallRuntime(Runtime::kCallIC_Miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002181
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002182 // Move result to a1 and exit the internal frame.
2183 __ mov(a1, v0);
Steve Block44f0eee2011-05-26 01:26:41 +01002184}
2185
2186
Ben Murdoch257744e2011-11-30 15:57:28 +00002187// StringCharCodeAtGenerator.
Steve Block44f0eee2011-05-26 01:26:41 +01002188void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002189 DCHECK(!t0.is(index_));
2190 DCHECK(!t0.is(result_));
2191 DCHECK(!t0.is(object_));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002192 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2193 // If the receiver is a smi trigger the non-string case.
2194 __ JumpIfSmi(object_, receiver_not_string_);
Ben Murdoch257744e2011-11-30 15:57:28 +00002195
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002196 // Fetch the instance type of the receiver into result register.
2197 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2198 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2199 // If the receiver is not a string trigger the non-string case.
2200 __ And(t0, result_, Operand(kIsNotStringMask));
2201 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
2202 }
Ben Murdoch257744e2011-11-30 15:57:28 +00002203
2204 // If the index is non-smi trigger the non-smi case.
2205 __ JumpIfNotSmi(index_, &index_not_smi_);
2206
Ben Murdoch257744e2011-11-30 15:57:28 +00002207 __ bind(&got_smi_index_);
2208
2209 // Check for index out of range.
2210 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002211 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
Ben Murdoch257744e2011-11-30 15:57:28 +00002212
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002213 __ sra(index_, index_, kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002214
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002215 StringCharLoadGenerator::Generate(masm,
2216 object_,
2217 index_,
2218 result_,
2219 &call_runtime_);
Ben Murdoch257744e2011-11-30 15:57:28 +00002220
Ben Murdoch257744e2011-11-30 15:57:28 +00002221 __ sll(result_, result_, kSmiTagSize);
2222 __ bind(&exit_);
Steve Block44f0eee2011-05-26 01:26:41 +01002223}
2224
2225
2226void StringCharCodeAtGenerator::GenerateSlow(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002227 MacroAssembler* masm, EmbedMode embed_mode,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002228 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002229 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
Ben Murdoch257744e2011-11-30 15:57:28 +00002230
2231 // Index is not a smi.
2232 __ bind(&index_not_smi_);
2233 // If index is a heap number, try converting it to an integer.
2234 __ CheckMap(index_,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002235 result_,
Ben Murdoch257744e2011-11-30 15:57:28 +00002236 Heap::kHeapNumberMapRootIndex,
2237 index_not_number_,
2238 DONT_DO_SMI_CHECK);
2239 call_helper.BeforeCall(masm);
2240 // Consumed by runtime conversion function:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002241 if (embed_mode == PART_OF_IC_HANDLER) {
2242 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2243 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2244 } else {
2245 __ Push(object_, index_);
2246 }
Ben Murdoch61f157c2016-09-16 13:49:30 +01002247 __ CallRuntime(Runtime::kNumberToSmi);
Ben Murdoch257744e2011-11-30 15:57:28 +00002248
2249 // Save the conversion result before the pop instructions below
2250 // have a chance to overwrite it.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002251 __ Move(index_, v0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002252 if (embed_mode == PART_OF_IC_HANDLER) {
2253 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2254 LoadWithVectorDescriptor::SlotRegister(), object_);
2255 } else {
2256 __ pop(object_);
2257 }
Ben Murdoch257744e2011-11-30 15:57:28 +00002258 // Reload the instance type.
2259 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2260 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2261 call_helper.AfterCall(masm);
2262 // If index is still not a smi, it must be out of range.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002263 __ JumpIfNotSmi(index_, index_out_of_range_);
Ben Murdoch257744e2011-11-30 15:57:28 +00002264 // Otherwise, return to the fast path.
2265 __ Branch(&got_smi_index_);
2266
2267 // Call runtime. We get here when the receiver is a string and the
2268 // index is a number, but the code of getting the actual character
2269 // is too complex (e.g., when the string needs to be flattened).
2270 __ bind(&call_runtime_);
2271 call_helper.BeforeCall(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002272 __ sll(index_, index_, kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002273 __ Push(object_, index_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002274 __ CallRuntime(Runtime::kStringCharCodeAtRT);
Ben Murdoch257744e2011-11-30 15:57:28 +00002275
2276 __ Move(result_, v0);
2277
2278 call_helper.AfterCall(masm);
2279 __ jmp(&exit_);
2280
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002281 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
Steve Block44f0eee2011-05-26 01:26:41 +01002282}
2283
2284
2285// -------------------------------------------------------------------------
2286// StringCharFromCodeGenerator
2287
2288void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002289 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2290
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002291 DCHECK(!t0.is(result_));
2292 DCHECK(!t0.is(code_));
Ben Murdoch257744e2011-11-30 15:57:28 +00002293
2294 STATIC_ASSERT(kSmiTag == 0);
2295 STATIC_ASSERT(kSmiShiftSize == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002296 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2297 __ And(t0, code_, Operand(kSmiTagMask |
2298 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002299 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
2300
2301 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002302 // At this point code register contains smi tagged one-byte char code.
Ben Murdoch257744e2011-11-30 15:57:28 +00002303 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002304 __ Lsa(result_, result_, code_, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002305 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
2306 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
2307 __ Branch(&slow_case_, eq, result_, Operand(t0));
2308 __ bind(&exit_);
Steve Block44f0eee2011-05-26 01:26:41 +01002309}
2310
2311
2312void StringCharFromCodeGenerator::GenerateSlow(
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002313 MacroAssembler* masm,
2314 const RuntimeCallHelper& call_helper) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002315 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
Ben Murdoch257744e2011-11-30 15:57:28 +00002316
2317 __ bind(&slow_case_);
2318 call_helper.BeforeCall(masm);
2319 __ push(code_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002320 __ CallRuntime(Runtime::kStringCharFromCode);
Ben Murdoch257744e2011-11-30 15:57:28 +00002321 __ Move(result_, v0);
2322
2323 call_helper.AfterCall(masm);
2324 __ Branch(&exit_);
2325
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002326 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
Steve Block44f0eee2011-05-26 01:26:41 +01002327}
2328
2329
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002330enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
Steve Block44f0eee2011-05-26 01:26:41 +01002331
2332
Steve Block44f0eee2011-05-26 01:26:41 +01002333void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2334 Register dest,
2335 Register src,
2336 Register count,
2337 Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002338 String::Encoding encoding) {
2339 if (FLAG_debug_code) {
2340 // Check that destination is word aligned.
2341 __ And(scratch, dest, Operand(kPointerAlignmentMask));
Ben Murdoch257744e2011-11-30 15:57:28 +00002342 __ Check(eq,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002343 kDestinationOfCopyNotAligned,
2344 scratch,
Ben Murdoch257744e2011-11-30 15:57:28 +00002345 Operand(zero_reg));
2346 }
2347
Ben Murdoch257744e2011-11-30 15:57:28 +00002348 // Assumes word reads and writes are little endian.
2349 // Nothing to do for zero characters.
2350 Label done;
2351
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002352 if (encoding == String::TWO_BYTE_ENCODING) {
2353 __ Addu(count, count, count);
Ben Murdoch257744e2011-11-30 15:57:28 +00002354 }
2355
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002356 Register limit = count; // Read until dest equals this.
2357 __ Addu(limit, dest, Operand(count));
Ben Murdoch257744e2011-11-30 15:57:28 +00002358
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002359 Label loop_entry, loop;
Ben Murdoch257744e2011-11-30 15:57:28 +00002360 // Copy bytes from src to dest until dest hits limit.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002361 __ Branch(&loop_entry);
2362 __ bind(&loop);
2363 __ lbu(scratch, MemOperand(src));
2364 __ Addu(src, src, Operand(1));
2365 __ sb(scratch, MemOperand(dest));
2366 __ Addu(dest, dest, Operand(1));
2367 __ bind(&loop_entry);
2368 __ Branch(&loop, lt, dest, Operand(limit));
Ben Murdoch257744e2011-11-30 15:57:28 +00002369
2370 __ bind(&done);
Steve Block44f0eee2011-05-26 01:26:41 +01002371}
2372
2373
Steve Block44f0eee2011-05-26 01:26:41 +01002374void SubStringStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002375 Label runtime;
Ben Murdoch257744e2011-11-30 15:57:28 +00002376 // Stack frame on entry.
2377 // ra: return address
2378 // sp[0]: to
2379 // sp[4]: from
2380 // sp[8]: string
2381
2382 // This stub is called from the native-call %_SubString(...), so
2383 // nothing can be assumed about the arguments. It is tested that:
2384 // "string" is a sequential string,
2385 // both "from" and "to" are smis, and
2386 // 0 <= from <= to <= string.length.
2387 // If any of these assumptions fail, we call the runtime system.
2388
Ben Murdochdb1b4382012-04-26 19:03:50 +01002389 const int kToOffset = 0 * kPointerSize;
2390 const int kFromOffset = 1 * kPointerSize;
2391 const int kStringOffset = 2 * kPointerSize;
Ben Murdoch257744e2011-11-30 15:57:28 +00002392
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002393 __ lw(a2, MemOperand(sp, kToOffset));
2394 __ lw(a3, MemOperand(sp, kFromOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00002395 STATIC_ASSERT(kFromOffset == kToOffset + 4);
2396 STATIC_ASSERT(kSmiTag == 0);
2397 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2398
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002399 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
2400 // safe in this case.
2401 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
2402 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
2403 // Both a2 and a3 are untagged integers.
Ben Murdoch257744e2011-11-30 15:57:28 +00002404
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002405 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
Ben Murdoch257744e2011-11-30 15:57:28 +00002406
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002407 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
2408 __ Subu(a2, a2, a3);
Ben Murdoch257744e2011-11-30 15:57:28 +00002409
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002410 // Make sure first argument is a string.
Ben Murdoch589d6972011-11-30 16:04:58 +00002411 __ lw(v0, MemOperand(sp, kStringOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002412 __ JumpIfSmi(v0, &runtime);
Ben Murdoch589d6972011-11-30 16:04:58 +00002413 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00002414 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002415 __ And(t0, a1, Operand(kIsNotStringMask));
Ben Murdoch257744e2011-11-30 15:57:28 +00002416
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002417 __ Branch(&runtime, ne, t0, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +00002418
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002419 Label single_char;
2420 __ Branch(&single_char, eq, a2, Operand(1));
2421
Ben Murdoch589d6972011-11-30 16:04:58 +00002422 // Short-cut for the case of trivial substring.
2423 Label return_v0;
2424 // v0: original string
2425 // a2: result string length
2426 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
2427 __ sra(t0, t0, 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002428 // Return original string.
Ben Murdoch589d6972011-11-30 16:04:58 +00002429 __ Branch(&return_v0, eq, a2, Operand(t0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002430 // Longer than original string's length or negative: unsafe arguments.
2431 __ Branch(&runtime, hi, a2, Operand(t0));
2432 // Shorter than original string's length: an actual substring.
Ben Murdoch257744e2011-11-30 15:57:28 +00002433
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002434 // Deal with different string types: update the index if necessary
2435 // and put the underlying string into t1.
2436 // v0: original string
2437 // a1: instance type
2438 // a2: length
2439 // a3: from index (untagged)
2440 Label underlying_unpacked, sliced_string, seq_or_external_string;
2441 // If the string is not indirect, it can only be sequential or external.
2442 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2443 STATIC_ASSERT(kIsIndirectStringMask != 0);
2444 __ And(t0, a1, Operand(kIsIndirectStringMask));
2445 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
2446 // t0 is used as a scratch register and can be overwritten in either case.
2447 __ And(t0, a1, Operand(kSlicedNotConsMask));
2448 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
2449 // Cons string. Check whether it is flat, then fetch first part.
2450 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002451 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002452 __ Branch(&runtime, ne, t1, Operand(t0));
2453 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
2454 // Update instance type.
2455 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
2456 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2457 __ jmp(&underlying_unpacked);
Ben Murdoch257744e2011-11-30 15:57:28 +00002458
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002459 __ bind(&sliced_string);
2460 // Sliced string. Fetch parent and correct start index by offset.
2461 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
2462 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
2463 __ sra(t0, t0, 1); // Add offset to index.
2464 __ Addu(a3, a3, t0);
2465 // Update instance type.
2466 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
2467 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2468 __ jmp(&underlying_unpacked);
Ben Murdochc7cc0282012-03-05 14:35:55 +00002469
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002470 __ bind(&seq_or_external_string);
2471 // Sequential or external string. Just move string to the expected register.
2472 __ mov(t1, v0);
2473
2474 __ bind(&underlying_unpacked);
2475
2476 if (FLAG_string_slices) {
2477 Label copy_routine;
2478 // t1: underlying subject string
2479 // a1: instance type of underlying subject string
2480 // a2: length
2481 // a3: adjusted start index (untagged)
2482 // Short slice. Copy instead of slicing.
2483 __ Branch(&copy_routine, lt, a2, Operand(SlicedString::kMinLength));
2484 // Allocate new sliced string. At this point we do not reload the instance
2485 // type including the string encoding because we simply rely on the info
2486 // provided by the original string. It does not matter if the original
2487 // string's encoding is wrong because we always have to recheck encoding of
2488 // the newly created string's parent anyways due to externalized strings.
2489 Label two_byte_slice, set_slice_header;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002490 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002491 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2492 __ And(t0, a1, Operand(kStringEncodingMask));
2493 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002494 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002495 __ jmp(&set_slice_header);
2496 __ bind(&two_byte_slice);
2497 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
2498 __ bind(&set_slice_header);
2499 __ sll(a3, a3, 1);
2500 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
2501 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
2502 __ jmp(&return_v0);
2503
2504 __ bind(&copy_routine);
2505 }
2506
2507 // t1: underlying subject string
2508 // a1: instance type of underlying subject string
2509 // a2: length
2510 // a3: adjusted start index (untagged)
2511 Label two_byte_sequential, sequential_string, allocate_result;
2512 STATIC_ASSERT(kExternalStringTag != 0);
2513 STATIC_ASSERT(kSeqStringTag == 0);
2514 __ And(t0, a1, Operand(kExternalStringTag));
2515 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
2516
2517 // Handle external string.
2518 // Rule out short external strings.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002519 STATIC_ASSERT(kShortExternalStringTag != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002520 __ And(t0, a1, Operand(kShortExternalStringTag));
2521 __ Branch(&runtime, ne, t0, Operand(zero_reg));
2522 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
2523 // t1 already points to the first character of underlying string.
2524 __ jmp(&allocate_result);
2525
2526 __ bind(&sequential_string);
2527 // Locate first character of underlying subject string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002528 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2529 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002530
2531 __ bind(&allocate_result);
2532 // Sequential acii string. Allocate the result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002533 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002534 __ And(t0, a1, Operand(kStringEncodingMask));
2535 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
2536
2537 // Allocate and copy the resulting ASCII string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002538 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002539
2540 // Locate first character of substring to copy.
2541 __ Addu(t1, t1, a3);
2542
Ben Murdoch257744e2011-11-30 15:57:28 +00002543 // Locate first character of result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002544 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch257744e2011-11-30 15:57:28 +00002545
Ben Murdoch589d6972011-11-30 16:04:58 +00002546 // v0: result string
2547 // a1: first character of result string
2548 // a2: result string length
2549 // t1: first character of substring to copy
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002550 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2551 StringHelper::GenerateCopyCharacters(
2552 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
Ben Murdoch589d6972011-11-30 16:04:58 +00002553 __ jmp(&return_v0);
Ben Murdoch257744e2011-11-30 15:57:28 +00002554
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002555 // Allocate and copy the resulting two-byte string.
2556 __ bind(&two_byte_sequential);
2557 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
Ben Murdoch257744e2011-11-30 15:57:28 +00002558
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002559 // Locate first character of substring to copy.
Ben Murdoch589d6972011-11-30 16:04:58 +00002560 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002561 __ Lsa(t1, t1, a3, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00002562 // Locate first character of result.
2563 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch589d6972011-11-30 16:04:58 +00002564
Ben Murdoch257744e2011-11-30 15:57:28 +00002565 // v0: result string.
2566 // a1: first character of result.
2567 // a2: result length.
Ben Murdoch589d6972011-11-30 16:04:58 +00002568 // t1: first character of substring to copy.
Ben Murdoch257744e2011-11-30 15:57:28 +00002569 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002570 StringHelper::GenerateCopyCharacters(
2571 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
Ben Murdoch589d6972011-11-30 16:04:58 +00002572
2573 __ bind(&return_v0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002574 Counters* counters = isolate()->counters();
Ben Murdoch257744e2011-11-30 15:57:28 +00002575 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002576 __ DropAndRet(3);
Ben Murdoch257744e2011-11-30 15:57:28 +00002577
2578 // Just jump to runtime to create the sub string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002579 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002580 __ TailCallRuntime(Runtime::kSubString);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002581
2582 __ bind(&single_char);
2583 // v0: original string
2584 // a1: instance type
2585 // a2: length
2586 // a3: from index (untagged)
2587 __ SmiTag(a3, a3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002588 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
Ben Murdoch61f157c2016-09-16 13:49:30 +01002589 RECEIVER_IS_STRING);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002590 generator.GenerateFast(masm);
2591 __ DropAndRet(3);
2592 generator.SkipSlow(masm, &runtime);
Ben Murdoch257744e2011-11-30 15:57:28 +00002593}
2594
2595
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002596void ToStringStub::Generate(MacroAssembler* masm) {
2597 // The ToString stub takes on argument in a0.
2598 Label is_number;
2599 __ JumpIfSmi(a0, &is_number);
2600
2601 Label not_string;
2602 __ GetObjectType(a0, a1, a1);
2603 // a0: receiver
2604 // a1: receiver instance type
2605 __ Branch(&not_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
2606 __ Ret(USE_DELAY_SLOT);
2607 __ mov(v0, a0);
2608 __ bind(&not_string);
2609
2610 Label not_heap_number;
2611 __ Branch(&not_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
2612 __ bind(&is_number);
2613 NumberToStringStub stub(isolate());
2614 __ TailCallStub(&stub);
2615 __ bind(&not_heap_number);
2616
2617 Label not_oddball;
2618 __ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
2619 __ Ret(USE_DELAY_SLOT);
2620 __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
2621 __ bind(&not_oddball);
2622
2623 __ push(a0); // Push argument.
2624 __ TailCallRuntime(Runtime::kToString);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002625}
2626
2627
Ben Murdoch097c5b22016-05-18 11:27:45 +01002628void ToNameStub::Generate(MacroAssembler* masm) {
2629 // The ToName stub takes on argument in a0.
2630 Label is_number;
2631 __ JumpIfSmi(a0, &is_number);
2632
2633 Label not_name;
2634 STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
2635 __ GetObjectType(a0, a1, a1);
2636 // a0: receiver
2637 // a1: receiver instance type
2638 __ Branch(&not_name, gt, a1, Operand(LAST_NAME_TYPE));
2639 __ Ret(USE_DELAY_SLOT);
2640 __ mov(v0, a0);
2641 __ bind(&not_name);
2642
2643 Label not_heap_number;
2644 __ Branch(&not_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
2645 __ bind(&is_number);
2646 NumberToStringStub stub(isolate());
2647 __ TailCallStub(&stub);
2648 __ bind(&not_heap_number);
2649
2650 Label not_oddball;
2651 __ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
2652 __ Ret(USE_DELAY_SLOT);
2653 __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
2654 __ bind(&not_oddball);
2655
2656 __ push(a0); // Push argument.
2657 __ TailCallRuntime(Runtime::kToName);
2658}
2659
2660
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002661void StringHelper::GenerateFlatOneByteStringEquals(
2662 MacroAssembler* masm, Register left, Register right, Register scratch1,
2663 Register scratch2, Register scratch3) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002664 Register length = scratch1;
2665
2666 // Compare lengths.
2667 Label strings_not_equal, check_zero_length;
2668 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
2669 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
2670 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
2671 __ bind(&strings_not_equal);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002672 DCHECK(is_int16(NOT_EQUAL));
2673 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00002674 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002675
2676 // Check if the length is zero.
2677 Label compare_chars;
2678 __ bind(&check_zero_length);
2679 STATIC_ASSERT(kSmiTag == 0);
2680 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002681 DCHECK(is_int16(EQUAL));
2682 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00002683 __ li(v0, Operand(Smi::FromInt(EQUAL)));
Ben Murdoch257744e2011-11-30 15:57:28 +00002684
2685 // Compare characters.
2686 __ bind(&compare_chars);
2687
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002688 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
2689 v0, &strings_not_equal);
Ben Murdoch257744e2011-11-30 15:57:28 +00002690
2691 // Characters are equal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002692 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00002693 __ li(v0, Operand(Smi::FromInt(EQUAL)));
Steve Block44f0eee2011-05-26 01:26:41 +01002694}
2695
2696
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002697void StringHelper::GenerateCompareFlatOneByteStrings(
2698 MacroAssembler* masm, Register left, Register right, Register scratch1,
2699 Register scratch2, Register scratch3, Register scratch4) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002700 Label result_not_equal, compare_lengths;
2701 // Find minimum length and length difference.
2702 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
2703 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
2704 __ Subu(scratch3, scratch1, Operand(scratch2));
2705 Register length_delta = scratch3;
2706 __ slt(scratch4, scratch2, scratch1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002707 __ Movn(scratch1, scratch2, scratch4);
Ben Murdoch257744e2011-11-30 15:57:28 +00002708 Register min_length = scratch1;
2709 STATIC_ASSERT(kSmiTag == 0);
2710 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
2711
2712 // Compare loop.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002713 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
2714 scratch4, v0, &result_not_equal);
Ben Murdoch257744e2011-11-30 15:57:28 +00002715
2716 // Compare lengths - strings up to min-length are equal.
2717 __ bind(&compare_lengths);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002718 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
Ben Murdoch257744e2011-11-30 15:57:28 +00002719 // Use length_delta as result if it's zero.
2720 __ mov(scratch2, length_delta);
2721 __ mov(scratch4, zero_reg);
2722 __ mov(v0, zero_reg);
2723
2724 __ bind(&result_not_equal);
2725 // Conditionally update the result based either on length_delta or
2726 // the last comparion performed in the loop above.
2727 Label ret;
2728 __ Branch(&ret, eq, scratch2, Operand(scratch4));
2729 __ li(v0, Operand(Smi::FromInt(GREATER)));
2730 __ Branch(&ret, gt, scratch2, Operand(scratch4));
2731 __ li(v0, Operand(Smi::FromInt(LESS)));
2732 __ bind(&ret);
2733 __ Ret();
2734}
2735
2736
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002737void StringHelper::GenerateOneByteCharsCompareLoop(
2738 MacroAssembler* masm, Register left, Register right, Register length,
2739 Register scratch1, Register scratch2, Register scratch3,
Ben Murdoch257744e2011-11-30 15:57:28 +00002740 Label* chars_not_equal) {
2741 // Change index to run from -length to -1 by adding length to string
2742 // start. This means that loop ends when index reaches zero, which
2743 // doesn't need an additional compare.
2744 __ SmiUntag(length);
2745 __ Addu(scratch1, length,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002746 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
Ben Murdoch257744e2011-11-30 15:57:28 +00002747 __ Addu(left, left, Operand(scratch1));
2748 __ Addu(right, right, Operand(scratch1));
2749 __ Subu(length, zero_reg, length);
2750 Register index = length; // index = -length;
2751
2752
2753 // Compare loop.
2754 Label loop;
2755 __ bind(&loop);
2756 __ Addu(scratch3, left, index);
2757 __ lbu(scratch1, MemOperand(scratch3));
2758 __ Addu(scratch3, right, index);
2759 __ lbu(scratch2, MemOperand(scratch3));
2760 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
2761 __ Addu(index, index, 1);
2762 __ Branch(&loop, ne, index, Operand(zero_reg));
Steve Block44f0eee2011-05-26 01:26:41 +01002763}
2764
2765
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002766void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
2767 // ----------- S t a t e -------------
2768 // -- a1 : left
2769 // -- a0 : right
2770 // -- ra : return address
2771 // -----------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00002772
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002773 // Load a2 with the allocation site. We stick an undefined dummy value here
2774 // and replace it with the real allocation site later when we instantiate this
2775 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
Ben Murdoch61f157c2016-09-16 13:49:30 +01002776 __ li(a2, isolate()->factory()->undefined_value());
Ben Murdoch257744e2011-11-30 15:57:28 +00002777
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002778 // Make sure that we actually patched the allocation site.
2779 if (FLAG_debug_code) {
2780 __ And(at, a2, Operand(kSmiTagMask));
2781 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
2782 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
2783 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2784 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
Ben Murdoch257744e2011-11-30 15:57:28 +00002785 }
2786
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002787 // Tail call into the stub that handles binary operations with allocation
2788 // sites.
2789 BinaryOpWithAllocationSiteStub stub(isolate(), state());
2790 __ TailCallStub(&stub);
Ben Murdoch257744e2011-11-30 15:57:28 +00002791}
2792
2793
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002794void CompareICStub::GenerateBooleans(MacroAssembler* masm) {
2795 DCHECK_EQ(CompareICState::BOOLEAN, state());
2796 Label miss;
2797
2798 __ CheckMap(a1, a2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
2799 __ CheckMap(a0, a3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002800 if (!Token::IsEqualityOp(op())) {
2801 __ lw(a1, FieldMemOperand(a1, Oddball::kToNumberOffset));
2802 __ AssertSmi(a1);
2803 __ lw(a0, FieldMemOperand(a0, Oddball::kToNumberOffset));
2804 __ AssertSmi(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002805 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002806 __ Ret(USE_DELAY_SLOT);
2807 __ Subu(v0, a1, a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002808
2809 __ bind(&miss);
2810 GenerateMiss(masm);
2811}
2812
2813
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002814void CompareICStub::GenerateSmis(MacroAssembler* masm) {
2815 DCHECK(state() == CompareICState::SMI);
Ben Murdoch257744e2011-11-30 15:57:28 +00002816 Label miss;
2817 __ Or(a2, a1, a0);
2818 __ JumpIfNotSmi(a2, &miss);
2819
2820 if (GetCondition() == eq) {
2821 // For equality we do not care about the sign of the result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002822 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00002823 __ Subu(v0, a0, a1);
2824 } else {
2825 // Untag before subtracting to avoid handling overflow.
2826 __ SmiUntag(a1);
2827 __ SmiUntag(a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002828 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00002829 __ Subu(v0, a1, a0);
2830 }
Ben Murdoch257744e2011-11-30 15:57:28 +00002831
2832 __ bind(&miss);
2833 GenerateMiss(masm);
Steve Block44f0eee2011-05-26 01:26:41 +01002834}
2835
2836
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002837void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
2838 DCHECK(state() == CompareICState::NUMBER);
Ben Murdoch257744e2011-11-30 15:57:28 +00002839
2840 Label generic_stub;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002841 Label unordered, maybe_undefined1, maybe_undefined2;
Ben Murdoch257744e2011-11-30 15:57:28 +00002842 Label miss;
Ben Murdoch257744e2011-11-30 15:57:28 +00002843
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002844 if (left() == CompareICState::SMI) {
2845 __ JumpIfNotSmi(a1, &miss);
2846 }
2847 if (right() == CompareICState::SMI) {
2848 __ JumpIfNotSmi(a0, &miss);
Ben Murdoch85b71792012-04-11 18:30:58 +01002849 }
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01002850
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002851 // Inlining the double comparison and falling back to the general compare
2852 // stub if NaN is involved.
2853 // Load left and right operand.
2854 Label done, left, left_smi, right_smi;
2855 __ JumpIfSmi(a0, &right_smi);
2856 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
2857 DONT_DO_SMI_CHECK);
2858 __ Subu(a2, a0, Operand(kHeapObjectTag));
2859 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
2860 __ Branch(&left);
2861 __ bind(&right_smi);
2862 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
2863 FPURegister single_scratch = f6;
2864 __ mtc1(a2, single_scratch);
2865 __ cvt_d_w(f2, single_scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002866
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002867 __ bind(&left);
2868 __ JumpIfSmi(a1, &left_smi);
2869 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
2870 DONT_DO_SMI_CHECK);
2871 __ Subu(a2, a1, Operand(kHeapObjectTag));
2872 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
2873 __ Branch(&done);
2874 __ bind(&left_smi);
2875 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
2876 single_scratch = f8;
2877 __ mtc1(a2, single_scratch);
2878 __ cvt_d_w(f0, single_scratch);
2879
2880 __ bind(&done);
2881
2882 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
2883 Label fpu_eq, fpu_lt;
2884 // Test if equal, and also handle the unordered/NaN case.
2885 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
2886
2887 // Test if less (unordered case is already handled).
2888 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
2889
2890 // Otherwise it's greater, so just fall thru, and return.
2891 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
2892 __ Ret(USE_DELAY_SLOT);
2893 __ li(v0, Operand(GREATER));
2894
2895 __ bind(&fpu_eq);
2896 __ Ret(USE_DELAY_SLOT);
2897 __ li(v0, Operand(EQUAL));
2898
2899 __ bind(&fpu_lt);
2900 __ Ret(USE_DELAY_SLOT);
2901 __ li(v0, Operand(LESS));
2902
2903 __ bind(&unordered);
Ben Murdoch257744e2011-11-30 15:57:28 +00002904 __ bind(&generic_stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002905 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002906 CompareICState::GENERIC, CompareICState::GENERIC);
Ben Murdoch257744e2011-11-30 15:57:28 +00002907 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
2908
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002909 __ bind(&maybe_undefined1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002910 if (Token::IsOrderedRelationalCompareOp(op())) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002911 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
2912 __ Branch(&miss, ne, a0, Operand(at));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002913 __ JumpIfSmi(a1, &unordered);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002914 __ GetObjectType(a1, a2, a2);
2915 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
2916 __ jmp(&unordered);
2917 }
2918
2919 __ bind(&maybe_undefined2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002920 if (Token::IsOrderedRelationalCompareOp(op())) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002921 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
2922 __ Branch(&unordered, eq, a1, Operand(at));
2923 }
2924
Ben Murdoch257744e2011-11-30 15:57:28 +00002925 __ bind(&miss);
2926 GenerateMiss(masm);
2927}
2928
2929
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002930void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
2931 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
Ben Murdoch257744e2011-11-30 15:57:28 +00002932 Label miss;
2933
2934 // Registers containing left and right operands respectively.
2935 Register left = a1;
2936 Register right = a0;
2937 Register tmp1 = a2;
2938 Register tmp2 = a3;
2939
2940 // Check that both operands are heap objects.
2941 __ JumpIfEitherSmi(left, right, &miss);
2942
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002943 // Check that both operands are internalized strings.
Ben Murdoch257744e2011-11-30 15:57:28 +00002944 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
2945 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
2946 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
2947 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002948 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
2949 __ Or(tmp1, tmp1, Operand(tmp2));
2950 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
2951 __ Branch(&miss, ne, at, Operand(zero_reg));
2952
Ben Murdoch257744e2011-11-30 15:57:28 +00002953 // Make sure a0 is non-zero. At this point input operands are
2954 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002955 DCHECK(right.is(a0));
Ben Murdoch257744e2011-11-30 15:57:28 +00002956 STATIC_ASSERT(EQUAL == 0);
2957 STATIC_ASSERT(kSmiTag == 0);
2958 __ mov(v0, right);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002959 // Internalized strings are compared by identity.
Ben Murdoch257744e2011-11-30 15:57:28 +00002960 __ Ret(ne, left, Operand(right));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002961 DCHECK(is_int16(EQUAL));
2962 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00002963 __ li(v0, Operand(Smi::FromInt(EQUAL)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002964
2965 __ bind(&miss);
2966 GenerateMiss(masm);
2967}
2968
2969
2970void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
2971 DCHECK(state() == CompareICState::UNIQUE_NAME);
2972 DCHECK(GetCondition() == eq);
2973 Label miss;
2974
2975 // Registers containing left and right operands respectively.
2976 Register left = a1;
2977 Register right = a0;
2978 Register tmp1 = a2;
2979 Register tmp2 = a3;
2980
2981 // Check that both operands are heap objects.
2982 __ JumpIfEitherSmi(left, right, &miss);
2983
2984 // Check that both operands are unique names. This leaves the instance
2985 // types loaded in tmp1 and tmp2.
2986 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
2987 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
2988 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
2989 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
2990
2991 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
2992 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
2993
2994 // Use a0 as result
2995 __ mov(v0, a0);
2996
2997 // Unique names are compared by identity.
2998 Label done;
2999 __ Branch(&done, ne, left, Operand(right));
3000 // Make sure a0 is non-zero. At this point input operands are
3001 // guaranteed to be non-zero.
3002 DCHECK(right.is(a0));
3003 STATIC_ASSERT(EQUAL == 0);
3004 STATIC_ASSERT(kSmiTag == 0);
3005 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3006 __ bind(&done);
Ben Murdoch257744e2011-11-30 15:57:28 +00003007 __ Ret();
3008
3009 __ bind(&miss);
3010 GenerateMiss(masm);
3011}
3012
3013
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003014void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3015 DCHECK(state() == CompareICState::STRING);
Ben Murdoch257744e2011-11-30 15:57:28 +00003016 Label miss;
3017
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003018 bool equality = Token::IsEqualityOp(op());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003019
Ben Murdoch257744e2011-11-30 15:57:28 +00003020 // Registers containing left and right operands respectively.
3021 Register left = a1;
3022 Register right = a0;
3023 Register tmp1 = a2;
3024 Register tmp2 = a3;
3025 Register tmp3 = t0;
3026 Register tmp4 = t1;
3027 Register tmp5 = t2;
3028
3029 // Check that both operands are heap objects.
3030 __ JumpIfEitherSmi(left, right, &miss);
3031
3032 // Check that both operands are strings. This leaves the instance
3033 // types loaded in tmp1 and tmp2.
3034 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3035 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3036 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3037 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3038 STATIC_ASSERT(kNotStringTag != 0);
3039 __ Or(tmp3, tmp1, tmp2);
3040 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3041 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3042
3043 // Fast check for identical strings.
3044 Label left_ne_right;
3045 STATIC_ASSERT(EQUAL == 0);
3046 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003047 __ Branch(&left_ne_right, ne, left, Operand(right));
3048 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00003049 __ mov(v0, zero_reg); // In the delay slot.
Ben Murdoch257744e2011-11-30 15:57:28 +00003050 __ bind(&left_ne_right);
3051
3052 // Handle not identical strings.
3053
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003054 // Check that both strings are internalized strings. If they are, we're done
3055 // because we already know they are not identical. We know they are both
3056 // strings.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003057 if (equality) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003058 DCHECK(GetCondition() == eq);
3059 STATIC_ASSERT(kInternalizedTag == 0);
3060 __ Or(tmp3, tmp1, Operand(tmp2));
3061 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003062 Label is_symbol;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003063 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003064 // Make sure a0 is non-zero. At this point input operands are
3065 // guaranteed to be non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003066 DCHECK(right.is(a0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003067 __ Ret(USE_DELAY_SLOT);
3068 __ mov(v0, a0); // In the delay slot.
3069 __ bind(&is_symbol);
3070 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003071
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003072 // Check that both strings are sequential one-byte.
Ben Murdoch257744e2011-11-30 15:57:28 +00003073 Label runtime;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003074 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3075 &runtime);
Ben Murdoch257744e2011-11-30 15:57:28 +00003076
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003077 // Compare flat one-byte strings. Returns when done.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003078 if (equality) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003079 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3080 tmp3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003081 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003082 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3083 tmp2, tmp3, tmp4);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003084 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003085
3086 // Handle more complex cases in runtime.
3087 __ bind(&runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003088 if (equality) {
Ben Murdochda12d292016-06-02 14:46:10 +01003089 {
3090 FrameScope scope(masm, StackFrame::INTERNAL);
3091 __ Push(left, right);
3092 __ CallRuntime(Runtime::kStringEqual);
3093 }
3094 __ LoadRoot(a0, Heap::kTrueValueRootIndex);
3095 __ Ret(USE_DELAY_SLOT);
3096 __ Subu(v0, v0, a0); // In delay slot.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003097 } else {
Ben Murdochda12d292016-06-02 14:46:10 +01003098 __ Push(left, right);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003099 __ TailCallRuntime(Runtime::kStringCompare);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003100 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003101
3102 __ bind(&miss);
3103 GenerateMiss(masm);
Steve Block44f0eee2011-05-26 01:26:41 +01003104}
3105
3106
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003107void CompareICStub::GenerateReceivers(MacroAssembler* masm) {
3108 DCHECK_EQ(CompareICState::RECEIVER, state());
Ben Murdoch257744e2011-11-30 15:57:28 +00003109 Label miss;
3110 __ And(a2, a1, Operand(a0));
3111 __ JumpIfSmi(a2, &miss);
3112
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003113 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Ben Murdoch257744e2011-11-30 15:57:28 +00003114 __ GetObjectType(a0, a2, a2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003115 __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdoch257744e2011-11-30 15:57:28 +00003116 __ GetObjectType(a1, a2, a2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003117 __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdoch257744e2011-11-30 15:57:28 +00003118
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003119 DCHECK_EQ(eq, GetCondition());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003120 __ Ret(USE_DELAY_SLOT);
3121 __ subu(v0, a0, a1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003122
3123 __ bind(&miss);
3124 GenerateMiss(masm);
Steve Block44f0eee2011-05-26 01:26:41 +01003125}
3126
3127
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003128void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003129 Label miss;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003130 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003131 __ And(a2, a1, a0);
3132 __ JumpIfSmi(a2, &miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003133 __ GetWeakValue(t0, cell);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003134 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3135 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003136 __ Branch(&miss, ne, a2, Operand(t0));
3137 __ Branch(&miss, ne, a3, Operand(t0));
Ben Murdoch85b71792012-04-11 18:30:58 +01003138
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003139 if (Token::IsEqualityOp(op())) {
3140 __ Ret(USE_DELAY_SLOT);
3141 __ subu(v0, a0, a1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003142 } else {
3143 if (op() == Token::LT || op() == Token::LTE) {
3144 __ li(a2, Operand(Smi::FromInt(GREATER)));
3145 } else {
3146 __ li(a2, Operand(Smi::FromInt(LESS)));
3147 }
3148 __ Push(a1, a0, a2);
3149 __ TailCallRuntime(Runtime::kCompare);
3150 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003151
3152 __ bind(&miss);
3153 GenerateMiss(masm);
3154}
3155
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003156
3157void CompareICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003158 {
3159 // Call the runtime system in a fresh internal frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003160 FrameScope scope(masm, StackFrame::INTERNAL);
3161 __ Push(a1, a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003162 __ Push(ra, a1, a0);
3163 __ li(t0, Operand(Smi::FromInt(op())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003164 __ addiu(sp, sp, -kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003165 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3166 USE_DELAY_SLOT);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003167 __ sw(t0, MemOperand(sp)); // In the delay slot.
3168 // Compute the entry point of the rewritten stub.
3169 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3170 // Restore registers.
3171 __ Pop(a1, a0, ra);
3172 }
Ben Murdoch257744e2011-11-30 15:57:28 +00003173 __ Jump(a2);
3174}
3175
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003176
Ben Murdoch257744e2011-11-30 15:57:28 +00003177void DirectCEntryStub::Generate(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003178 // Make place for arguments to fit C calling convention. Most of the callers
3179 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3180 // so they handle stack restoring and we don't have to do that here.
3181 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3182 // kCArgsSlotsSize stack space after the call.
3183 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
3184 // Place the return address on the stack, making the call
3185 // GC safe. The RegExp backend also relies on this.
3186 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
3187 __ Call(t9); // Call the C++ function.
Ben Murdoch257744e2011-11-30 15:57:28 +00003188 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
3189
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003190 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
Ben Murdoch257744e2011-11-30 15:57:28 +00003191 // In case of an error the return address may point to a memory area
3192 // filled with kZapValue by the GC.
3193 // Dereference the address and check for this.
3194 __ lw(t0, MemOperand(t9));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003195 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
Ben Murdoch257744e2011-11-30 15:57:28 +00003196 Operand(reinterpret_cast<uint32_t>(kZapValue)));
3197 }
3198 __ Jump(t9);
Steve Block44f0eee2011-05-26 01:26:41 +01003199}
3200
3201
Ben Murdoch257744e2011-11-30 15:57:28 +00003202void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
Ben Murdoch257744e2011-11-30 15:57:28 +00003203 Register target) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003204 intptr_t loc =
3205 reinterpret_cast<intptr_t>(GetCode().location());
Ben Murdoch257744e2011-11-30 15:57:28 +00003206 __ Move(t9, target);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003207 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3208 __ Call(at);
Ben Murdoch257744e2011-11-30 15:57:28 +00003209}
3210
3211
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003212void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3213 Label* miss,
3214 Label* done,
3215 Register receiver,
3216 Register properties,
3217 Handle<Name> name,
3218 Register scratch0) {
3219 DCHECK(name->IsUniqueName());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003220 // If names of slots in range from 1 to kProbes - 1 for the hash value are
Ben Murdoch257744e2011-11-30 15:57:28 +00003221 // not equal to the name and kProbes-th slot is not used (its name is the
3222 // undefined value), it guarantees the hash table doesn't contain the
3223 // property. It's true even if some slots represent deleted properties
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003224 // (their names are the hole value).
Ben Murdoch257744e2011-11-30 15:57:28 +00003225 for (int i = 0; i < kInlinedProbes; i++) {
3226 // scratch0 points to properties hash.
3227 // Compute the masked index: (hash + i + i * i) & mask.
3228 Register index = scratch0;
3229 // Capacity is smi 2^n.
3230 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
3231 __ Subu(index, index, Operand(1));
3232 __ And(index, index, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003233 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
Ben Murdoch257744e2011-11-30 15:57:28 +00003234
3235 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003236 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003237 __ Lsa(index, index, index, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003238
3239 Register entity_name = scratch0;
3240 // Having undefined at this place means the name is not contained.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003241 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003242 Register tmp = properties;
Ben Murdoch097c5b22016-05-18 11:27:45 +01003243 __ Lsa(tmp, properties, index, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003244 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3245
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003246 DCHECK(!tmp.is(entity_name));
Ben Murdoch257744e2011-11-30 15:57:28 +00003247 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3248 __ Branch(done, eq, entity_name, Operand(tmp));
3249
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003250 // Load the hole ready for use below:
3251 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003252
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003253 // Stop if found the property.
3254 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
Ben Murdoch257744e2011-11-30 15:57:28 +00003255
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003256 Label good;
3257 __ Branch(&good, eq, entity_name, Operand(tmp));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003258
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003259 // Check if the entry name is not a unique name.
3260 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3261 __ lbu(entity_name,
3262 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3263 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3264 __ bind(&good);
Ben Murdoch257744e2011-11-30 15:57:28 +00003265
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003266 // Restore the properties.
3267 __ lw(properties,
3268 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003269 }
3270
3271 const int spill_mask =
3272 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003273 a2.bit() | a1.bit() | a0.bit() | v0.bit());
Ben Murdoch257744e2011-11-30 15:57:28 +00003274
3275 __ MultiPush(spill_mask);
3276 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003277 __ li(a1, Operand(Handle<Name>(name)));
3278 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003279 __ CallStub(&stub);
3280 __ mov(at, v0);
Ben Murdoch257744e2011-11-30 15:57:28 +00003281 __ MultiPop(spill_mask);
3282
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003283 __ Branch(done, eq, at, Operand(zero_reg));
3284 __ Branch(miss, ne, at, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +00003285}
3286
3287
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003288// Probe the name dictionary in the |elements| register. Jump to the
Ben Murdoch257744e2011-11-30 15:57:28 +00003289// |done| label if a property with the given name is found. Jump to
3290// the |miss| label otherwise.
3291// If lookup was successful |scratch2| will be equal to elements + 4 * index.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003292void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3293 Label* miss,
3294 Label* done,
3295 Register elements,
3296 Register name,
3297 Register scratch1,
3298 Register scratch2) {
3299 DCHECK(!elements.is(scratch1));
3300 DCHECK(!elements.is(scratch2));
3301 DCHECK(!name.is(scratch1));
3302 DCHECK(!name.is(scratch2));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003303
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003304 __ AssertName(name);
Ben Murdoch257744e2011-11-30 15:57:28 +00003305
3306 // Compute the capacity mask.
3307 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
3308 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
3309 __ Subu(scratch1, scratch1, Operand(1));
3310
3311 // Generate an unrolled loop that performs a few probes before
3312 // giving up. Measurements done on Gmail indicate that 2 probes
3313 // cover ~93% of loads from dictionaries.
3314 for (int i = 0; i < kInlinedProbes; i++) {
3315 // Compute the masked index: (hash + i + i * i) & mask.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003316 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003317 if (i > 0) {
3318 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3319 // the hash in a separate instruction. The value hash + i + i * i is right
3320 // shifted in the following and instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003321 DCHECK(NameDictionary::GetProbeOffset(i) <
3322 1 << (32 - Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003323 __ Addu(scratch2, scratch2, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003324 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003325 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003326 __ srl(scratch2, scratch2, Name::kHashShift);
Ben Murdoch257744e2011-11-30 15:57:28 +00003327 __ And(scratch2, scratch1, scratch2);
3328
3329 // Scale the index by multiplying by the element size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003330 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003331 // scratch2 = scratch2 * 3.
3332
Ben Murdoch097c5b22016-05-18 11:27:45 +01003333 __ Lsa(scratch2, scratch2, scratch2, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003334
3335 // Check if the key is identical to the name.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003336 __ Lsa(scratch2, elements, scratch2, 2);
Ben Murdoch257744e2011-11-30 15:57:28 +00003337 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
3338 __ Branch(done, eq, name, Operand(at));
3339 }
3340
3341 const int spill_mask =
3342 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003343 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
Ben Murdoch257744e2011-11-30 15:57:28 +00003344 ~(scratch1.bit() | scratch2.bit());
3345
3346 __ MultiPush(spill_mask);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003347 if (name.is(a0)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003348 DCHECK(!elements.is(a1));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003349 __ Move(a1, name);
3350 __ Move(a0, elements);
3351 } else {
3352 __ Move(a0, elements);
3353 __ Move(a1, name);
3354 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003355 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
Ben Murdoch257744e2011-11-30 15:57:28 +00003356 __ CallStub(&stub);
3357 __ mov(scratch2, a2);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003358 __ mov(at, v0);
Ben Murdoch257744e2011-11-30 15:57:28 +00003359 __ MultiPop(spill_mask);
3360
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003361 __ Branch(done, ne, at, Operand(zero_reg));
3362 __ Branch(miss, eq, at, Operand(zero_reg));
Ben Murdoch257744e2011-11-30 15:57:28 +00003363}
3364
3365
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003366void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003367 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3368 // we cannot call anything that could cause a GC from this stub.
Ben Murdoch257744e2011-11-30 15:57:28 +00003369 // Registers:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003370 // result: NameDictionary to probe
Ben Murdoch257744e2011-11-30 15:57:28 +00003371 // a1: key
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003372 // dictionary: NameDictionary to probe.
3373 // index: will hold an index of entry if lookup is successful.
3374 // might alias with result_.
Ben Murdoch257744e2011-11-30 15:57:28 +00003375 // Returns:
3376 // result_ is zero if lookup failed, non zero otherwise.
3377
3378 Register result = v0;
3379 Register dictionary = a0;
3380 Register key = a1;
3381 Register index = a2;
3382 Register mask = a3;
3383 Register hash = t0;
3384 Register undefined = t1;
3385 Register entry_key = t2;
3386
3387 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3388
3389 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
3390 __ sra(mask, mask, kSmiTagSize);
3391 __ Subu(mask, mask, Operand(1));
3392
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003393 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003394
3395 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3396
3397 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3398 // Compute the masked index: (hash + i + i * i) & mask.
3399 // Capacity is smi 2^n.
3400 if (i > 0) {
3401 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3402 // the hash in a separate instruction. The value hash + i + i * i is right
3403 // shifted in the following and instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003404 DCHECK(NameDictionary::GetProbeOffset(i) <
3405 1 << (32 - Name::kHashFieldOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +00003406 __ Addu(index, hash, Operand(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003407 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
Ben Murdoch257744e2011-11-30 15:57:28 +00003408 } else {
3409 __ mov(index, hash);
3410 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003411 __ srl(index, index, Name::kHashShift);
Ben Murdoch257744e2011-11-30 15:57:28 +00003412 __ And(index, mask, index);
3413
3414 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003415 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch257744e2011-11-30 15:57:28 +00003416 // index *= 3.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003417 __ Lsa(index, index, index, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003418
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003419 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003420 __ Lsa(index, dictionary, index, 2);
Ben Murdoch257744e2011-11-30 15:57:28 +00003421 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
3422
3423 // Having undefined at this place means the name is not contained.
3424 __ Branch(&not_in_dictionary, eq, entry_key, Operand(undefined));
3425
3426 // Stop if found the property.
3427 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
3428
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003429 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3430 // Check if the entry name is not a unique name.
Ben Murdoch257744e2011-11-30 15:57:28 +00003431 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3432 __ lbu(entry_key,
3433 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003434 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
Ben Murdoch257744e2011-11-30 15:57:28 +00003435 }
3436 }
3437
3438 __ bind(&maybe_in_dictionary);
3439 // If we are doing negative lookup then probing failure should be
3440 // treated as a lookup success. For positive lookup probing failure
3441 // should be treated as lookup failure.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003442 if (mode() == POSITIVE_LOOKUP) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003443 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00003444 __ mov(result, zero_reg);
Ben Murdoch257744e2011-11-30 15:57:28 +00003445 }
3446
3447 __ bind(&in_dictionary);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003448 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00003449 __ li(result, 1);
Ben Murdoch257744e2011-11-30 15:57:28 +00003450
3451 __ bind(&not_in_dictionary);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003452 __ Ret(USE_DELAY_SLOT);
Ben Murdoch257744e2011-11-30 15:57:28 +00003453 __ mov(result, zero_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003454}
3455
3456
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003457void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3458 Isolate* isolate) {
3459 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3460 stub1.GetCode();
3461 // Hydrogen code stubs need stub2 at snapshot time.
3462 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3463 stub2.GetCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003464}
3465
3466
3467// Takes the input in 3 registers: address_ value_ and object_. A pointer to
3468// the value has just been written into the object, now this stub makes sure
3469// we keep the GC informed. The word in the object where the value has been
3470// written is in the address register.
3471void RecordWriteStub::Generate(MacroAssembler* masm) {
3472 Label skip_to_incremental_noncompacting;
3473 Label skip_to_incremental_compacting;
3474
3475 // The first two branch+nop instructions are generated with labels so as to
3476 // get the offset fixed up correctly by the bind(Label*) call. We patch it
3477 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
3478 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
3479 // incremental heap marking.
3480 // See RecordWriteStub::Patch for details.
3481 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
3482 __ nop();
3483 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
3484 __ nop();
3485
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003486 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3487 __ RememberedSetHelper(object(),
3488 address(),
3489 value(),
3490 save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003491 MacroAssembler::kReturnAtEnd);
3492 }
Ben Murdoch592a9fc2012-03-05 11:04:45 +00003493 __ Ret();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003494
3495 __ bind(&skip_to_incremental_noncompacting);
3496 GenerateIncremental(masm, INCREMENTAL);
3497
3498 __ bind(&skip_to_incremental_compacting);
3499 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3500
3501 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3502 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3503
3504 PatchBranchIntoNop(masm, 0);
3505 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
3506}
3507
3508
3509void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3510 regs_.Save(masm);
3511
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003512 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003513 Label dont_need_remembered_set;
3514
3515 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
3516 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
3517 regs_.scratch0(),
3518 &dont_need_remembered_set);
3519
Ben Murdoch097c5b22016-05-18 11:27:45 +01003520 __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(),
3521 &dont_need_remembered_set);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003522
3523 // First notify the incremental marker if necessary, then update the
3524 // remembered set.
3525 CheckNeedsToInformIncrementalMarker(
3526 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003527 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003528 regs_.Restore(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003529 __ RememberedSetHelper(object(),
3530 address(),
3531 value(),
3532 save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003533 MacroAssembler::kReturnAtEnd);
3534
3535 __ bind(&dont_need_remembered_set);
3536 }
3537
3538 CheckNeedsToInformIncrementalMarker(
3539 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003540 InformIncrementalMarker(masm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003541 regs_.Restore(masm);
3542 __ Ret();
3543}
3544
3545
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003546void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3547 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003548 int argument_count = 3;
3549 __ PrepareCallCFunction(argument_count, regs_.scratch0());
3550 Register address =
3551 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003552 DCHECK(!address.is(regs_.object()));
3553 DCHECK(!address.is(a0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003554 __ Move(address, regs_.address());
3555 __ Move(a0, regs_.object());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003556 __ Move(a1, address);
3557 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003558
3559 AllowExternalCallThatCantCauseGC scope(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003560 __ CallCFunction(
3561 ExternalReference::incremental_marking_record_write_function(isolate()),
3562 argument_count);
3563 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003564}
3565
3566
3567void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
3568 MacroAssembler* masm,
3569 OnNoNeedToInformIncrementalMarker on_no_need,
3570 Mode mode) {
3571 Label on_black;
3572 Label need_incremental;
3573 Label need_incremental_pop_scratch;
3574
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003575 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
3576 __ lw(regs_.scratch1(),
3577 MemOperand(regs_.scratch0(),
3578 MemoryChunk::kWriteBarrierCounterOffset));
3579 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
3580 __ sw(regs_.scratch1(),
3581 MemOperand(regs_.scratch0(),
3582 MemoryChunk::kWriteBarrierCounterOffset));
3583 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
3584
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003585 // Let's look at the color of the object: If it is not black we don't have
3586 // to inform the incremental marker.
3587 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
3588
3589 regs_.Restore(masm);
3590 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003591 __ RememberedSetHelper(object(),
3592 address(),
3593 value(),
3594 save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003595 MacroAssembler::kReturnAtEnd);
3596 } else {
3597 __ Ret();
3598 }
3599
3600 __ bind(&on_black);
3601
3602 // Get the value from the slot.
3603 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
3604
3605 if (mode == INCREMENTAL_COMPACTION) {
3606 Label ensure_not_white;
3607
3608 __ CheckPageFlag(regs_.scratch0(), // Contains value.
3609 regs_.scratch1(), // Scratch.
3610 MemoryChunk::kEvacuationCandidateMask,
3611 eq,
3612 &ensure_not_white);
3613
3614 __ CheckPageFlag(regs_.object(),
3615 regs_.scratch1(), // Scratch.
3616 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
3617 eq,
3618 &need_incremental);
3619
3620 __ bind(&ensure_not_white);
3621 }
3622
3623 // We need extra registers for this, so we push the object and the address
3624 // register temporarily.
3625 __ Push(regs_.object(), regs_.address());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003626 __ JumpIfWhite(regs_.scratch0(), // The value.
3627 regs_.scratch1(), // Scratch.
3628 regs_.object(), // Scratch.
3629 regs_.address(), // Scratch.
3630 &need_incremental_pop_scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003631 __ Pop(regs_.object(), regs_.address());
3632
3633 regs_.Restore(masm);
3634 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003635 __ RememberedSetHelper(object(),
3636 address(),
3637 value(),
3638 save_fp_regs_mode(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003639 MacroAssembler::kReturnAtEnd);
3640 } else {
3641 __ Ret();
3642 }
3643
3644 __ bind(&need_incremental_pop_scratch);
3645 __ Pop(regs_.object(), regs_.address());
3646
3647 __ bind(&need_incremental);
3648
3649 // Fall through when we need to inform the incremental marker.
3650}
3651
3652
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003653void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
3654 CEntryStub ces(isolate(), 1, kSaveFPRegs);
3655 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
3656 int parameter_count_offset =
Ben Murdochda12d292016-06-02 14:46:10 +01003657 StubFailureTrampolineFrameConstants::kArgumentsLengthOffset;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003658 __ lw(a1, MemOperand(fp, parameter_count_offset));
3659 if (function_mode() == JS_FUNCTION_STUB_MODE) {
3660 __ Addu(a1, a1, Operand(1));
3661 }
3662 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
3663 __ sll(a1, a1, kPointerSizeLog2);
3664 __ Ret(USE_DELAY_SLOT);
3665 __ Addu(sp, sp, a1);
3666}
3667
3668
3669void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003670 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
Ben Murdoch61f157c2016-09-16 13:49:30 +01003671 LoadICStub stub(isolate());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003672 stub.GenerateForTrampoline(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003673}
3674
3675
3676void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003677 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
Ben Murdoch61f157c2016-09-16 13:49:30 +01003678 KeyedLoadICStub stub(isolate());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003679 stub.GenerateForTrampoline(masm);
3680}
3681
3682
3683void CallICTrampolineStub::Generate(MacroAssembler* masm) {
3684 __ EmitLoadTypeFeedbackVector(a2);
3685 CallICStub stub(isolate(), state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003686 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3687}
3688
3689
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003690void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
3691
3692
3693void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3694 GenerateImpl(masm, true);
3695}
3696
3697
3698static void HandleArrayCases(MacroAssembler* masm, Register feedback,
3699 Register receiver_map, Register scratch1,
3700 Register scratch2, bool is_polymorphic,
3701 Label* miss) {
3702 // feedback initially contains the feedback array
3703 Label next_loop, prepare_next;
3704 Label start_polymorphic;
3705
3706 Register cached_map = scratch1;
3707
3708 __ lw(cached_map,
3709 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
3710 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3711 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
3712 // found, now call handler.
3713 Register handler = feedback;
3714 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
3715 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3716 __ Jump(t9);
3717
3718
3719 Register length = scratch2;
3720 __ bind(&start_polymorphic);
3721 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
3722 if (!is_polymorphic) {
3723 // If the IC could be monomorphic we have to make sure we don't go past the
3724 // end of the feedback array.
3725 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
3726 }
3727
3728 Register too_far = length;
3729 Register pointer_reg = feedback;
3730
3731 // +-----+------+------+-----+-----+ ... ----+
3732 // | map | len | wm0 | h0 | wm1 | hN |
3733 // +-----+------+------+-----+-----+ ... ----+
3734 // 0 1 2 len-1
3735 // ^ ^
3736 // | |
3737 // pointer_reg too_far
3738 // aka feedback scratch2
3739 // also need receiver_map
3740 // use cached_map (scratch1) to look in the weak map values.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003741 __ Lsa(too_far, feedback, length, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003742 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3743 __ Addu(pointer_reg, feedback,
3744 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
3745
3746 __ bind(&next_loop);
3747 __ lw(cached_map, MemOperand(pointer_reg));
3748 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3749 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
3750 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
3751 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3752 __ Jump(t9);
3753
3754 __ bind(&prepare_next);
3755 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
3756 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
3757
3758 // We exhausted our array of map handler pairs.
3759 __ jmp(miss);
3760}
3761
3762
3763static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
3764 Register receiver_map, Register feedback,
3765 Register vector, Register slot,
3766 Register scratch, Label* compare_map,
3767 Label* load_smi_map, Label* try_array) {
3768 __ JumpIfSmi(receiver, load_smi_map);
3769 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
3770 __ bind(compare_map);
3771 Register cached_map = scratch;
3772 // Move the weak map into the weak_cell register.
3773 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
3774 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
3775 Register handler = feedback;
3776
Ben Murdoch097c5b22016-05-18 11:27:45 +01003777 __ Lsa(handler, vector, slot, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003778 __ lw(handler,
3779 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
3780 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3781 __ Jump(t9);
3782}
3783
3784
3785void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3786 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
3787 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
3788 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
3789 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
3790 Register feedback = t0;
3791 Register receiver_map = t1;
3792 Register scratch1 = t4;
3793
Ben Murdoch097c5b22016-05-18 11:27:45 +01003794 __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003795 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3796
3797 // Try to quickly handle the monomorphic case without knowing for sure
3798 // if we have a weak cell in feedback. We do know it's safe to look
3799 // at WeakCell::kValueOffset.
3800 Label try_array, load_smi_map, compare_map;
3801 Label not_array, miss;
3802 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3803 scratch1, &compare_map, &load_smi_map, &try_array);
3804
3805 // Is it a fixed array?
3806 __ bind(&try_array);
3807 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3808 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
3809 __ Branch(&not_array, ne, at, Operand(scratch1));
3810 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
3811
3812 __ bind(&not_array);
3813 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
3814 __ Branch(&miss, ne, at, Operand(feedback));
Ben Murdochc5610432016-08-08 18:44:38 +01003815 Code::Flags code_flags =
3816 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003817 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
3818 receiver, name, feedback,
3819 receiver_map, scratch1, t5);
3820
3821 __ bind(&miss);
3822 LoadIC::GenerateMiss(masm);
3823
3824 __ bind(&load_smi_map);
3825 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3826 __ jmp(&compare_map);
3827}
3828
3829
3830void KeyedLoadICStub::Generate(MacroAssembler* masm) {
3831 GenerateImpl(masm, false);
3832}
3833
3834
3835void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3836 GenerateImpl(masm, true);
3837}
3838
3839
3840void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3841 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
3842 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
3843 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
3844 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
3845 Register feedback = t0;
3846 Register receiver_map = t1;
3847 Register scratch1 = t4;
3848
Ben Murdoch097c5b22016-05-18 11:27:45 +01003849 __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003850 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3851
3852 // Try to quickly handle the monomorphic case without knowing for sure
3853 // if we have a weak cell in feedback. We do know it's safe to look
3854 // at WeakCell::kValueOffset.
3855 Label try_array, load_smi_map, compare_map;
3856 Label not_array, miss;
3857 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3858 scratch1, &compare_map, &load_smi_map, &try_array);
3859
3860 __ bind(&try_array);
3861 // Is it a fixed array?
3862 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3863 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
3864 __ Branch(&not_array, ne, at, Operand(scratch1));
3865 // We have a polymorphic element handler.
3866 __ JumpIfNotSmi(key, &miss);
3867
3868 Label polymorphic, try_poly_name;
3869 __ bind(&polymorphic);
3870 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
3871
3872 __ bind(&not_array);
3873 // Is it generic?
3874 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
3875 __ Branch(&try_poly_name, ne, at, Operand(feedback));
3876 Handle<Code> megamorphic_stub =
3877 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
3878 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
3879
3880 __ bind(&try_poly_name);
3881 // We might have a name in feedback, and a fixed array in the next slot.
3882 __ Branch(&miss, ne, key, Operand(feedback));
3883 // If the name comparison succeeded, we know we have a fixed array with
3884 // at least one map/handler pair.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003885 __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003886 __ lw(feedback,
3887 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
3888 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, false, &miss);
3889
3890 __ bind(&miss);
3891 KeyedLoadIC::GenerateMiss(masm);
3892
3893 __ bind(&load_smi_map);
3894 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
3895 __ jmp(&compare_map);
3896}
3897
3898
3899void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3900 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3901 VectorStoreICStub stub(isolate(), state());
3902 stub.GenerateForTrampoline(masm);
3903}
3904
3905
3906void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
3907 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
3908 VectorKeyedStoreICStub stub(isolate(), state());
3909 stub.GenerateForTrampoline(masm);
3910}
3911
3912
3913void VectorStoreICStub::Generate(MacroAssembler* masm) {
3914 GenerateImpl(masm, false);
3915}
3916
3917
3918void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
3919 GenerateImpl(masm, true);
3920}
3921
3922
3923void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
3924 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
3925 Register key = VectorStoreICDescriptor::NameRegister(); // a2
3926 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
3927 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
3928 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
3929 Register feedback = t1;
3930 Register receiver_map = t2;
3931 Register scratch1 = t5;
3932
Ben Murdoch097c5b22016-05-18 11:27:45 +01003933 __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003934 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
3935
3936 // Try to quickly handle the monomorphic case without knowing for sure
3937 // if we have a weak cell in feedback. We do know it's safe to look
3938 // at WeakCell::kValueOffset.
3939 Label try_array, load_smi_map, compare_map;
3940 Label not_array, miss;
3941 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
3942 scratch1, &compare_map, &load_smi_map, &try_array);
3943
3944 // Is it a fixed array?
3945 __ bind(&try_array);
3946 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
3947 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
3948 __ Branch(&not_array, ne, scratch1, Operand(at));
3949
3950 Register scratch2 = t4;
3951 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
3952 &miss);
3953
3954 __ bind(&not_array);
3955 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
3956 __ Branch(&miss, ne, feedback, Operand(at));
Ben Murdochc5610432016-08-08 18:44:38 +01003957 Code::Flags code_flags =
3958 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::STORE_IC));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003959 masm->isolate()->stub_cache()->GenerateProbe(
3960 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
3961 scratch1, scratch2);
3962
3963 __ bind(&miss);
3964 StoreIC::GenerateMiss(masm);
3965
3966 __ bind(&load_smi_map);
3967 __ Branch(USE_DELAY_SLOT, &compare_map);
3968 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
3969}
3970
3971
3972void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
3973 GenerateImpl(masm, false);
3974}
3975
3976
3977void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
3978 GenerateImpl(masm, true);
3979}
3980
3981
3982static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
3983 Register receiver_map, Register scratch1,
3984 Register scratch2, Label* miss) {
3985 // feedback initially contains the feedback array
3986 Label next_loop, prepare_next;
3987 Label start_polymorphic;
3988 Label transition_call;
3989
3990 Register cached_map = scratch1;
3991 Register too_far = scratch2;
3992 Register pointer_reg = feedback;
3993 __ lw(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
3994
3995 // +-----+------+------+-----+-----+-----+ ... ----+
3996 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
3997 // +-----+------+------+-----+-----+ ----+ ... ----+
3998 // 0 1 2 len-1
3999 // ^ ^
4000 // | |
4001 // pointer_reg too_far
4002 // aka feedback scratch2
4003 // also need receiver_map
4004 // use cached_map (scratch1) to look in the weak map values.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004005 __ Lsa(too_far, feedback, too_far, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004006 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4007 __ Addu(pointer_reg, feedback,
4008 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4009
4010 __ bind(&next_loop);
4011 __ lw(cached_map, MemOperand(pointer_reg));
4012 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4013 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4014 // Is it a transitioning store?
4015 __ lw(too_far, MemOperand(pointer_reg, kPointerSize));
4016 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4017 __ Branch(&transition_call, ne, too_far, Operand(at));
4018 __ lw(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4019 __ Addu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4020 __ Jump(t9);
4021
4022 __ bind(&transition_call);
4023 __ lw(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4024 __ JumpIfSmi(too_far, miss);
4025
4026 __ lw(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4027
4028 // Load the map into the correct register.
4029 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4030 __ mov(feedback, too_far);
4031
4032 __ Addu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4033 __ Jump(t9);
4034
4035 __ bind(&prepare_next);
4036 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4037 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4038
4039 // We exhausted our array of map handler pairs.
4040 __ jmp(miss);
4041}
4042
4043
4044void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4045 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4046 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4047 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4048 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
4049 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4050 Register feedback = t1;
4051 Register receiver_map = t2;
4052 Register scratch1 = t5;
4053
Ben Murdoch097c5b22016-05-18 11:27:45 +01004054 __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004055 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4056
4057 // Try to quickly handle the monomorphic case without knowing for sure
4058 // if we have a weak cell in feedback. We do know it's safe to look
4059 // at WeakCell::kValueOffset.
4060 Label try_array, load_smi_map, compare_map;
4061 Label not_array, miss;
4062 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4063 scratch1, &compare_map, &load_smi_map, &try_array);
4064
4065 __ bind(&try_array);
4066 // Is it a fixed array?
4067 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4068 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4069 __ Branch(&not_array, ne, scratch1, Operand(at));
4070
4071 // We have a polymorphic element handler.
4072 Label polymorphic, try_poly_name;
4073 __ bind(&polymorphic);
4074
4075 Register scratch2 = t4;
4076
4077 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4078 &miss);
4079
4080 __ bind(&not_array);
4081 // Is it generic?
4082 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4083 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4084 Handle<Code> megamorphic_stub =
4085 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4086 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4087
4088 __ bind(&try_poly_name);
4089 // We might have a name in feedback, and a fixed array in the next slot.
4090 __ Branch(&miss, ne, key, Operand(feedback));
4091 // If the name comparison succeeded, we know we have a fixed array with
4092 // at least one map/handler pair.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004093 __ Lsa(feedback, vector, slot, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004094 __ lw(feedback,
4095 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4096 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4097 &miss);
4098
4099 __ bind(&miss);
4100 KeyedStoreIC::GenerateMiss(masm);
4101
4102 __ bind(&load_smi_map);
4103 __ Branch(USE_DELAY_SLOT, &compare_map);
4104 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4105}
4106
4107
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004108void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4109 if (masm->isolate()->function_entry_hook() != NULL) {
4110 ProfileEntryHookStub stub(masm->isolate());
4111 __ push(ra);
4112 __ CallStub(&stub);
4113 __ pop(ra);
4114 }
4115}
4116
4117
4118void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4119 // The entry hook is a "push ra" instruction, followed by a call.
4120 // Note: on MIPS "push" is 2 instruction
4121 const int32_t kReturnAddressDistanceFromFunctionStart =
4122 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4123
4124 // This should contain all kJSCallerSaved registers.
4125 const RegList kSavedRegs =
4126 kJSCallerSaved | // Caller saved registers.
4127 s5.bit(); // Saved stack pointer.
4128
4129 // We also save ra, so the count here is one higher than the mask indicates.
4130 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4131
4132 // Save all caller-save registers as this may be called from anywhere.
4133 __ MultiPush(kSavedRegs | ra.bit());
4134
4135 // Compute the function's address for the first argument.
4136 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4137
4138 // The caller's return address is above the saved temporaries.
4139 // Grab that for the second argument to the hook.
4140 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4141
4142 // Align the stack if necessary.
4143 int frame_alignment = masm->ActivationFrameAlignment();
4144 if (frame_alignment > kPointerSize) {
4145 __ mov(s5, sp);
4146 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4147 __ And(sp, sp, Operand(-frame_alignment));
4148 }
4149 __ Subu(sp, sp, kCArgsSlotsSize);
4150#if defined(V8_HOST_ARCH_MIPS)
4151 int32_t entry_hook =
4152 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4153 __ li(t9, Operand(entry_hook));
4154#else
4155 // Under the simulator we need to indirect the entry hook through a
4156 // trampoline function at a known address.
4157 // It additionally takes an isolate as a third parameter.
4158 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4159
4160 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4161 __ li(t9, Operand(ExternalReference(&dispatcher,
4162 ExternalReference::BUILTIN_CALL,
4163 isolate())));
4164#endif
4165 // Call C function through t9 to conform ABI for PIC.
4166 __ Call(t9);
4167
4168 // Restore the stack pointer if needed.
4169 if (frame_alignment > kPointerSize) {
4170 __ mov(sp, s5);
4171 } else {
4172 __ Addu(sp, sp, kCArgsSlotsSize);
4173 }
4174
4175 // Also pop ra to get Ret(0).
4176 __ MultiPop(kSavedRegs | ra.bit());
4177 __ Ret();
4178}
4179
4180
4181template<class T>
4182static void CreateArrayDispatch(MacroAssembler* masm,
4183 AllocationSiteOverrideMode mode) {
4184 if (mode == DISABLE_ALLOCATION_SITES) {
4185 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4186 __ TailCallStub(&stub);
4187 } else if (mode == DONT_OVERRIDE) {
4188 int last_index = GetSequenceIndexFromFastElementsKind(
4189 TERMINAL_FAST_ELEMENTS_KIND);
4190 for (int i = 0; i <= last_index; ++i) {
4191 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4192 T stub(masm->isolate(), kind);
4193 __ TailCallStub(&stub, eq, a3, Operand(kind));
4194 }
4195
4196 // If we reached this point there is a problem.
4197 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4198 } else {
4199 UNREACHABLE();
4200 }
4201}
4202
4203
4204static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4205 AllocationSiteOverrideMode mode) {
4206 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4207 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4208 // a0 - number of arguments
4209 // a1 - constructor?
4210 // sp[0] - last argument
4211 Label normal_sequence;
4212 if (mode == DONT_OVERRIDE) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004213 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4214 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4215 STATIC_ASSERT(FAST_ELEMENTS == 2);
4216 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4217 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4218 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004219
4220 // is the low bit set? If so, we are holey and that is good.
4221 __ And(at, a3, Operand(1));
4222 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
4223 }
4224
4225 // look at the first argument
4226 __ lw(t1, MemOperand(sp, 0));
4227 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
4228
4229 if (mode == DISABLE_ALLOCATION_SITES) {
4230 ElementsKind initial = GetInitialFastElementsKind();
4231 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4232
4233 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4234 holey_initial,
4235 DISABLE_ALLOCATION_SITES);
4236 __ TailCallStub(&stub_holey);
4237
4238 __ bind(&normal_sequence);
4239 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4240 initial,
4241 DISABLE_ALLOCATION_SITES);
4242 __ TailCallStub(&stub);
4243 } else if (mode == DONT_OVERRIDE) {
4244 // We are going to create a holey array, but our kind is non-holey.
4245 // Fix kind and retry (only if we have an allocation site in the slot).
4246 __ Addu(a3, a3, Operand(1));
4247
4248 if (FLAG_debug_code) {
4249 __ lw(t1, FieldMemOperand(a2, 0));
4250 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
4251 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
4252 }
4253
4254 // Save the resulting elements kind in type info. We can't just store a3
4255 // in the AllocationSite::transition_info field because elements kind is
4256 // restricted to a portion of the field...upper bits need to be left alone.
4257 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4258 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4259 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4260 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4261
4262
4263 __ bind(&normal_sequence);
4264 int last_index = GetSequenceIndexFromFastElementsKind(
4265 TERMINAL_FAST_ELEMENTS_KIND);
4266 for (int i = 0; i <= last_index; ++i) {
4267 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4268 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4269 __ TailCallStub(&stub, eq, a3, Operand(kind));
4270 }
4271
4272 // If we reached this point there is a problem.
4273 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4274 } else {
4275 UNREACHABLE();
4276 }
4277}
4278
4279
4280template<class T>
4281static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4282 int to_index = GetSequenceIndexFromFastElementsKind(
4283 TERMINAL_FAST_ELEMENTS_KIND);
4284 for (int i = 0; i <= to_index; ++i) {
4285 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4286 T stub(isolate, kind);
4287 stub.GetCode();
4288 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4289 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4290 stub1.GetCode();
4291 }
4292 }
4293}
4294
Ben Murdoch61f157c2016-09-16 13:49:30 +01004295void CommonArrayConstructorStub::GenerateStubsAheadOfTime(Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004296 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4297 isolate);
4298 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4299 isolate);
Ben Murdoch61f157c2016-09-16 13:49:30 +01004300 ArrayNArgumentsConstructorStub stub(isolate);
4301 stub.GetCode();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004302 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4303 for (int i = 0; i < 2; i++) {
4304 // For internal arrays we only need a few things.
4305 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4306 stubh1.GetCode();
4307 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4308 stubh2.GetCode();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004309 }
4310}
4311
4312
4313void ArrayConstructorStub::GenerateDispatchToArrayStub(
4314 MacroAssembler* masm,
4315 AllocationSiteOverrideMode mode) {
4316 if (argument_count() == ANY) {
4317 Label not_zero_case, not_one_case;
4318 __ And(at, a0, a0);
4319 __ Branch(&not_zero_case, ne, at, Operand(zero_reg));
4320 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4321
4322 __ bind(&not_zero_case);
4323 __ Branch(&not_one_case, gt, a0, Operand(1));
4324 CreateArrayDispatchOneArgument(masm, mode);
4325
4326 __ bind(&not_one_case);
Ben Murdoch61f157c2016-09-16 13:49:30 +01004327 ArrayNArgumentsConstructorStub stub(masm->isolate());
4328 __ TailCallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004329 } else if (argument_count() == NONE) {
4330 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4331 } else if (argument_count() == ONE) {
4332 CreateArrayDispatchOneArgument(masm, mode);
4333 } else if (argument_count() == MORE_THAN_ONE) {
Ben Murdoch61f157c2016-09-16 13:49:30 +01004334 ArrayNArgumentsConstructorStub stub(masm->isolate());
4335 __ TailCallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004336 } else {
4337 UNREACHABLE();
4338 }
4339}
4340
4341
4342void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4343 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004344 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004345 // -- a1 : constructor
4346 // -- a2 : AllocationSite or undefined
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004347 // -- a3 : Original constructor
4348 // -- sp[0] : last argument
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004349 // -----------------------------------
4350
4351 if (FLAG_debug_code) {
4352 // The array construct code is only set for the global and natives
4353 // builtin Array functions which always have maps.
4354
4355 // Initial map for the builtin Array function should be a map.
4356 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
4357 // Will both indicate a NULL and a Smi.
4358 __ SmiTst(t0, at);
4359 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
4360 at, Operand(zero_reg));
4361 __ GetObjectType(t0, t0, t1);
4362 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
4363 t1, Operand(MAP_TYPE));
4364
4365 // We should either have undefined in a2 or a valid AllocationSite
4366 __ AssertUndefinedOrAllocationSite(a2, t0);
4367 }
4368
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004369 // Enter the context of the Array function.
4370 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
4371
4372 Label subclassing;
4373 __ Branch(&subclassing, ne, a1, Operand(a3));
4374
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004375 Label no_info;
4376 // Get the elements kind and case on that.
4377 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4378 __ Branch(&no_info, eq, a2, Operand(at));
4379
4380 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4381 __ SmiUntag(a3);
4382 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4383 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
4384 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4385
4386 __ bind(&no_info);
4387 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004388
4389 // Subclassing.
4390 __ bind(&subclassing);
4391 switch (argument_count()) {
4392 case ANY:
4393 case MORE_THAN_ONE:
Ben Murdoch097c5b22016-05-18 11:27:45 +01004394 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004395 __ sw(a1, MemOperand(at));
4396 __ li(at, Operand(3));
4397 __ addu(a0, a0, at);
4398 break;
4399 case NONE:
4400 __ sw(a1, MemOperand(sp, 0 * kPointerSize));
4401 __ li(a0, Operand(3));
4402 break;
4403 case ONE:
4404 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
4405 __ li(a0, Operand(4));
4406 break;
4407 }
4408 __ Push(a3, a2);
4409 __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004410}
4411
4412
4413void InternalArrayConstructorStub::GenerateCase(
4414 MacroAssembler* masm, ElementsKind kind) {
4415
4416 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4417 __ TailCallStub(&stub0, lo, a0, Operand(1));
4418
Ben Murdoch61f157c2016-09-16 13:49:30 +01004419 ArrayNArgumentsConstructorStub stubN(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004420 __ TailCallStub(&stubN, hi, a0, Operand(1));
4421
4422 if (IsFastPackedElementsKind(kind)) {
4423 // We might need to create a holey array
4424 // look at the first argument.
4425 __ lw(at, MemOperand(sp, 0));
4426
4427 InternalArraySingleArgumentConstructorStub
4428 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4429 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
4430 }
4431
4432 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4433 __ TailCallStub(&stub1);
4434}
4435
4436
4437void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4438 // ----------- S t a t e -------------
4439 // -- a0 : argc
4440 // -- a1 : constructor
4441 // -- sp[0] : return address
4442 // -- sp[4] : last argument
4443 // -----------------------------------
4444
4445 if (FLAG_debug_code) {
4446 // The array construct code is only set for the global and natives
4447 // builtin Array functions which always have maps.
4448
4449 // Initial map for the builtin Array function should be a map.
4450 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
4451 // Will both indicate a NULL and a Smi.
4452 __ SmiTst(a3, at);
4453 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
4454 at, Operand(zero_reg));
4455 __ GetObjectType(a3, a3, t0);
4456 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
4457 t0, Operand(MAP_TYPE));
4458 }
4459
4460 // Figure out the right elements kind.
4461 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
4462
4463 // Load the map's "bit field 2" into a3. We only need the first byte,
4464 // but the following bit field extraction takes care of that anyway.
4465 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
4466 // Retrieve elements_kind from bit field 2.
4467 __ DecodeField<Map::ElementsKindBits>(a3);
4468
4469 if (FLAG_debug_code) {
4470 Label done;
4471 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
4472 __ Assert(
4473 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
4474 a3, Operand(FAST_HOLEY_ELEMENTS));
4475 __ bind(&done);
4476 }
4477
4478 Label fast_elements_case;
4479 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
4480 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4481
4482 __ bind(&fast_elements_case);
4483 GenerateCase(masm, FAST_ELEMENTS);
4484}
4485
4486
Ben Murdoch097c5b22016-05-18 11:27:45 +01004487void FastNewObjectStub::Generate(MacroAssembler* masm) {
4488 // ----------- S t a t e -------------
4489 // -- a1 : target
4490 // -- a3 : new target
4491 // -- cp : context
4492 // -- ra : return address
4493 // -----------------------------------
4494 __ AssertFunction(a1);
4495 __ AssertReceiver(a3);
4496
4497 // Verify that the new target is a JSFunction.
4498 Label new_object;
4499 __ GetObjectType(a3, a2, a2);
4500 __ Branch(&new_object, ne, a2, Operand(JS_FUNCTION_TYPE));
4501
4502 // Load the initial map and verify that it's in fact a map.
4503 __ lw(a2, FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset));
4504 __ JumpIfSmi(a2, &new_object);
4505 __ GetObjectType(a2, a0, a0);
4506 __ Branch(&new_object, ne, a0, Operand(MAP_TYPE));
4507
4508 // Fall back to runtime if the target differs from the new target's
4509 // initial map constructor.
4510 __ lw(a0, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset));
4511 __ Branch(&new_object, ne, a0, Operand(a1));
4512
4513 // Allocate the JSObject on the heap.
4514 Label allocate, done_allocate;
4515 __ lbu(t0, FieldMemOperand(a2, Map::kInstanceSizeOffset));
4516 __ Allocate(t0, v0, t1, a0, &allocate, SIZE_IN_WORDS);
4517 __ bind(&done_allocate);
4518
4519 // Initialize the JSObject fields.
Ben Murdochc5610432016-08-08 18:44:38 +01004520 __ sw(a2, FieldMemOperand(v0, JSObject::kMapOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004521 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
Ben Murdochc5610432016-08-08 18:44:38 +01004522 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
4523 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004524 STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize);
Ben Murdochc5610432016-08-08 18:44:38 +01004525 __ Addu(a1, v0, Operand(JSObject::kHeaderSize - kHeapObjectTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004526
4527 // ----------- S t a t e -------------
Ben Murdochc5610432016-08-08 18:44:38 +01004528 // -- v0 : result (tagged)
Ben Murdoch097c5b22016-05-18 11:27:45 +01004529 // -- a1 : result fields (untagged)
4530 // -- t1 : result end (untagged)
4531 // -- a2 : initial map
4532 // -- cp : context
4533 // -- ra : return address
4534 // -----------------------------------
4535
4536 // Perform in-object slack tracking if requested.
4537 Label slack_tracking;
4538 STATIC_ASSERT(Map::kNoSlackTracking == 0);
4539 __ lw(a3, FieldMemOperand(a2, Map::kBitField3Offset));
4540 __ And(at, a3, Operand(Map::ConstructionCounter::kMask));
4541 __ Branch(USE_DELAY_SLOT, &slack_tracking, ne, at, Operand(0));
4542 __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); // In delay slot.
4543 {
4544 // Initialize all in-object fields with undefined.
4545 __ InitializeFieldsWithFiller(a1, t1, a0);
Ben Murdochc5610432016-08-08 18:44:38 +01004546 __ Ret();
Ben Murdoch097c5b22016-05-18 11:27:45 +01004547 }
4548 __ bind(&slack_tracking);
4549 {
4550 // Decrease generous allocation count.
4551 STATIC_ASSERT(Map::ConstructionCounter::kNext == 32);
4552 __ Subu(a3, a3, Operand(1 << Map::ConstructionCounter::kShift));
4553 __ sw(a3, FieldMemOperand(a2, Map::kBitField3Offset));
4554
4555 // Initialize the in-object fields with undefined.
4556 __ lbu(t0, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset));
4557 __ sll(t0, t0, kPointerSizeLog2);
4558 __ subu(t0, t1, t0);
4559 __ InitializeFieldsWithFiller(a1, t0, a0);
4560
4561 // Initialize the remaining (reserved) fields with one pointer filler map.
4562 __ LoadRoot(a0, Heap::kOnePointerFillerMapRootIndex);
4563 __ InitializeFieldsWithFiller(a1, t1, a0);
4564
4565 // Check if we can finalize the instance size.
4566 Label finalize;
4567 STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1);
4568 __ And(a3, a3, Operand(Map::ConstructionCounter::kMask));
Ben Murdochc5610432016-08-08 18:44:38 +01004569 __ Branch(&finalize, eq, a3, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004570 __ Ret();
4571
4572 // Finalize the instance size.
4573 __ bind(&finalize);
4574 {
4575 FrameScope scope(masm, StackFrame::INTERNAL);
4576 __ Push(v0, a2);
4577 __ CallRuntime(Runtime::kFinalizeInstanceSize);
4578 __ Pop(v0);
4579 }
4580 __ Ret();
4581 }
4582
4583 // Fall back to %AllocateInNewSpace.
4584 __ bind(&allocate);
4585 {
4586 FrameScope scope(masm, StackFrame::INTERNAL);
4587 STATIC_ASSERT(kSmiTag == 0);
4588 STATIC_ASSERT(kSmiTagSize == 1);
4589 __ sll(t0, t0, kPointerSizeLog2 + kSmiTagSize);
4590 __ Push(a2, t0);
4591 __ CallRuntime(Runtime::kAllocateInNewSpace);
4592 __ Pop(a2);
4593 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01004594 __ lbu(t1, FieldMemOperand(a2, Map::kInstanceSizeOffset));
4595 __ Lsa(t1, v0, t1, kPointerSizeLog2);
Ben Murdochc5610432016-08-08 18:44:38 +01004596 STATIC_ASSERT(kHeapObjectTag == 1);
4597 __ Subu(t1, t1, Operand(kHeapObjectTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004598 __ jmp(&done_allocate);
4599
4600 // Fall back to %NewObject.
4601 __ bind(&new_object);
4602 __ Push(a1, a3);
4603 __ TailCallRuntime(Runtime::kNewObject);
4604}
4605
4606
4607void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
4608 // ----------- S t a t e -------------
4609 // -- a1 : function
4610 // -- cp : context
4611 // -- fp : frame pointer
4612 // -- ra : return address
4613 // -----------------------------------
4614 __ AssertFunction(a1);
4615
Ben Murdochc5610432016-08-08 18:44:38 +01004616 // Make a2 point to the JavaScript frame.
4617 __ mov(a2, fp);
4618 if (skip_stub_frame()) {
4619 // For Ignition we need to skip the handler/stub frame to reach the
4620 // JavaScript frame for the function.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004621 __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01004622 }
4623 if (FLAG_debug_code) {
4624 Label ok;
Ben Murdochda12d292016-06-02 14:46:10 +01004625 __ lw(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01004626 __ Branch(&ok, eq, a1, Operand(a3));
4627 __ Abort(kInvalidFrameForFastNewRestArgumentsStub);
4628 __ bind(&ok);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004629 }
4630
4631 // Check if we have rest parameters (only possible if we have an
4632 // arguments adaptor frame below the function frame).
4633 Label no_rest_parameters;
4634 __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01004635 __ lw(a3, MemOperand(a2, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004636 __ Branch(&no_rest_parameters, ne, a3,
4637 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4638
4639 // Check if the arguments adaptor frame contains more arguments than
4640 // specified by the function's internal formal parameter count.
4641 Label rest_parameters;
4642 __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
Ben Murdoch61f157c2016-09-16 13:49:30 +01004643 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
4644 __ lw(a3,
4645 FieldMemOperand(a3, SharedFunctionInfo::kFormalParameterCountOffset));
4646 __ Subu(a0, a0, Operand(a3));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004647 __ Branch(&rest_parameters, gt, a0, Operand(zero_reg));
4648
4649 // Return an empty rest parameter array.
4650 __ bind(&no_rest_parameters);
4651 {
4652 // ----------- S t a t e -------------
4653 // -- cp : context
4654 // -- ra : return address
4655 // -----------------------------------
4656
4657 // Allocate an empty rest parameter array.
4658 Label allocate, done_allocate;
Ben Murdochc5610432016-08-08 18:44:38 +01004659 __ Allocate(JSArray::kSize, v0, a0, a1, &allocate, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004660 __ bind(&done_allocate);
4661
4662 // Setup the rest parameter array in v0.
4663 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, a1);
4664 __ sw(a1, FieldMemOperand(v0, JSArray::kMapOffset));
4665 __ LoadRoot(a1, Heap::kEmptyFixedArrayRootIndex);
4666 __ sw(a1, FieldMemOperand(v0, JSArray::kPropertiesOffset));
4667 __ sw(a1, FieldMemOperand(v0, JSArray::kElementsOffset));
4668 __ Move(a1, Smi::FromInt(0));
4669 __ Ret(USE_DELAY_SLOT);
4670 __ sw(a1, FieldMemOperand(v0, JSArray::kLengthOffset)); // In delay slot
4671 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4672
4673 // Fall back to %AllocateInNewSpace.
4674 __ bind(&allocate);
4675 {
4676 FrameScope scope(masm, StackFrame::INTERNAL);
4677 __ Push(Smi::FromInt(JSArray::kSize));
4678 __ CallRuntime(Runtime::kAllocateInNewSpace);
4679 }
4680 __ jmp(&done_allocate);
4681 }
4682
4683 __ bind(&rest_parameters);
4684 {
4685 // Compute the pointer to the first rest parameter (skippping the receiver).
4686 __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1);
4687 __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset -
4688 1 * kPointerSize));
4689
4690 // ----------- S t a t e -------------
4691 // -- cp : context
4692 // -- a0 : number of rest parameters (tagged)
Ben Murdoch61f157c2016-09-16 13:49:30 +01004693 // -- a1 : function
Ben Murdoch097c5b22016-05-18 11:27:45 +01004694 // -- a2 : pointer to first rest parameters
4695 // -- ra : return address
4696 // -----------------------------------
4697
4698 // Allocate space for the rest parameter array plus the backing store.
4699 Label allocate, done_allocate;
Ben Murdoch61f157c2016-09-16 13:49:30 +01004700 __ li(t0, Operand(JSArray::kSize + FixedArray::kHeaderSize));
4701 __ Lsa(t0, t0, a0, kPointerSizeLog2 - 1);
4702 __ Allocate(t0, v0, a3, t1, &allocate, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004703 __ bind(&done_allocate);
4704
4705 // Setup the elements array in v0.
4706 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4707 __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset));
4708 __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset));
4709 __ Addu(a3, v0, Operand(FixedArray::kHeaderSize));
4710 {
4711 Label loop, done_loop;
4712 __ sll(at, a0, kPointerSizeLog2 - 1);
4713 __ Addu(a1, a3, at);
4714 __ bind(&loop);
4715 __ Branch(&done_loop, eq, a1, Operand(a3));
4716 __ lw(at, MemOperand(a2, 0 * kPointerSize));
4717 __ sw(at, FieldMemOperand(a3, 0 * kPointerSize));
4718 __ Subu(a2, a2, Operand(1 * kPointerSize));
4719 __ Addu(a3, a3, Operand(1 * kPointerSize));
4720 __ jmp(&loop);
4721 __ bind(&done_loop);
4722 }
4723
4724 // Setup the rest parameter array in a3.
4725 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, at);
4726 __ sw(at, FieldMemOperand(a3, JSArray::kMapOffset));
4727 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
4728 __ sw(at, FieldMemOperand(a3, JSArray::kPropertiesOffset));
4729 __ sw(v0, FieldMemOperand(a3, JSArray::kElementsOffset));
4730 __ sw(a0, FieldMemOperand(a3, JSArray::kLengthOffset));
4731 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4732 __ Ret(USE_DELAY_SLOT);
4733 __ mov(v0, a3); // In delay slot
4734
Ben Murdoch61f157c2016-09-16 13:49:30 +01004735 // Fall back to %AllocateInNewSpace (if not too big).
4736 Label too_big_for_new_space;
Ben Murdoch097c5b22016-05-18 11:27:45 +01004737 __ bind(&allocate);
Ben Murdoch61f157c2016-09-16 13:49:30 +01004738 __ Branch(&too_big_for_new_space, gt, t0,
4739 Operand(Page::kMaxRegularHeapObjectSize));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004740 {
4741 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch61f157c2016-09-16 13:49:30 +01004742 __ SmiTag(t0);
4743 __ Push(a0, a2, t0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004744 __ CallRuntime(Runtime::kAllocateInNewSpace);
4745 __ Pop(a0, a2);
4746 }
4747 __ jmp(&done_allocate);
Ben Murdoch61f157c2016-09-16 13:49:30 +01004748
4749 // Fall back to %NewStrictArguments.
4750 __ bind(&too_big_for_new_space);
4751 __ Push(a1);
4752 __ TailCallRuntime(Runtime::kNewStrictArguments);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004753 }
4754}
4755
4756
4757void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) {
4758 // ----------- S t a t e -------------
4759 // -- a1 : function
4760 // -- cp : context
4761 // -- fp : frame pointer
4762 // -- ra : return address
4763 // -----------------------------------
4764 __ AssertFunction(a1);
4765
Ben Murdochc5610432016-08-08 18:44:38 +01004766 // Make t0 point to the JavaScript frame.
4767 __ mov(t0, fp);
4768 if (skip_stub_frame()) {
4769 // For Ignition we need to skip the handler/stub frame to reach the
4770 // JavaScript frame for the function.
4771 __ lw(t0, MemOperand(t0, StandardFrameConstants::kCallerFPOffset));
4772 }
4773 if (FLAG_debug_code) {
4774 Label ok;
4775 __ lw(a3, MemOperand(t0, StandardFrameConstants::kFunctionOffset));
4776 __ Branch(&ok, eq, a1, Operand(a3));
4777 __ Abort(kInvalidFrameForFastNewRestArgumentsStub);
4778 __ bind(&ok);
4779 }
4780
Ben Murdoch097c5b22016-05-18 11:27:45 +01004781 // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub.
4782 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
4783 __ lw(a2,
4784 FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01004785 __ Lsa(a3, t0, a2, kPointerSizeLog2 - 1);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004786 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
4787
4788 // a1 : function
4789 // a2 : number of parameters (tagged)
4790 // a3 : parameters pointer
Ben Murdochc5610432016-08-08 18:44:38 +01004791 // t0 : Javascript frame pointer
Ben Murdoch097c5b22016-05-18 11:27:45 +01004792 // Registers used over whole function:
4793 // t1 : arguments count (tagged)
4794 // t2 : mapped parameter count (tagged)
4795
4796 // Check if the calling frame is an arguments adaptor frame.
4797 Label adaptor_frame, try_allocate, runtime;
Ben Murdochc5610432016-08-08 18:44:38 +01004798 __ lw(t0, MemOperand(t0, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01004799 __ lw(a0, MemOperand(t0, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01004800 __ Branch(&adaptor_frame, eq, a0,
4801 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4802
4803 // No adaptor, parameter count = argument count.
4804 __ mov(t1, a2);
4805 __ Branch(USE_DELAY_SLOT, &try_allocate);
4806 __ mov(t2, a2); // In delay slot.
4807
4808 // We have an adaptor frame. Patch the parameters pointer.
4809 __ bind(&adaptor_frame);
4810 __ lw(t1, MemOperand(t0, ArgumentsAdaptorFrameConstants::kLengthOffset));
4811 __ Lsa(t0, t0, t1, 1);
4812 __ Addu(a3, t0, Operand(StandardFrameConstants::kCallerSPOffset));
4813
4814 // t1 = argument count (tagged)
4815 // t2 = parameter count (tagged)
4816 // Compute the mapped parameter count = min(t2, t1) in t2.
4817 __ mov(t2, a2);
4818 __ Branch(&try_allocate, le, t2, Operand(t1));
4819 __ mov(t2, t1);
4820
4821 __ bind(&try_allocate);
4822
4823 // Compute the sizes of backing store, parameter map, and arguments object.
4824 // 1. Parameter map, has 2 extra words containing context and backing store.
4825 const int kParameterMapHeaderSize =
4826 FixedArray::kHeaderSize + 2 * kPointerSize;
4827 // If there are no mapped parameters, we do not need the parameter_map.
4828 Label param_map_size;
4829 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
4830 __ Branch(USE_DELAY_SLOT, &param_map_size, eq, t2, Operand(zero_reg));
4831 __ mov(t5, zero_reg); // In delay slot: param map size = 0 when t2 == 0.
4832 __ sll(t5, t2, 1);
4833 __ addiu(t5, t5, kParameterMapHeaderSize);
4834 __ bind(&param_map_size);
4835
4836 // 2. Backing store.
4837 __ Lsa(t5, t5, t1, 1);
4838 __ Addu(t5, t5, Operand(FixedArray::kHeaderSize));
4839
4840 // 3. Arguments object.
4841 __ Addu(t5, t5, Operand(JSSloppyArgumentsObject::kSize));
4842
4843 // Do the allocation of all three objects in one go.
Ben Murdochc5610432016-08-08 18:44:38 +01004844 __ Allocate(t5, v0, t5, t0, &runtime, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004845
4846 // v0 = address of new object(s) (tagged)
4847 // a2 = argument count (smi-tagged)
4848 // Get the arguments boilerplate from the current native context into t0.
4849 const int kNormalOffset =
4850 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
4851 const int kAliasedOffset =
4852 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
4853
4854 __ lw(t0, NativeContextMemOperand());
4855 Label skip2_ne, skip2_eq;
4856 __ Branch(&skip2_ne, ne, t2, Operand(zero_reg));
4857 __ lw(t0, MemOperand(t0, kNormalOffset));
4858 __ bind(&skip2_ne);
4859
4860 __ Branch(&skip2_eq, eq, t2, Operand(zero_reg));
4861 __ lw(t0, MemOperand(t0, kAliasedOffset));
4862 __ bind(&skip2_eq);
4863
4864 // v0 = address of new object (tagged)
4865 // a2 = argument count (smi-tagged)
4866 // t0 = address of arguments map (tagged)
4867 // t2 = mapped parameter count (tagged)
4868 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
4869 __ LoadRoot(t5, Heap::kEmptyFixedArrayRootIndex);
4870 __ sw(t5, FieldMemOperand(v0, JSObject::kPropertiesOffset));
4871 __ sw(t5, FieldMemOperand(v0, JSObject::kElementsOffset));
4872
4873 // Set up the callee in-object property.
4874 __ AssertNotSmi(a1);
4875 __ sw(a1, FieldMemOperand(v0, JSSloppyArgumentsObject::kCalleeOffset));
4876
4877 // Use the length (smi tagged) and set that as an in-object property too.
4878 __ AssertSmi(t1);
4879 __ sw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset));
4880
4881 // Set up the elements pointer in the allocated arguments object.
4882 // If we allocated a parameter map, t0 will point there, otherwise
4883 // it will point to the backing store.
4884 __ Addu(t0, v0, Operand(JSSloppyArgumentsObject::kSize));
4885 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
4886
4887 // v0 = address of new object (tagged)
4888 // a2 = argument count (tagged)
4889 // t0 = address of parameter map or backing store (tagged)
4890 // t2 = mapped parameter count (tagged)
4891 // Initialize parameter map. If there are no mapped arguments, we're done.
4892 Label skip_parameter_map;
4893 Label skip3;
4894 __ Branch(&skip3, ne, t2, Operand(Smi::FromInt(0)));
4895 // Move backing store address to a1, because it is
4896 // expected there when filling in the unmapped arguments.
4897 __ mov(a1, t0);
4898 __ bind(&skip3);
4899
4900 __ Branch(&skip_parameter_map, eq, t2, Operand(Smi::FromInt(0)));
4901
4902 __ LoadRoot(t1, Heap::kSloppyArgumentsElementsMapRootIndex);
4903 __ sw(t1, FieldMemOperand(t0, FixedArray::kMapOffset));
4904 __ Addu(t1, t2, Operand(Smi::FromInt(2)));
4905 __ sw(t1, FieldMemOperand(t0, FixedArray::kLengthOffset));
4906 __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize));
4907 __ Lsa(t1, t0, t2, 1);
4908 __ Addu(t1, t1, Operand(kParameterMapHeaderSize));
4909 __ sw(t1, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize));
4910
4911 // Copy the parameter slots and the holes in the arguments.
4912 // We need to fill in mapped_parameter_count slots. They index the context,
4913 // where parameters are stored in reverse order, at
4914 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
4915 // The mapped parameter thus need to get indices
4916 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
4917 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
4918 // We loop from right to left.
4919 Label parameters_loop, parameters_test;
4920 __ mov(t1, t2);
4921 __ Addu(t5, a2, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
4922 __ Subu(t5, t5, Operand(t2));
4923 __ LoadRoot(t3, Heap::kTheHoleValueRootIndex);
4924 __ Lsa(a1, t0, t1, 1);
4925 __ Addu(a1, a1, Operand(kParameterMapHeaderSize));
4926
4927 // a1 = address of backing store (tagged)
4928 // t0 = address of parameter map (tagged)
4929 // a0 = temporary scratch (a.o., for address calculation)
4930 // t1 = loop variable (tagged)
4931 // t3 = the hole value
4932 __ jmp(&parameters_test);
4933
4934 __ bind(&parameters_loop);
4935 __ Subu(t1, t1, Operand(Smi::FromInt(1)));
4936 __ sll(a0, t1, 1);
4937 __ Addu(a0, a0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
4938 __ Addu(t6, t0, a0);
4939 __ sw(t5, MemOperand(t6));
4940 __ Subu(a0, a0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
4941 __ Addu(t6, a1, a0);
4942 __ sw(t3, MemOperand(t6));
4943 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
4944 __ bind(&parameters_test);
4945 __ Branch(&parameters_loop, ne, t1, Operand(Smi::FromInt(0)));
4946
4947 // t1 = argument count (tagged).
4948 __ lw(t1, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset));
4949
4950 __ bind(&skip_parameter_map);
4951 // v0 = address of new object (tagged)
4952 // a1 = address of backing store (tagged)
4953 // t1 = argument count (tagged)
4954 // t2 = mapped parameter count (tagged)
4955 // t5 = scratch
4956 // Copy arguments header and remaining slots (if there are any).
4957 __ LoadRoot(t5, Heap::kFixedArrayMapRootIndex);
4958 __ sw(t5, FieldMemOperand(a1, FixedArray::kMapOffset));
4959 __ sw(t1, FieldMemOperand(a1, FixedArray::kLengthOffset));
4960
4961 Label arguments_loop, arguments_test;
4962 __ sll(t6, t2, 1);
4963 __ Subu(a3, a3, Operand(t6));
4964 __ jmp(&arguments_test);
4965
4966 __ bind(&arguments_loop);
4967 __ Subu(a3, a3, Operand(kPointerSize));
4968 __ lw(t0, MemOperand(a3, 0));
4969 __ Lsa(t5, a1, t2, 1);
4970 __ sw(t0, FieldMemOperand(t5, FixedArray::kHeaderSize));
4971 __ Addu(t2, t2, Operand(Smi::FromInt(1)));
4972
4973 __ bind(&arguments_test);
4974 __ Branch(&arguments_loop, lt, t2, Operand(t1));
4975
4976 // Return.
4977 __ Ret();
4978
4979 // Do the runtime call to allocate the arguments object.
4980 // t1 = argument count (tagged)
4981 __ bind(&runtime);
4982 __ Push(a1, a3, t1);
4983 __ TailCallRuntime(Runtime::kNewSloppyArguments);
4984}
4985
4986
4987void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) {
4988 // ----------- S t a t e -------------
4989 // -- a1 : function
4990 // -- cp : context
4991 // -- fp : frame pointer
4992 // -- ra : return address
4993 // -----------------------------------
4994 __ AssertFunction(a1);
4995
Ben Murdochc5610432016-08-08 18:44:38 +01004996 // Make a2 point to the JavaScript frame.
4997 __ mov(a2, fp);
4998 if (skip_stub_frame()) {
4999 // For Ignition we need to skip the handler/stub frame to reach the
5000 // JavaScript frame for the function.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005001 __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01005002 }
5003 if (FLAG_debug_code) {
5004 Label ok;
Ben Murdochda12d292016-06-02 14:46:10 +01005005 __ lw(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset));
Ben Murdochc5610432016-08-08 18:44:38 +01005006 __ Branch(&ok, eq, a1, Operand(a3));
5007 __ Abort(kInvalidFrameForFastNewRestArgumentsStub);
5008 __ bind(&ok);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005009 }
5010
5011 // Check if we have an arguments adaptor frame below the function frame.
5012 Label arguments_adaptor, arguments_done;
5013 __ lw(a3, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
Ben Murdochda12d292016-06-02 14:46:10 +01005014 __ lw(a0, MemOperand(a3, CommonFrameConstants::kContextOrFrameTypeOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005015 __ Branch(&arguments_adaptor, eq, a0,
5016 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5017 {
Ben Murdoch61f157c2016-09-16 13:49:30 +01005018 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005019 __ lw(a0,
Ben Murdoch61f157c2016-09-16 13:49:30 +01005020 FieldMemOperand(t0, SharedFunctionInfo::kFormalParameterCountOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005021 __ Lsa(a2, a2, a0, kPointerSizeLog2 - 1);
5022 __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset -
5023 1 * kPointerSize));
5024 }
5025 __ Branch(&arguments_done);
5026 __ bind(&arguments_adaptor);
5027 {
5028 __ lw(a0, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
5029 __ Lsa(a2, a3, a0, kPointerSizeLog2 - 1);
5030 __ Addu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset -
5031 1 * kPointerSize));
5032 }
5033 __ bind(&arguments_done);
5034
5035 // ----------- S t a t e -------------
5036 // -- cp : context
5037 // -- a0 : number of rest parameters (tagged)
Ben Murdoch61f157c2016-09-16 13:49:30 +01005038 // -- a1 : function
Ben Murdoch097c5b22016-05-18 11:27:45 +01005039 // -- a2 : pointer to first rest parameters
5040 // -- ra : return address
5041 // -----------------------------------
5042
5043 // Allocate space for the strict arguments object plus the backing store.
5044 Label allocate, done_allocate;
Ben Murdoch61f157c2016-09-16 13:49:30 +01005045 __ li(t0, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize));
5046 __ Lsa(t0, t0, a0, kPointerSizeLog2 - 1);
5047 __ Allocate(t0, v0, a3, t1, &allocate, NO_ALLOCATION_FLAGS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005048 __ bind(&done_allocate);
5049
5050 // Setup the elements array in v0.
5051 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
5052 __ sw(at, FieldMemOperand(v0, FixedArray::kMapOffset));
5053 __ sw(a0, FieldMemOperand(v0, FixedArray::kLengthOffset));
5054 __ Addu(a3, v0, Operand(FixedArray::kHeaderSize));
5055 {
5056 Label loop, done_loop;
5057 __ sll(at, a0, kPointerSizeLog2 - 1);
5058 __ Addu(a1, a3, at);
5059 __ bind(&loop);
5060 __ Branch(&done_loop, eq, a1, Operand(a3));
5061 __ lw(at, MemOperand(a2, 0 * kPointerSize));
5062 __ sw(at, FieldMemOperand(a3, 0 * kPointerSize));
5063 __ Subu(a2, a2, Operand(1 * kPointerSize));
5064 __ Addu(a3, a3, Operand(1 * kPointerSize));
5065 __ Branch(&loop);
5066 __ bind(&done_loop);
5067 }
5068
5069 // Setup the strict arguments object in a3.
5070 __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, at);
5071 __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kMapOffset));
5072 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
5073 __ sw(at, FieldMemOperand(a3, JSStrictArgumentsObject::kPropertiesOffset));
5074 __ sw(v0, FieldMemOperand(a3, JSStrictArgumentsObject::kElementsOffset));
5075 __ sw(a0, FieldMemOperand(a3, JSStrictArgumentsObject::kLengthOffset));
5076 STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize);
5077 __ Ret(USE_DELAY_SLOT);
5078 __ mov(v0, a3); // In delay slot
5079
Ben Murdoch61f157c2016-09-16 13:49:30 +01005080 // Fall back to %AllocateInNewSpace (if not too big).
5081 Label too_big_for_new_space;
Ben Murdoch097c5b22016-05-18 11:27:45 +01005082 __ bind(&allocate);
Ben Murdoch61f157c2016-09-16 13:49:30 +01005083 __ Branch(&too_big_for_new_space, gt, t0,
5084 Operand(Page::kMaxRegularHeapObjectSize));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005085 {
5086 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch61f157c2016-09-16 13:49:30 +01005087 __ SmiTag(t0);
5088 __ Push(a0, a2, t0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005089 __ CallRuntime(Runtime::kAllocateInNewSpace);
5090 __ Pop(a0, a2);
5091 }
5092 __ jmp(&done_allocate);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005093
Ben Murdoch61f157c2016-09-16 13:49:30 +01005094 // Fall back to %NewStrictArguments.
5095 __ bind(&too_big_for_new_space);
5096 __ Push(a1);
5097 __ TailCallRuntime(Runtime::kNewStrictArguments);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005098}
5099
5100
5101void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5102 Register context_reg = cp;
5103 Register slot_reg = a2;
5104 Register value_reg = a0;
5105 Register cell_reg = t0;
5106 Register cell_value_reg = t1;
5107 Register cell_details_reg = t2;
5108 Label fast_heapobject_case, fast_smi_case, slow_case;
5109
5110 if (FLAG_debug_code) {
5111 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5112 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5113 }
5114
5115 // Go up context chain to the script context.
5116 for (int i = 0; i < depth(); ++i) {
5117 __ lw(cell_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX));
5118 context_reg = cell_reg;
5119 }
5120
5121 // Load the PropertyCell at the specified slot.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005122 __ Lsa(at, context_reg, slot_reg, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005123 __ lw(cell_reg, ContextMemOperand(at, 0));
5124
5125 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5126 __ lw(cell_details_reg,
5127 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5128 __ SmiUntag(cell_details_reg);
5129 __ And(cell_details_reg, cell_details_reg,
5130 PropertyDetails::PropertyCellTypeField::kMask |
5131 PropertyDetails::KindField::kMask |
5132 PropertyDetails::kAttributesReadOnlyMask);
5133
5134 // Check if PropertyCell holds mutable data.
5135 Label not_mutable_data;
5136 __ Branch(&not_mutable_data, ne, cell_details_reg,
5137 Operand(PropertyDetails::PropertyCellTypeField::encode(
5138 PropertyCellType::kMutable) |
5139 PropertyDetails::KindField::encode(kData)));
5140 __ JumpIfSmi(value_reg, &fast_smi_case);
5141 __ bind(&fast_heapobject_case);
5142 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5143 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5144 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5145 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5146 // RecordWriteField clobbers the value register, so we need to reload.
5147 __ Ret(USE_DELAY_SLOT);
5148 __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5149 __ bind(&not_mutable_data);
5150
5151 // Check if PropertyCell value matches the new value (relevant for Constant,
5152 // ConstantType and Undefined cells).
5153 Label not_same_value;
5154 __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5155 __ Branch(&not_same_value, ne, value_reg, Operand(cell_value_reg));
5156 // Make sure the PropertyCell is not marked READ_ONLY.
5157 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5158 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5159 if (FLAG_debug_code) {
5160 Label done;
5161 // This can only be true for Constant, ConstantType and Undefined cells,
5162 // because we never store the_hole via this stub.
5163 __ Branch(&done, eq, cell_details_reg,
5164 Operand(PropertyDetails::PropertyCellTypeField::encode(
5165 PropertyCellType::kConstant) |
5166 PropertyDetails::KindField::encode(kData)));
5167 __ Branch(&done, eq, cell_details_reg,
5168 Operand(PropertyDetails::PropertyCellTypeField::encode(
5169 PropertyCellType::kConstantType) |
5170 PropertyDetails::KindField::encode(kData)));
5171 __ Check(eq, kUnexpectedValue, cell_details_reg,
5172 Operand(PropertyDetails::PropertyCellTypeField::encode(
5173 PropertyCellType::kUndefined) |
5174 PropertyDetails::KindField::encode(kData)));
5175 __ bind(&done);
5176 }
5177 __ Ret();
5178 __ bind(&not_same_value);
5179
5180 // Check if PropertyCell contains data with constant type (and is not
5181 // READ_ONLY).
5182 __ Branch(&slow_case, ne, cell_details_reg,
5183 Operand(PropertyDetails::PropertyCellTypeField::encode(
5184 PropertyCellType::kConstantType) |
5185 PropertyDetails::KindField::encode(kData)));
5186
5187 // Now either both old and new values must be SMIs or both must be heap
5188 // objects with same map.
5189 Label value_is_heap_object;
5190 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5191 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5192 // Old and new values are SMIs, no need for a write barrier here.
5193 __ bind(&fast_smi_case);
5194 __ Ret(USE_DELAY_SLOT);
5195 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5196 __ bind(&value_is_heap_object);
5197 __ JumpIfSmi(cell_value_reg, &slow_case);
5198 Register cell_value_map_reg = cell_value_reg;
5199 __ lw(cell_value_map_reg,
5200 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5201 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5202 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5203
5204 // Fallback to the runtime.
5205 __ bind(&slow_case);
5206 __ SmiTag(slot_reg);
5207 __ Push(slot_reg, value_reg);
5208 __ TailCallRuntime(is_strict(language_mode())
5209 ? Runtime::kStoreGlobalViaContext_Strict
5210 : Runtime::kStoreGlobalViaContext_Sloppy);
5211}
5212
5213
5214static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5215 return ref0.address() - ref1.address();
5216}
5217
5218
5219// Calls an API function. Allocates HandleScope, extracts returned value
5220// from handle and propagates exceptions. Restores context. stack_space
5221// - space to be unwound on exit (includes the call JS arguments space and
5222// the additional space allocated for the fast call).
5223static void CallApiFunctionAndReturn(
5224 MacroAssembler* masm, Register function_address,
5225 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5226 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5227 Isolate* isolate = masm->isolate();
5228 ExternalReference next_address =
5229 ExternalReference::handle_scope_next_address(isolate);
5230 const int kNextOffset = 0;
5231 const int kLimitOffset = AddressOffset(
5232 ExternalReference::handle_scope_limit_address(isolate), next_address);
5233 const int kLevelOffset = AddressOffset(
5234 ExternalReference::handle_scope_level_address(isolate), next_address);
5235
5236 DCHECK(function_address.is(a1) || function_address.is(a2));
5237
5238 Label profiler_disabled;
5239 Label end_profiler_check;
5240 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5241 __ lb(t9, MemOperand(t9, 0));
5242 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5243
5244 // Additional parameter is the address of the actual callback.
5245 __ li(t9, Operand(thunk_ref));
5246 __ jmp(&end_profiler_check);
5247
5248 __ bind(&profiler_disabled);
5249 __ mov(t9, function_address);
5250 __ bind(&end_profiler_check);
5251
5252 // Allocate HandleScope in callee-save registers.
5253 __ li(s3, Operand(next_address));
5254 __ lw(s0, MemOperand(s3, kNextOffset));
5255 __ lw(s1, MemOperand(s3, kLimitOffset));
5256 __ lw(s2, MemOperand(s3, kLevelOffset));
5257 __ Addu(s2, s2, Operand(1));
5258 __ sw(s2, MemOperand(s3, kLevelOffset));
5259
5260 if (FLAG_log_timer_events) {
5261 FrameScope frame(masm, StackFrame::MANUAL);
5262 __ PushSafepointRegisters();
5263 __ PrepareCallCFunction(1, a0);
5264 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5265 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5266 1);
5267 __ PopSafepointRegisters();
5268 }
5269
5270 // Native call returns to the DirectCEntry stub which redirects to the
5271 // return address pushed on stack (could have moved after GC).
5272 // DirectCEntry stub itself is generated early and never moves.
5273 DirectCEntryStub stub(isolate);
5274 stub.GenerateCall(masm, t9);
5275
5276 if (FLAG_log_timer_events) {
5277 FrameScope frame(masm, StackFrame::MANUAL);
5278 __ PushSafepointRegisters();
5279 __ PrepareCallCFunction(1, a0);
5280 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5281 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5282 1);
5283 __ PopSafepointRegisters();
5284 }
5285
5286 Label promote_scheduled_exception;
5287 Label delete_allocated_handles;
5288 Label leave_exit_frame;
5289 Label return_value_loaded;
5290
5291 // Load value from ReturnValue.
5292 __ lw(v0, return_value_operand);
5293 __ bind(&return_value_loaded);
5294
5295 // No more valid handles (the result handle was the last one). Restore
5296 // previous handle scope.
5297 __ sw(s0, MemOperand(s3, kNextOffset));
5298 if (__ emit_debug_code()) {
5299 __ lw(a1, MemOperand(s3, kLevelOffset));
5300 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5301 }
5302 __ Subu(s2, s2, Operand(1));
5303 __ sw(s2, MemOperand(s3, kLevelOffset));
5304 __ lw(at, MemOperand(s3, kLimitOffset));
5305 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5306
5307 // Leave the API exit frame.
5308 __ bind(&leave_exit_frame);
5309
5310 bool restore_context = context_restore_operand != NULL;
5311 if (restore_context) {
5312 __ lw(cp, *context_restore_operand);
5313 }
5314 if (stack_space_offset != kInvalidStackOffset) {
5315 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5316 // so this must be accounted for.
5317 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5318 } else {
5319 __ li(s0, Operand(stack_space));
5320 }
5321 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5322 stack_space_offset != kInvalidStackOffset);
5323
5324 // Check if the function scheduled an exception.
5325 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5326 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5327 __ lw(t1, MemOperand(at));
5328 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5329
5330 __ Ret();
5331
5332 // Re-throw by promoting a scheduled exception.
5333 __ bind(&promote_scheduled_exception);
5334 __ TailCallRuntime(Runtime::kPromoteScheduledException);
5335
5336 // HandleScope limit has changed. Delete allocated extensions.
5337 __ bind(&delete_allocated_handles);
5338 __ sw(s1, MemOperand(s3, kLimitOffset));
5339 __ mov(s0, v0);
5340 __ mov(a0, v0);
5341 __ PrepareCallCFunction(1, s1);
5342 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5343 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5344 1);
5345 __ mov(v0, s0);
5346 __ jmp(&leave_exit_frame);
5347}
5348
Ben Murdochda12d292016-06-02 14:46:10 +01005349void CallApiCallbackStub::Generate(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005350 // ----------- S t a t e -------------
5351 // -- a0 : callee
5352 // -- t0 : call_data
5353 // -- a2 : holder
5354 // -- a1 : api_function_address
5355 // -- cp : context
5356 // --
5357 // -- sp[0] : last argument
5358 // -- ...
5359 // -- sp[(argc - 1)* 4] : first argument
5360 // -- sp[argc * 4] : receiver
5361 // -----------------------------------
5362
5363 Register callee = a0;
5364 Register call_data = t0;
5365 Register holder = a2;
5366 Register api_function_address = a1;
5367 Register context = cp;
5368
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005369 typedef FunctionCallbackArguments FCA;
5370
5371 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5372 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5373 STATIC_ASSERT(FCA::kDataIndex == 4);
5374 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5375 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5376 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5377 STATIC_ASSERT(FCA::kHolderIndex == 0);
Ben Murdochc5610432016-08-08 18:44:38 +01005378 STATIC_ASSERT(FCA::kNewTargetIndex == 7);
5379 STATIC_ASSERT(FCA::kArgsLength == 8);
5380
5381 // new target
5382 __ PushRoot(Heap::kUndefinedValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005383
5384 // Save context, callee and call data.
5385 __ Push(context, callee, call_data);
Ben Murdochda12d292016-06-02 14:46:10 +01005386 if (!is_lazy()) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01005387 // Load context from callee.
5388 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5389 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005390
5391 Register scratch = call_data;
Ben Murdochda12d292016-06-02 14:46:10 +01005392 if (!call_data_undefined()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005393 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5394 }
5395 // Push return value and default return value.
5396 __ Push(scratch, scratch);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005397 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005398 // Push isolate and holder.
5399 __ Push(scratch, holder);
5400
5401 // Prepare arguments.
5402 __ mov(scratch, sp);
5403
5404 // Allocate the v8::Arguments structure in the arguments' space since
5405 // it's not controlled by GC.
Ben Murdochc5610432016-08-08 18:44:38 +01005406 const int kApiStackSpace = 3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005407
5408 FrameScope frame_scope(masm, StackFrame::MANUAL);
5409 __ EnterExitFrame(false, kApiStackSpace);
5410
5411 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5412 // a0 = FunctionCallbackInfo&
5413 // Arguments is after the return address.
5414 __ Addu(a0, sp, Operand(1 * kPointerSize));
5415 // FunctionCallbackInfo::implicit_args_
5416 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
Ben Murdochda12d292016-06-02 14:46:10 +01005417 // FunctionCallbackInfo::values_
5418 __ Addu(at, scratch, Operand((FCA::kArgsLength - 1 + argc()) * kPointerSize));
5419 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5420 // FunctionCallbackInfo::length_ = argc
5421 __ li(at, Operand(argc()));
5422 __ sw(at, MemOperand(a0, 2 * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005423
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005424 ExternalReference thunk_ref =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005425 ExternalReference::invoke_function_callback(masm->isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005426
5427 AllowExternalCallThatCantCauseGC scope(masm);
5428 MemOperand context_restore_operand(
5429 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5430 // Stores return the first js argument.
5431 int return_value_offset = 0;
Ben Murdochda12d292016-06-02 14:46:10 +01005432 if (is_store()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005433 return_value_offset = 2 + FCA::kArgsLength;
5434 } else {
5435 return_value_offset = 2 + FCA::kReturnValueOffset;
5436 }
5437 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005438 int stack_space = 0;
Ben Murdochc5610432016-08-08 18:44:38 +01005439 int32_t stack_space_offset = 3 * kPointerSize;
Ben Murdochda12d292016-06-02 14:46:10 +01005440 stack_space = argc() + FCA::kArgsLength + 1;
Ben Murdochc5610432016-08-08 18:44:38 +01005441 // TODO(adamk): Why are we clobbering this immediately?
Ben Murdochda12d292016-06-02 14:46:10 +01005442 stack_space_offset = kInvalidStackOffset;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005443 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5444 stack_space_offset, return_value_operand,
5445 &context_restore_operand);
5446}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005447
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005448
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005449void CallApiGetterStub::Generate(MacroAssembler* masm) {
Ben Murdochc5610432016-08-08 18:44:38 +01005450 // Build v8::PropertyCallbackInfo::args_ array on the stack and push property
5451 // name below the exit frame to make GC aware of them.
5452 STATIC_ASSERT(PropertyCallbackArguments::kShouldThrowOnErrorIndex == 0);
5453 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 1);
5454 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 2);
5455 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 3);
5456 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 4);
5457 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 5);
5458 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 6);
5459 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 7);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005460
Ben Murdochc5610432016-08-08 18:44:38 +01005461 Register receiver = ApiGetterDescriptor::ReceiverRegister();
5462 Register holder = ApiGetterDescriptor::HolderRegister();
5463 Register callback = ApiGetterDescriptor::CallbackRegister();
5464 Register scratch = t0;
5465 DCHECK(!AreAliased(receiver, holder, callback, scratch));
5466
5467 Register api_function_address = a2;
5468
5469 // Here and below +1 is for name() pushed after the args_ array.
5470 typedef PropertyCallbackArguments PCA;
5471 __ Subu(sp, sp, (PCA::kArgsLength + 1) * kPointerSize);
5472 __ sw(receiver, MemOperand(sp, (PCA::kThisIndex + 1) * kPointerSize));
5473 __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kDataOffset));
5474 __ sw(scratch, MemOperand(sp, (PCA::kDataIndex + 1) * kPointerSize));
5475 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5476 __ sw(scratch, MemOperand(sp, (PCA::kReturnValueOffset + 1) * kPointerSize));
5477 __ sw(scratch, MemOperand(sp, (PCA::kReturnValueDefaultValueIndex + 1) *
5478 kPointerSize));
5479 __ li(scratch, Operand(ExternalReference::isolate_address(isolate())));
5480 __ sw(scratch, MemOperand(sp, (PCA::kIsolateIndex + 1) * kPointerSize));
5481 __ sw(holder, MemOperand(sp, (PCA::kHolderIndex + 1) * kPointerSize));
5482 // should_throw_on_error -> false
5483 DCHECK(Smi::FromInt(0) == nullptr);
5484 __ sw(zero_reg,
5485 MemOperand(sp, (PCA::kShouldThrowOnErrorIndex + 1) * kPointerSize));
5486 __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kNameOffset));
5487 __ sw(scratch, MemOperand(sp, 0 * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005488
Ben Murdoch097c5b22016-05-18 11:27:45 +01005489 // v8::PropertyCallbackInfo::args_ array and name handle.
5490 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5491
5492 // Load address of v8::PropertyAccessorInfo::args_ array and name handle.
5493 __ mov(a0, sp); // a0 = Handle<Name>
5494 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = v8::PCI::args_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005495
5496 const int kApiStackSpace = 1;
5497 FrameScope frame_scope(masm, StackFrame::MANUAL);
5498 __ EnterExitFrame(false, kApiStackSpace);
5499
Ben Murdoch097c5b22016-05-18 11:27:45 +01005500 // Create v8::PropertyCallbackInfo object on the stack and initialize
5501 // it's args_ field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005502 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005503 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = v8::PropertyCallbackInfo&
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005504
5505 ExternalReference thunk_ref =
5506 ExternalReference::invoke_accessor_getter_callback(isolate());
Ben Murdoch097c5b22016-05-18 11:27:45 +01005507
Ben Murdochc5610432016-08-08 18:44:38 +01005508 __ lw(scratch, FieldMemOperand(callback, AccessorInfo::kJsGetterOffset));
5509 __ lw(api_function_address,
5510 FieldMemOperand(scratch, Foreign::kForeignAddressOffset));
5511
Ben Murdoch097c5b22016-05-18 11:27:45 +01005512 // +3 is to skip prolog, return address and name handle.
5513 MemOperand return_value_operand(
5514 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005515 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5516 kStackUnwindSpace, kInvalidStackOffset,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005517 return_value_operand, NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005518}
5519
Steve Block44f0eee2011-05-26 01:26:41 +01005520#undef __
5521
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005522} // namespace internal
5523} // namespace v8
Steve Block44f0eee2011-05-26 01:26:41 +01005524
5525#endif // V8_TARGET_ARCH_MIPS