blob: 28812ad9973219fad9cb4f69ff3569d0e537df88 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2012 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_MIPS64
6
7#include "src/bootstrapper.h"
8#include "src/code-stubs.h"
9#include "src/codegen.h"
10#include "src/ic/handler-compiler.h"
11#include "src/ic/ic.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/ic/stub-cache.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014#include "src/mips64/code-stubs-mips64.h"
15#include "src/regexp/jsregexp.h"
16#include "src/regexp/regexp-macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040017#include "src/runtime/runtime.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000018
19namespace v8 {
20namespace internal {
21
22
23static void InitializeArrayConstructorDescriptor(
24 Isolate* isolate, CodeStubDescriptor* descriptor,
25 int constant_stack_parameter_count) {
26 Address deopt_handler = Runtime::FunctionForId(
27 Runtime::kArrayConstructor)->entry;
28
29 if (constant_stack_parameter_count == 0) {
30 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
31 JS_FUNCTION_STUB_MODE);
32 } else {
33 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000035 }
36}
37
38
39static void InitializeInternalArrayConstructorDescriptor(
40 Isolate* isolate, CodeStubDescriptor* descriptor,
41 int constant_stack_parameter_count) {
42 Address deopt_handler = Runtime::FunctionForId(
43 Runtime::kInternalArrayConstructor)->entry;
44
45 if (constant_stack_parameter_count == 0) {
46 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
47 JS_FUNCTION_STUB_MODE);
48 } else {
49 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000050 JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051 }
52}
53
54
55void ArrayNoArgumentConstructorStub::InitializeDescriptor(
56 CodeStubDescriptor* descriptor) {
57 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
58}
59
60
61void ArraySingleArgumentConstructorStub::InitializeDescriptor(
62 CodeStubDescriptor* descriptor) {
63 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
64}
65
66
67void ArrayNArgumentsConstructorStub::InitializeDescriptor(
68 CodeStubDescriptor* descriptor) {
69 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
70}
71
72
73void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
74 CodeStubDescriptor* descriptor) {
75 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
76}
77
78
79void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
80 CodeStubDescriptor* descriptor) {
81 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
82}
83
84
85void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
86 CodeStubDescriptor* descriptor) {
87 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
88}
89
90
91#define __ ACCESS_MASM(masm)
92
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +010094 Condition cc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095static void EmitSmiNonsmiComparison(MacroAssembler* masm,
96 Register lhs,
97 Register rhs,
98 Label* rhs_not_nan,
99 Label* slow,
100 bool strict);
101static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
102 Register lhs,
103 Register rhs);
104
105
106void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
107 ExternalReference miss) {
108 // Update the static counter each time a new code stub is generated.
109 isolate()->counters()->code_stubs()->Increment();
110
111 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112 int param_count = descriptor.GetRegisterParameterCount();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113 {
114 // Call the runtime system in a fresh internal frame.
115 FrameScope scope(masm, StackFrame::INTERNAL);
116 DCHECK((param_count == 0) ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118 // Push arguments, adjust sp.
119 __ Dsubu(sp, sp, Operand(param_count * kPointerSize));
120 for (int i = 0; i < param_count; ++i) {
121 // Store argument to stack.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000122 __ sd(descriptor.GetRegisterParameter(i),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000123 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
124 }
125 __ CallExternalReference(miss, param_count);
126 }
127
128 __ Ret();
129}
130
131
132void DoubleToIStub::Generate(MacroAssembler* masm) {
133 Label out_of_range, only_low, negate, done;
134 Register input_reg = source();
135 Register result_reg = destination();
136
137 int double_offset = offset();
138 // Account for saved regs if input is sp.
139 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
140
141 Register scratch =
142 GetRegisterThatIsNotOneOf(input_reg, result_reg);
143 Register scratch2 =
144 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
145 Register scratch3 =
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
147 DoubleRegister double_scratch = kLithiumScratchDouble;
148
149 __ Push(scratch, scratch2, scratch3);
150 if (!skip_fastpath()) {
151 // Load double input.
152 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
153
154 // Clear cumulative exception flags and save the FCSR.
155 __ cfc1(scratch2, FCSR);
156 __ ctc1(zero_reg, FCSR);
157
158 // Try a conversion to a signed integer.
159 __ Trunc_w_d(double_scratch, double_scratch);
160 // Move the converted value into the result register.
161 __ mfc1(scratch3, double_scratch);
162
163 // Retrieve and restore the FCSR.
164 __ cfc1(scratch, FCSR);
165 __ ctc1(scratch2, FCSR);
166
167 // Check for overflow and NaNs.
168 __ And(
169 scratch, scratch,
170 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
171 | kFCSRInvalidOpFlagMask);
172 // If we had no exceptions then set result_reg and we are done.
173 Label error;
174 __ Branch(&error, ne, scratch, Operand(zero_reg));
175 __ Move(result_reg, scratch3);
176 __ Branch(&done);
177 __ bind(&error);
178 }
179
180 // Load the double value and perform a manual truncation.
181 Register input_high = scratch2;
182 Register input_low = scratch3;
183
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000184 __ lw(input_low,
185 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
186 __ lw(input_high,
187 MemOperand(input_reg, double_offset + Register::kExponentOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000188
189 Label normal_exponent, restore_sign;
190 // Extract the biased exponent in result.
191 __ Ext(result_reg,
192 input_high,
193 HeapNumber::kExponentShift,
194 HeapNumber::kExponentBits);
195
196 // Check for Infinity and NaNs, which should return 0.
197 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
198 __ Movz(result_reg, zero_reg, scratch);
199 __ Branch(&done, eq, scratch, Operand(zero_reg));
200
201 // Express exponent as delta to (number of mantissa bits + 31).
202 __ Subu(result_reg,
203 result_reg,
204 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
205
206 // If the delta is strictly positive, all bits would be shifted away,
207 // which means that we can return 0.
208 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
209 __ mov(result_reg, zero_reg);
210 __ Branch(&done);
211
212 __ bind(&normal_exponent);
213 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
214 // Calculate shift.
215 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
216
217 // Save the sign.
218 Register sign = result_reg;
219 result_reg = no_reg;
220 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
221
222 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
223 // to check for this specific case.
224 Label high_shift_needed, high_shift_done;
225 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
226 __ mov(input_high, zero_reg);
227 __ Branch(&high_shift_done);
228 __ bind(&high_shift_needed);
229
230 // Set the implicit 1 before the mantissa part in input_high.
231 __ Or(input_high,
232 input_high,
233 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
234 // Shift the mantissa bits to the correct position.
235 // We don't need to clear non-mantissa bits as they will be shifted away.
236 // If they weren't, it would mean that the answer is in the 32bit range.
237 __ sllv(input_high, input_high, scratch);
238
239 __ bind(&high_shift_done);
240
241 // Replace the shifted bits with bits from the lower mantissa word.
242 Label pos_shift, shift_done;
243 __ li(at, 32);
244 __ subu(scratch, at, scratch);
245 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
246
247 // Negate scratch.
248 __ Subu(scratch, zero_reg, scratch);
249 __ sllv(input_low, input_low, scratch);
250 __ Branch(&shift_done);
251
252 __ bind(&pos_shift);
253 __ srlv(input_low, input_low, scratch);
254
255 __ bind(&shift_done);
256 __ Or(input_high, input_high, Operand(input_low));
257 // Restore sign if necessary.
258 __ mov(scratch, sign);
259 result_reg = sign;
260 sign = no_reg;
261 __ Subu(result_reg, zero_reg, input_high);
262 __ Movz(result_reg, input_high, scratch);
263
264 __ bind(&done);
265
266 __ Pop(scratch, scratch2, scratch3);
267 __ Ret();
268}
269
270
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000271// Handle the case where the lhs and rhs are the same object.
272// Equality is almost reflexive (everything but NaN), so this is a test
273// for "identity and not NaN".
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000274static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100275 Condition cc) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 Label not_identical;
277 Label heap_number, return_equal;
278 Register exp_mask_reg = t1;
279
280 __ Branch(&not_identical, ne, a0, Operand(a1));
281
282 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
283
284 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
285 // so we do the second best thing - test it ourselves.
286 // They are both equal and they are not both Smis so both of them are not
287 // Smis. If it's not a heap number, then return equal.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000288 __ GetObjectType(a0, t0, t0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 if (cc == less || cc == greater) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000290 // Call runtime on identical JSObjects.
291 __ Branch(slow, greater, t0, Operand(FIRST_JS_RECEIVER_TYPE));
292 // Call runtime on identical symbols since we need to throw a TypeError.
293 __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE));
294 // Call runtime on identical SIMD values since we must throw a TypeError.
295 __ Branch(slow, eq, t0, Operand(SIMD128_VALUE_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000296 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000297 __ Branch(&heap_number, eq, t0, Operand(HEAP_NUMBER_TYPE));
298 // Comparing JS objects with <=, >= is complicated.
299 if (cc != eq) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000300 __ Branch(slow, greater, t0, Operand(FIRST_JS_RECEIVER_TYPE));
301 // Call runtime on identical symbols since we need to throw a TypeError.
302 __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE));
303 // Call runtime on identical SIMD values since we must throw a TypeError.
304 __ Branch(slow, eq, t0, Operand(SIMD128_VALUE_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000305 // Normally here we fall through to return_equal, but undefined is
306 // special: (undefined == undefined) == true, but
307 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
308 if (cc == less_equal || cc == greater_equal) {
309 __ Branch(&return_equal, ne, t0, Operand(ODDBALL_TYPE));
310 __ LoadRoot(a6, Heap::kUndefinedValueRootIndex);
311 __ Branch(&return_equal, ne, a0, Operand(a6));
312 DCHECK(is_int16(GREATER) && is_int16(LESS));
313 __ Ret(USE_DELAY_SLOT);
314 if (cc == le) {
315 // undefined <= undefined should fail.
316 __ li(v0, Operand(GREATER));
317 } else {
318 // undefined >= undefined should fail.
319 __ li(v0, Operand(LESS));
320 }
321 }
322 }
323 }
324
325 __ bind(&return_equal);
326 DCHECK(is_int16(GREATER) && is_int16(LESS));
327 __ Ret(USE_DELAY_SLOT);
328 if (cc == less) {
329 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
330 } else if (cc == greater) {
331 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
332 } else {
333 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
334 }
335 // For less and greater we don't have to check for NaN since the result of
336 // x < x is false regardless. For the others here is some code to check
337 // for NaN.
338 if (cc != lt && cc != gt) {
339 __ bind(&heap_number);
340 // It is a heap number, so return non-equal if it's NaN and equal if it's
341 // not NaN.
342
343 // The representation of NaN values has all exponent bits (52..62) set,
344 // and not all mantissa bits (0..51) clear.
345 // Read top bits of double representation (second word of value).
346 __ lwu(a6, FieldMemOperand(a0, HeapNumber::kExponentOffset));
347 // Test that exponent bits are all set.
348 __ And(a7, a6, Operand(exp_mask_reg));
349 // If all bits not set (ne cond), then not a NaN, objects are equal.
350 __ Branch(&return_equal, ne, a7, Operand(exp_mask_reg));
351
352 // Shift out flag and all exponent bits, retaining only mantissa.
353 __ sll(a6, a6, HeapNumber::kNonMantissaBitsInTopWord);
354 // Or with all low-bits of mantissa.
355 __ lwu(a7, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
356 __ Or(v0, a7, Operand(a6));
357 // For equal we already have the right value in v0: Return zero (equal)
358 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
359 // not (it's a NaN). For <= and >= we need to load v0 with the failing
360 // value if it's a NaN.
361 if (cc != eq) {
362 // All-zero means Infinity means equal.
363 __ Ret(eq, v0, Operand(zero_reg));
364 DCHECK(is_int16(GREATER) && is_int16(LESS));
365 __ Ret(USE_DELAY_SLOT);
366 if (cc == le) {
367 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
368 } else {
369 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
370 }
371 }
372 }
373 // No fall through here.
374
375 __ bind(&not_identical);
376}
377
378
379static void EmitSmiNonsmiComparison(MacroAssembler* masm,
380 Register lhs,
381 Register rhs,
382 Label* both_loaded_as_doubles,
383 Label* slow,
384 bool strict) {
385 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
386 (lhs.is(a1) && rhs.is(a0)));
387
388 Label lhs_is_smi;
389 __ JumpIfSmi(lhs, &lhs_is_smi);
390 // Rhs is a Smi.
391 // Check whether the non-smi is a heap number.
392 __ GetObjectType(lhs, t0, t0);
393 if (strict) {
394 // If lhs was not a number and rhs was a Smi then strict equality cannot
395 // succeed. Return non-equal (lhs is already not zero).
396 __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE));
397 __ mov(v0, lhs);
398 } else {
399 // Smi compared non-strictly with a non-Smi non-heap-number. Call
400 // the runtime.
401 __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE));
402 }
403 // Rhs is a smi, lhs is a number.
404 // Convert smi rhs to double.
405 __ SmiUntag(at, rhs);
406 __ mtc1(at, f14);
407 __ cvt_d_w(f14, f14);
408 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
409
410 // We now have both loaded as doubles.
411 __ jmp(both_loaded_as_doubles);
412
413 __ bind(&lhs_is_smi);
414 // Lhs is a Smi. Check whether the non-smi is a heap number.
415 __ GetObjectType(rhs, t0, t0);
416 if (strict) {
417 // If lhs was not a number and rhs was a Smi then strict equality cannot
418 // succeed. Return non-equal.
419 __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE));
420 __ li(v0, Operand(1));
421 } else {
422 // Smi compared non-strictly with a non-Smi non-heap-number. Call
423 // the runtime.
424 __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE));
425 }
426
427 // Lhs is a smi, rhs is a number.
428 // Convert smi lhs to double.
429 __ SmiUntag(at, lhs);
430 __ mtc1(at, f12);
431 __ cvt_d_w(f12, f12);
432 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
433 // Fall through to both_loaded_as_doubles.
434}
435
436
437static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
438 Register lhs,
439 Register rhs) {
440 // If either operand is a JS object or an oddball value, then they are
441 // not equal since their pointers are different.
442 // There is no test for undetectability in strict equality.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000443 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000444 Label first_non_object;
445 // Get the type of the first operand into a2 and compare it with
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000446 // FIRST_JS_RECEIVER_TYPE.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000447 __ GetObjectType(lhs, a2, a2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448 __ Branch(&first_non_object, less, a2, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000449
450 // Return non-zero.
451 Label return_not_equal;
452 __ bind(&return_not_equal);
453 __ Ret(USE_DELAY_SLOT);
454 __ li(v0, Operand(1));
455
456 __ bind(&first_non_object);
457 // Check for oddballs: true, false, null, undefined.
458 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
459
460 __ GetObjectType(rhs, a3, a3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000461 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000462
463 // Check for oddballs: true, false, null, undefined.
464 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
465
466 // Now that we have the types we might as well check for
467 // internalized-internalized.
468 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
469 __ Or(a2, a2, Operand(a3));
470 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
471 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
472}
473
474
475static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
476 Register lhs,
477 Register rhs,
478 Label* both_loaded_as_doubles,
479 Label* not_heap_numbers,
480 Label* slow) {
481 __ GetObjectType(lhs, a3, a2);
482 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
483 __ ld(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
484 // If first was a heap number & second wasn't, go to slow case.
485 __ Branch(slow, ne, a3, Operand(a2));
486
487 // Both are heap numbers. Load them up then jump to the code we have
488 // for that.
489 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
490 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
491
492 __ jmp(both_loaded_as_doubles);
493}
494
495
496// Fast negative check for internalized-to-internalized equality.
497static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100498 Register lhs, Register rhs,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000499 Label* possible_strings,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100500 Label* runtime_call) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000501 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
502 (lhs.is(a1) && rhs.is(a0)));
503
504 // a2 is object type of rhs.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100505 Label object_test, return_unequal, undetectable;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000506 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
507 __ And(at, a2, Operand(kIsNotStringMask));
508 __ Branch(&object_test, ne, at, Operand(zero_reg));
509 __ And(at, a2, Operand(kIsNotInternalizedMask));
510 __ Branch(possible_strings, ne, at, Operand(zero_reg));
511 __ GetObjectType(rhs, a3, a3);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100512 __ Branch(runtime_call, ge, a3, Operand(FIRST_NONSTRING_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000513 __ And(at, a3, Operand(kIsNotInternalizedMask));
514 __ Branch(possible_strings, ne, at, Operand(zero_reg));
515
Ben Murdoch097c5b22016-05-18 11:27:45 +0100516 // Both are internalized. We already checked they weren't the same pointer so
517 // they are not equal. Return non-equal by returning the non-zero object
518 // pointer in v0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000519 __ Ret(USE_DELAY_SLOT);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100520 __ mov(v0, a0); // In delay slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000521
522 __ bind(&object_test);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100523 __ ld(a2, FieldMemOperand(lhs, HeapObject::kMapOffset));
524 __ ld(a3, FieldMemOperand(rhs, HeapObject::kMapOffset));
525 __ lbu(t0, FieldMemOperand(a2, Map::kBitFieldOffset));
526 __ lbu(t1, FieldMemOperand(a3, Map::kBitFieldOffset));
527 __ And(at, t0, Operand(1 << Map::kIsUndetectable));
528 __ Branch(&undetectable, ne, at, Operand(zero_reg));
529 __ And(at, t1, Operand(1 << Map::kIsUndetectable));
530 __ Branch(&return_unequal, ne, at, Operand(zero_reg));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000531
Ben Murdoch097c5b22016-05-18 11:27:45 +0100532 __ GetInstanceType(a2, a2);
533 __ Branch(runtime_call, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE));
534 __ GetInstanceType(a3, a3);
535 __ Branch(runtime_call, lt, a3, Operand(FIRST_JS_RECEIVER_TYPE));
536
537 __ bind(&return_unequal);
538 // Return non-equal by returning the non-zero object pointer in v0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000539 __ Ret(USE_DELAY_SLOT);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100540 __ mov(v0, a0); // In delay slot.
541
542 __ bind(&undetectable);
543 __ And(at, t1, Operand(1 << Map::kIsUndetectable));
544 __ Branch(&return_unequal, eq, at, Operand(zero_reg));
545 __ Ret(USE_DELAY_SLOT);
546 __ li(v0, Operand(EQUAL)); // In delay slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000547}
548
549
550static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
551 Register scratch,
552 CompareICState::State expected,
553 Label* fail) {
554 Label ok;
555 if (expected == CompareICState::SMI) {
556 __ JumpIfNotSmi(input, fail);
557 } else if (expected == CompareICState::NUMBER) {
558 __ JumpIfSmi(input, &ok);
559 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
560 DONT_DO_SMI_CHECK);
561 }
562 // We could be strict about internalized/string here, but as long as
563 // hydrogen doesn't care, the stub doesn't have to care either.
564 __ bind(&ok);
565}
566
567
568// On entry a1 and a2 are the values to be compared.
569// On exit a0 is 0, positive or negative to indicate the result of
570// the comparison.
571void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
572 Register lhs = a1;
573 Register rhs = a0;
574 Condition cc = GetCondition();
575
576 Label miss;
577 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
578 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
579
580 Label slow; // Call builtin.
581 Label not_smis, both_loaded_as_doubles;
582
583 Label not_two_smis, smi_done;
584 __ Or(a2, a1, a0);
585 __ JumpIfNotSmi(a2, &not_two_smis);
586 __ SmiUntag(a1);
587 __ SmiUntag(a0);
588
589 __ Ret(USE_DELAY_SLOT);
590 __ dsubu(v0, a1, a0);
591 __ bind(&not_two_smis);
592
593 // NOTICE! This code is only reached after a smi-fast-case check, so
594 // it is certain that at least one operand isn't a smi.
595
596 // Handle the case where the objects are identical. Either returns the answer
597 // or goes to slow. Only falls through if the objects were not identical.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100598 EmitIdenticalObjectComparison(masm, &slow, cc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000599
600 // If either is a Smi (we know that not both are), then they can only
601 // be strictly equal if the other is a HeapNumber.
602 STATIC_ASSERT(kSmiTag == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000603 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000604 __ And(a6, lhs, Operand(rhs));
605 __ JumpIfNotSmi(a6, &not_smis, a4);
606 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
607 // 1) Return the answer.
608 // 2) Go to slow.
609 // 3) Fall through to both_loaded_as_doubles.
610 // 4) Jump to rhs_not_nan.
611 // In cases 3 and 4 we have found out we were dealing with a number-number
612 // comparison and the numbers have been loaded into f12 and f14 as doubles,
613 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
614 EmitSmiNonsmiComparison(masm, lhs, rhs,
615 &both_loaded_as_doubles, &slow, strict());
616
617 __ bind(&both_loaded_as_doubles);
618 // f12, f14 are the double representations of the left hand side
619 // and the right hand side if we have FPU. Otherwise a2, a3 represent
620 // left hand side and a0, a1 represent right hand side.
621
622 Label nan;
623 __ li(a4, Operand(LESS));
624 __ li(a5, Operand(GREATER));
625 __ li(a6, Operand(EQUAL));
626
627 // Check if either rhs or lhs is NaN.
628 __ BranchF(NULL, &nan, eq, f12, f14);
629
630 // Check if LESS condition is satisfied. If true, move conditionally
631 // result to v0.
632 if (kArchVariant != kMips64r6) {
633 __ c(OLT, D, f12, f14);
634 __ Movt(v0, a4);
635 // Use previous check to store conditionally to v0 oposite condition
636 // (GREATER). If rhs is equal to lhs, this will be corrected in next
637 // check.
638 __ Movf(v0, a5);
639 // Check if EQUAL condition is satisfied. If true, move conditionally
640 // result to v0.
641 __ c(EQ, D, f12, f14);
642 __ Movt(v0, a6);
643 } else {
644 Label skip;
645 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
646 __ mov(v0, a4); // Return LESS as result.
647
648 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
649 __ mov(v0, a6); // Return EQUAL as result.
650
651 __ mov(v0, a5); // Return GREATER as result.
652 __ bind(&skip);
653 }
654 __ Ret();
655
656 __ bind(&nan);
657 // NaN comparisons always fail.
658 // Load whatever we need in v0 to make the comparison fail.
659 DCHECK(is_int16(GREATER) && is_int16(LESS));
660 __ Ret(USE_DELAY_SLOT);
661 if (cc == lt || cc == le) {
662 __ li(v0, Operand(GREATER));
663 } else {
664 __ li(v0, Operand(LESS));
665 }
666
667
668 __ bind(&not_smis);
669 // At this point we know we are dealing with two different objects,
670 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
671 if (strict()) {
672 // This returns non-equal for some object types, or falls through if it
673 // was not lucky.
674 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
675 }
676
677 Label check_for_internalized_strings;
678 Label flat_string_check;
679 // Check for heap-number-heap-number comparison. Can jump to slow case,
680 // or load both doubles and jump to the code that handles
681 // that case. If the inputs are not doubles then jumps to
682 // check_for_internalized_strings.
683 // In this case a2 will contain the type of lhs_.
684 EmitCheckForTwoHeapNumbers(masm,
685 lhs,
686 rhs,
687 &both_loaded_as_doubles,
688 &check_for_internalized_strings,
689 &flat_string_check);
690
691 __ bind(&check_for_internalized_strings);
692 if (cc == eq && !strict()) {
693 // Returns an answer for two internalized strings or two
694 // detectable objects.
695 // Otherwise jumps to string case or not both strings case.
696 // Assumes that a2 is the type of lhs_ on entry.
697 EmitCheckForInternalizedStringsOrObjects(
698 masm, lhs, rhs, &flat_string_check, &slow);
699 }
700
701 // Check for both being sequential one-byte strings,
702 // and inline if that is the case.
703 __ bind(&flat_string_check);
704
705 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
706
707 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
708 a3);
709 if (cc == eq) {
710 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, a4);
711 } else {
712 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, a4,
713 a5);
714 }
715 // Never falls through to here.
716
717 __ bind(&slow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000718 if (cc == eq) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100719 {
720 FrameScope scope(masm, StackFrame::INTERNAL);
721 __ Push(lhs, rhs);
722 __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual);
723 }
724 // Turn true into 0 and false into some non-zero value.
725 STATIC_ASSERT(EQUAL == 0);
726 __ LoadRoot(a0, Heap::kTrueValueRootIndex);
727 __ Ret(USE_DELAY_SLOT);
728 __ subu(v0, v0, a0); // In delay slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000729 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100730 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
731 // a1 (rhs) second.
732 __ Push(lhs, rhs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000733 int ncr; // NaN compare result.
734 if (cc == lt || cc == le) {
735 ncr = GREATER;
736 } else {
737 DCHECK(cc == gt || cc == ge); // Remaining cases.
738 ncr = LESS;
739 }
740 __ li(a0, Operand(Smi::FromInt(ncr)));
741 __ push(a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000742
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000743 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
744 // tagged as a small integer.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100745 __ TailCallRuntime(Runtime::kCompare);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000746 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000747
748 __ bind(&miss);
749 GenerateMiss(masm);
750}
751
752
753void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
754 __ mov(t9, ra);
755 __ pop(ra);
756 __ PushSafepointRegisters();
757 __ Jump(t9);
758}
759
760
761void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
762 __ mov(t9, ra);
763 __ pop(ra);
764 __ PopSafepointRegisters();
765 __ Jump(t9);
766}
767
768
769void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
770 // We don't allow a GC during a store buffer overflow so there is no need to
771 // store the registers in any particular way, but we do have to store and
772 // restore them.
773 __ MultiPush(kJSCallerSaved | ra.bit());
774 if (save_doubles()) {
775 __ MultiPushFPU(kCallerSavedFPU);
776 }
777 const int argument_count = 1;
778 const int fp_argument_count = 0;
779 const Register scratch = a1;
780
781 AllowExternalCallThatCantCauseGC scope(masm);
782 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
783 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
784 __ CallCFunction(
785 ExternalReference::store_buffer_overflow_function(isolate()),
786 argument_count);
787 if (save_doubles()) {
788 __ MultiPopFPU(kCallerSavedFPU);
789 }
790
791 __ MultiPop(kJSCallerSaved | ra.bit());
792 __ Ret();
793}
794
795
796void MathPowStub::Generate(MacroAssembler* masm) {
797 const Register base = a1;
798 const Register exponent = MathPowTaggedDescriptor::exponent();
799 DCHECK(exponent.is(a2));
800 const Register heapnumbermap = a5;
801 const Register heapnumber = v0;
802 const DoubleRegister double_base = f2;
803 const DoubleRegister double_exponent = f4;
804 const DoubleRegister double_result = f0;
805 const DoubleRegister double_scratch = f6;
806 const FPURegister single_scratch = f8;
807 const Register scratch = t1;
808 const Register scratch2 = a7;
809
810 Label call_runtime, done, int_exponent;
811 if (exponent_type() == ON_STACK) {
812 Label base_is_smi, unpack_exponent;
813 // The exponent and base are supplied as arguments on the stack.
814 // This can only happen if the stub is called from non-optimized code.
815 // Load input parameters from stack to double registers.
816 __ ld(base, MemOperand(sp, 1 * kPointerSize));
817 __ ld(exponent, MemOperand(sp, 0 * kPointerSize));
818
819 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
820
821 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
822 __ ld(scratch, FieldMemOperand(base, JSObject::kMapOffset));
823 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
824
825 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
826 __ jmp(&unpack_exponent);
827
828 __ bind(&base_is_smi);
829 __ mtc1(scratch, single_scratch);
830 __ cvt_d_w(double_base, single_scratch);
831 __ bind(&unpack_exponent);
832
833 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
834
835 __ ld(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
836 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
837 __ ldc1(double_exponent,
838 FieldMemOperand(exponent, HeapNumber::kValueOffset));
839 } else if (exponent_type() == TAGGED) {
840 // Base is already in double_base.
841 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
842
843 __ ldc1(double_exponent,
844 FieldMemOperand(exponent, HeapNumber::kValueOffset));
845 }
846
847 if (exponent_type() != INTEGER) {
848 Label int_exponent_convert;
849 // Detect integer exponents stored as double.
850 __ EmitFPUTruncate(kRoundToMinusInf,
851 scratch,
852 double_exponent,
853 at,
854 double_scratch,
855 scratch2,
856 kCheckForInexactConversion);
857 // scratch2 == 0 means there was no conversion error.
858 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
859
860 if (exponent_type() == ON_STACK) {
861 // Detect square root case. Crankshaft detects constant +/-0.5 at
862 // compile time and uses DoMathPowHalf instead. We then skip this check
863 // for non-constant cases of +/-0.5 as these hardly occur.
864 Label not_plus_half;
865
866 // Test for 0.5.
867 __ Move(double_scratch, 0.5);
868 __ BranchF(USE_DELAY_SLOT,
869 &not_plus_half,
870 NULL,
871 ne,
872 double_exponent,
873 double_scratch);
874 // double_scratch can be overwritten in the delay slot.
875 // Calculates square root of base. Check for the special case of
876 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400877 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000878 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
879 __ neg_d(double_result, double_scratch);
880
881 // Add +0 to convert -0 to +0.
882 __ add_d(double_scratch, double_base, kDoubleRegZero);
883 __ sqrt_d(double_result, double_scratch);
884 __ jmp(&done);
885
886 __ bind(&not_plus_half);
887 __ Move(double_scratch, -0.5);
888 __ BranchF(USE_DELAY_SLOT,
889 &call_runtime,
890 NULL,
891 ne,
892 double_exponent,
893 double_scratch);
894 // double_scratch can be overwritten in the delay slot.
895 // Calculates square root of base. Check for the special case of
896 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400897 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000898 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
899 __ Move(double_result, kDoubleRegZero);
900
901 // Add +0 to convert -0 to +0.
902 __ add_d(double_scratch, double_base, kDoubleRegZero);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400903 __ Move(double_result, 1.);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000904 __ sqrt_d(double_scratch, double_scratch);
905 __ div_d(double_result, double_result, double_scratch);
906 __ jmp(&done);
907 }
908
909 __ push(ra);
910 {
911 AllowExternalCallThatCantCauseGC scope(masm);
912 __ PrepareCallCFunction(0, 2, scratch2);
913 __ MovToFloatParameters(double_base, double_exponent);
914 __ CallCFunction(
915 ExternalReference::power_double_double_function(isolate()),
916 0, 2);
917 }
918 __ pop(ra);
919 __ MovFromFloatResult(double_result);
920 __ jmp(&done);
921
922 __ bind(&int_exponent_convert);
923 }
924
925 // Calculate power with integer exponent.
926 __ bind(&int_exponent);
927
928 // Get two copies of exponent in the registers scratch and exponent.
929 if (exponent_type() == INTEGER) {
930 __ mov(scratch, exponent);
931 } else {
932 // Exponent has previously been stored into scratch as untagged integer.
933 __ mov(exponent, scratch);
934 }
935
936 __ mov_d(double_scratch, double_base); // Back up base.
937 __ Move(double_result, 1.0);
938
939 // Get absolute value of exponent.
940 Label positive_exponent;
941 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
942 __ Dsubu(scratch, zero_reg, scratch);
943 __ bind(&positive_exponent);
944
945 Label while_true, no_carry, loop_end;
946 __ bind(&while_true);
947
948 __ And(scratch2, scratch, 1);
949
950 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
951 __ mul_d(double_result, double_result, double_scratch);
952 __ bind(&no_carry);
953
954 __ dsra(scratch, scratch, 1);
955
956 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
957 __ mul_d(double_scratch, double_scratch, double_scratch);
958
959 __ Branch(&while_true);
960
961 __ bind(&loop_end);
962
963 __ Branch(&done, ge, exponent, Operand(zero_reg));
964 __ Move(double_scratch, 1.0);
965 __ div_d(double_result, double_scratch, double_result);
966 // Test whether result is zero. Bail out to check for subnormal result.
967 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
968 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
969
970 // double_exponent may not contain the exponent value if the input was a
971 // smi. We set it with exponent value before bailing out.
972 __ mtc1(exponent, single_scratch);
973 __ cvt_d_w(double_exponent, single_scratch);
974
975 // Returning or bailing out.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000976 if (exponent_type() == ON_STACK) {
977 // The arguments are still on the stack.
978 __ bind(&call_runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000979 __ TailCallRuntime(Runtime::kMathPowRT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000980
981 // The stub is called from non-optimized code, which expects the result
982 // as heap number in exponent.
983 __ bind(&done);
984 __ AllocateHeapNumber(
985 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
986 __ sdc1(double_result,
987 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
988 DCHECK(heapnumber.is(v0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000989 __ DropAndRet(2);
990 } else {
991 __ push(ra);
992 {
993 AllowExternalCallThatCantCauseGC scope(masm);
994 __ PrepareCallCFunction(0, 2, scratch);
995 __ MovToFloatParameters(double_base, double_exponent);
996 __ CallCFunction(
997 ExternalReference::power_double_double_function(isolate()),
998 0, 2);
999 }
1000 __ pop(ra);
1001 __ MovFromFloatResult(double_result);
1002
1003 __ bind(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001004 __ Ret();
1005 }
1006}
1007
1008
1009bool CEntryStub::NeedsImmovableCode() {
1010 return true;
1011}
1012
1013
1014void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1015 CEntryStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1017 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1018 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1019 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001020 CreateWeakCellStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001021 BinaryOpICStub::GenerateAheadOfTime(isolate);
1022 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1023 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1024 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001025 StoreFastElementStub::GenerateAheadOfTime(isolate);
1026 TypeofStub::GenerateAheadOfTime(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001027}
1028
1029
1030void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1031 StoreRegistersStateStub stub(isolate);
1032 stub.GetCode();
1033}
1034
1035
1036void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1037 RestoreRegistersStateStub stub(isolate);
1038 stub.GetCode();
1039}
1040
1041
1042void CodeStub::GenerateFPStubs(Isolate* isolate) {
1043 // Generate if not already in cache.
1044 SaveFPRegsMode mode = kSaveFPRegs;
1045 CEntryStub(isolate, 1, mode).GetCode();
1046 StoreBufferOverflowStub(isolate, mode).GetCode();
1047 isolate->set_fp_stubs_generated(true);
1048}
1049
1050
1051void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1052 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1053 stub.GetCode();
1054}
1055
1056
1057void CEntryStub::Generate(MacroAssembler* masm) {
1058 // Called from JavaScript; parameters are on stack as if calling JS function
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001059 // a0: number of arguments including receiver
1060 // a1: pointer to builtin function
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001061 // fp: frame pointer (restored after C call)
1062 // sp: stack pointer (restored as callee's sp after C call)
1063 // cp: current context (C callee-saved)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001064 //
1065 // If argv_in_register():
1066 // a2: pointer to the first argument
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001067
1068 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1069
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001070 if (argv_in_register()) {
1071 // Move argv into the correct register.
1072 __ mov(s1, a2);
1073 } else {
1074 // Compute the argv pointer in a callee-saved register.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001075 __ Dlsa(s1, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001076 __ Dsubu(s1, s1, kPointerSize);
1077 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001078
1079 // Enter the exit frame that transitions from JavaScript to C++.
1080 FrameScope scope(masm, StackFrame::MANUAL);
1081 __ EnterExitFrame(save_doubles());
1082
1083 // s0: number of arguments including receiver (C callee-saved)
1084 // s1: pointer to first argument (C callee-saved)
1085 // s2: pointer to builtin function (C callee-saved)
1086
1087 // Prepare arguments for C routine.
1088 // a0 = argc
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001089 __ mov(s0, a0);
1090 __ mov(s2, a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001091
1092 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1093 // also need to reserve the 4 argument slots on the stack.
1094
1095 __ AssertStackIsAligned();
1096
Ben Murdoch097c5b22016-05-18 11:27:45 +01001097 int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1098 int frame_alignment_mask = frame_alignment - 1;
1099 int result_stack_size;
1100 if (result_size() <= 2) {
1101 // a0 = argc, a1 = argv, a2 = isolate
1102 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1103 __ mov(a1, s1);
1104 result_stack_size = 0;
1105 } else {
1106 DCHECK_EQ(3, result_size());
1107 // Allocate additional space for the result.
1108 result_stack_size =
1109 ((result_size() * kPointerSize) + frame_alignment_mask) &
1110 ~frame_alignment_mask;
1111 __ Dsubu(sp, sp, Operand(result_stack_size));
1112
1113 // a0 = hidden result argument, a1 = argc, a2 = argv, a3 = isolate.
1114 __ li(a3, Operand(ExternalReference::isolate_address(isolate())));
1115 __ mov(a2, s1);
1116 __ mov(a1, a0);
1117 __ mov(a0, sp);
1118 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001119
1120 // To let the GC traverse the return address of the exit frames, we need to
1121 // know where the return address is. The CEntryStub is unmovable, so
1122 // we can store the address on the stack to be able to find it again and
1123 // we never have to restore it, because it will not change.
1124 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001125 int kNumInstructionsToJump = 4;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001126 Label find_ra;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001127 // Adjust the value in ra to point to the correct return location, 2nd
1128 // instruction past the real call into C code (the jalr(t9)), and push it.
1129 // This is the return address of the exit frame.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001130 if (kArchVariant >= kMips64r6) {
1131 __ addiupc(ra, kNumInstructionsToJump + 1);
1132 } else {
1133 // This branch-and-link sequence is needed to find the current PC on mips
1134 // before r6, saved to the ra register.
1135 __ bal(&find_ra); // bal exposes branch delay slot.
1136 __ Daddu(ra, ra, kNumInstructionsToJump * Instruction::kInstrSize);
1137 }
1138 __ bind(&find_ra);
1139
1140 // This spot was reserved in EnterExitFrame.
1141 __ sd(ra, MemOperand(sp, result_stack_size));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001142 // Stack space reservation moved to the branch delay slot below.
1143 // Stack is still aligned.
1144
1145 // Call the C routine.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001146 __ mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1147 __ jalr(t9);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001148 // Set up sp in the delay slot.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001149 __ daddiu(sp, sp, -kCArgsSlotsSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001150 // Make sure the stored 'ra' points to this position.
1151 DCHECK_EQ(kNumInstructionsToJump,
1152 masm->InstructionsGeneratedSince(&find_ra));
1153 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001154 if (result_size() > 2) {
1155 DCHECK_EQ(3, result_size());
1156 // Read result values stored on stack.
1157 __ ld(a0, MemOperand(v0, 2 * kPointerSize));
1158 __ ld(v1, MemOperand(v0, 1 * kPointerSize));
1159 __ ld(v0, MemOperand(v0, 0 * kPointerSize));
1160 }
1161 // Result returned in v0, v1:v0 or a0:v1:v0 - do not destroy these registers!
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001162
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001163 // Check result for exception sentinel.
1164 Label exception_returned;
1165 __ LoadRoot(a4, Heap::kExceptionRootIndex);
1166 __ Branch(&exception_returned, eq, a4, Operand(v0));
1167
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001168 // Check that there is no pending exception, otherwise we
1169 // should have returned the exception sentinel.
1170 if (FLAG_debug_code) {
1171 Label okay;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001172 ExternalReference pending_exception_address(
1173 Isolate::kPendingExceptionAddress, isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001174 __ li(a2, Operand(pending_exception_address));
1175 __ ld(a2, MemOperand(a2));
1176 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
1177 // Cannot use check here as it attempts to generate call into runtime.
1178 __ Branch(&okay, eq, a4, Operand(a2));
1179 __ stop("Unexpected pending exception");
1180 __ bind(&okay);
1181 }
1182
1183 // Exit C frame and return.
1184 // v0:v1: result
1185 // sp: stack pointer
1186 // fp: frame pointer
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001187 Register argc;
1188 if (argv_in_register()) {
1189 // We don't want to pop arguments so set argc to no_reg.
1190 argc = no_reg;
1191 } else {
1192 // s0: still holds argc (callee-saved).
1193 argc = s0;
1194 }
1195 __ LeaveExitFrame(save_doubles(), argc, true, EMIT_RETURN);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001196
1197 // Handling of exception.
1198 __ bind(&exception_returned);
1199
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001200 ExternalReference pending_handler_context_address(
1201 Isolate::kPendingHandlerContextAddress, isolate());
1202 ExternalReference pending_handler_code_address(
1203 Isolate::kPendingHandlerCodeAddress, isolate());
1204 ExternalReference pending_handler_offset_address(
1205 Isolate::kPendingHandlerOffsetAddress, isolate());
1206 ExternalReference pending_handler_fp_address(
1207 Isolate::kPendingHandlerFPAddress, isolate());
1208 ExternalReference pending_handler_sp_address(
1209 Isolate::kPendingHandlerSPAddress, isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001210
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001211 // Ask the runtime for help to determine the handler. This will set v0 to
1212 // contain the current pending exception, don't clobber it.
1213 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1214 isolate());
1215 {
1216 FrameScope scope(masm, StackFrame::MANUAL);
1217 __ PrepareCallCFunction(3, 0, a0);
1218 __ mov(a0, zero_reg);
1219 __ mov(a1, zero_reg);
1220 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1221 __ CallCFunction(find_handler, 3);
1222 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001223
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001224 // Retrieve the handler context, SP and FP.
1225 __ li(cp, Operand(pending_handler_context_address));
1226 __ ld(cp, MemOperand(cp));
1227 __ li(sp, Operand(pending_handler_sp_address));
1228 __ ld(sp, MemOperand(sp));
1229 __ li(fp, Operand(pending_handler_fp_address));
1230 __ ld(fp, MemOperand(fp));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001231
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001232 // If the handler is a JS frame, restore the context to the frame. Note that
1233 // the context will be set to (cp == 0) for non-JS frames.
1234 Label zero;
1235 __ Branch(&zero, eq, cp, Operand(zero_reg));
1236 __ sd(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1237 __ bind(&zero);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001238
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001239 // Compute the handler entry address and jump to it.
1240 __ li(a1, Operand(pending_handler_code_address));
1241 __ ld(a1, MemOperand(a1));
1242 __ li(a2, Operand(pending_handler_offset_address));
1243 __ ld(a2, MemOperand(a2));
1244 __ Daddu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1245 __ Daddu(t9, a1, a2);
1246 __ Jump(t9);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001247}
1248
1249
1250void JSEntryStub::Generate(MacroAssembler* masm) {
1251 Label invoke, handler_entry, exit;
1252 Isolate* isolate = masm->isolate();
1253
1254 // TODO(plind): unify the ABI description here.
1255 // Registers:
1256 // a0: entry address
1257 // a1: function
1258 // a2: receiver
1259 // a3: argc
1260 // a4 (a4): on mips64
1261
1262 // Stack:
1263 // 0 arg slots on mips64 (4 args slots on mips)
1264 // args -- in a4/a4 on mips64, on stack on mips
1265
1266 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1267
1268 // Save callee saved registers on the stack.
1269 __ MultiPush(kCalleeSaved | ra.bit());
1270
1271 // Save callee-saved FPU registers.
1272 __ MultiPushFPU(kCalleeSavedFPU);
1273 // Set up the reserved register for 0.0.
1274 __ Move(kDoubleRegZero, 0.0);
1275
1276 // Load argv in s0 register.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001277 __ mov(s0, a4); // 5th parameter in mips64 a4 (a4) register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001278
1279 __ InitializeRootRegister();
1280
1281 // We build an EntryFrame.
1282 __ li(a7, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1283 int marker = type();
1284 __ li(a6, Operand(Smi::FromInt(marker)));
1285 __ li(a5, Operand(Smi::FromInt(marker)));
1286 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate);
1287 __ li(a4, Operand(c_entry_fp));
1288 __ ld(a4, MemOperand(a4));
1289 __ Push(a7, a6, a5, a4);
1290 // Set up frame pointer for the frame to be pushed.
1291 __ daddiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1292
1293 // Registers:
1294 // a0: entry_address
1295 // a1: function
1296 // a2: receiver_pointer
1297 // a3: argc
1298 // s0: argv
1299 //
1300 // Stack:
1301 // caller fp |
1302 // function slot | entry frame
1303 // context slot |
1304 // bad fp (0xff...f) |
1305 // callee saved registers + ra
1306 // [ O32: 4 args slots]
1307 // args
1308
1309 // If this is the outermost JS call, set js_entry_sp value.
1310 Label non_outermost_js;
1311 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1312 __ li(a5, Operand(ExternalReference(js_entry_sp)));
1313 __ ld(a6, MemOperand(a5));
1314 __ Branch(&non_outermost_js, ne, a6, Operand(zero_reg));
1315 __ sd(fp, MemOperand(a5));
1316 __ li(a4, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1317 Label cont;
1318 __ b(&cont);
1319 __ nop(); // Branch delay slot nop.
1320 __ bind(&non_outermost_js);
1321 __ li(a4, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1322 __ bind(&cont);
1323 __ push(a4);
1324
1325 // Jump to a faked try block that does the invoke, with a faked catch
1326 // block that sets the pending exception.
1327 __ jmp(&invoke);
1328 __ bind(&handler_entry);
1329 handler_offset_ = handler_entry.pos();
1330 // Caught exception: Store result (exception) in the pending exception
1331 // field in the JSEnv and return a failure sentinel. Coming in here the
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001332 // fp will be invalid because the PushStackHandler below sets it to 0 to
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001333 // signal the existence of the JSEntry frame.
1334 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1335 isolate)));
1336 __ sd(v0, MemOperand(a4)); // We come back from 'invoke'. result is in v0.
1337 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1338 __ b(&exit); // b exposes branch delay slot.
1339 __ nop(); // Branch delay slot nop.
1340
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001341 // Invoke: Link this frame into the handler chain.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001342 __ bind(&invoke);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001343 __ PushStackHandler();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001344 // If an exception not caught by another handler occurs, this handler
1345 // returns control to the code after the bal(&invoke) above, which
1346 // restores all kCalleeSaved registers (including cp and fp) to their
1347 // saved values before returning a failure to C.
1348
1349 // Clear any pending exceptions.
1350 __ LoadRoot(a5, Heap::kTheHoleValueRootIndex);
1351 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1352 isolate)));
1353 __ sd(a5, MemOperand(a4));
1354
1355 // Invoke the function by calling through JS entry trampoline builtin.
1356 // Notice that we cannot store a reference to the trampoline code directly in
1357 // this stub, because runtime stubs are not traversed when doing GC.
1358
1359 // Registers:
1360 // a0: entry_address
1361 // a1: function
1362 // a2: receiver_pointer
1363 // a3: argc
1364 // s0: argv
1365 //
1366 // Stack:
1367 // handler frame
1368 // entry frame
1369 // callee saved registers + ra
1370 // [ O32: 4 args slots]
1371 // args
1372
1373 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1374 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1375 isolate);
1376 __ li(a4, Operand(construct_entry));
1377 } else {
1378 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1379 __ li(a4, Operand(entry));
1380 }
1381 __ ld(t9, MemOperand(a4)); // Deref address.
1382 // Call JSEntryTrampoline.
1383 __ daddiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1384 __ Call(t9);
1385
1386 // Unlink this frame from the handler chain.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001387 __ PopStackHandler();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001388
1389 __ bind(&exit); // v0 holds result
1390 // Check if the current stack frame is marked as the outermost JS frame.
1391 Label non_outermost_js_2;
1392 __ pop(a5);
1393 __ Branch(&non_outermost_js_2,
1394 ne,
1395 a5,
1396 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1397 __ li(a5, Operand(ExternalReference(js_entry_sp)));
1398 __ sd(zero_reg, MemOperand(a5));
1399 __ bind(&non_outermost_js_2);
1400
1401 // Restore the top frame descriptors from the stack.
1402 __ pop(a5);
1403 __ li(a4, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1404 isolate)));
1405 __ sd(a5, MemOperand(a4));
1406
1407 // Reset the stack to the callee saved registers.
1408 __ daddiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1409
1410 // Restore callee-saved fpu registers.
1411 __ MultiPopFPU(kCalleeSavedFPU);
1412
1413 // Restore callee saved registers from the stack.
1414 __ MultiPop(kCalleeSaved | ra.bit());
1415 // Return.
1416 __ Jump(ra);
1417}
1418
1419
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001420void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1421 // Return address is in ra.
1422 Label miss;
1423
1424 Register receiver = LoadDescriptor::ReceiverRegister();
1425 Register index = LoadDescriptor::NameRegister();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001426 Register scratch = a5;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001427 Register result = v0;
1428 DCHECK(!scratch.is(receiver) && !scratch.is(index));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001429 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001430
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001431 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1432 &miss, // When not a string.
1433 &miss, // When not a number.
1434 &miss, // When index out of range.
1435 STRING_INDEX_IS_ARRAY_INDEX,
1436 RECEIVER_IS_STRING);
1437 char_at_generator.GenerateFast(masm);
1438 __ Ret();
1439
1440 StubRuntimeCallHelper call_helper;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001441 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001442
1443 __ bind(&miss);
1444 PropertyAccessCompiler::TailCallBuiltin(
1445 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1446}
1447
1448
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001449void InstanceOfStub::Generate(MacroAssembler* masm) {
1450 Register const object = a1; // Object (lhs).
1451 Register const function = a0; // Function (rhs).
1452 Register const object_map = a2; // Map of {object}.
1453 Register const function_map = a3; // Map of {function}.
1454 Register const function_prototype = a4; // Prototype of {function}.
1455 Register const scratch = a5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001456
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001457 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1458 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001459
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001460 // Check if {object} is a smi.
1461 Label object_is_smi;
1462 __ JumpIfSmi(object, &object_is_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001463
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001464 // Lookup the {function} and the {object} map in the global instanceof cache.
1465 // Note: This is safe because we clear the global instanceof cache whenever
1466 // we change the prototype of any object.
1467 Label fast_case, slow_case;
1468 __ ld(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1469 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1470 __ Branch(&fast_case, ne, function, Operand(at));
1471 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1472 __ Branch(&fast_case, ne, object_map, Operand(at));
1473 __ Ret(USE_DELAY_SLOT);
1474 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001475
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001476 // If {object} is a smi we can safely return false if {function} is a JS
1477 // function, otherwise we have to miss to the runtime and throw an exception.
1478 __ bind(&object_is_smi);
1479 __ JumpIfSmi(function, &slow_case);
1480 __ GetObjectType(function, function_map, scratch);
1481 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1482 __ Ret(USE_DELAY_SLOT);
1483 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001484
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001485 // Fast-case: The {function} must be a valid JSFunction.
1486 __ bind(&fast_case);
1487 __ JumpIfSmi(function, &slow_case);
1488 __ GetObjectType(function, function_map, scratch);
1489 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001490
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001491 // Ensure that {function} has an instance prototype.
1492 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1493 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1494 __ Branch(&slow_case, ne, at, Operand(zero_reg));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001495
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001496 // Get the "prototype" (or initial map) of the {function}.
1497 __ ld(function_prototype,
1498 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1499 __ AssertNotSmi(function_prototype);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001500
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001501 // Resolve the prototype if the {function} has an initial map. Afterwards the
1502 // {function_prototype} will be either the JSReceiver prototype object or the
1503 // hole value, which means that no instances of the {function} were created so
1504 // far and hence we should return false.
1505 Label function_prototype_valid;
1506 __ GetObjectType(function_prototype, scratch, scratch);
1507 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1508 __ ld(function_prototype,
1509 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1510 __ bind(&function_prototype_valid);
1511 __ AssertNotSmi(function_prototype);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001512
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001513 // Update the global instanceof cache with the current {object} map and
1514 // {function}. The cached answer will be set when it is known below.
1515 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1516 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001517
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001518 // Loop through the prototype chain looking for the {function} prototype.
1519 // Assume true, and change to false if not found.
1520 Register const object_instance_type = function_map;
1521 Register const map_bit_field = function_map;
1522 Register const null = scratch;
1523 Register const result = v0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001524
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001525 Label done, loop, fast_runtime_fallback;
1526 __ LoadRoot(result, Heap::kTrueValueRootIndex);
1527 __ LoadRoot(null, Heap::kNullValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001528 __ bind(&loop);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001529
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001530 // Check if the object needs to be access checked.
1531 __ lbu(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset));
1532 __ And(map_bit_field, map_bit_field, Operand(1 << Map::kIsAccessCheckNeeded));
1533 __ Branch(&fast_runtime_fallback, ne, map_bit_field, Operand(zero_reg));
1534 // Check if the current object is a Proxy.
1535 __ lbu(object_instance_type,
1536 FieldMemOperand(object_map, Map::kInstanceTypeOffset));
1537 __ Branch(&fast_runtime_fallback, eq, object_instance_type,
1538 Operand(JS_PROXY_TYPE));
1539
1540 __ ld(object, FieldMemOperand(object_map, Map::kPrototypeOffset));
1541 __ Branch(&done, eq, object, Operand(function_prototype));
1542 __ Branch(USE_DELAY_SLOT, &loop, ne, object, Operand(null));
1543 __ ld(object_map,
1544 FieldMemOperand(object, HeapObject::kMapOffset)); // In delay slot.
1545 __ LoadRoot(result, Heap::kFalseValueRootIndex);
1546 __ bind(&done);
1547 __ Ret(USE_DELAY_SLOT);
1548 __ StoreRoot(result,
1549 Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1550
1551 // Found Proxy or access check needed: Call the runtime
1552 __ bind(&fast_runtime_fallback);
1553 __ Push(object, function_prototype);
1554 // Invalidate the instanceof cache.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001555 DCHECK(Smi::FromInt(0) == 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001556 __ StoreRoot(zero_reg, Heap::kInstanceofCacheFunctionRootIndex);
1557 __ TailCallRuntime(Runtime::kHasInPrototypeChain);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001558
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001559 // Slow-case: Call the %InstanceOf runtime function.
1560 __ bind(&slow_case);
1561 __ Push(object, function);
1562 __ TailCallRuntime(Runtime::kInstanceOf);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001563}
1564
1565
1566void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1567 Label miss;
1568 Register receiver = LoadDescriptor::ReceiverRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001569 // Ensure that the vector and slot registers won't be clobbered before
1570 // calling the miss handler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001571 DCHECK(!AreAliased(a4, a5, LoadWithVectorDescriptor::VectorRegister(),
1572 LoadWithVectorDescriptor::SlotRegister()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001573
1574 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, a4,
1575 a5, &miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001576 __ bind(&miss);
1577 PropertyAccessCompiler::TailCallBuiltin(
1578 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1579}
1580
1581
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001582void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1583 // Return address is in ra.
1584 Label slow;
1585
1586 Register receiver = LoadDescriptor::ReceiverRegister();
1587 Register key = LoadDescriptor::NameRegister();
1588
1589 // Check that the key is an array index, that is Uint32.
1590 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1591 __ Branch(&slow, ne, t0, Operand(zero_reg));
1592
1593 // Everything is fine, call runtime.
1594 __ Push(receiver, key); // Receiver, key.
1595
1596 // Perform tail call to the entry.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001597 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001598
1599 __ bind(&slow);
1600 PropertyAccessCompiler::TailCallBuiltin(
1601 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1602}
1603
1604
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001605void RegExpExecStub::Generate(MacroAssembler* masm) {
1606 // Just jump directly to runtime if native RegExp is not selected at compile
1607 // time or if regexp entry in generated code is turned off runtime switch or
1608 // at compilation.
1609#ifdef V8_INTERPRETED_REGEXP
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001610 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001611#else // V8_INTERPRETED_REGEXP
1612
1613 // Stack frame on entry.
1614 // sp[0]: last_match_info (expected JSArray)
1615 // sp[4]: previous index
1616 // sp[8]: subject string
1617 // sp[12]: JSRegExp object
1618
1619 const int kLastMatchInfoOffset = 0 * kPointerSize;
1620 const int kPreviousIndexOffset = 1 * kPointerSize;
1621 const int kSubjectOffset = 2 * kPointerSize;
1622 const int kJSRegExpOffset = 3 * kPointerSize;
1623
1624 Label runtime;
1625 // Allocation of registers for this function. These are in callee save
1626 // registers and will be preserved by the call to the native RegExp code, as
1627 // this code is called using the normal C calling convention. When calling
1628 // directly from generated code the native RegExp code will not do a GC and
1629 // therefore the content of these registers are safe to use after the call.
1630 // MIPS - using s0..s2, since we are not using CEntry Stub.
1631 Register subject = s0;
1632 Register regexp_data = s1;
1633 Register last_match_info_elements = s2;
1634
1635 // Ensure that a RegExp stack is allocated.
1636 ExternalReference address_of_regexp_stack_memory_address =
1637 ExternalReference::address_of_regexp_stack_memory_address(
1638 isolate());
1639 ExternalReference address_of_regexp_stack_memory_size =
1640 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1641 __ li(a0, Operand(address_of_regexp_stack_memory_size));
1642 __ ld(a0, MemOperand(a0, 0));
1643 __ Branch(&runtime, eq, a0, Operand(zero_reg));
1644
1645 // Check that the first argument is a JSRegExp object.
1646 __ ld(a0, MemOperand(sp, kJSRegExpOffset));
1647 STATIC_ASSERT(kSmiTag == 0);
1648 __ JumpIfSmi(a0, &runtime);
1649 __ GetObjectType(a0, a1, a1);
1650 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
1651
1652 // Check that the RegExp has been compiled (data contains a fixed array).
1653 __ ld(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
1654 if (FLAG_debug_code) {
1655 __ SmiTst(regexp_data, a4);
1656 __ Check(nz,
1657 kUnexpectedTypeForRegExpDataFixedArrayExpected,
1658 a4,
1659 Operand(zero_reg));
1660 __ GetObjectType(regexp_data, a0, a0);
1661 __ Check(eq,
1662 kUnexpectedTypeForRegExpDataFixedArrayExpected,
1663 a0,
1664 Operand(FIXED_ARRAY_TYPE));
1665 }
1666
1667 // regexp_data: RegExp data (FixedArray)
1668 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
1669 __ ld(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
1670 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
1671
1672 // regexp_data: RegExp data (FixedArray)
1673 // Check that the number of captures fit in the static offsets vector buffer.
1674 __ ld(a2,
1675 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1676 // Check (number_of_captures + 1) * 2 <= offsets vector size
1677 // Or number_of_captures * 2 <= offsets vector size - 2
1678 // Or number_of_captures <= offsets vector size / 2 - 1
1679 // Multiplying by 2 comes for free since a2 is smi-tagged.
1680 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
1681 int temp = Isolate::kJSRegexpStaticOffsetsVectorSize / 2 - 1;
1682 __ Branch(&runtime, hi, a2, Operand(Smi::FromInt(temp)));
1683
1684 // Reset offset for possibly sliced string.
1685 __ mov(t0, zero_reg);
1686 __ ld(subject, MemOperand(sp, kSubjectOffset));
1687 __ JumpIfSmi(subject, &runtime);
1688 __ mov(a3, subject); // Make a copy of the original subject string.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001689
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001690 // subject: subject string
1691 // a3: subject string
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001692 // regexp_data: RegExp data (FixedArray)
1693 // Handle subject string according to its encoding and representation:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001694 // (1) Sequential string? If yes, go to (4).
1695 // (2) Sequential or cons? If not, go to (5).
1696 // (3) Cons string. If the string is flat, replace subject with first string
1697 // and go to (1). Otherwise bail out to runtime.
1698 // (4) Sequential string. Load regexp code according to encoding.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001699 // (E) Carry on.
1700 /// [...]
1701
1702 // Deferred code at the end of the stub:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001703 // (5) Long external string? If not, go to (7).
1704 // (6) External string. Make it, offset-wise, look like a sequential string.
1705 // Go to (4).
1706 // (7) Short external string or not a string? If yes, bail out to runtime.
1707 // (8) Sliced string. Replace subject with parent. Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001708
Ben Murdoch097c5b22016-05-18 11:27:45 +01001709 Label check_underlying; // (1)
1710 Label seq_string; // (4)
1711 Label not_seq_nor_cons; // (5)
1712 Label external_string; // (6)
1713 Label not_long_external; // (7)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001714
Ben Murdoch097c5b22016-05-18 11:27:45 +01001715 __ bind(&check_underlying);
1716 __ ld(a2, FieldMemOperand(subject, HeapObject::kMapOffset));
1717 __ lbu(a0, FieldMemOperand(a2, Map::kInstanceTypeOffset));
1718
1719 // (1) Sequential string? If yes, go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001720 __ And(a1,
1721 a0,
1722 Operand(kIsNotStringMask |
1723 kStringRepresentationMask |
1724 kShortExternalStringMask));
1725 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001726 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001727
Ben Murdoch097c5b22016-05-18 11:27:45 +01001728 // (2) Sequential or cons? If not, go to (5).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001729 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
1730 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
1731 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
1732 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001733 // Go to (5).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001734 __ Branch(&not_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
1735
1736 // (3) Cons string. Check that it's flat.
1737 // Replace subject with first string and reload instance type.
1738 __ ld(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
1739 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
1740 __ Branch(&runtime, ne, a0, Operand(a1));
1741 __ ld(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001742 __ jmp(&check_underlying);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001743
Ben Murdoch097c5b22016-05-18 11:27:45 +01001744 // (4) Sequential string. Load regexp code according to encoding.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001745 __ bind(&seq_string);
1746 // subject: sequential subject string (or look-alike, external string)
1747 // a3: original subject string
1748 // Load previous index and check range before a3 is overwritten. We have to
1749 // use a3 instead of subject here because subject might have been only made
1750 // to look like a sequential string when it actually is an external string.
1751 __ ld(a1, MemOperand(sp, kPreviousIndexOffset));
1752 __ JumpIfNotSmi(a1, &runtime);
1753 __ ld(a3, FieldMemOperand(a3, String::kLengthOffset));
1754 __ Branch(&runtime, ls, a3, Operand(a1));
1755 __ SmiUntag(a1);
1756
1757 STATIC_ASSERT(kStringEncodingMask == 4);
1758 STATIC_ASSERT(kOneByteStringTag == 4);
1759 STATIC_ASSERT(kTwoByteStringTag == 0);
1760 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one_byte.
1761 __ ld(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
1762 __ dsra(a3, a0, 2); // a3 is 1 for one_byte, 0 for UC16 (used below).
1763 __ ld(a5, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
1764 __ Movz(t9, a5, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
1765
1766 // (E) Carry on. String handling is done.
1767 // t9: irregexp code
1768 // Check that the irregexp code has been generated for the actual string
1769 // encoding. If it has, the field contains a code object otherwise it contains
1770 // a smi (code flushing support).
1771 __ JumpIfSmi(t9, &runtime);
1772
1773 // a1: previous index
1774 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
1775 // t9: code
1776 // subject: Subject string
1777 // regexp_data: RegExp data (FixedArray)
1778 // All checks done. Now push arguments for native regexp code.
1779 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
1780 1, a0, a2);
1781
1782 // Isolates: note we add an additional parameter here (isolate pointer).
1783 const int kRegExpExecuteArguments = 9;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001784 const int kParameterRegisters = 8;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001785 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
1786
1787 // Stack pointer now points to cell where return address is to be written.
1788 // Arguments are before that on the stack or in registers, meaning we
1789 // treat the return address as argument 5. Thus every argument after that
1790 // needs to be shifted back by 1. Since DirectCEntryStub will handle
1791 // allocating space for the c argument slots, we don't need to calculate
1792 // that into the argument positions on the stack. This is how the stack will
1793 // look (sp meaning the value of sp at this moment):
1794 // Abi n64:
1795 // [sp + 1] - Argument 9
1796 // [sp + 0] - saved ra
1797 // Abi O32:
1798 // [sp + 5] - Argument 9
1799 // [sp + 4] - Argument 8
1800 // [sp + 3] - Argument 7
1801 // [sp + 2] - Argument 6
1802 // [sp + 1] - Argument 5
1803 // [sp + 0] - saved ra
1804
Ben Murdoch097c5b22016-05-18 11:27:45 +01001805 // Argument 9: Pass current isolate address.
1806 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
1807 __ sd(a0, MemOperand(sp, 1 * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001808
Ben Murdoch097c5b22016-05-18 11:27:45 +01001809 // Argument 8: Indicate that this is a direct call from JavaScript.
1810 __ li(a7, Operand(1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001811
Ben Murdoch097c5b22016-05-18 11:27:45 +01001812 // Argument 7: Start (high end) of backtracking stack memory area.
1813 __ li(a0, Operand(address_of_regexp_stack_memory_address));
1814 __ ld(a0, MemOperand(a0, 0));
1815 __ li(a2, Operand(address_of_regexp_stack_memory_size));
1816 __ ld(a2, MemOperand(a2, 0));
1817 __ daddu(a6, a0, a2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001818
Ben Murdoch097c5b22016-05-18 11:27:45 +01001819 // Argument 6: Set the number of capture registers to zero to force global
1820 // regexps to behave as non-global. This does not affect non-global regexps.
1821 __ mov(a5, zero_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001822
Ben Murdoch097c5b22016-05-18 11:27:45 +01001823 // Argument 5: static offsets vector buffer.
1824 __ li(
1825 a4,
1826 Operand(ExternalReference::address_of_static_offsets_vector(isolate())));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001827
1828 // For arguments 4 and 3 get string length, calculate start of string data
1829 // and calculate the shift of the index (0 for one_byte and 1 for two byte).
1830 __ Daddu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
1831 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
1832 // Load the length from the original subject string from the previous stack
1833 // frame. Therefore we have to use fp, which points exactly to two pointer
1834 // sizes below the previous sp. (Because creating a new stack frame pushes
1835 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
1836 __ ld(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
1837 // If slice offset is not 0, load the length from the original sliced string.
1838 // Argument 4, a3: End of string data
1839 // Argument 3, a2: Start of string data
1840 // Prepare start and end index of the input.
1841 __ dsllv(t1, t0, a3);
1842 __ daddu(t0, t2, t1);
1843 __ dsllv(t1, a1, a3);
1844 __ daddu(a2, t0, t1);
1845
1846 __ ld(t2, FieldMemOperand(subject, String::kLengthOffset));
1847
1848 __ SmiUntag(t2);
1849 __ dsllv(t1, t2, a3);
1850 __ daddu(a3, t0, t1);
1851 // Argument 2 (a1): Previous index.
1852 // Already there
1853
1854 // Argument 1 (a0): Subject string.
1855 __ mov(a0, subject);
1856
1857 // Locate the code entry and call it.
1858 __ Daddu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
1859 DirectCEntryStub stub(isolate());
1860 stub.GenerateCall(masm, t9);
1861
1862 __ LeaveExitFrame(false, no_reg, true);
1863
1864 // v0: result
1865 // subject: subject string (callee saved)
1866 // regexp_data: RegExp data (callee saved)
1867 // last_match_info_elements: Last match info elements (callee saved)
1868 // Check the result.
1869 Label success;
1870 __ Branch(&success, eq, v0, Operand(1));
1871 // We expect exactly one result since we force the called regexp to behave
1872 // as non-global.
1873 Label failure;
1874 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
1875 // If not exception it can only be retry. Handle that in the runtime system.
1876 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
1877 // Result must now be exception. If there is no pending exception already a
1878 // stack overflow (on the backtrack stack) was detected in RegExp code but
1879 // haven't created the exception yet. Handle that in the runtime system.
1880 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
1881 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
1882 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1883 isolate())));
1884 __ ld(v0, MemOperand(a2, 0));
1885 __ Branch(&runtime, eq, v0, Operand(a1));
1886
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001887 // For exception, throw the exception again.
1888 __ TailCallRuntime(Runtime::kRegExpExecReThrow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001889
1890 __ bind(&failure);
1891 // For failure and exception return null.
1892 __ li(v0, Operand(isolate()->factory()->null_value()));
1893 __ DropAndRet(4);
1894
1895 // Process the result from the native regexp code.
1896 __ bind(&success);
1897
1898 __ lw(a1, UntagSmiFieldMemOperand(
1899 regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
1900 // Calculate number of capture registers (number_of_captures + 1) * 2.
1901 __ Daddu(a1, a1, Operand(1));
1902 __ dsll(a1, a1, 1); // Multiply by 2.
1903
1904 __ ld(a0, MemOperand(sp, kLastMatchInfoOffset));
1905 __ JumpIfSmi(a0, &runtime);
1906 __ GetObjectType(a0, a2, a2);
1907 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
1908 // Check that the JSArray is in fast case.
1909 __ ld(last_match_info_elements,
1910 FieldMemOperand(a0, JSArray::kElementsOffset));
1911 __ ld(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
1912 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
1913 __ Branch(&runtime, ne, a0, Operand(at));
1914 // Check that the last match info has space for the capture registers and the
1915 // additional information.
1916 __ ld(a0,
1917 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
1918 __ Daddu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
1919
1920 __ SmiUntag(at, a0);
1921 __ Branch(&runtime, gt, a2, Operand(at));
1922
1923 // a1: number of capture registers
1924 // subject: subject string
1925 // Store the capture count.
1926 __ SmiTag(a2, a1); // To smi.
1927 __ sd(a2, FieldMemOperand(last_match_info_elements,
1928 RegExpImpl::kLastCaptureCountOffset));
1929 // Store last subject and last input.
1930 __ sd(subject,
1931 FieldMemOperand(last_match_info_elements,
1932 RegExpImpl::kLastSubjectOffset));
1933 __ mov(a2, subject);
1934 __ RecordWriteField(last_match_info_elements,
1935 RegExpImpl::kLastSubjectOffset,
1936 subject,
1937 a7,
1938 kRAHasNotBeenSaved,
1939 kDontSaveFPRegs);
1940 __ mov(subject, a2);
1941 __ sd(subject,
1942 FieldMemOperand(last_match_info_elements,
1943 RegExpImpl::kLastInputOffset));
1944 __ RecordWriteField(last_match_info_elements,
1945 RegExpImpl::kLastInputOffset,
1946 subject,
1947 a7,
1948 kRAHasNotBeenSaved,
1949 kDontSaveFPRegs);
1950
1951 // Get the static offsets vector filled by the native regexp code.
1952 ExternalReference address_of_static_offsets_vector =
1953 ExternalReference::address_of_static_offsets_vector(isolate());
1954 __ li(a2, Operand(address_of_static_offsets_vector));
1955
1956 // a1: number of capture registers
1957 // a2: offsets vector
1958 Label next_capture, done;
1959 // Capture register counter starts from number of capture registers and
1960 // counts down until wrapping after zero.
1961 __ Daddu(a0,
1962 last_match_info_elements,
1963 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
1964 __ bind(&next_capture);
1965 __ Dsubu(a1, a1, Operand(1));
1966 __ Branch(&done, lt, a1, Operand(zero_reg));
1967 // Read the value from the static offsets vector buffer.
1968 __ lw(a3, MemOperand(a2, 0));
1969 __ daddiu(a2, a2, kIntSize);
1970 // Store the smi value in the last match info.
1971 __ SmiTag(a3);
1972 __ sd(a3, MemOperand(a0, 0));
1973 __ Branch(&next_capture, USE_DELAY_SLOT);
1974 __ daddiu(a0, a0, kPointerSize); // In branch delay slot.
1975
1976 __ bind(&done);
1977
1978 // Return last match info.
1979 __ ld(v0, MemOperand(sp, kLastMatchInfoOffset));
1980 __ DropAndRet(4);
1981
1982 // Do the runtime call to execute the regexp.
1983 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001984 __ TailCallRuntime(Runtime::kRegExpExec);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001985
1986 // Deferred code for string handling.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001987 // (5) Long external string? If not, go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001988 __ bind(&not_seq_nor_cons);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001989 // Go to (7).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001990 __ Branch(&not_long_external, gt, a1, Operand(kExternalStringTag));
1991
Ben Murdoch097c5b22016-05-18 11:27:45 +01001992 // (6) External string. Make it, offset-wise, look like a sequential string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001993 __ bind(&external_string);
1994 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
1995 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
1996 if (FLAG_debug_code) {
1997 // Assert that we do not have a cons or slice (indirect strings) here.
1998 // Sequential strings have already been ruled out.
1999 __ And(at, a0, Operand(kIsIndirectStringMask));
2000 __ Assert(eq,
2001 kExternalStringExpectedButNotFound,
2002 at,
2003 Operand(zero_reg));
2004 }
2005 __ ld(subject,
2006 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2007 // Move the pointer so that offset-wise, it looks like a sequential string.
2008 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2009 __ Dsubu(subject,
2010 subject,
2011 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002012 __ jmp(&seq_string); // Go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002013
Ben Murdoch097c5b22016-05-18 11:27:45 +01002014 // (7) Short external string or not a string? If yes, bail out to runtime.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002015 __ bind(&not_long_external);
2016 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2017 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2018 __ Branch(&runtime, ne, at, Operand(zero_reg));
2019
Ben Murdoch097c5b22016-05-18 11:27:45 +01002020 // (8) Sliced string. Replace subject with parent. Go to (4).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002021 // Load offset into t0 and replace subject string with parent.
2022 __ ld(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2023 __ SmiUntag(t0);
2024 __ ld(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002025 __ jmp(&check_underlying); // Go to (1).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002026#endif // V8_INTERPRETED_REGEXP
2027}
2028
2029
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002030static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
2031 // a0 : number of arguments to the construct function
2032 // a2 : feedback vector
2033 // a3 : slot in feedback vector (Smi)
2034 // a1 : the function to call
2035 FrameScope scope(masm, StackFrame::INTERNAL);
2036 const RegList kSavedRegs = 1 << 4 | // a0
2037 1 << 5 | // a1
2038 1 << 6 | // a2
2039 1 << 7; // a3
2040
2041
2042 // Number-of-arguments register must be smi-tagged to call out.
2043 __ SmiTag(a0);
2044 __ MultiPush(kSavedRegs);
2045
2046 __ CallStub(stub);
2047
2048 __ MultiPop(kSavedRegs);
2049 __ SmiUntag(a0);
2050}
2051
2052
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002053static void GenerateRecordCallTarget(MacroAssembler* masm) {
2054 // Cache the called function in a feedback vector slot. Cache states
2055 // are uninitialized, monomorphic (indicated by a JSFunction), and
2056 // megamorphic.
2057 // a0 : number of arguments to the construct function
2058 // a1 : the function to call
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002059 // a2 : feedback vector
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002060 // a3 : slot in feedback vector (Smi)
2061 Label initialize, done, miss, megamorphic, not_array_function;
2062
2063 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2064 masm->isolate()->heap()->megamorphic_symbol());
2065 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2066 masm->isolate()->heap()->uninitialized_symbol());
2067
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002068 // Load the cache state into a5.
2069 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2070 __ Daddu(a5, a2, Operand(a5));
2071 __ ld(a5, FieldMemOperand(a5, FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002072
2073 // A monomorphic cache hit or an already megamorphic state: invoke the
2074 // function without changing the state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002075 // We don't know if a5 is a WeakCell or a Symbol, but it's harmless to read at
2076 // this position in a symbol (see static asserts in type-feedback-vector.h).
2077 Label check_allocation_site;
2078 Register feedback_map = a6;
2079 Register weak_value = t0;
2080 __ ld(weak_value, FieldMemOperand(a5, WeakCell::kValueOffset));
2081 __ Branch(&done, eq, a1, Operand(weak_value));
2082 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2083 __ Branch(&done, eq, a5, Operand(at));
2084 __ ld(feedback_map, FieldMemOperand(a5, HeapObject::kMapOffset));
2085 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2086 __ Branch(&check_allocation_site, ne, feedback_map, Operand(at));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002087
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002088 // If the weak cell is cleared, we have a new chance to become monomorphic.
2089 __ JumpIfSmi(weak_value, &initialize);
2090 __ jmp(&megamorphic);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002091
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002092 __ bind(&check_allocation_site);
2093 // If we came here, we need to see if we are the array function.
2094 // If we didn't have a matching function, and we didn't find the megamorph
2095 // sentinel, then we have in the slot either some other function or an
2096 // AllocationSite.
2097 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2098 __ Branch(&miss, ne, feedback_map, Operand(at));
2099
2100 // Make sure the function is the Array() function
2101 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, a5);
2102 __ Branch(&megamorphic, ne, a1, Operand(a5));
2103 __ jmp(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002104
2105 __ bind(&miss);
2106
2107 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2108 // megamorphic.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002109 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002110 __ Branch(&initialize, eq, a5, Operand(at));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002111 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2112 // write-barrier is needed.
2113 __ bind(&megamorphic);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002114 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2115 __ Daddu(a5, a2, Operand(a5));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002116 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002117 __ sd(at, FieldMemOperand(a5, FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002118 __ jmp(&done);
2119
2120 // An uninitialized cache is patched with the function.
2121 __ bind(&initialize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002122 // Make sure the function is the Array() function.
2123 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, a5);
2124 __ Branch(&not_array_function, ne, a1, Operand(a5));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002125
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002126 // The target function is the Array constructor,
2127 // Create an AllocationSite if we don't already have it, store it in the
2128 // slot.
2129 CreateAllocationSiteStub create_stub(masm->isolate());
2130 CallStubInRecordCallTarget(masm, &create_stub);
2131 __ Branch(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002132
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002133 __ bind(&not_array_function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002134
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002135 CreateWeakCellStub weak_cell_stub(masm->isolate());
2136 CallStubInRecordCallTarget(masm, &weak_cell_stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002137 __ bind(&done);
2138}
2139
2140
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002141void CallConstructStub::Generate(MacroAssembler* masm) {
2142 // a0 : number of arguments
2143 // a1 : the function to call
2144 // a2 : feedback vector
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002145 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2146
2147 Label non_function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002148 // Check that the function is not a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002149 __ JumpIfSmi(a1, &non_function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002150 // Check that the function is a JSFunction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002151 __ GetObjectType(a1, a5, a5);
2152 __ Branch(&non_function, ne, a5, Operand(JS_FUNCTION_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002153
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002154 GenerateRecordCallTarget(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002155
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002156 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2157 __ Daddu(a5, a2, at);
2158 Label feedback_register_initialized;
2159 // Put the AllocationSite from the feedback vector into a2, or undefined.
2160 __ ld(a2, FieldMemOperand(a5, FixedArray::kHeaderSize));
2161 __ ld(a5, FieldMemOperand(a2, AllocationSite::kMapOffset));
2162 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2163 __ Branch(&feedback_register_initialized, eq, a5, Operand(at));
2164 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2165 __ bind(&feedback_register_initialized);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002166
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002167 __ AssertUndefinedOrAllocationSite(a2, a5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002168
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002169 // Pass function as new target.
2170 __ mov(a3, a1);
2171
2172 // Tail call to the function-specific construct stub (still in the caller
2173 // context at this point).
2174 __ ld(a4, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2175 __ ld(a4, FieldMemOperand(a4, SharedFunctionInfo::kConstructStubOffset));
2176 __ Daddu(at, a4, Operand(Code::kHeaderSize - kHeapObjectTag));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002177 __ Jump(at);
2178
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002179 __ bind(&non_function);
2180 __ mov(a3, a1);
2181 __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002182}
2183
2184
2185// StringCharCodeAtGenerator.
2186void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2187 DCHECK(!a4.is(index_));
2188 DCHECK(!a4.is(result_));
2189 DCHECK(!a4.is(object_));
2190
2191 // If the receiver is a smi trigger the non-string case.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002192 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2193 __ JumpIfSmi(object_, receiver_not_string_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002194
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002195 // Fetch the instance type of the receiver into result register.
2196 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2197 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2198 // If the receiver is not a string trigger the non-string case.
2199 __ And(a4, result_, Operand(kIsNotStringMask));
2200 __ Branch(receiver_not_string_, ne, a4, Operand(zero_reg));
2201 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002202
2203 // If the index is non-smi trigger the non-smi case.
2204 __ JumpIfNotSmi(index_, &index_not_smi_);
2205
2206 __ bind(&got_smi_index_);
2207
2208 // Check for index out of range.
2209 __ ld(a4, FieldMemOperand(object_, String::kLengthOffset));
2210 __ Branch(index_out_of_range_, ls, a4, Operand(index_));
2211
2212 __ SmiUntag(index_);
2213
2214 StringCharLoadGenerator::Generate(masm,
2215 object_,
2216 index_,
2217 result_,
2218 &call_runtime_);
2219
2220 __ SmiTag(result_);
2221 __ bind(&exit_);
2222}
2223
2224
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002225void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002226 // a1 - function
2227 // a3 - slot id
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002228 // a2 - vector
2229 // a4 - allocation site (loaded from vector[slot])
2230 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, at);
2231 __ Branch(miss, ne, a1, Operand(at));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002232
2233 __ li(a0, Operand(arg_count()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002234
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002235 // Increment the call count for monomorphic function calls.
2236 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2237 __ Daddu(a3, a2, Operand(t0));
2238 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2239 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2240 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002241
2242 __ mov(a2, a4);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002243 __ mov(a3, a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002244 ArrayConstructorStub stub(masm->isolate(), arg_count());
2245 __ TailCallStub(&stub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002246}
2247
2248
2249void CallICStub::Generate(MacroAssembler* masm) {
2250 // a1 - function
2251 // a3 - slot id (Smi)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002252 // a2 - vector
2253 Label extra_checks_or_miss, call, call_function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002254 int argc = arg_count();
2255 ParameterCount actual(argc);
2256
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002257 // The checks. First, does r1 match the recorded monomorphic target?
2258 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
2259 __ Daddu(a4, a2, Operand(a4));
2260 __ ld(a4, FieldMemOperand(a4, FixedArray::kHeaderSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002261
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002262 // We don't know that we have a weak cell. We might have a private symbol
2263 // or an AllocationSite, but the memory is safe to examine.
2264 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2265 // FixedArray.
2266 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2267 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2268 // computed, meaning that it can't appear to be a pointer. If the low bit is
2269 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2270 // to be a pointer.
2271 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2272 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2273 WeakCell::kValueOffset &&
2274 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002275
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002276 __ ld(a5, FieldMemOperand(a4, WeakCell::kValueOffset));
2277 __ Branch(&extra_checks_or_miss, ne, a1, Operand(a5));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002278
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002279 // The compare above could have been a SMI/SMI comparison. Guard against this
2280 // convincing us that we have a monomorphic JSFunction.
2281 __ JumpIfSmi(a1, &extra_checks_or_miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002282
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002283 // Increment the call count for monomorphic function calls.
2284 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2285 __ Daddu(a3, a2, Operand(t0));
2286 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2287 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2288 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002289
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002290 __ bind(&call_function);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002291 __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(),
2292 tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002293 RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg),
2294 USE_DELAY_SLOT);
2295 __ li(a0, Operand(argc)); // In delay slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002296
2297 __ bind(&extra_checks_or_miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002298 Label uninitialized, miss, not_allocation_site;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002299
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002300 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002301 __ Branch(&call, eq, a4, Operand(at));
2302
2303 // Verify that a4 contains an AllocationSite
2304 __ ld(a5, FieldMemOperand(a4, HeapObject::kMapOffset));
2305 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2306 __ Branch(&not_allocation_site, ne, a5, Operand(at));
2307
2308 HandleArrayCase(masm, &miss);
2309
2310 __ bind(&not_allocation_site);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002311
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002312 // The following cases attempt to handle MISS cases without going to the
2313 // runtime.
2314 if (FLAG_trace_ic) {
2315 __ Branch(&miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002316 }
2317
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002318 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2319 __ Branch(&uninitialized, eq, a4, Operand(at));
2320
2321 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2322 // to handle it here. More complex cases are dealt with in the runtime.
2323 __ AssertNotSmi(a4);
2324 __ GetObjectType(a4, a5, a5);
2325 __ Branch(&miss, ne, a5, Operand(JS_FUNCTION_TYPE));
2326 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
2327 __ Daddu(a4, a2, Operand(a4));
2328 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2329 __ sd(at, FieldMemOperand(a4, FixedArray::kHeaderSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002330
2331 __ bind(&call);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002332 __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002333 RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg),
2334 USE_DELAY_SLOT);
2335 __ li(a0, Operand(argc)); // In delay slot.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002336
2337 __ bind(&uninitialized);
2338
2339 // We are going monomorphic, provided we actually have a JSFunction.
2340 __ JumpIfSmi(a1, &miss);
2341
2342 // Goto miss case if we do not have a function.
2343 __ GetObjectType(a1, a4, a4);
2344 __ Branch(&miss, ne, a4, Operand(JS_FUNCTION_TYPE));
2345
2346 // Make sure the function is not the Array() function, which requires special
2347 // behavior on MISS.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002348 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, a4);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002349 __ Branch(&miss, eq, a1, Operand(a4));
2350
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002351 // Make sure the function belongs to the same native context.
2352 __ ld(t0, FieldMemOperand(a1, JSFunction::kContextOffset));
2353 __ ld(t0, ContextMemOperand(t0, Context::NATIVE_CONTEXT_INDEX));
2354 __ ld(t1, NativeContextMemOperand());
2355 __ Branch(&miss, ne, t0, Operand(t1));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002356
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002357 // Initialize the call counter.
2358 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2359 __ Daddu(at, a2, Operand(at));
2360 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2361 __ sd(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002362
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002363 // Store the function. Use a stub since we need a frame for allocation.
2364 // a2 - vector
2365 // a3 - slot
2366 // a1 - function
2367 {
2368 FrameScope scope(masm, StackFrame::INTERNAL);
2369 CreateWeakCellStub create_stub(masm->isolate());
2370 __ Push(a1);
2371 __ CallStub(&create_stub);
2372 __ Pop(a1);
2373 }
2374
2375 __ Branch(&call_function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002376
2377 // We are here because tracing is on or we encountered a MISS case we can't
2378 // handle here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002379 __ bind(&miss);
2380 GenerateMiss(masm);
2381
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002382 __ Branch(&call);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002383}
2384
2385
2386void CallICStub::GenerateMiss(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002387 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002388
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002389 // Push the receiver and the function and feedback info.
2390 __ Push(a1, a2, a3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002391
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002392 // Call the entry.
2393 __ CallRuntime(Runtime::kCallIC_Miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002394
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002395 // Move result to a1 and exit the internal frame.
2396 __ mov(a1, v0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002397}
2398
2399
2400void StringCharCodeAtGenerator::GenerateSlow(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002401 MacroAssembler* masm, EmbedMode embed_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002402 const RuntimeCallHelper& call_helper) {
2403 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2404
2405 // Index is not a smi.
2406 __ bind(&index_not_smi_);
2407 // If index is a heap number, try converting it to an integer.
2408 __ CheckMap(index_,
2409 result_,
2410 Heap::kHeapNumberMapRootIndex,
2411 index_not_number_,
2412 DONT_DO_SMI_CHECK);
2413 call_helper.BeforeCall(masm);
2414 // Consumed by runtime conversion function:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002415 if (embed_mode == PART_OF_IC_HANDLER) {
2416 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2417 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2418 } else {
2419 __ Push(object_, index_);
2420 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002421 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002422 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002423 } else {
2424 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2425 // NumberToSmi discards numbers that are not exact integers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002426 __ CallRuntime(Runtime::kNumberToSmi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002427 }
2428
2429 // Save the conversion result before the pop instructions below
2430 // have a chance to overwrite it.
2431
2432 __ Move(index_, v0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002433 if (embed_mode == PART_OF_IC_HANDLER) {
2434 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2435 LoadWithVectorDescriptor::SlotRegister(), object_);
2436 } else {
2437 __ pop(object_);
2438 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002439 // Reload the instance type.
2440 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2441 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2442 call_helper.AfterCall(masm);
2443 // If index is still not a smi, it must be out of range.
2444 __ JumpIfNotSmi(index_, index_out_of_range_);
2445 // Otherwise, return to the fast path.
2446 __ Branch(&got_smi_index_);
2447
2448 // Call runtime. We get here when the receiver is a string and the
2449 // index is a number, but the code of getting the actual character
2450 // is too complex (e.g., when the string needs to be flattened).
2451 __ bind(&call_runtime_);
2452 call_helper.BeforeCall(masm);
2453 __ SmiTag(index_);
2454 __ Push(object_, index_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002455 __ CallRuntime(Runtime::kStringCharCodeAtRT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002456
2457 __ Move(result_, v0);
2458
2459 call_helper.AfterCall(masm);
2460 __ jmp(&exit_);
2461
2462 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2463}
2464
2465
2466// -------------------------------------------------------------------------
2467// StringCharFromCodeGenerator
2468
2469void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2470 // Fast case of Heap::LookupSingleCharacterStringFromCode.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002471 __ JumpIfNotSmi(code_, &slow_case_);
2472 __ Branch(&slow_case_, hi, code_,
2473 Operand(Smi::FromInt(String::kMaxOneByteCharCode)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002474
2475 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
2476 // At this point code register contains smi tagged one_byte char code.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002477 __ SmiScale(at, code_, kPointerSizeLog2);
2478 __ Daddu(result_, result_, at);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002479 __ ld(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002480 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
2481 __ Branch(&slow_case_, eq, result_, Operand(at));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002482 __ bind(&exit_);
2483}
2484
2485
2486void StringCharFromCodeGenerator::GenerateSlow(
2487 MacroAssembler* masm,
2488 const RuntimeCallHelper& call_helper) {
2489 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2490
2491 __ bind(&slow_case_);
2492 call_helper.BeforeCall(masm);
2493 __ push(code_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002494 __ CallRuntime(Runtime::kStringCharFromCode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002495 __ Move(result_, v0);
2496
2497 call_helper.AfterCall(masm);
2498 __ Branch(&exit_);
2499
2500 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2501}
2502
2503
2504enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
2505
2506
2507void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2508 Register dest,
2509 Register src,
2510 Register count,
2511 Register scratch,
2512 String::Encoding encoding) {
2513 if (FLAG_debug_code) {
2514 // Check that destination is word aligned.
2515 __ And(scratch, dest, Operand(kPointerAlignmentMask));
2516 __ Check(eq,
2517 kDestinationOfCopyNotAligned,
2518 scratch,
2519 Operand(zero_reg));
2520 }
2521
2522 // Assumes word reads and writes are little endian.
2523 // Nothing to do for zero characters.
2524 Label done;
2525
2526 if (encoding == String::TWO_BYTE_ENCODING) {
2527 __ Daddu(count, count, count);
2528 }
2529
2530 Register limit = count; // Read until dest equals this.
2531 __ Daddu(limit, dest, Operand(count));
2532
2533 Label loop_entry, loop;
2534 // Copy bytes from src to dest until dest hits limit.
2535 __ Branch(&loop_entry);
2536 __ bind(&loop);
2537 __ lbu(scratch, MemOperand(src));
2538 __ daddiu(src, src, 1);
2539 __ sb(scratch, MemOperand(dest));
2540 __ daddiu(dest, dest, 1);
2541 __ bind(&loop_entry);
2542 __ Branch(&loop, lt, dest, Operand(limit));
2543
2544 __ bind(&done);
2545}
2546
2547
2548void SubStringStub::Generate(MacroAssembler* masm) {
2549 Label runtime;
2550 // Stack frame on entry.
2551 // ra: return address
2552 // sp[0]: to
2553 // sp[4]: from
2554 // sp[8]: string
2555
2556 // This stub is called from the native-call %_SubString(...), so
2557 // nothing can be assumed about the arguments. It is tested that:
2558 // "string" is a sequential string,
2559 // both "from" and "to" are smis, and
2560 // 0 <= from <= to <= string.length.
2561 // If any of these assumptions fail, we call the runtime system.
2562
2563 const int kToOffset = 0 * kPointerSize;
2564 const int kFromOffset = 1 * kPointerSize;
2565 const int kStringOffset = 2 * kPointerSize;
2566
2567 __ ld(a2, MemOperand(sp, kToOffset));
2568 __ ld(a3, MemOperand(sp, kFromOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002569
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002570 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002571
2572 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
2573 // safe in this case.
2574 __ JumpIfNotSmi(a2, &runtime);
2575 __ JumpIfNotSmi(a3, &runtime);
2576 // Both a2 and a3 are untagged integers.
2577
2578 __ SmiUntag(a2, a2);
2579 __ SmiUntag(a3, a3);
2580 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
2581
2582 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
2583 __ Dsubu(a2, a2, a3);
2584
2585 // Make sure first argument is a string.
2586 __ ld(v0, MemOperand(sp, kStringOffset));
2587 __ JumpIfSmi(v0, &runtime);
2588 __ ld(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
2589 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2590 __ And(a4, a1, Operand(kIsNotStringMask));
2591
2592 __ Branch(&runtime, ne, a4, Operand(zero_reg));
2593
2594 Label single_char;
2595 __ Branch(&single_char, eq, a2, Operand(1));
2596
2597 // Short-cut for the case of trivial substring.
2598 Label return_v0;
2599 // v0: original string
2600 // a2: result string length
2601 __ ld(a4, FieldMemOperand(v0, String::kLengthOffset));
2602 __ SmiUntag(a4);
2603 // Return original string.
2604 __ Branch(&return_v0, eq, a2, Operand(a4));
2605 // Longer than original string's length or negative: unsafe arguments.
2606 __ Branch(&runtime, hi, a2, Operand(a4));
2607 // Shorter than original string's length: an actual substring.
2608
2609 // Deal with different string types: update the index if necessary
2610 // and put the underlying string into a5.
2611 // v0: original string
2612 // a1: instance type
2613 // a2: length
2614 // a3: from index (untagged)
2615 Label underlying_unpacked, sliced_string, seq_or_external_string;
2616 // If the string is not indirect, it can only be sequential or external.
2617 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2618 STATIC_ASSERT(kIsIndirectStringMask != 0);
2619 __ And(a4, a1, Operand(kIsIndirectStringMask));
2620 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, a4, Operand(zero_reg));
2621 // a4 is used as a scratch register and can be overwritten in either case.
2622 __ And(a4, a1, Operand(kSlicedNotConsMask));
2623 __ Branch(&sliced_string, ne, a4, Operand(zero_reg));
2624 // Cons string. Check whether it is flat, then fetch first part.
2625 __ ld(a5, FieldMemOperand(v0, ConsString::kSecondOffset));
2626 __ LoadRoot(a4, Heap::kempty_stringRootIndex);
2627 __ Branch(&runtime, ne, a5, Operand(a4));
2628 __ ld(a5, FieldMemOperand(v0, ConsString::kFirstOffset));
2629 // Update instance type.
2630 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
2631 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2632 __ jmp(&underlying_unpacked);
2633
2634 __ bind(&sliced_string);
2635 // Sliced string. Fetch parent and correct start index by offset.
2636 __ ld(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
2637 __ ld(a4, FieldMemOperand(v0, SlicedString::kOffsetOffset));
2638 __ SmiUntag(a4); // Add offset to index.
2639 __ Daddu(a3, a3, a4);
2640 // Update instance type.
2641 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
2642 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2643 __ jmp(&underlying_unpacked);
2644
2645 __ bind(&seq_or_external_string);
2646 // Sequential or external string. Just move string to the expected register.
2647 __ mov(a5, v0);
2648
2649 __ bind(&underlying_unpacked);
2650
2651 if (FLAG_string_slices) {
2652 Label copy_routine;
2653 // a5: underlying subject string
2654 // a1: instance type of underlying subject string
2655 // a2: length
2656 // a3: adjusted start index (untagged)
2657 // Short slice. Copy instead of slicing.
2658 __ Branch(&copy_routine, lt, a2, Operand(SlicedString::kMinLength));
2659 // Allocate new sliced string. At this point we do not reload the instance
2660 // type including the string encoding because we simply rely on the info
2661 // provided by the original string. It does not matter if the original
2662 // string's encoding is wrong because we always have to recheck encoding of
2663 // the newly created string's parent anyways due to externalized strings.
2664 Label two_byte_slice, set_slice_header;
2665 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
2666 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2667 __ And(a4, a1, Operand(kStringEncodingMask));
2668 __ Branch(&two_byte_slice, eq, a4, Operand(zero_reg));
2669 __ AllocateOneByteSlicedString(v0, a2, a6, a7, &runtime);
2670 __ jmp(&set_slice_header);
2671 __ bind(&two_byte_slice);
2672 __ AllocateTwoByteSlicedString(v0, a2, a6, a7, &runtime);
2673 __ bind(&set_slice_header);
2674 __ SmiTag(a3);
2675 __ sd(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
2676 __ sd(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
2677 __ jmp(&return_v0);
2678
2679 __ bind(&copy_routine);
2680 }
2681
2682 // a5: underlying subject string
2683 // a1: instance type of underlying subject string
2684 // a2: length
2685 // a3: adjusted start index (untagged)
2686 Label two_byte_sequential, sequential_string, allocate_result;
2687 STATIC_ASSERT(kExternalStringTag != 0);
2688 STATIC_ASSERT(kSeqStringTag == 0);
2689 __ And(a4, a1, Operand(kExternalStringTag));
2690 __ Branch(&sequential_string, eq, a4, Operand(zero_reg));
2691
2692 // Handle external string.
2693 // Rule out short external strings.
2694 STATIC_ASSERT(kShortExternalStringTag != 0);
2695 __ And(a4, a1, Operand(kShortExternalStringTag));
2696 __ Branch(&runtime, ne, a4, Operand(zero_reg));
2697 __ ld(a5, FieldMemOperand(a5, ExternalString::kResourceDataOffset));
2698 // a5 already points to the first character of underlying string.
2699 __ jmp(&allocate_result);
2700
2701 __ bind(&sequential_string);
2702 // Locate first character of underlying subject string.
2703 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2704 __ Daddu(a5, a5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2705
2706 __ bind(&allocate_result);
2707 // Sequential acii string. Allocate the result.
2708 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
2709 __ And(a4, a1, Operand(kStringEncodingMask));
2710 __ Branch(&two_byte_sequential, eq, a4, Operand(zero_reg));
2711
2712 // Allocate and copy the resulting one_byte string.
2713 __ AllocateOneByteString(v0, a2, a4, a6, a7, &runtime);
2714
2715 // Locate first character of substring to copy.
2716 __ Daddu(a5, a5, a3);
2717
2718 // Locate first character of result.
2719 __ Daddu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2720
2721 // v0: result string
2722 // a1: first character of result string
2723 // a2: result string length
2724 // a5: first character of substring to copy
2725 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2726 StringHelper::GenerateCopyCharacters(
2727 masm, a1, a5, a2, a3, String::ONE_BYTE_ENCODING);
2728 __ jmp(&return_v0);
2729
2730 // Allocate and copy the resulting two-byte string.
2731 __ bind(&two_byte_sequential);
2732 __ AllocateTwoByteString(v0, a2, a4, a6, a7, &runtime);
2733
2734 // Locate first character of substring to copy.
2735 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002736 __ Dlsa(a5, a5, a3, 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002737 // Locate first character of result.
2738 __ Daddu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2739
2740 // v0: result string.
2741 // a1: first character of result.
2742 // a2: result length.
2743 // a5: first character of substring to copy.
2744 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2745 StringHelper::GenerateCopyCharacters(
2746 masm, a1, a5, a2, a3, String::TWO_BYTE_ENCODING);
2747
2748 __ bind(&return_v0);
2749 Counters* counters = isolate()->counters();
2750 __ IncrementCounter(counters->sub_string_native(), 1, a3, a4);
2751 __ DropAndRet(3);
2752
2753 // Just jump to runtime to create the sub string.
2754 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002755 __ TailCallRuntime(Runtime::kSubString);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002756
2757 __ bind(&single_char);
2758 // v0: original string
2759 // a1: instance type
2760 // a2: length
2761 // a3: from index (untagged)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002762 __ SmiTag(a3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002763 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
2764 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002765 generator.GenerateFast(masm);
2766 __ DropAndRet(3);
2767 generator.SkipSlow(masm, &runtime);
2768}
2769
2770
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002771void ToNumberStub::Generate(MacroAssembler* masm) {
2772 // The ToNumber stub takes one argument in a0.
2773 Label not_smi;
2774 __ JumpIfNotSmi(a0, &not_smi);
2775 __ Ret(USE_DELAY_SLOT);
2776 __ mov(v0, a0);
2777 __ bind(&not_smi);
2778
2779 Label not_heap_number;
2780 __ ld(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
2781 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2782 // a0: object
2783 // a1: instance type.
2784 __ Branch(&not_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
2785 __ Ret(USE_DELAY_SLOT);
2786 __ mov(v0, a0);
2787 __ bind(&not_heap_number);
2788
2789 Label not_string, slow_string;
2790 __ Branch(&not_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
2791 // Check if string has a cached array index.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002792 __ lwu(a2, FieldMemOperand(a0, String::kHashFieldOffset));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002793 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
2794 __ Branch(&slow_string, ne, at, Operand(zero_reg));
2795 __ IndexFromHash(a2, a0);
2796 __ Ret(USE_DELAY_SLOT);
2797 __ mov(v0, a0);
2798 __ bind(&slow_string);
2799 __ push(a0); // Push argument.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002800 __ TailCallRuntime(Runtime::kStringToNumber);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002801 __ bind(&not_string);
2802
2803 Label not_oddball;
2804 __ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
2805 __ Ret(USE_DELAY_SLOT);
2806 __ ld(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
2807 __ bind(&not_oddball);
2808
2809 __ push(a0); // Push argument.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002810 __ TailCallRuntime(Runtime::kToNumber);
2811}
2812
2813
2814void ToLengthStub::Generate(MacroAssembler* masm) {
2815 // The ToLength stub takes on argument in a0.
2816 Label not_smi, positive_smi;
2817 __ JumpIfNotSmi(a0, &not_smi);
2818 STATIC_ASSERT(kSmiTag == 0);
2819 __ Branch(&positive_smi, ge, a0, Operand(zero_reg));
2820 __ mov(a0, zero_reg);
2821 __ bind(&positive_smi);
2822 __ Ret(USE_DELAY_SLOT);
2823 __ mov(v0, a0);
2824 __ bind(&not_smi);
2825
2826 __ push(a0); // Push argument.
2827 __ TailCallRuntime(Runtime::kToLength);
2828}
2829
2830
2831void ToStringStub::Generate(MacroAssembler* masm) {
2832 // The ToString stub takes on argument in a0.
2833 Label is_number;
2834 __ JumpIfSmi(a0, &is_number);
2835
2836 Label not_string;
2837 __ GetObjectType(a0, a1, a1);
2838 // a0: receiver
2839 // a1: receiver instance type
2840 __ Branch(&not_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
2841 __ Ret(USE_DELAY_SLOT);
2842 __ mov(v0, a0);
2843 __ bind(&not_string);
2844
2845 Label not_heap_number;
2846 __ Branch(&not_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
2847 __ bind(&is_number);
2848 NumberToStringStub stub(isolate());
2849 __ TailCallStub(&stub);
2850 __ bind(&not_heap_number);
2851
2852 Label not_oddball;
2853 __ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
2854 __ Ret(USE_DELAY_SLOT);
2855 __ ld(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
2856 __ bind(&not_oddball);
2857
2858 __ push(a0); // Push argument.
2859 __ TailCallRuntime(Runtime::kToString);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002860}
2861
2862
Ben Murdoch097c5b22016-05-18 11:27:45 +01002863void ToNameStub::Generate(MacroAssembler* masm) {
2864 // The ToName stub takes on argument in a0.
2865 Label is_number;
2866 __ JumpIfSmi(a0, &is_number);
2867
2868 Label not_name;
2869 STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
2870 __ GetObjectType(a0, a1, a1);
2871 // a0: receiver
2872 // a1: receiver instance type
2873 __ Branch(&not_name, gt, a1, Operand(LAST_NAME_TYPE));
2874 __ Ret(USE_DELAY_SLOT);
2875 __ mov(v0, a0);
2876 __ bind(&not_name);
2877
2878 Label not_heap_number;
2879 __ Branch(&not_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
2880 __ bind(&is_number);
2881 NumberToStringStub stub(isolate());
2882 __ TailCallStub(&stub);
2883 __ bind(&not_heap_number);
2884
2885 Label not_oddball;
2886 __ Branch(&not_oddball, ne, a1, Operand(ODDBALL_TYPE));
2887 __ Ret(USE_DELAY_SLOT);
2888 __ ld(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
2889 __ bind(&not_oddball);
2890
2891 __ push(a0); // Push argument.
2892 __ TailCallRuntime(Runtime::kToName);
2893}
2894
2895
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002896void StringHelper::GenerateFlatOneByteStringEquals(
2897 MacroAssembler* masm, Register left, Register right, Register scratch1,
2898 Register scratch2, Register scratch3) {
2899 Register length = scratch1;
2900
2901 // Compare lengths.
2902 Label strings_not_equal, check_zero_length;
2903 __ ld(length, FieldMemOperand(left, String::kLengthOffset));
2904 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
2905 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
2906 __ bind(&strings_not_equal);
2907 // Can not put li in delayslot, it has multi instructions.
2908 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
2909 __ Ret();
2910
2911 // Check if the length is zero.
2912 Label compare_chars;
2913 __ bind(&check_zero_length);
2914 STATIC_ASSERT(kSmiTag == 0);
2915 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
2916 DCHECK(is_int16((intptr_t)Smi::FromInt(EQUAL)));
2917 __ Ret(USE_DELAY_SLOT);
2918 __ li(v0, Operand(Smi::FromInt(EQUAL)));
2919
2920 // Compare characters.
2921 __ bind(&compare_chars);
2922
2923 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
2924 v0, &strings_not_equal);
2925
2926 // Characters are equal.
2927 __ Ret(USE_DELAY_SLOT);
2928 __ li(v0, Operand(Smi::FromInt(EQUAL)));
2929}
2930
2931
2932void StringHelper::GenerateCompareFlatOneByteStrings(
2933 MacroAssembler* masm, Register left, Register right, Register scratch1,
2934 Register scratch2, Register scratch3, Register scratch4) {
2935 Label result_not_equal, compare_lengths;
2936 // Find minimum length and length difference.
2937 __ ld(scratch1, FieldMemOperand(left, String::kLengthOffset));
2938 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
2939 __ Dsubu(scratch3, scratch1, Operand(scratch2));
2940 Register length_delta = scratch3;
2941 __ slt(scratch4, scratch2, scratch1);
2942 __ Movn(scratch1, scratch2, scratch4);
2943 Register min_length = scratch1;
2944 STATIC_ASSERT(kSmiTag == 0);
2945 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
2946
2947 // Compare loop.
2948 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
2949 scratch4, v0, &result_not_equal);
2950
2951 // Compare lengths - strings up to min-length are equal.
2952 __ bind(&compare_lengths);
2953 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
2954 // Use length_delta as result if it's zero.
2955 __ mov(scratch2, length_delta);
2956 __ mov(scratch4, zero_reg);
2957 __ mov(v0, zero_reg);
2958
2959 __ bind(&result_not_equal);
2960 // Conditionally update the result based either on length_delta or
2961 // the last comparion performed in the loop above.
2962 Label ret;
2963 __ Branch(&ret, eq, scratch2, Operand(scratch4));
2964 __ li(v0, Operand(Smi::FromInt(GREATER)));
2965 __ Branch(&ret, gt, scratch2, Operand(scratch4));
2966 __ li(v0, Operand(Smi::FromInt(LESS)));
2967 __ bind(&ret);
2968 __ Ret();
2969}
2970
2971
2972void StringHelper::GenerateOneByteCharsCompareLoop(
2973 MacroAssembler* masm, Register left, Register right, Register length,
2974 Register scratch1, Register scratch2, Register scratch3,
2975 Label* chars_not_equal) {
2976 // Change index to run from -length to -1 by adding length to string
2977 // start. This means that loop ends when index reaches zero, which
2978 // doesn't need an additional compare.
2979 __ SmiUntag(length);
2980 __ Daddu(scratch1, length,
2981 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2982 __ Daddu(left, left, Operand(scratch1));
2983 __ Daddu(right, right, Operand(scratch1));
2984 __ Dsubu(length, zero_reg, length);
2985 Register index = length; // index = -length;
2986
2987
2988 // Compare loop.
2989 Label loop;
2990 __ bind(&loop);
2991 __ Daddu(scratch3, left, index);
2992 __ lbu(scratch1, MemOperand(scratch3));
2993 __ Daddu(scratch3, right, index);
2994 __ lbu(scratch2, MemOperand(scratch3));
2995 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
2996 __ Daddu(index, index, 1);
2997 __ Branch(&loop, ne, index, Operand(zero_reg));
2998}
2999
3000
3001void StringCompareStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003002 // ----------- S t a t e -------------
3003 // -- a1 : left
3004 // -- a0 : right
3005 // -- ra : return address
3006 // -----------------------------------
3007 __ AssertString(a1);
3008 __ AssertString(a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003009
3010 Label not_same;
3011 __ Branch(&not_same, ne, a0, Operand(a1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003012 __ li(v0, Operand(Smi::FromInt(EQUAL)));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003013 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a1,
3014 a2);
3015 __ Ret();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003016
3017 __ bind(&not_same);
3018
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003019 // Check that both objects are sequential one-byte strings.
3020 Label runtime;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003021 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3022
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003023 // Compare flat ASCII strings natively.
3024 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
3025 a3);
3026 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003027
3028 __ bind(&runtime);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003029 __ Push(a1, a0);
3030 __ TailCallRuntime(Runtime::kStringCompare);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003031}
3032
3033
3034void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3035 // ----------- S t a t e -------------
3036 // -- a1 : left
3037 // -- a0 : right
3038 // -- ra : return address
3039 // -----------------------------------
3040
3041 // Load a2 with the allocation site. We stick an undefined dummy value here
3042 // and replace it with the real allocation site later when we instantiate this
3043 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3044 __ li(a2, handle(isolate()->heap()->undefined_value()));
3045
3046 // Make sure that we actually patched the allocation site.
3047 if (FLAG_debug_code) {
3048 __ And(at, a2, Operand(kSmiTagMask));
3049 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3050 __ ld(a4, FieldMemOperand(a2, HeapObject::kMapOffset));
3051 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3052 __ Assert(eq, kExpectedAllocationSite, a4, Operand(at));
3053 }
3054
3055 // Tail call into the stub that handles binary operations with allocation
3056 // sites.
3057 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3058 __ TailCallStub(&stub);
3059}
3060
3061
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003062void CompareICStub::GenerateBooleans(MacroAssembler* masm) {
3063 DCHECK_EQ(CompareICState::BOOLEAN, state());
3064 Label miss;
3065
3066 __ CheckMap(a1, a2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
3067 __ CheckMap(a0, a3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003068 if (!Token::IsEqualityOp(op())) {
3069 __ ld(a1, FieldMemOperand(a1, Oddball::kToNumberOffset));
3070 __ AssertSmi(a1);
3071 __ ld(a0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3072 __ AssertSmi(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003073 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01003074 __ Ret(USE_DELAY_SLOT);
3075 __ Dsubu(v0, a1, a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003076
3077 __ bind(&miss);
3078 GenerateMiss(masm);
3079}
3080
3081
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003082void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3083 DCHECK(state() == CompareICState::SMI);
3084 Label miss;
3085 __ Or(a2, a1, a0);
3086 __ JumpIfNotSmi(a2, &miss);
3087
3088 if (GetCondition() == eq) {
3089 // For equality we do not care about the sign of the result.
3090 __ Ret(USE_DELAY_SLOT);
3091 __ Dsubu(v0, a0, a1);
3092 } else {
3093 // Untag before subtracting to avoid handling overflow.
3094 __ SmiUntag(a1);
3095 __ SmiUntag(a0);
3096 __ Ret(USE_DELAY_SLOT);
3097 __ Dsubu(v0, a1, a0);
3098 }
3099
3100 __ bind(&miss);
3101 GenerateMiss(masm);
3102}
3103
3104
3105void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3106 DCHECK(state() == CompareICState::NUMBER);
3107
3108 Label generic_stub;
3109 Label unordered, maybe_undefined1, maybe_undefined2;
3110 Label miss;
3111
3112 if (left() == CompareICState::SMI) {
3113 __ JumpIfNotSmi(a1, &miss);
3114 }
3115 if (right() == CompareICState::SMI) {
3116 __ JumpIfNotSmi(a0, &miss);
3117 }
3118
3119 // Inlining the double comparison and falling back to the general compare
3120 // stub if NaN is involved.
3121 // Load left and right operand.
3122 Label done, left, left_smi, right_smi;
3123 __ JumpIfSmi(a0, &right_smi);
3124 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3125 DONT_DO_SMI_CHECK);
3126 __ Dsubu(a2, a0, Operand(kHeapObjectTag));
3127 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3128 __ Branch(&left);
3129 __ bind(&right_smi);
3130 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3131 FPURegister single_scratch = f6;
3132 __ mtc1(a2, single_scratch);
3133 __ cvt_d_w(f2, single_scratch);
3134
3135 __ bind(&left);
3136 __ JumpIfSmi(a1, &left_smi);
3137 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3138 DONT_DO_SMI_CHECK);
3139 __ Dsubu(a2, a1, Operand(kHeapObjectTag));
3140 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3141 __ Branch(&done);
3142 __ bind(&left_smi);
3143 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3144 single_scratch = f8;
3145 __ mtc1(a2, single_scratch);
3146 __ cvt_d_w(f0, single_scratch);
3147
3148 __ bind(&done);
3149
3150 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3151 Label fpu_eq, fpu_lt;
3152 // Test if equal, and also handle the unordered/NaN case.
3153 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3154
3155 // Test if less (unordered case is already handled).
3156 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3157
3158 // Otherwise it's greater, so just fall thru, and return.
3159 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3160 __ Ret(USE_DELAY_SLOT);
3161 __ li(v0, Operand(GREATER));
3162
3163 __ bind(&fpu_eq);
3164 __ Ret(USE_DELAY_SLOT);
3165 __ li(v0, Operand(EQUAL));
3166
3167 __ bind(&fpu_lt);
3168 __ Ret(USE_DELAY_SLOT);
3169 __ li(v0, Operand(LESS));
3170
3171 __ bind(&unordered);
3172 __ bind(&generic_stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003173 CompareICStub stub(isolate(), op(), CompareICState::GENERIC,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003174 CompareICState::GENERIC, CompareICState::GENERIC);
3175 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3176
3177 __ bind(&maybe_undefined1);
3178 if (Token::IsOrderedRelationalCompareOp(op())) {
3179 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3180 __ Branch(&miss, ne, a0, Operand(at));
3181 __ JumpIfSmi(a1, &unordered);
3182 __ GetObjectType(a1, a2, a2);
3183 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3184 __ jmp(&unordered);
3185 }
3186
3187 __ bind(&maybe_undefined2);
3188 if (Token::IsOrderedRelationalCompareOp(op())) {
3189 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3190 __ Branch(&unordered, eq, a1, Operand(at));
3191 }
3192
3193 __ bind(&miss);
3194 GenerateMiss(masm);
3195}
3196
3197
3198void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3199 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3200 Label miss;
3201
3202 // Registers containing left and right operands respectively.
3203 Register left = a1;
3204 Register right = a0;
3205 Register tmp1 = a2;
3206 Register tmp2 = a3;
3207
3208 // Check that both operands are heap objects.
3209 __ JumpIfEitherSmi(left, right, &miss);
3210
3211 // Check that both operands are internalized strings.
3212 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3213 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3214 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3215 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3216 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3217 __ Or(tmp1, tmp1, Operand(tmp2));
3218 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3219 __ Branch(&miss, ne, at, Operand(zero_reg));
3220
3221 // Make sure a0 is non-zero. At this point input operands are
3222 // guaranteed to be non-zero.
3223 DCHECK(right.is(a0));
3224 STATIC_ASSERT(EQUAL == 0);
3225 STATIC_ASSERT(kSmiTag == 0);
3226 __ mov(v0, right);
3227 // Internalized strings are compared by identity.
3228 __ Ret(ne, left, Operand(right));
3229 DCHECK(is_int16(EQUAL));
3230 __ Ret(USE_DELAY_SLOT);
3231 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3232
3233 __ bind(&miss);
3234 GenerateMiss(masm);
3235}
3236
3237
3238void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3239 DCHECK(state() == CompareICState::UNIQUE_NAME);
3240 DCHECK(GetCondition() == eq);
3241 Label miss;
3242
3243 // Registers containing left and right operands respectively.
3244 Register left = a1;
3245 Register right = a0;
3246 Register tmp1 = a2;
3247 Register tmp2 = a3;
3248
3249 // Check that both operands are heap objects.
3250 __ JumpIfEitherSmi(left, right, &miss);
3251
3252 // Check that both operands are unique names. This leaves the instance
3253 // types loaded in tmp1 and tmp2.
3254 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3255 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3256 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3257 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3258
3259 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3260 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3261
3262 // Use a0 as result
3263 __ mov(v0, a0);
3264
3265 // Unique names are compared by identity.
3266 Label done;
3267 __ Branch(&done, ne, left, Operand(right));
3268 // Make sure a0 is non-zero. At this point input operands are
3269 // guaranteed to be non-zero.
3270 DCHECK(right.is(a0));
3271 STATIC_ASSERT(EQUAL == 0);
3272 STATIC_ASSERT(kSmiTag == 0);
3273 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3274 __ bind(&done);
3275 __ Ret();
3276
3277 __ bind(&miss);
3278 GenerateMiss(masm);
3279}
3280
3281
3282void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3283 DCHECK(state() == CompareICState::STRING);
3284 Label miss;
3285
3286 bool equality = Token::IsEqualityOp(op());
3287
3288 // Registers containing left and right operands respectively.
3289 Register left = a1;
3290 Register right = a0;
3291 Register tmp1 = a2;
3292 Register tmp2 = a3;
3293 Register tmp3 = a4;
3294 Register tmp4 = a5;
3295 Register tmp5 = a6;
3296
3297 // Check that both operands are heap objects.
3298 __ JumpIfEitherSmi(left, right, &miss);
3299
3300 // Check that both operands are strings. This leaves the instance
3301 // types loaded in tmp1 and tmp2.
3302 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3303 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3304 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3305 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3306 STATIC_ASSERT(kNotStringTag != 0);
3307 __ Or(tmp3, tmp1, tmp2);
3308 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3309 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3310
3311 // Fast check for identical strings.
3312 Label left_ne_right;
3313 STATIC_ASSERT(EQUAL == 0);
3314 STATIC_ASSERT(kSmiTag == 0);
3315 __ Branch(&left_ne_right, ne, left, Operand(right));
3316 __ Ret(USE_DELAY_SLOT);
3317 __ mov(v0, zero_reg); // In the delay slot.
3318 __ bind(&left_ne_right);
3319
3320 // Handle not identical strings.
3321
3322 // Check that both strings are internalized strings. If they are, we're done
3323 // because we already know they are not identical. We know they are both
3324 // strings.
3325 if (equality) {
3326 DCHECK(GetCondition() == eq);
3327 STATIC_ASSERT(kInternalizedTag == 0);
3328 __ Or(tmp3, tmp1, Operand(tmp2));
3329 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3330 Label is_symbol;
3331 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3332 // Make sure a0 is non-zero. At this point input operands are
3333 // guaranteed to be non-zero.
3334 DCHECK(right.is(a0));
3335 __ Ret(USE_DELAY_SLOT);
3336 __ mov(v0, a0); // In the delay slot.
3337 __ bind(&is_symbol);
3338 }
3339
3340 // Check that both strings are sequential one_byte.
3341 Label runtime;
3342 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3343 &runtime);
3344
3345 // Compare flat one_byte strings. Returns when done.
3346 if (equality) {
3347 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3348 tmp3);
3349 } else {
3350 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3351 tmp2, tmp3, tmp4);
3352 }
3353
3354 // Handle more complex cases in runtime.
3355 __ bind(&runtime);
3356 __ Push(left, right);
3357 if (equality) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003358 __ TailCallRuntime(Runtime::kStringEquals);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003359 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003360 __ TailCallRuntime(Runtime::kStringCompare);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003361 }
3362
3363 __ bind(&miss);
3364 GenerateMiss(masm);
3365}
3366
3367
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003368void CompareICStub::GenerateReceivers(MacroAssembler* masm) {
3369 DCHECK_EQ(CompareICState::RECEIVER, state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003370 Label miss;
3371 __ And(a2, a1, Operand(a0));
3372 __ JumpIfSmi(a2, &miss);
3373
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003374 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003375 __ GetObjectType(a0, a2, a2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003376 __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003377 __ GetObjectType(a1, a2, a2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003378 __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003379
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003380 DCHECK_EQ(eq, GetCondition());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003381 __ Ret(USE_DELAY_SLOT);
3382 __ dsubu(v0, a0, a1);
3383
3384 __ bind(&miss);
3385 GenerateMiss(masm);
3386}
3387
3388
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003389void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003390 Label miss;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003391 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003392 __ And(a2, a1, a0);
3393 __ JumpIfSmi(a2, &miss);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003394 __ GetWeakValue(a4, cell);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003395 __ ld(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3396 __ ld(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003397 __ Branch(&miss, ne, a2, Operand(a4));
3398 __ Branch(&miss, ne, a3, Operand(a4));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003399
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003400 if (Token::IsEqualityOp(op())) {
3401 __ Ret(USE_DELAY_SLOT);
3402 __ dsubu(v0, a0, a1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003403 } else {
3404 if (op() == Token::LT || op() == Token::LTE) {
3405 __ li(a2, Operand(Smi::FromInt(GREATER)));
3406 } else {
3407 __ li(a2, Operand(Smi::FromInt(LESS)));
3408 }
3409 __ Push(a1, a0, a2);
3410 __ TailCallRuntime(Runtime::kCompare);
3411 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003412
3413 __ bind(&miss);
3414 GenerateMiss(masm);
3415}
3416
3417
3418void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3419 {
3420 // Call the runtime system in a fresh internal frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003421 FrameScope scope(masm, StackFrame::INTERNAL);
3422 __ Push(a1, a0);
3423 __ Push(ra, a1, a0);
3424 __ li(a4, Operand(Smi::FromInt(op())));
3425 __ daddiu(sp, sp, -kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003426 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3427 USE_DELAY_SLOT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003428 __ sd(a4, MemOperand(sp)); // In the delay slot.
3429 // Compute the entry point of the rewritten stub.
3430 __ Daddu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3431 // Restore registers.
3432 __ Pop(a1, a0, ra);
3433 }
3434 __ Jump(a2);
3435}
3436
3437
3438void DirectCEntryStub::Generate(MacroAssembler* masm) {
3439 // Make place for arguments to fit C calling convention. Most of the callers
3440 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3441 // so they handle stack restoring and we don't have to do that here.
3442 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3443 // kCArgsSlotsSize stack space after the call.
3444 __ daddiu(sp, sp, -kCArgsSlotsSize);
3445 // Place the return address on the stack, making the call
3446 // GC safe. The RegExp backend also relies on this.
3447 __ sd(ra, MemOperand(sp, kCArgsSlotsSize));
3448 __ Call(t9); // Call the C++ function.
3449 __ ld(t9, MemOperand(sp, kCArgsSlotsSize));
3450
3451 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3452 // In case of an error the return address may point to a memory area
3453 // filled with kZapValue by the GC.
3454 // Dereference the address and check for this.
3455 __ Uld(a4, MemOperand(t9));
3456 __ Assert(ne, kReceivedInvalidReturnAddress, a4,
3457 Operand(reinterpret_cast<uint64_t>(kZapValue)));
3458 }
3459 __ Jump(t9);
3460}
3461
3462
3463void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3464 Register target) {
3465 intptr_t loc =
3466 reinterpret_cast<intptr_t>(GetCode().location());
3467 __ Move(t9, target);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003468 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3469 __ Call(at);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003470}
3471
3472
3473void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3474 Label* miss,
3475 Label* done,
3476 Register receiver,
3477 Register properties,
3478 Handle<Name> name,
3479 Register scratch0) {
3480 DCHECK(name->IsUniqueName());
3481 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3482 // not equal to the name and kProbes-th slot is not used (its name is the
3483 // undefined value), it guarantees the hash table doesn't contain the
3484 // property. It's true even if some slots represent deleted properties
3485 // (their names are the hole value).
3486 for (int i = 0; i < kInlinedProbes; i++) {
3487 // scratch0 points to properties hash.
3488 // Compute the masked index: (hash + i + i * i) & mask.
3489 Register index = scratch0;
3490 // Capacity is smi 2^n.
3491 __ SmiLoadUntag(index, FieldMemOperand(properties, kCapacityOffset));
3492 __ Dsubu(index, index, Operand(1));
3493 __ And(index, index,
3494 Operand(name->Hash() + NameDictionary::GetProbeOffset(i)));
3495
3496 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003497 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003498 __ Dlsa(index, index, index, 1); // index *= 3.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003499
3500 Register entity_name = scratch0;
3501 // Having undefined at this place means the name is not contained.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003502 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003503 Register tmp = properties;
3504
Ben Murdoch097c5b22016-05-18 11:27:45 +01003505 __ Dlsa(tmp, properties, index, kPointerSizeLog2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003506 __ ld(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3507
3508 DCHECK(!tmp.is(entity_name));
3509 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3510 __ Branch(done, eq, entity_name, Operand(tmp));
3511
3512 // Load the hole ready for use below:
3513 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3514
3515 // Stop if found the property.
3516 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
3517
3518 Label good;
3519 __ Branch(&good, eq, entity_name, Operand(tmp));
3520
3521 // Check if the entry name is not a unique name.
3522 __ ld(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3523 __ lbu(entity_name,
3524 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3525 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3526 __ bind(&good);
3527
3528 // Restore the properties.
3529 __ ld(properties,
3530 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3531 }
3532
3533 const int spill_mask =
3534 (ra.bit() | a6.bit() | a5.bit() | a4.bit() | a3.bit() |
3535 a2.bit() | a1.bit() | a0.bit() | v0.bit());
3536
3537 __ MultiPush(spill_mask);
3538 __ ld(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3539 __ li(a1, Operand(Handle<Name>(name)));
3540 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3541 __ CallStub(&stub);
3542 __ mov(at, v0);
3543 __ MultiPop(spill_mask);
3544
3545 __ Branch(done, eq, at, Operand(zero_reg));
3546 __ Branch(miss, ne, at, Operand(zero_reg));
3547}
3548
3549
3550// Probe the name dictionary in the |elements| register. Jump to the
3551// |done| label if a property with the given name is found. Jump to
3552// the |miss| label otherwise.
3553// If lookup was successful |scratch2| will be equal to elements + 4 * index.
3554void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3555 Label* miss,
3556 Label* done,
3557 Register elements,
3558 Register name,
3559 Register scratch1,
3560 Register scratch2) {
3561 DCHECK(!elements.is(scratch1));
3562 DCHECK(!elements.is(scratch2));
3563 DCHECK(!name.is(scratch1));
3564 DCHECK(!name.is(scratch2));
3565
3566 __ AssertName(name);
3567
3568 // Compute the capacity mask.
3569 __ ld(scratch1, FieldMemOperand(elements, kCapacityOffset));
3570 __ SmiUntag(scratch1);
3571 __ Dsubu(scratch1, scratch1, Operand(1));
3572
3573 // Generate an unrolled loop that performs a few probes before
3574 // giving up. Measurements done on Gmail indicate that 2 probes
3575 // cover ~93% of loads from dictionaries.
3576 for (int i = 0; i < kInlinedProbes; i++) {
3577 // Compute the masked index: (hash + i + i * i) & mask.
3578 __ lwu(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
3579 if (i > 0) {
3580 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3581 // the hash in a separate instruction. The value hash + i + i * i is right
3582 // shifted in the following and instruction.
3583 DCHECK(NameDictionary::GetProbeOffset(i) <
3584 1 << (32 - Name::kHashFieldOffset));
3585 __ Daddu(scratch2, scratch2, Operand(
3586 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3587 }
3588 __ dsrl(scratch2, scratch2, Name::kHashShift);
3589 __ And(scratch2, scratch1, scratch2);
3590
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003591 // Scale the index by multiplying by the entry size.
3592 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003593 // scratch2 = scratch2 * 3.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003594 __ Dlsa(scratch2, scratch2, scratch2, 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003595
3596 // Check if the key is identical to the name.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003597 __ Dlsa(scratch2, elements, scratch2, kPointerSizeLog2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003598 __ ld(at, FieldMemOperand(scratch2, kElementsStartOffset));
3599 __ Branch(done, eq, name, Operand(at));
3600 }
3601
3602 const int spill_mask =
3603 (ra.bit() | a6.bit() | a5.bit() | a4.bit() |
3604 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
3605 ~(scratch1.bit() | scratch2.bit());
3606
3607 __ MultiPush(spill_mask);
3608 if (name.is(a0)) {
3609 DCHECK(!elements.is(a1));
3610 __ Move(a1, name);
3611 __ Move(a0, elements);
3612 } else {
3613 __ Move(a0, elements);
3614 __ Move(a1, name);
3615 }
3616 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
3617 __ CallStub(&stub);
3618 __ mov(scratch2, a2);
3619 __ mov(at, v0);
3620 __ MultiPop(spill_mask);
3621
3622 __ Branch(done, ne, at, Operand(zero_reg));
3623 __ Branch(miss, eq, at, Operand(zero_reg));
3624}
3625
3626
3627void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3628 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3629 // we cannot call anything that could cause a GC from this stub.
3630 // Registers:
3631 // result: NameDictionary to probe
3632 // a1: key
3633 // dictionary: NameDictionary to probe.
3634 // index: will hold an index of entry if lookup is successful.
3635 // might alias with result_.
3636 // Returns:
3637 // result_ is zero if lookup failed, non zero otherwise.
3638
3639 Register result = v0;
3640 Register dictionary = a0;
3641 Register key = a1;
3642 Register index = a2;
3643 Register mask = a3;
3644 Register hash = a4;
3645 Register undefined = a5;
3646 Register entry_key = a6;
3647
3648 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3649
3650 __ ld(mask, FieldMemOperand(dictionary, kCapacityOffset));
3651 __ SmiUntag(mask);
3652 __ Dsubu(mask, mask, Operand(1));
3653
3654 __ lwu(hash, FieldMemOperand(key, Name::kHashFieldOffset));
3655
3656 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
3657
3658 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3659 // Compute the masked index: (hash + i + i * i) & mask.
3660 // Capacity is smi 2^n.
3661 if (i > 0) {
3662 // Add the probe offset (i + i * i) left shifted to avoid right shifting
3663 // the hash in a separate instruction. The value hash + i + i * i is right
3664 // shifted in the following and instruction.
3665 DCHECK(NameDictionary::GetProbeOffset(i) <
3666 1 << (32 - Name::kHashFieldOffset));
3667 __ Daddu(index, hash, Operand(
3668 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
3669 } else {
3670 __ mov(index, hash);
3671 }
3672 __ dsrl(index, index, Name::kHashShift);
3673 __ And(index, mask, index);
3674
3675 // Scale the index by multiplying by the entry size.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003676 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003677 // index *= 3.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003678 __ Dlsa(index, index, index, 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003679
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003680 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003681 __ Dlsa(index, dictionary, index, kPointerSizeLog2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003682 __ ld(entry_key, FieldMemOperand(index, kElementsStartOffset));
3683
3684 // Having undefined at this place means the name is not contained.
3685 __ Branch(&not_in_dictionary, eq, entry_key, Operand(undefined));
3686
3687 // Stop if found the property.
3688 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
3689
3690 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3691 // Check if the entry name is not a unique name.
3692 __ ld(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
3693 __ lbu(entry_key,
3694 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
3695 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
3696 }
3697 }
3698
3699 __ bind(&maybe_in_dictionary);
3700 // If we are doing negative lookup then probing failure should be
3701 // treated as a lookup success. For positive lookup probing failure
3702 // should be treated as lookup failure.
3703 if (mode() == POSITIVE_LOOKUP) {
3704 __ Ret(USE_DELAY_SLOT);
3705 __ mov(result, zero_reg);
3706 }
3707
3708 __ bind(&in_dictionary);
3709 __ Ret(USE_DELAY_SLOT);
3710 __ li(result, 1);
3711
3712 __ bind(&not_in_dictionary);
3713 __ Ret(USE_DELAY_SLOT);
3714 __ mov(result, zero_reg);
3715}
3716
3717
3718void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3719 Isolate* isolate) {
3720 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
3721 stub1.GetCode();
3722 // Hydrogen code stubs need stub2 at snapshot time.
3723 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3724 stub2.GetCode();
3725}
3726
3727
3728// Takes the input in 3 registers: address_ value_ and object_. A pointer to
3729// the value has just been written into the object, now this stub makes sure
3730// we keep the GC informed. The word in the object where the value has been
3731// written is in the address register.
3732void RecordWriteStub::Generate(MacroAssembler* masm) {
3733 Label skip_to_incremental_noncompacting;
3734 Label skip_to_incremental_compacting;
3735
3736 // The first two branch+nop instructions are generated with labels so as to
3737 // get the offset fixed up correctly by the bind(Label*) call. We patch it
3738 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
3739 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
3740 // incremental heap marking.
3741 // See RecordWriteStub::Patch for details.
3742 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
3743 __ nop();
3744 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
3745 __ nop();
3746
3747 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3748 __ RememberedSetHelper(object(),
3749 address(),
3750 value(),
3751 save_fp_regs_mode(),
3752 MacroAssembler::kReturnAtEnd);
3753 }
3754 __ Ret();
3755
3756 __ bind(&skip_to_incremental_noncompacting);
3757 GenerateIncremental(masm, INCREMENTAL);
3758
3759 __ bind(&skip_to_incremental_compacting);
3760 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3761
3762 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3763 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3764
3765 PatchBranchIntoNop(masm, 0);
3766 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
3767}
3768
3769
3770void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3771 regs_.Save(masm);
3772
3773 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3774 Label dont_need_remembered_set;
3775
3776 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
3777 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
3778 regs_.scratch0(),
3779 &dont_need_remembered_set);
3780
Ben Murdoch097c5b22016-05-18 11:27:45 +01003781 __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(),
3782 &dont_need_remembered_set);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003783
3784 // First notify the incremental marker if necessary, then update the
3785 // remembered set.
3786 CheckNeedsToInformIncrementalMarker(
3787 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
3788 InformIncrementalMarker(masm);
3789 regs_.Restore(masm);
3790 __ RememberedSetHelper(object(),
3791 address(),
3792 value(),
3793 save_fp_regs_mode(),
3794 MacroAssembler::kReturnAtEnd);
3795
3796 __ bind(&dont_need_remembered_set);
3797 }
3798
3799 CheckNeedsToInformIncrementalMarker(
3800 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
3801 InformIncrementalMarker(masm);
3802 regs_.Restore(masm);
3803 __ Ret();
3804}
3805
3806
3807void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3808 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
3809 int argument_count = 3;
3810 __ PrepareCallCFunction(argument_count, regs_.scratch0());
3811 Register address =
3812 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
3813 DCHECK(!address.is(regs_.object()));
3814 DCHECK(!address.is(a0));
3815 __ Move(address, regs_.address());
3816 __ Move(a0, regs_.object());
3817 __ Move(a1, address);
3818 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
3819
3820 AllowExternalCallThatCantCauseGC scope(masm);
3821 __ CallCFunction(
3822 ExternalReference::incremental_marking_record_write_function(isolate()),
3823 argument_count);
3824 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
3825}
3826
3827
3828void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
3829 MacroAssembler* masm,
3830 OnNoNeedToInformIncrementalMarker on_no_need,
3831 Mode mode) {
3832 Label on_black;
3833 Label need_incremental;
3834 Label need_incremental_pop_scratch;
3835
3836 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
3837 __ ld(regs_.scratch1(),
3838 MemOperand(regs_.scratch0(),
3839 MemoryChunk::kWriteBarrierCounterOffset));
3840 __ Dsubu(regs_.scratch1(), regs_.scratch1(), Operand(1));
3841 __ sd(regs_.scratch1(),
3842 MemOperand(regs_.scratch0(),
3843 MemoryChunk::kWriteBarrierCounterOffset));
3844 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
3845
3846 // Let's look at the color of the object: If it is not black we don't have
3847 // to inform the incremental marker.
3848 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
3849
3850 regs_.Restore(masm);
3851 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3852 __ RememberedSetHelper(object(),
3853 address(),
3854 value(),
3855 save_fp_regs_mode(),
3856 MacroAssembler::kReturnAtEnd);
3857 } else {
3858 __ Ret();
3859 }
3860
3861 __ bind(&on_black);
3862
3863 // Get the value from the slot.
3864 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
3865
3866 if (mode == INCREMENTAL_COMPACTION) {
3867 Label ensure_not_white;
3868
3869 __ CheckPageFlag(regs_.scratch0(), // Contains value.
3870 regs_.scratch1(), // Scratch.
3871 MemoryChunk::kEvacuationCandidateMask,
3872 eq,
3873 &ensure_not_white);
3874
3875 __ CheckPageFlag(regs_.object(),
3876 regs_.scratch1(), // Scratch.
3877 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
3878 eq,
3879 &need_incremental);
3880
3881 __ bind(&ensure_not_white);
3882 }
3883
3884 // We need extra registers for this, so we push the object and the address
3885 // register temporarily.
3886 __ Push(regs_.object(), regs_.address());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003887 __ JumpIfWhite(regs_.scratch0(), // The value.
3888 regs_.scratch1(), // Scratch.
3889 regs_.object(), // Scratch.
3890 regs_.address(), // Scratch.
3891 &need_incremental_pop_scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003892 __ Pop(regs_.object(), regs_.address());
3893
3894 regs_.Restore(masm);
3895 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3896 __ RememberedSetHelper(object(),
3897 address(),
3898 value(),
3899 save_fp_regs_mode(),
3900 MacroAssembler::kReturnAtEnd);
3901 } else {
3902 __ Ret();
3903 }
3904
3905 __ bind(&need_incremental_pop_scratch);
3906 __ Pop(regs_.object(), regs_.address());
3907
3908 __ bind(&need_incremental);
3909
3910 // Fall through when we need to inform the incremental marker.
3911}
3912
3913
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003914void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
3915 CEntryStub ces(isolate(), 1, kSaveFPRegs);
3916 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
3917 int parameter_count_offset =
3918 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
3919 __ ld(a1, MemOperand(fp, parameter_count_offset));
3920 if (function_mode() == JS_FUNCTION_STUB_MODE) {
3921 __ Daddu(a1, a1, Operand(1));
3922 }
3923 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
3924 __ dsll(a1, a1, kPointerSizeLog2);
3925 __ Ret(USE_DELAY_SLOT);
3926 __ Daddu(sp, sp, a1);
3927}
3928
3929
3930void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003931 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3932 LoadICStub stub(isolate(), state());
3933 stub.GenerateForTrampoline(masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003934}
3935
3936
3937void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003938 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister());
3939 KeyedLoadICStub stub(isolate(), state());
3940 stub.GenerateForTrampoline(masm);
3941}
3942
3943
3944void CallICTrampolineStub::Generate(MacroAssembler* masm) {
3945 __ EmitLoadTypeFeedbackVector(a2);
3946 CallICStub stub(isolate(), state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003947 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3948}
3949
3950
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003951void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
3952
3953
3954void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
3955 GenerateImpl(masm, true);
3956}
3957
3958
3959static void HandleArrayCases(MacroAssembler* masm, Register feedback,
3960 Register receiver_map, Register scratch1,
3961 Register scratch2, bool is_polymorphic,
3962 Label* miss) {
3963 // feedback initially contains the feedback array
3964 Label next_loop, prepare_next;
3965 Label start_polymorphic;
3966
3967 Register cached_map = scratch1;
3968
3969 __ ld(cached_map,
3970 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
3971 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
3972 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
3973 // found, now call handler.
3974 Register handler = feedback;
3975 __ ld(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
3976 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
3977 __ Jump(t9);
3978
3979 Register length = scratch2;
3980 __ bind(&start_polymorphic);
3981 __ ld(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
3982 if (!is_polymorphic) {
3983 // If the IC could be monomorphic we have to make sure we don't go past the
3984 // end of the feedback array.
3985 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
3986 }
3987
3988 Register too_far = length;
3989 Register pointer_reg = feedback;
3990
3991 // +-----+------+------+-----+-----+ ... ----+
3992 // | map | len | wm0 | h0 | wm1 | hN |
3993 // +-----+------+------+-----+-----+ ... ----+
3994 // 0 1 2 len-1
3995 // ^ ^
3996 // | |
3997 // pointer_reg too_far
3998 // aka feedback scratch2
3999 // also need receiver_map
4000 // use cached_map (scratch1) to look in the weak map values.
4001 __ SmiScale(too_far, length, kPointerSizeLog2);
4002 __ Daddu(too_far, feedback, Operand(too_far));
4003 __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4004 __ Daddu(pointer_reg, feedback,
4005 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4006
4007 __ bind(&next_loop);
4008 __ ld(cached_map, MemOperand(pointer_reg));
4009 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4010 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4011 __ ld(handler, MemOperand(pointer_reg, kPointerSize));
4012 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4013 __ Jump(t9);
4014
4015 __ bind(&prepare_next);
4016 __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4017 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4018
4019 // We exhausted our array of map handler pairs.
4020 __ Branch(miss);
4021}
4022
4023
4024static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4025 Register receiver_map, Register feedback,
4026 Register vector, Register slot,
4027 Register scratch, Label* compare_map,
4028 Label* load_smi_map, Label* try_array) {
4029 __ JumpIfSmi(receiver, load_smi_map);
4030 __ ld(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4031 __ bind(compare_map);
4032 Register cached_map = scratch;
4033 // Move the weak map into the weak_cell register.
4034 __ ld(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4035 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4036 Register handler = feedback;
4037 __ SmiScale(handler, slot, kPointerSizeLog2);
4038 __ Daddu(handler, vector, Operand(handler));
4039 __ ld(handler,
4040 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4041 __ Daddu(t9, handler, Code::kHeaderSize - kHeapObjectTag);
4042 __ Jump(t9);
4043}
4044
4045
4046void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4047 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4048 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4049 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4050 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4051 Register feedback = a4;
4052 Register receiver_map = a5;
4053 Register scratch1 = a6;
4054
4055 __ SmiScale(feedback, slot, kPointerSizeLog2);
4056 __ Daddu(feedback, vector, Operand(feedback));
4057 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4058
4059 // Try to quickly handle the monomorphic case without knowing for sure
4060 // if we have a weak cell in feedback. We do know it's safe to look
4061 // at WeakCell::kValueOffset.
4062 Label try_array, load_smi_map, compare_map;
4063 Label not_array, miss;
4064 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4065 scratch1, &compare_map, &load_smi_map, &try_array);
4066
4067 // Is it a fixed array?
4068 __ bind(&try_array);
4069 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4070 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4071 __ Branch(&not_array, ne, scratch1, Operand(at));
4072 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss);
4073
4074 __ bind(&not_array);
4075 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4076 __ Branch(&miss, ne, feedback, Operand(at));
4077 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4078 Code::ComputeHandlerFlags(Code::LOAD_IC));
4079 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4080 receiver, name, feedback,
4081 receiver_map, scratch1, a7);
4082
4083 __ bind(&miss);
4084 LoadIC::GenerateMiss(masm);
4085
4086 __ bind(&load_smi_map);
4087 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4088 __ Branch(&compare_map);
4089}
4090
4091
4092void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4093 GenerateImpl(masm, false);
4094}
4095
4096
4097void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4098 GenerateImpl(masm, true);
4099}
4100
4101
4102void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4103 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4104 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4105 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4106 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4107 Register feedback = a4;
4108 Register receiver_map = a5;
4109 Register scratch1 = a6;
4110
4111 __ SmiScale(feedback, slot, kPointerSizeLog2);
4112 __ Daddu(feedback, vector, Operand(feedback));
4113 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4114
4115 // Try to quickly handle the monomorphic case without knowing for sure
4116 // if we have a weak cell in feedback. We do know it's safe to look
4117 // at WeakCell::kValueOffset.
4118 Label try_array, load_smi_map, compare_map;
4119 Label not_array, miss;
4120 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4121 scratch1, &compare_map, &load_smi_map, &try_array);
4122
4123 __ bind(&try_array);
4124 // Is it a fixed array?
4125 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4126 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4127 __ Branch(&not_array, ne, scratch1, Operand(at));
4128 // We have a polymorphic element handler.
4129 __ JumpIfNotSmi(key, &miss);
4130
4131 Label polymorphic, try_poly_name;
4132 __ bind(&polymorphic);
4133 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss);
4134
4135 __ bind(&not_array);
4136 // Is it generic?
4137 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4138 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4139 Handle<Code> megamorphic_stub =
4140 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4141 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4142
4143 __ bind(&try_poly_name);
4144 // We might have a name in feedback, and a fixed array in the next slot.
4145 __ Branch(&miss, ne, key, Operand(feedback));
4146 // If the name comparison succeeded, we know we have a fixed array with
4147 // at least one map/handler pair.
4148 __ SmiScale(feedback, slot, kPointerSizeLog2);
4149 __ Daddu(feedback, vector, Operand(feedback));
4150 __ ld(feedback,
4151 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4152 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, false, &miss);
4153
4154 __ bind(&miss);
4155 KeyedLoadIC::GenerateMiss(masm);
4156
4157 __ bind(&load_smi_map);
4158 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4159 __ Branch(&compare_map);
4160}
4161
4162
4163void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4164 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
4165 VectorStoreICStub stub(isolate(), state());
4166 stub.GenerateForTrampoline(masm);
4167}
4168
4169
4170void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4171 __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister());
4172 VectorKeyedStoreICStub stub(isolate(), state());
4173 stub.GenerateForTrampoline(masm);
4174}
4175
4176
4177void VectorStoreICStub::Generate(MacroAssembler* masm) {
4178 GenerateImpl(masm, false);
4179}
4180
4181
4182void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4183 GenerateImpl(masm, true);
4184}
4185
4186
4187void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4188 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4189 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4190 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4191 Register slot = VectorStoreICDescriptor::SlotRegister(); // a4
4192 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4193 Register feedback = a5;
4194 Register receiver_map = a6;
4195 Register scratch1 = a7;
4196
4197 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4198 __ Daddu(feedback, vector, Operand(scratch1));
4199 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4200
4201 // Try to quickly handle the monomorphic case without knowing for sure
4202 // if we have a weak cell in feedback. We do know it's safe to look
4203 // at WeakCell::kValueOffset.
4204 Label try_array, load_smi_map, compare_map;
4205 Label not_array, miss;
4206 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4207 scratch1, &compare_map, &load_smi_map, &try_array);
4208
4209 // Is it a fixed array?
4210 __ bind(&try_array);
4211 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4212 __ Branch(&not_array, ne, scratch1, Heap::kFixedArrayMapRootIndex);
4213
4214 Register scratch2 = t0;
4215 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4216 &miss);
4217
4218 __ bind(&not_array);
4219 __ Branch(&miss, ne, feedback, Heap::kmegamorphic_symbolRootIndex);
4220 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4221 Code::ComputeHandlerFlags(Code::STORE_IC));
4222 masm->isolate()->stub_cache()->GenerateProbe(
4223 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4224 scratch1, scratch2);
4225
4226 __ bind(&miss);
4227 StoreIC::GenerateMiss(masm);
4228
4229 __ bind(&load_smi_map);
4230 __ Branch(USE_DELAY_SLOT, &compare_map);
4231 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4232}
4233
4234
4235void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4236 GenerateImpl(masm, false);
4237}
4238
4239
4240void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4241 GenerateImpl(masm, true);
4242}
4243
4244
4245static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4246 Register receiver_map, Register scratch1,
4247 Register scratch2, Label* miss) {
4248 // feedback initially contains the feedback array
4249 Label next_loop, prepare_next;
4250 Label start_polymorphic;
4251 Label transition_call;
4252
4253 Register cached_map = scratch1;
4254 Register too_far = scratch2;
4255 Register pointer_reg = feedback;
4256
4257 __ ld(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4258
4259 // +-----+------+------+-----+-----+-----+ ... ----+
4260 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4261 // +-----+------+------+-----+-----+ ----+ ... ----+
4262 // 0 1 2 len-1
4263 // ^ ^
4264 // | |
4265 // pointer_reg too_far
4266 // aka feedback scratch2
4267 // also need receiver_map
4268 // use cached_map (scratch1) to look in the weak map values.
4269 __ SmiScale(too_far, too_far, kPointerSizeLog2);
4270 __ Daddu(too_far, feedback, Operand(too_far));
4271 __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4272 __ Daddu(pointer_reg, feedback,
4273 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4274
4275 __ bind(&next_loop);
4276 __ ld(cached_map, MemOperand(pointer_reg));
4277 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4278 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4279 // Is it a transitioning store?
4280 __ ld(too_far, MemOperand(pointer_reg, kPointerSize));
4281 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4282 __ Branch(&transition_call, ne, too_far, Operand(at));
4283
4284 __ ld(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4285 __ Daddu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4286 __ Jump(t9);
4287
4288 __ bind(&transition_call);
4289 __ ld(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4290 __ JumpIfSmi(too_far, miss);
4291
4292 __ ld(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4293 // Load the map into the correct register.
4294 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4295 __ Move(feedback, too_far);
4296 __ Daddu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4297 __ Jump(t9);
4298
4299 __ bind(&prepare_next);
4300 __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4301 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4302
4303 // We exhausted our array of map handler pairs.
4304 __ Branch(miss);
4305}
4306
4307
4308void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4309 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4310 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4311 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4312 Register slot = VectorStoreICDescriptor::SlotRegister(); // a4
4313 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4314 Register feedback = a5;
4315 Register receiver_map = a6;
4316 Register scratch1 = a7;
4317
4318 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4319 __ Daddu(feedback, vector, Operand(scratch1));
4320 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4321
4322 // Try to quickly handle the monomorphic case without knowing for sure
4323 // if we have a weak cell in feedback. We do know it's safe to look
4324 // at WeakCell::kValueOffset.
4325 Label try_array, load_smi_map, compare_map;
4326 Label not_array, miss;
4327 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4328 scratch1, &compare_map, &load_smi_map, &try_array);
4329
4330 __ bind(&try_array);
4331 // Is it a fixed array?
4332 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4333 __ Branch(&not_array, ne, scratch1, Heap::kFixedArrayMapRootIndex);
4334
4335 // We have a polymorphic element handler.
4336 Label try_poly_name;
4337
4338 Register scratch2 = t0;
4339
4340 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4341 &miss);
4342
4343 __ bind(&not_array);
4344 // Is it generic?
4345 __ Branch(&try_poly_name, ne, feedback, Heap::kmegamorphic_symbolRootIndex);
4346 Handle<Code> megamorphic_stub =
4347 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4348 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4349
4350 __ bind(&try_poly_name);
4351 // We might have a name in feedback, and a fixed array in the next slot.
4352 __ Branch(&miss, ne, key, Operand(feedback));
4353 // If the name comparison succeeded, we know we have a fixed array with
4354 // at least one map/handler pair.
4355 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4356 __ Daddu(feedback, vector, Operand(scratch1));
4357 __ ld(feedback,
4358 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4359 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4360 &miss);
4361
4362 __ bind(&miss);
4363 KeyedStoreIC::GenerateMiss(masm);
4364
4365 __ bind(&load_smi_map);
4366 __ Branch(USE_DELAY_SLOT, &compare_map);
4367 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4368}
4369
4370
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004371void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4372 if (masm->isolate()->function_entry_hook() != NULL) {
4373 ProfileEntryHookStub stub(masm->isolate());
4374 __ push(ra);
4375 __ CallStub(&stub);
4376 __ pop(ra);
4377 }
4378}
4379
4380
4381void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4382 // The entry hook is a "push ra" instruction, followed by a call.
4383 // Note: on MIPS "push" is 2 instruction
4384 const int32_t kReturnAddressDistanceFromFunctionStart =
4385 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4386
4387 // This should contain all kJSCallerSaved registers.
4388 const RegList kSavedRegs =
4389 kJSCallerSaved | // Caller saved registers.
4390 s5.bit(); // Saved stack pointer.
4391
4392 // We also save ra, so the count here is one higher than the mask indicates.
4393 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4394
4395 // Save all caller-save registers as this may be called from anywhere.
4396 __ MultiPush(kSavedRegs | ra.bit());
4397
4398 // Compute the function's address for the first argument.
4399 __ Dsubu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4400
4401 // The caller's return address is above the saved temporaries.
4402 // Grab that for the second argument to the hook.
4403 __ Daddu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4404
4405 // Align the stack if necessary.
4406 int frame_alignment = masm->ActivationFrameAlignment();
4407 if (frame_alignment > kPointerSize) {
4408 __ mov(s5, sp);
4409 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4410 __ And(sp, sp, Operand(-frame_alignment));
4411 }
4412
4413 __ Dsubu(sp, sp, kCArgsSlotsSize);
4414#if defined(V8_HOST_ARCH_MIPS) || defined(V8_HOST_ARCH_MIPS64)
4415 int64_t entry_hook =
4416 reinterpret_cast<int64_t>(isolate()->function_entry_hook());
4417 __ li(t9, Operand(entry_hook));
4418#else
4419 // Under the simulator we need to indirect the entry hook through a
4420 // trampoline function at a known address.
4421 // It additionally takes an isolate as a third parameter.
4422 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4423
4424 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4425 __ li(t9, Operand(ExternalReference(&dispatcher,
4426 ExternalReference::BUILTIN_CALL,
4427 isolate())));
4428#endif
4429 // Call C function through t9 to conform ABI for PIC.
4430 __ Call(t9);
4431
4432 // Restore the stack pointer if needed.
4433 if (frame_alignment > kPointerSize) {
4434 __ mov(sp, s5);
4435 } else {
4436 __ Daddu(sp, sp, kCArgsSlotsSize);
4437 }
4438
4439 // Also pop ra to get Ret(0).
4440 __ MultiPop(kSavedRegs | ra.bit());
4441 __ Ret();
4442}
4443
4444
4445template<class T>
4446static void CreateArrayDispatch(MacroAssembler* masm,
4447 AllocationSiteOverrideMode mode) {
4448 if (mode == DISABLE_ALLOCATION_SITES) {
4449 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4450 __ TailCallStub(&stub);
4451 } else if (mode == DONT_OVERRIDE) {
4452 int last_index = GetSequenceIndexFromFastElementsKind(
4453 TERMINAL_FAST_ELEMENTS_KIND);
4454 for (int i = 0; i <= last_index; ++i) {
4455 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4456 T stub(masm->isolate(), kind);
4457 __ TailCallStub(&stub, eq, a3, Operand(kind));
4458 }
4459
4460 // If we reached this point there is a problem.
4461 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4462 } else {
4463 UNREACHABLE();
4464 }
4465}
4466
4467
4468static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4469 AllocationSiteOverrideMode mode) {
4470 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4471 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4472 // a0 - number of arguments
4473 // a1 - constructor?
4474 // sp[0] - last argument
4475 Label normal_sequence;
4476 if (mode == DONT_OVERRIDE) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004477 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4478 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4479 STATIC_ASSERT(FAST_ELEMENTS == 2);
4480 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4481 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4482 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004483
4484 // is the low bit set? If so, we are holey and that is good.
4485 __ And(at, a3, Operand(1));
4486 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
4487 }
4488 // look at the first argument
4489 __ ld(a5, MemOperand(sp, 0));
4490 __ Branch(&normal_sequence, eq, a5, Operand(zero_reg));
4491
4492 if (mode == DISABLE_ALLOCATION_SITES) {
4493 ElementsKind initial = GetInitialFastElementsKind();
4494 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4495
4496 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4497 holey_initial,
4498 DISABLE_ALLOCATION_SITES);
4499 __ TailCallStub(&stub_holey);
4500
4501 __ bind(&normal_sequence);
4502 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4503 initial,
4504 DISABLE_ALLOCATION_SITES);
4505 __ TailCallStub(&stub);
4506 } else if (mode == DONT_OVERRIDE) {
4507 // We are going to create a holey array, but our kind is non-holey.
4508 // Fix kind and retry (only if we have an allocation site in the slot).
4509 __ Daddu(a3, a3, Operand(1));
4510
4511 if (FLAG_debug_code) {
4512 __ ld(a5, FieldMemOperand(a2, 0));
4513 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
4514 __ Assert(eq, kExpectedAllocationSite, a5, Operand(at));
4515 }
4516
4517 // Save the resulting elements kind in type info. We can't just store a3
4518 // in the AllocationSite::transition_info field because elements kind is
4519 // restricted to a portion of the field...upper bits need to be left alone.
4520 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4521 __ ld(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4522 __ Daddu(a4, a4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4523 __ sd(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4524
4525
4526 __ bind(&normal_sequence);
4527 int last_index = GetSequenceIndexFromFastElementsKind(
4528 TERMINAL_FAST_ELEMENTS_KIND);
4529 for (int i = 0; i <= last_index; ++i) {
4530 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4531 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4532 __ TailCallStub(&stub, eq, a3, Operand(kind));
4533 }
4534
4535 // If we reached this point there is a problem.
4536 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4537 } else {
4538 UNREACHABLE();
4539 }
4540}
4541
4542
4543template<class T>
4544static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4545 int to_index = GetSequenceIndexFromFastElementsKind(
4546 TERMINAL_FAST_ELEMENTS_KIND);
4547 for (int i = 0; i <= to_index; ++i) {
4548 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4549 T stub(isolate, kind);
4550 stub.GetCode();
4551 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4552 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4553 stub1.GetCode();
4554 }
4555 }
4556}
4557
4558
4559void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4560 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4561 isolate);
4562 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4563 isolate);
4564 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4565 isolate);
4566}
4567
4568
4569void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4570 Isolate* isolate) {
4571 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4572 for (int i = 0; i < 2; i++) {
4573 // For internal arrays we only need a few things.
4574 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4575 stubh1.GetCode();
4576 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4577 stubh2.GetCode();
4578 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4579 stubh3.GetCode();
4580 }
4581}
4582
4583
4584void ArrayConstructorStub::GenerateDispatchToArrayStub(
4585 MacroAssembler* masm,
4586 AllocationSiteOverrideMode mode) {
4587 if (argument_count() == ANY) {
4588 Label not_zero_case, not_one_case;
4589 __ And(at, a0, a0);
4590 __ Branch(&not_zero_case, ne, at, Operand(zero_reg));
4591 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4592
4593 __ bind(&not_zero_case);
4594 __ Branch(&not_one_case, gt, a0, Operand(1));
4595 CreateArrayDispatchOneArgument(masm, mode);
4596
4597 __ bind(&not_one_case);
4598 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4599 } else if (argument_count() == NONE) {
4600 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4601 } else if (argument_count() == ONE) {
4602 CreateArrayDispatchOneArgument(masm, mode);
4603 } else if (argument_count() == MORE_THAN_ONE) {
4604 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4605 } else {
4606 UNREACHABLE();
4607 }
4608}
4609
4610
4611void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4612 // ----------- S t a t e -------------
4613 // -- a0 : argc (only if argument_count() == ANY)
4614 // -- a1 : constructor
4615 // -- a2 : AllocationSite or undefined
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004616 // -- a3 : new target
4617 // -- sp[0] : last argument
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004618 // -----------------------------------
4619
4620 if (FLAG_debug_code) {
4621 // The array construct code is only set for the global and natives
4622 // builtin Array functions which always have maps.
4623
4624 // Initial map for the builtin Array function should be a map.
4625 __ ld(a4, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
4626 // Will both indicate a NULL and a Smi.
4627 __ SmiTst(a4, at);
4628 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
4629 at, Operand(zero_reg));
4630 __ GetObjectType(a4, a4, a5);
4631 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
4632 a5, Operand(MAP_TYPE));
4633
4634 // We should either have undefined in a2 or a valid AllocationSite
4635 __ AssertUndefinedOrAllocationSite(a2, a4);
4636 }
4637
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004638 // Enter the context of the Array function.
4639 __ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
4640
4641 Label subclassing;
4642 __ Branch(&subclassing, ne, a1, Operand(a3));
4643
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004644 Label no_info;
4645 // Get the elements kind and case on that.
4646 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4647 __ Branch(&no_info, eq, a2, Operand(at));
4648
4649 __ ld(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4650 __ SmiUntag(a3);
4651 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4652 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
4653 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4654
4655 __ bind(&no_info);
4656 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004657
4658 // Subclassing.
4659 __ bind(&subclassing);
4660 switch (argument_count()) {
4661 case ANY:
4662 case MORE_THAN_ONE:
Ben Murdoch097c5b22016-05-18 11:27:45 +01004663 __ Dlsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004664 __ sd(a1, MemOperand(at));
4665 __ li(at, Operand(3));
4666 __ Daddu(a0, a0, at);
4667 break;
4668 case NONE:
4669 __ sd(a1, MemOperand(sp, 0 * kPointerSize));
4670 __ li(a0, Operand(3));
4671 break;
4672 case ONE:
4673 __ sd(a1, MemOperand(sp, 1 * kPointerSize));
4674 __ li(a0, Operand(4));
4675 break;
4676 }
4677 __ Push(a3, a2);
4678 __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004679}
4680
4681
4682void InternalArrayConstructorStub::GenerateCase(
4683 MacroAssembler* masm, ElementsKind kind) {
4684
4685 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4686 __ TailCallStub(&stub0, lo, a0, Operand(1));
4687
4688 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4689 __ TailCallStub(&stubN, hi, a0, Operand(1));
4690
4691 if (IsFastPackedElementsKind(kind)) {
4692 // We might need to create a holey array
4693 // look at the first argument.
4694 __ ld(at, MemOperand(sp, 0));
4695
4696 InternalArraySingleArgumentConstructorStub
4697 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4698 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
4699 }
4700
4701 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4702 __ TailCallStub(&stub1);
4703}
4704
4705
4706void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4707 // ----------- S t a t e -------------
4708 // -- a0 : argc
4709 // -- a1 : constructor
4710 // -- sp[0] : return address
4711 // -- sp[4] : last argument
4712 // -----------------------------------
4713
4714 if (FLAG_debug_code) {
4715 // The array construct code is only set for the global and natives
4716 // builtin Array functions which always have maps.
4717
4718 // Initial map for the builtin Array function should be a map.
4719 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
4720 // Will both indicate a NULL and a Smi.
4721 __ SmiTst(a3, at);
4722 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
4723 at, Operand(zero_reg));
4724 __ GetObjectType(a3, a3, a4);
4725 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
4726 a4, Operand(MAP_TYPE));
4727 }
4728
4729 // Figure out the right elements kind.
4730 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
4731
4732 // Load the map's "bit field 2" into a3. We only need the first byte,
4733 // but the following bit field extraction takes care of that anyway.
4734 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
4735 // Retrieve elements_kind from bit field 2.
4736 __ DecodeField<Map::ElementsKindBits>(a3);
4737
4738 if (FLAG_debug_code) {
4739 Label done;
4740 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
4741 __ Assert(
4742 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
4743 a3, Operand(FAST_HOLEY_ELEMENTS));
4744 __ bind(&done);
4745 }
4746
4747 Label fast_elements_case;
4748 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
4749 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4750
4751 __ bind(&fast_elements_case);
4752 GenerateCase(masm, FAST_ELEMENTS);
4753}
4754
4755
Ben Murdoch097c5b22016-05-18 11:27:45 +01004756void FastNewObjectStub::Generate(MacroAssembler* masm) {
4757 // ----------- S t a t e -------------
4758 // -- a1 : target
4759 // -- a3 : new target
4760 // -- cp : context
4761 // -- ra : return address
4762 // -----------------------------------
4763 __ AssertFunction(a1);
4764 __ AssertReceiver(a3);
4765
4766 // Verify that the new target is a JSFunction.
4767 Label new_object;
4768 __ GetObjectType(a3, a2, a2);
4769 __ Branch(&new_object, ne, a2, Operand(JS_FUNCTION_TYPE));
4770
4771 // Load the initial map and verify that it's in fact a map.
4772 __ ld(a2, FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset));
4773 __ JumpIfSmi(a2, &new_object);
4774 __ GetObjectType(a2, a0, a0);
4775 __ Branch(&new_object, ne, a0, Operand(MAP_TYPE));
4776
4777 // Fall back to runtime if the target differs from the new target's
4778 // initial map constructor.
4779 __ ld(a0, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset));
4780 __ Branch(&new_object, ne, a0, Operand(a1));
4781
4782 // Allocate the JSObject on the heap.
4783 Label allocate, done_allocate;
4784 __ lbu(a4, FieldMemOperand(a2, Map::kInstanceSizeOffset));
4785 __ Allocate(a4, v0, a5, a0, &allocate, SIZE_IN_WORDS);
4786 __ bind(&done_allocate);
4787
4788 // Initialize the JSObject fields.
4789 __ sd(a2, MemOperand(v0, JSObject::kMapOffset));
4790 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
4791 __ sd(a3, MemOperand(v0, JSObject::kPropertiesOffset));
4792 __ sd(a3, MemOperand(v0, JSObject::kElementsOffset));
4793 STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize);
4794 __ Daddu(a1, v0, Operand(JSObject::kHeaderSize));
4795
4796 // ----------- S t a t e -------------
4797 // -- v0 : result (untagged)
4798 // -- a1 : result fields (untagged)
4799 // -- a5 : result end (untagged)
4800 // -- a2 : initial map
4801 // -- cp : context
4802 // -- ra : return address
4803 // -----------------------------------
4804
4805 // Perform in-object slack tracking if requested.
4806 Label slack_tracking;
4807 STATIC_ASSERT(Map::kNoSlackTracking == 0);
4808 __ lwu(a3, FieldMemOperand(a2, Map::kBitField3Offset));
4809 __ And(at, a3, Operand(Map::ConstructionCounter::kMask));
4810 __ Branch(USE_DELAY_SLOT, &slack_tracking, ne, at, Operand(zero_reg));
4811 __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); // In delay slot.
4812 {
4813 // Initialize all in-object fields with undefined.
4814 __ InitializeFieldsWithFiller(a1, a5, a0);
4815
4816 // Add the object tag to make the JSObject real.
4817 STATIC_ASSERT(kHeapObjectTag == 1);
4818 __ Ret(USE_DELAY_SLOT);
4819 __ Daddu(v0, v0, Operand(kHeapObjectTag)); // In delay slot.
4820 }
4821 __ bind(&slack_tracking);
4822 {
4823 // Decrease generous allocation count.
4824 STATIC_ASSERT(Map::ConstructionCounter::kNext == 32);
4825 __ Subu(a3, a3, Operand(1 << Map::ConstructionCounter::kShift));
4826 __ sw(a3, FieldMemOperand(a2, Map::kBitField3Offset));
4827
4828 // Initialize the in-object fields with undefined.
4829 __ lbu(a4, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset));
4830 __ dsll(a4, a4, kPointerSizeLog2);
4831 __ Dsubu(a4, a5, a4);
4832 __ InitializeFieldsWithFiller(a1, a4, a0);
4833
4834 // Initialize the remaining (reserved) fields with one pointer filler map.
4835 __ LoadRoot(a0, Heap::kOnePointerFillerMapRootIndex);
4836 __ InitializeFieldsWithFiller(a1, a5, a0);
4837
4838 // Check if we can finalize the instance size.
4839 Label finalize;
4840 STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1);
4841 __ And(a3, a3, Operand(Map::ConstructionCounter::kMask));
4842 __ Branch(USE_DELAY_SLOT, &finalize, eq, a3, Operand(zero_reg));
4843 STATIC_ASSERT(kHeapObjectTag == 1);
4844 __ Daddu(v0, v0, Operand(kHeapObjectTag)); // In delay slot.
4845 __ Ret();
4846
4847 // Finalize the instance size.
4848 __ bind(&finalize);
4849 {
4850 FrameScope scope(masm, StackFrame::INTERNAL);
4851 __ Push(v0, a2);
4852 __ CallRuntime(Runtime::kFinalizeInstanceSize);
4853 __ Pop(v0);
4854 }
4855 __ Ret();
4856 }
4857
4858 // Fall back to %AllocateInNewSpace.
4859 __ bind(&allocate);
4860 {
4861 FrameScope scope(masm, StackFrame::INTERNAL);
4862 STATIC_ASSERT(kSmiTag == 0);
4863 STATIC_ASSERT(kSmiTagSize == 1);
4864 __ dsll(a4, a4, kPointerSizeLog2 + kSmiShiftSize + kSmiTagSize);
4865 __ SmiTag(a4);
4866 __ Push(a2, a4);
4867 __ CallRuntime(Runtime::kAllocateInNewSpace);
4868 __ Pop(a2);
4869 }
4870 STATIC_ASSERT(kHeapObjectTag == 1);
4871 __ Dsubu(v0, v0, Operand(kHeapObjectTag));
4872 __ lbu(a5, FieldMemOperand(a2, Map::kInstanceSizeOffset));
4873 __ Dlsa(a5, v0, a5, kPointerSizeLog2);
4874 __ jmp(&done_allocate);
4875
4876 // Fall back to %NewObject.
4877 __ bind(&new_object);
4878 __ Push(a1, a3);
4879 __ TailCallRuntime(Runtime::kNewObject);
4880}
4881
4882
4883void FastNewRestParameterStub::Generate(MacroAssembler* masm) {
4884 // ----------- S t a t e -------------
4885 // -- a1 : function
4886 // -- cp : context
4887 // -- fp : frame pointer
4888 // -- ra : return address
4889 // -----------------------------------
4890 __ AssertFunction(a1);
4891
4892 // For Ignition we need to skip all possible handler/stub frames until
4893 // we reach the JavaScript frame for the function (similar to what the
4894 // runtime fallback implementation does). So make a2 point to that
4895 // JavaScript frame.
4896 {
4897 Label loop, loop_entry;
4898 __ Branch(USE_DELAY_SLOT, &loop_entry);
4899 __ mov(a2, fp); // In delay slot.
4900 __ bind(&loop);
4901 __ ld(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
4902 __ bind(&loop_entry);
4903 __ ld(a3, MemOperand(a2, StandardFrameConstants::kMarkerOffset));
4904 __ Branch(&loop, ne, a1, Operand(a3));
4905 }
4906
4907 // Check if we have rest parameters (only possible if we have an
4908 // arguments adaptor frame below the function frame).
4909 Label no_rest_parameters;
4910 __ ld(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
4911 __ ld(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
4912 __ Branch(&no_rest_parameters, ne, a3,
4913 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4914
4915 // Check if the arguments adaptor frame contains more arguments than
4916 // specified by the function's internal formal parameter count.
4917 Label rest_parameters;
4918 __ SmiLoadUntag(
4919 a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
4920 __ ld(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
4921 __ lw(a1,
4922 FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset));
4923 __ Dsubu(a0, a0, Operand(a1));
4924 __ Branch(&rest_parameters, gt, a0, Operand(zero_reg));
4925
4926 // Return an empty rest parameter array.
4927 __ bind(&no_rest_parameters);
4928 {
4929 // ----------- S t a t e -------------
4930 // -- cp : context
4931 // -- ra : return address
4932 // -----------------------------------
4933
4934 // Allocate an empty rest parameter array.
4935 Label allocate, done_allocate;
4936 __ Allocate(JSArray::kSize, v0, a0, a1, &allocate, TAG_OBJECT);
4937 __ bind(&done_allocate);
4938
4939 // Setup the rest parameter array in v0.
4940 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, a1);
4941 __ sd(a1, FieldMemOperand(v0, JSArray::kMapOffset));
4942 __ LoadRoot(a1, Heap::kEmptyFixedArrayRootIndex);
4943 __ sd(a1, FieldMemOperand(v0, JSArray::kPropertiesOffset));
4944 __ sd(a1, FieldMemOperand(v0, JSArray::kElementsOffset));
4945 __ Move(a1, Smi::FromInt(0));
4946 __ Ret(USE_DELAY_SLOT);
4947 __ sd(a1, FieldMemOperand(v0, JSArray::kLengthOffset)); // In delay slot
4948 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
4949
4950 // Fall back to %AllocateInNewSpace.
4951 __ bind(&allocate);
4952 {
4953 FrameScope scope(masm, StackFrame::INTERNAL);
4954 __ Push(Smi::FromInt(JSArray::kSize));
4955 __ CallRuntime(Runtime::kAllocateInNewSpace);
4956 }
4957 __ jmp(&done_allocate);
4958 }
4959
4960 __ bind(&rest_parameters);
4961 {
4962 // Compute the pointer to the first rest parameter (skippping the receiver).
4963 __ Dlsa(a2, a2, a0, kPointerSizeLog2);
4964 __ Daddu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset -
4965 1 * kPointerSize));
4966
4967 // ----------- S t a t e -------------
4968 // -- cp : context
4969 // -- a0 : number of rest parameters
4970 // -- a2 : pointer to first rest parameters
4971 // -- ra : return address
4972 // -----------------------------------
4973
4974 // Allocate space for the rest parameter array plus the backing store.
4975 Label allocate, done_allocate;
4976 __ li(a1, Operand(JSArray::kSize + FixedArray::kHeaderSize));
4977 __ Dlsa(a1, a1, a0, kPointerSizeLog2);
4978 __ Allocate(a1, v0, a3, a4, &allocate, TAG_OBJECT);
4979 __ bind(&done_allocate);
4980
4981 // Compute arguments.length in a4.
4982 __ SmiTag(a4, a0);
4983
4984 // Setup the elements array in v0.
4985 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4986 __ sd(at, FieldMemOperand(v0, FixedArray::kMapOffset));
4987 __ sd(a4, FieldMemOperand(v0, FixedArray::kLengthOffset));
4988 __ Daddu(a3, v0, Operand(FixedArray::kHeaderSize));
4989 {
4990 Label loop, done_loop;
4991 __ Dlsa(a1, a3, a0, kPointerSizeLog2);
4992 __ bind(&loop);
4993 __ Branch(&done_loop, eq, a1, Operand(a3));
4994 __ ld(at, MemOperand(a2, 0 * kPointerSize));
4995 __ sd(at, FieldMemOperand(a3, 0 * kPointerSize));
4996 __ Dsubu(a2, a2, Operand(1 * kPointerSize));
4997 __ Daddu(a3, a3, Operand(1 * kPointerSize));
4998 __ Branch(&loop);
4999 __ bind(&done_loop);
5000 }
5001
5002 // Setup the rest parameter array in a3.
5003 __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, at);
5004 __ sd(at, FieldMemOperand(a3, JSArray::kMapOffset));
5005 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
5006 __ sd(at, FieldMemOperand(a3, JSArray::kPropertiesOffset));
5007 __ sd(v0, FieldMemOperand(a3, JSArray::kElementsOffset));
5008 __ sd(a4, FieldMemOperand(a3, JSArray::kLengthOffset));
5009 STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize);
5010 __ Ret(USE_DELAY_SLOT);
5011 __ mov(v0, a3); // In delay slot
5012
5013 // Fall back to %AllocateInNewSpace.
5014 __ bind(&allocate);
5015 {
5016 FrameScope scope(masm, StackFrame::INTERNAL);
5017 __ SmiTag(a0);
5018 __ SmiTag(a1);
5019 __ Push(a0, a2, a1);
5020 __ CallRuntime(Runtime::kAllocateInNewSpace);
5021 __ Pop(a0, a2);
5022 __ SmiUntag(a0);
5023 }
5024 __ jmp(&done_allocate);
5025 }
5026}
5027
5028
5029void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) {
5030 // ----------- S t a t e -------------
5031 // -- a1 : function
5032 // -- cp : context
5033 // -- fp : frame pointer
5034 // -- ra : return address
5035 // -----------------------------------
5036 __ AssertFunction(a1);
5037
5038 // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub.
5039 __ ld(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
5040 __ lw(a2,
5041 FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
5042 __ Lsa(a3, fp, a2, kPointerSizeLog2);
5043 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
5044 __ SmiTag(a2);
5045
5046 // a1 : function
5047 // a2 : number of parameters (tagged)
5048 // a3 : parameters pointer
5049 // Registers used over whole function:
5050 // a5 : arguments count (tagged)
5051 // a6 : mapped parameter count (tagged)
5052
5053 // Check if the calling frame is an arguments adaptor frame.
5054 Label adaptor_frame, try_allocate, runtime;
5055 __ ld(a4, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
5056 __ ld(a0, MemOperand(a4, StandardFrameConstants::kContextOffset));
5057 __ Branch(&adaptor_frame, eq, a0,
5058 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5059
5060 // No adaptor, parameter count = argument count.
5061 __ mov(a5, a2);
5062 __ Branch(USE_DELAY_SLOT, &try_allocate);
5063 __ mov(a6, a2); // In delay slot.
5064
5065 // We have an adaptor frame. Patch the parameters pointer.
5066 __ bind(&adaptor_frame);
5067 __ ld(a5, MemOperand(a4, ArgumentsAdaptorFrameConstants::kLengthOffset));
5068 __ SmiScale(t2, a5, kPointerSizeLog2);
5069 __ Daddu(a4, a4, Operand(t2));
5070 __ Daddu(a3, a4, Operand(StandardFrameConstants::kCallerSPOffset));
5071
5072 // a5 = argument count (tagged)
5073 // a6 = parameter count (tagged)
5074 // Compute the mapped parameter count = min(a6, a5) in a6.
5075 __ mov(a6, a2);
5076 __ Branch(&try_allocate, le, a6, Operand(a5));
5077 __ mov(a6, a5);
5078
5079 __ bind(&try_allocate);
5080
5081 // Compute the sizes of backing store, parameter map, and arguments object.
5082 // 1. Parameter map, has 2 extra words containing context and backing store.
5083 const int kParameterMapHeaderSize =
5084 FixedArray::kHeaderSize + 2 * kPointerSize;
5085 // If there are no mapped parameters, we do not need the parameter_map.
5086 Label param_map_size;
5087 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
5088 __ Branch(USE_DELAY_SLOT, &param_map_size, eq, a6, Operand(zero_reg));
5089 __ mov(t1, zero_reg); // In delay slot: param map size = 0 when a6 == 0.
5090 __ SmiScale(t1, a6, kPointerSizeLog2);
5091 __ daddiu(t1, t1, kParameterMapHeaderSize);
5092 __ bind(&param_map_size);
5093
5094 // 2. Backing store.
5095 __ SmiScale(t2, a5, kPointerSizeLog2);
5096 __ Daddu(t1, t1, Operand(t2));
5097 __ Daddu(t1, t1, Operand(FixedArray::kHeaderSize));
5098
5099 // 3. Arguments object.
5100 __ Daddu(t1, t1, Operand(JSSloppyArgumentsObject::kSize));
5101
5102 // Do the allocation of all three objects in one go.
5103 __ Allocate(t1, v0, t1, a4, &runtime, TAG_OBJECT);
5104
5105 // v0 = address of new object(s) (tagged)
5106 // a2 = argument count (smi-tagged)
5107 // Get the arguments boilerplate from the current native context into a4.
5108 const int kNormalOffset =
5109 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
5110 const int kAliasedOffset =
5111 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
5112
5113 __ ld(a4, NativeContextMemOperand());
5114 Label skip2_ne, skip2_eq;
5115 __ Branch(&skip2_ne, ne, a6, Operand(zero_reg));
5116 __ ld(a4, MemOperand(a4, kNormalOffset));
5117 __ bind(&skip2_ne);
5118
5119 __ Branch(&skip2_eq, eq, a6, Operand(zero_reg));
5120 __ ld(a4, MemOperand(a4, kAliasedOffset));
5121 __ bind(&skip2_eq);
5122
5123 // v0 = address of new object (tagged)
5124 // a2 = argument count (smi-tagged)
5125 // a4 = address of arguments map (tagged)
5126 // a6 = mapped parameter count (tagged)
5127 __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset));
5128 __ LoadRoot(t1, Heap::kEmptyFixedArrayRootIndex);
5129 __ sd(t1, FieldMemOperand(v0, JSObject::kPropertiesOffset));
5130 __ sd(t1, FieldMemOperand(v0, JSObject::kElementsOffset));
5131
5132 // Set up the callee in-object property.
5133 __ AssertNotSmi(a1);
5134 __ sd(a1, FieldMemOperand(v0, JSSloppyArgumentsObject::kCalleeOffset));
5135
5136 // Use the length (smi tagged) and set that as an in-object property too.
5137 __ AssertSmi(a5);
5138 __ sd(a5, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset));
5139
5140 // Set up the elements pointer in the allocated arguments object.
5141 // If we allocated a parameter map, a4 will point there, otherwise
5142 // it will point to the backing store.
5143 __ Daddu(a4, v0, Operand(JSSloppyArgumentsObject::kSize));
5144 __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset));
5145
5146 // v0 = address of new object (tagged)
5147 // a2 = argument count (tagged)
5148 // a4 = address of parameter map or backing store (tagged)
5149 // a6 = mapped parameter count (tagged)
5150 // Initialize parameter map. If there are no mapped arguments, we're done.
5151 Label skip_parameter_map;
5152 Label skip3;
5153 __ Branch(&skip3, ne, a6, Operand(Smi::FromInt(0)));
5154 // Move backing store address to a1, because it is
5155 // expected there when filling in the unmapped arguments.
5156 __ mov(a1, a4);
5157 __ bind(&skip3);
5158
5159 __ Branch(&skip_parameter_map, eq, a6, Operand(Smi::FromInt(0)));
5160
5161 __ LoadRoot(a5, Heap::kSloppyArgumentsElementsMapRootIndex);
5162 __ sd(a5, FieldMemOperand(a4, FixedArray::kMapOffset));
5163 __ Daddu(a5, a6, Operand(Smi::FromInt(2)));
5164 __ sd(a5, FieldMemOperand(a4, FixedArray::kLengthOffset));
5165 __ sd(cp, FieldMemOperand(a4, FixedArray::kHeaderSize + 0 * kPointerSize));
5166 __ SmiScale(t2, a6, kPointerSizeLog2);
5167 __ Daddu(a5, a4, Operand(t2));
5168 __ Daddu(a5, a5, Operand(kParameterMapHeaderSize));
5169 __ sd(a5, FieldMemOperand(a4, FixedArray::kHeaderSize + 1 * kPointerSize));
5170
5171 // Copy the parameter slots and the holes in the arguments.
5172 // We need to fill in mapped_parameter_count slots. They index the context,
5173 // where parameters are stored in reverse order, at
5174 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
5175 // The mapped parameter thus need to get indices
5176 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
5177 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
5178 // We loop from right to left.
5179 Label parameters_loop, parameters_test;
5180 __ mov(a5, a6);
5181 __ Daddu(t1, a2, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
5182 __ Dsubu(t1, t1, Operand(a6));
5183 __ LoadRoot(a7, Heap::kTheHoleValueRootIndex);
5184 __ SmiScale(t2, a5, kPointerSizeLog2);
5185 __ Daddu(a1, a4, Operand(t2));
5186 __ Daddu(a1, a1, Operand(kParameterMapHeaderSize));
5187
5188 // a1 = address of backing store (tagged)
5189 // a4 = address of parameter map (tagged)
5190 // a0 = temporary scratch (a.o., for address calculation)
5191 // t1 = loop variable (tagged)
5192 // a7 = the hole value
5193 __ jmp(&parameters_test);
5194
5195 __ bind(&parameters_loop);
5196 __ Dsubu(a5, a5, Operand(Smi::FromInt(1)));
5197 __ SmiScale(a0, a5, kPointerSizeLog2);
5198 __ Daddu(a0, a0, Operand(kParameterMapHeaderSize - kHeapObjectTag));
5199 __ Daddu(t2, a4, a0);
5200 __ sd(t1, MemOperand(t2));
5201 __ Dsubu(a0, a0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
5202 __ Daddu(t2, a1, a0);
5203 __ sd(a7, MemOperand(t2));
5204 __ Daddu(t1, t1, Operand(Smi::FromInt(1)));
5205 __ bind(&parameters_test);
5206 __ Branch(&parameters_loop, ne, a5, Operand(Smi::FromInt(0)));
5207
5208 // Restore t1 = argument count (tagged).
5209 __ ld(a5, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset));
5210
5211 __ bind(&skip_parameter_map);
5212 // v0 = address of new object (tagged)
5213 // a1 = address of backing store (tagged)
5214 // a5 = argument count (tagged)
5215 // a6 = mapped parameter count (tagged)
5216 // t1 = scratch
5217 // Copy arguments header and remaining slots (if there are any).
5218 __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex);
5219 __ sd(t1, FieldMemOperand(a1, FixedArray::kMapOffset));
5220 __ sd(a5, FieldMemOperand(a1, FixedArray::kLengthOffset));
5221
5222 Label arguments_loop, arguments_test;
5223 __ SmiScale(t2, a6, kPointerSizeLog2);
5224 __ Dsubu(a3, a3, Operand(t2));
5225 __ jmp(&arguments_test);
5226
5227 __ bind(&arguments_loop);
5228 __ Dsubu(a3, a3, Operand(kPointerSize));
5229 __ ld(a4, MemOperand(a3, 0));
5230 __ SmiScale(t2, a6, kPointerSizeLog2);
5231 __ Daddu(t1, a1, Operand(t2));
5232 __ sd(a4, FieldMemOperand(t1, FixedArray::kHeaderSize));
5233 __ Daddu(a6, a6, Operand(Smi::FromInt(1)));
5234
5235 __ bind(&arguments_test);
5236 __ Branch(&arguments_loop, lt, a6, Operand(a5));
5237
5238 // Return.
5239 __ Ret();
5240
5241 // Do the runtime call to allocate the arguments object.
5242 // a5 = argument count (tagged)
5243 __ bind(&runtime);
5244 __ Push(a1, a3, a5);
5245 __ TailCallRuntime(Runtime::kNewSloppyArguments);
5246}
5247
5248
5249void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) {
5250 // ----------- S t a t e -------------
5251 // -- a1 : function
5252 // -- cp : context
5253 // -- fp : frame pointer
5254 // -- ra : return address
5255 // -----------------------------------
5256 __ AssertFunction(a1);
5257
5258 // For Ignition we need to skip all possible handler/stub frames until
5259 // we reach the JavaScript frame for the function (similar to what the
5260 // runtime fallback implementation does). So make a2 point to that
5261 // JavaScript frame.
5262 {
5263 Label loop, loop_entry;
5264 __ Branch(USE_DELAY_SLOT, &loop_entry);
5265 __ mov(a2, fp); // In delay slot.
5266 __ bind(&loop);
5267 __ ld(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
5268 __ bind(&loop_entry);
5269 __ ld(a3, MemOperand(a2, StandardFrameConstants::kMarkerOffset));
5270 __ Branch(&loop, ne, a1, Operand(a3));
5271 }
5272
5273 // Check if we have an arguments adaptor frame below the function frame.
5274 Label arguments_adaptor, arguments_done;
5275 __ ld(a3, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
5276 __ ld(a0, MemOperand(a3, StandardFrameConstants::kContextOffset));
5277 __ Branch(&arguments_adaptor, eq, a0,
5278 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5279 {
5280 __ ld(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
5281 __ lw(a0,
5282 FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset));
5283 __ Dlsa(a2, a2, a0, kPointerSizeLog2);
5284 __ Daddu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset -
5285 1 * kPointerSize));
5286 }
5287 __ Branch(&arguments_done);
5288 __ bind(&arguments_adaptor);
5289 {
5290 __ SmiLoadUntag(
5291 a0, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
5292 __ Dlsa(a2, a3, a0, kPointerSizeLog2);
5293 __ Daddu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset -
5294 1 * kPointerSize));
5295 }
5296 __ bind(&arguments_done);
5297
5298 // ----------- S t a t e -------------
5299 // -- cp : context
5300 // -- a0 : number of rest parameters
5301 // -- a2 : pointer to first rest parameters
5302 // -- ra : return address
5303 // -----------------------------------
5304
5305 // Allocate space for the rest parameter array plus the backing store.
5306 Label allocate, done_allocate;
5307 __ li(a1, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize));
5308 __ Dlsa(a1, a1, a0, kPointerSizeLog2);
5309 __ Allocate(a1, v0, a3, a4, &allocate, TAG_OBJECT);
5310 __ bind(&done_allocate);
5311
5312 // Compute arguments.length in a4.
5313 __ SmiTag(a4, a0);
5314
5315 // Setup the elements array in v0.
5316 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
5317 __ sd(at, FieldMemOperand(v0, FixedArray::kMapOffset));
5318 __ sd(a4, FieldMemOperand(v0, FixedArray::kLengthOffset));
5319 __ Daddu(a3, v0, Operand(FixedArray::kHeaderSize));
5320 {
5321 Label loop, done_loop;
5322 __ Dlsa(a1, a3, a0, kPointerSizeLog2);
5323 __ bind(&loop);
5324 __ Branch(&done_loop, eq, a1, Operand(a3));
5325 __ ld(at, MemOperand(a2, 0 * kPointerSize));
5326 __ sd(at, FieldMemOperand(a3, 0 * kPointerSize));
5327 __ Dsubu(a2, a2, Operand(1 * kPointerSize));
5328 __ Daddu(a3, a3, Operand(1 * kPointerSize));
5329 __ Branch(&loop);
5330 __ bind(&done_loop);
5331 }
5332
5333 // Setup the strict arguments object in a3.
5334 __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, at);
5335 __ sd(at, FieldMemOperand(a3, JSStrictArgumentsObject::kMapOffset));
5336 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
5337 __ sd(at, FieldMemOperand(a3, JSStrictArgumentsObject::kPropertiesOffset));
5338 __ sd(v0, FieldMemOperand(a3, JSStrictArgumentsObject::kElementsOffset));
5339 __ sd(a4, FieldMemOperand(a3, JSStrictArgumentsObject::kLengthOffset));
5340 STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize);
5341 __ Ret(USE_DELAY_SLOT);
5342 __ mov(v0, a3); // In delay slot
5343
5344 // Fall back to %AllocateInNewSpace.
5345 __ bind(&allocate);
5346 {
5347 FrameScope scope(masm, StackFrame::INTERNAL);
5348 __ SmiTag(a0);
5349 __ SmiTag(a1);
5350 __ Push(a0, a2, a1);
5351 __ CallRuntime(Runtime::kAllocateInNewSpace);
5352 __ Pop(a0, a2);
5353 __ SmiUntag(a0);
5354 }
5355 __ jmp(&done_allocate);
5356}
5357
5358
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005359void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5360 Register context_reg = cp;
5361 Register slot_reg = a2;
5362 Register result_reg = v0;
5363 Label slow_case;
5364
5365 // Go up context chain to the script context.
5366 for (int i = 0; i < depth(); ++i) {
5367 __ ld(result_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX));
5368 context_reg = result_reg;
5369 }
5370
5371 // Load the PropertyCell value at the specified slot.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005372 __ Dlsa(at, context_reg, slot_reg, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005373 __ ld(result_reg, ContextMemOperand(at, 0));
5374 __ ld(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5375
5376 // Check that value is not the_hole.
5377 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5378 __ Branch(&slow_case, eq, result_reg, Operand(at));
5379 __ Ret();
5380
5381 // Fallback to the runtime.
5382 __ bind(&slow_case);
5383 __ SmiTag(slot_reg);
5384 __ Push(slot_reg);
5385 __ TailCallRuntime(Runtime::kLoadGlobalViaContext);
5386}
5387
5388
5389void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5390 Register context_reg = cp;
5391 Register slot_reg = a2;
5392 Register value_reg = a0;
5393 Register cell_reg = a4;
5394 Register cell_value_reg = a5;
5395 Register cell_details_reg = a6;
5396 Label fast_heapobject_case, fast_smi_case, slow_case;
5397
5398 if (FLAG_debug_code) {
5399 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5400 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5401 }
5402
5403 // Go up context chain to the script context.
5404 for (int i = 0; i < depth(); ++i) {
5405 __ ld(cell_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX));
5406 context_reg = cell_reg;
5407 }
5408
5409 // Load the PropertyCell at the specified slot.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005410 __ Dlsa(at, context_reg, slot_reg, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005411 __ ld(cell_reg, ContextMemOperand(at, 0));
5412
5413 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5414 __ ld(cell_details_reg,
5415 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5416 __ SmiUntag(cell_details_reg);
5417 __ And(cell_details_reg, cell_details_reg,
5418 PropertyDetails::PropertyCellTypeField::kMask |
5419 PropertyDetails::KindField::kMask |
5420 PropertyDetails::kAttributesReadOnlyMask);
5421
5422 // Check if PropertyCell holds mutable data.
5423 Label not_mutable_data;
5424 __ Branch(&not_mutable_data, ne, cell_details_reg,
5425 Operand(PropertyDetails::PropertyCellTypeField::encode(
5426 PropertyCellType::kMutable) |
5427 PropertyDetails::KindField::encode(kData)));
5428 __ JumpIfSmi(value_reg, &fast_smi_case);
5429 __ bind(&fast_heapobject_case);
5430 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5431 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5432 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5433 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5434 // RecordWriteField clobbers the value register, so we need to reload.
5435 __ Ret(USE_DELAY_SLOT);
5436 __ ld(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5437 __ bind(&not_mutable_data);
5438
5439 // Check if PropertyCell value matches the new value (relevant for Constant,
5440 // ConstantType and Undefined cells).
5441 Label not_same_value;
5442 __ ld(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5443 __ Branch(&not_same_value, ne, value_reg, Operand(cell_value_reg));
5444 // Make sure the PropertyCell is not marked READ_ONLY.
5445 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5446 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5447 if (FLAG_debug_code) {
5448 Label done;
5449 // This can only be true for Constant, ConstantType and Undefined cells,
5450 // because we never store the_hole via this stub.
5451 __ Branch(&done, eq, cell_details_reg,
5452 Operand(PropertyDetails::PropertyCellTypeField::encode(
5453 PropertyCellType::kConstant) |
5454 PropertyDetails::KindField::encode(kData)));
5455 __ Branch(&done, eq, cell_details_reg,
5456 Operand(PropertyDetails::PropertyCellTypeField::encode(
5457 PropertyCellType::kConstantType) |
5458 PropertyDetails::KindField::encode(kData)));
5459 __ Check(eq, kUnexpectedValue, cell_details_reg,
5460 Operand(PropertyDetails::PropertyCellTypeField::encode(
5461 PropertyCellType::kUndefined) |
5462 PropertyDetails::KindField::encode(kData)));
5463 __ bind(&done);
5464 }
5465 __ Ret();
5466 __ bind(&not_same_value);
5467
5468 // Check if PropertyCell contains data with constant type (and is not
5469 // READ_ONLY).
5470 __ Branch(&slow_case, ne, cell_details_reg,
5471 Operand(PropertyDetails::PropertyCellTypeField::encode(
5472 PropertyCellType::kConstantType) |
5473 PropertyDetails::KindField::encode(kData)));
5474
5475 // Now either both old and new values must be SMIs or both must be heap
5476 // objects with same map.
5477 Label value_is_heap_object;
5478 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5479 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5480 // Old and new values are SMIs, no need for a write barrier here.
5481 __ bind(&fast_smi_case);
5482 __ Ret(USE_DELAY_SLOT);
5483 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5484 __ bind(&value_is_heap_object);
5485 __ JumpIfSmi(cell_value_reg, &slow_case);
5486 Register cell_value_map_reg = cell_value_reg;
5487 __ ld(cell_value_map_reg,
5488 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5489 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5490 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5491
5492 // Fallback to the runtime.
5493 __ bind(&slow_case);
5494 __ SmiTag(slot_reg);
5495 __ Push(slot_reg, value_reg);
5496 __ TailCallRuntime(is_strict(language_mode())
5497 ? Runtime::kStoreGlobalViaContext_Strict
5498 : Runtime::kStoreGlobalViaContext_Sloppy);
5499}
5500
5501
5502static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5503 int64_t offset = (ref0.address() - ref1.address());
5504 DCHECK(static_cast<int>(offset) == offset);
5505 return static_cast<int>(offset);
5506}
5507
5508
5509// Calls an API function. Allocates HandleScope, extracts returned value
5510// from handle and propagates exceptions. Restores context. stack_space
5511// - space to be unwound on exit (includes the call JS arguments space and
5512// the additional space allocated for the fast call).
5513static void CallApiFunctionAndReturn(
5514 MacroAssembler* masm, Register function_address,
5515 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5516 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5517 Isolate* isolate = masm->isolate();
5518 ExternalReference next_address =
5519 ExternalReference::handle_scope_next_address(isolate);
5520 const int kNextOffset = 0;
5521 const int kLimitOffset = AddressOffset(
5522 ExternalReference::handle_scope_limit_address(isolate), next_address);
5523 const int kLevelOffset = AddressOffset(
5524 ExternalReference::handle_scope_level_address(isolate), next_address);
5525
5526 DCHECK(function_address.is(a1) || function_address.is(a2));
5527
5528 Label profiler_disabled;
5529 Label end_profiler_check;
5530 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5531 __ lb(t9, MemOperand(t9, 0));
5532 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5533
5534 // Additional parameter is the address of the actual callback.
5535 __ li(t9, Operand(thunk_ref));
5536 __ jmp(&end_profiler_check);
5537
5538 __ bind(&profiler_disabled);
5539 __ mov(t9, function_address);
5540 __ bind(&end_profiler_check);
5541
5542 // Allocate HandleScope in callee-save registers.
5543 __ li(s3, Operand(next_address));
5544 __ ld(s0, MemOperand(s3, kNextOffset));
5545 __ ld(s1, MemOperand(s3, kLimitOffset));
5546 __ lw(s2, MemOperand(s3, kLevelOffset));
5547 __ Addu(s2, s2, Operand(1));
5548 __ sw(s2, MemOperand(s3, kLevelOffset));
5549
5550 if (FLAG_log_timer_events) {
5551 FrameScope frame(masm, StackFrame::MANUAL);
5552 __ PushSafepointRegisters();
5553 __ PrepareCallCFunction(1, a0);
5554 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5555 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5556 1);
5557 __ PopSafepointRegisters();
5558 }
5559
5560 // Native call returns to the DirectCEntry stub which redirects to the
5561 // return address pushed on stack (could have moved after GC).
5562 // DirectCEntry stub itself is generated early and never moves.
5563 DirectCEntryStub stub(isolate);
5564 stub.GenerateCall(masm, t9);
5565
5566 if (FLAG_log_timer_events) {
5567 FrameScope frame(masm, StackFrame::MANUAL);
5568 __ PushSafepointRegisters();
5569 __ PrepareCallCFunction(1, a0);
5570 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5571 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5572 1);
5573 __ PopSafepointRegisters();
5574 }
5575
5576 Label promote_scheduled_exception;
5577 Label delete_allocated_handles;
5578 Label leave_exit_frame;
5579 Label return_value_loaded;
5580
5581 // Load value from ReturnValue.
5582 __ ld(v0, return_value_operand);
5583 __ bind(&return_value_loaded);
5584
5585 // No more valid handles (the result handle was the last one). Restore
5586 // previous handle scope.
5587 __ sd(s0, MemOperand(s3, kNextOffset));
5588 if (__ emit_debug_code()) {
5589 __ lw(a1, MemOperand(s3, kLevelOffset));
5590 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5591 }
5592 __ Subu(s2, s2, Operand(1));
5593 __ sw(s2, MemOperand(s3, kLevelOffset));
5594 __ ld(at, MemOperand(s3, kLimitOffset));
5595 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5596
5597 // Leave the API exit frame.
5598 __ bind(&leave_exit_frame);
5599
5600 bool restore_context = context_restore_operand != NULL;
5601 if (restore_context) {
5602 __ ld(cp, *context_restore_operand);
5603 }
5604 if (stack_space_offset != kInvalidStackOffset) {
5605 DCHECK(kCArgsSlotsSize == 0);
5606 __ ld(s0, MemOperand(sp, stack_space_offset));
5607 } else {
5608 __ li(s0, Operand(stack_space));
5609 }
5610 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5611 stack_space_offset != kInvalidStackOffset);
5612
5613 // Check if the function scheduled an exception.
5614 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
5615 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5616 __ ld(a5, MemOperand(at));
5617 __ Branch(&promote_scheduled_exception, ne, a4, Operand(a5));
5618
5619 __ Ret();
5620
5621 // Re-throw by promoting a scheduled exception.
5622 __ bind(&promote_scheduled_exception);
5623 __ TailCallRuntime(Runtime::kPromoteScheduledException);
5624
5625 // HandleScope limit has changed. Delete allocated extensions.
5626 __ bind(&delete_allocated_handles);
5627 __ sd(s1, MemOperand(s3, kLimitOffset));
5628 __ mov(s0, v0);
5629 __ mov(a0, v0);
5630 __ PrepareCallCFunction(1, s1);
5631 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5632 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5633 1);
5634 __ mov(v0, s0);
5635 __ jmp(&leave_exit_frame);
5636}
5637
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005638static void CallApiFunctionStubHelper(MacroAssembler* masm,
5639 const ParameterCount& argc,
5640 bool return_first_arg,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005641 bool call_data_undefined, bool is_lazy) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005642 // ----------- S t a t e -------------
5643 // -- a0 : callee
5644 // -- a4 : call_data
5645 // -- a2 : holder
5646 // -- a1 : api_function_address
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005647 // -- a3 : number of arguments if argc is a register
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005648 // -- cp : context
5649 // --
5650 // -- sp[0] : last argument
5651 // -- ...
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005652 // -- sp[(argc - 1)* 8] : first argument
5653 // -- sp[argc * 8] : receiver
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005654 // -----------------------------------
5655
5656 Register callee = a0;
5657 Register call_data = a4;
5658 Register holder = a2;
5659 Register api_function_address = a1;
5660 Register context = cp;
5661
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005662 typedef FunctionCallbackArguments FCA;
5663
5664 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5665 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5666 STATIC_ASSERT(FCA::kDataIndex == 4);
5667 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5668 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5669 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5670 STATIC_ASSERT(FCA::kHolderIndex == 0);
5671 STATIC_ASSERT(FCA::kArgsLength == 7);
5672
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005673 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5674
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005675 // Save context, callee and call data.
5676 __ Push(context, callee, call_data);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005677 if (!is_lazy) {
5678 // Load context from callee.
5679 __ ld(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5680 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005681
5682 Register scratch = call_data;
5683 if (!call_data_undefined) {
5684 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5685 }
5686 // Push return value and default return value.
5687 __ Push(scratch, scratch);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005688 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005689 // Push isolate and holder.
5690 __ Push(scratch, holder);
5691
5692 // Prepare arguments.
5693 __ mov(scratch, sp);
5694
5695 // Allocate the v8::Arguments structure in the arguments' space since
5696 // it's not controlled by GC.
5697 const int kApiStackSpace = 4;
5698
5699 FrameScope frame_scope(masm, StackFrame::MANUAL);
5700 __ EnterExitFrame(false, kApiStackSpace);
5701
5702 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5703 // a0 = FunctionCallbackInfo&
5704 // Arguments is after the return address.
5705 __ Daddu(a0, sp, Operand(1 * kPointerSize));
5706 // FunctionCallbackInfo::implicit_args_
5707 __ sd(scratch, MemOperand(a0, 0 * kPointerSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005708 if (argc.is_immediate()) {
5709 // FunctionCallbackInfo::values_
5710 __ Daddu(at, scratch,
5711 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5712 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5713 // FunctionCallbackInfo::length_ = argc
5714 // Stored as int field, 32-bit integers within struct on stack always left
5715 // justified by n64 ABI.
5716 __ li(at, Operand(argc.immediate()));
5717 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5718 // FunctionCallbackInfo::is_construct_call_ = 0
5719 __ sw(zero_reg, MemOperand(a0, 2 * kPointerSize + kIntSize));
5720 } else {
5721 // FunctionCallbackInfo::values_
5722 __ dsll(at, argc.reg(), kPointerSizeLog2);
5723 __ Daddu(at, at, scratch);
5724 __ Daddu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5725 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5726 // FunctionCallbackInfo::length_ = argc
5727 // Stored as int field, 32-bit integers within struct on stack always left
5728 // justified by n64 ABI.
5729 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5730 // FunctionCallbackInfo::is_construct_call_
5731 __ Daddu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5732 __ dsll(at, argc.reg(), kPointerSizeLog2);
5733 __ sw(at, MemOperand(a0, 2 * kPointerSize + kIntSize));
5734 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005735
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005736 ExternalReference thunk_ref =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005737 ExternalReference::invoke_function_callback(masm->isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005738
5739 AllowExternalCallThatCantCauseGC scope(masm);
5740 MemOperand context_restore_operand(
5741 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5742 // Stores return the first js argument.
5743 int return_value_offset = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005744 if (return_first_arg) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005745 return_value_offset = 2 + FCA::kArgsLength;
5746 } else {
5747 return_value_offset = 2 + FCA::kReturnValueOffset;
5748 }
5749 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005750 int stack_space = 0;
5751 int32_t stack_space_offset = 4 * kPointerSize;
5752 if (argc.is_immediate()) {
5753 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5754 stack_space_offset = kInvalidStackOffset;
5755 }
5756 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5757 stack_space_offset, return_value_operand,
5758 &context_restore_operand);
5759}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005760
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005761
5762void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5763 bool call_data_undefined = this->call_data_undefined();
5764 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005765 call_data_undefined, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005766}
5767
5768
5769void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5770 bool is_store = this->is_store();
5771 int argc = this->argc();
5772 bool call_data_undefined = this->call_data_undefined();
Ben Murdoch097c5b22016-05-18 11:27:45 +01005773 bool is_lazy = this->is_lazy();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005774 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005775 call_data_undefined, is_lazy);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005776}
5777
5778
5779void CallApiGetterStub::Generate(MacroAssembler* masm) {
5780 // ----------- S t a t e -------------
Ben Murdoch097c5b22016-05-18 11:27:45 +01005781 // -- sp[0] : name
5782 // -- sp[8 .. (8 + kArgsLength*8)] : v8::PropertyCallbackInfo::args_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005783 // -- ...
Ben Murdoch097c5b22016-05-18 11:27:45 +01005784 // -- a2 : api_function_address
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005785 // -----------------------------------
5786
5787 Register api_function_address = ApiGetterDescriptor::function_address();
5788 DCHECK(api_function_address.is(a2));
5789
Ben Murdoch097c5b22016-05-18 11:27:45 +01005790 // v8::PropertyCallbackInfo::args_ array and name handle.
5791 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5792
5793 // Load address of v8::PropertyAccessorInfo::args_ array and name handle.
5794 __ mov(a0, sp); // a0 = Handle<Name>
5795 __ Daddu(a1, a0, Operand(1 * kPointerSize)); // a1 = v8::PCI::args_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005796
5797 const int kApiStackSpace = 1;
5798 FrameScope frame_scope(masm, StackFrame::MANUAL);
5799 __ EnterExitFrame(false, kApiStackSpace);
5800
Ben Murdoch097c5b22016-05-18 11:27:45 +01005801 // Create v8::PropertyCallbackInfo object on the stack and initialize
5802 // it's args_ field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005803 __ sd(a1, MemOperand(sp, 1 * kPointerSize));
Ben Murdoch097c5b22016-05-18 11:27:45 +01005804 __ Daddu(a1, sp, Operand(1 * kPointerSize));
5805 // a1 = v8::PropertyCallbackInfo&
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005806
5807 ExternalReference thunk_ref =
5808 ExternalReference::invoke_accessor_getter_callback(isolate());
Ben Murdoch097c5b22016-05-18 11:27:45 +01005809
5810 // +3 is to skip prolog, return address and name handle.
5811 MemOperand return_value_operand(
5812 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005813 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5814 kStackUnwindSpace, kInvalidStackOffset,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005815 return_value_operand, NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005816}
5817
5818
5819#undef __
5820
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005821} // namespace internal
5822} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005823
5824#endif // V8_TARGET_ARCH_MIPS64