1 // 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.
5 #if V8_TARGET_ARCH_MIPS
7 #include "src/base/bits.h"
8 #include "src/bootstrapper.h"
9 #include "src/code-stubs.h"
10 #include "src/codegen.h"
11 #include "src/ic/handler-compiler.h"
12 #include "src/ic/ic.h"
13 #include "src/ic/stub-cache.h"
14 #include "src/isolate.h"
15 #include "src/regexp/jsregexp.h"
16 #include "src/regexp/regexp-macro-assembler.h"
17 #include "src/runtime/runtime.h"
23 static void InitializeArrayConstructorDescriptor(
24 Isolate* isolate, CodeStubDescriptor* descriptor,
25 int constant_stack_parameter_count) {
26 Address deopt_handler = Runtime::FunctionForId(
27 Runtime::kArrayConstructor)->entry;
29 if (constant_stack_parameter_count == 0) {
30 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
31 JS_FUNCTION_STUB_MODE);
33 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
34 JS_FUNCTION_STUB_MODE);
39 static void InitializeInternalArrayConstructorDescriptor(
40 Isolate* isolate, CodeStubDescriptor* descriptor,
41 int constant_stack_parameter_count) {
42 Address deopt_handler = Runtime::FunctionForId(
43 Runtime::kInternalArrayConstructor)->entry;
45 if (constant_stack_parameter_count == 0) {
46 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
47 JS_FUNCTION_STUB_MODE);
49 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
50 JS_FUNCTION_STUB_MODE);
55 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
56 CodeStubDescriptor* descriptor) {
57 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
61 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
62 CodeStubDescriptor* descriptor) {
63 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
67 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
68 CodeStubDescriptor* descriptor) {
69 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
73 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
74 CodeStubDescriptor* descriptor) {
75 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
79 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
80 CodeStubDescriptor* descriptor) {
81 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
85 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
86 CodeStubDescriptor* descriptor) {
87 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
91 #define __ ACCESS_MASM(masm)
94 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
95 Condition cc, Strength strength);
96 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
102 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
107 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
108 ExternalReference miss) {
109 // Update the static counter each time a new code stub is generated.
110 isolate()->counters()->code_stubs()->Increment();
112 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
113 int param_count = descriptor.GetRegisterParameterCount();
115 // Call the runtime system in a fresh internal frame.
116 FrameScope scope(masm, StackFrame::INTERNAL);
117 DCHECK(param_count == 0 ||
118 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
119 // Push arguments, adjust sp.
120 __ Subu(sp, sp, Operand(param_count * kPointerSize));
121 for (int i = 0; i < param_count; ++i) {
122 // Store argument to stack.
123 __ sw(descriptor.GetRegisterParameter(i),
124 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
126 __ CallExternalReference(miss, param_count);
133 void DoubleToIStub::Generate(MacroAssembler* masm) {
134 Label out_of_range, only_low, negate, done;
135 Register input_reg = source();
136 Register result_reg = destination();
138 int double_offset = offset();
139 // Account for saved regs if input is sp.
140 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
143 GetRegisterThatIsNotOneOf(input_reg, result_reg);
145 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
147 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
148 DoubleRegister double_scratch = kLithiumScratchDouble;
150 __ Push(scratch, scratch2, scratch3);
152 if (!skip_fastpath()) {
153 // Load double input.
154 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
156 // Clear cumulative exception flags and save the FCSR.
157 __ cfc1(scratch2, FCSR);
158 __ ctc1(zero_reg, FCSR);
160 // Try a conversion to a signed integer.
161 __ Trunc_w_d(double_scratch, double_scratch);
162 // Move the converted value into the result register.
163 __ mfc1(scratch3, double_scratch);
165 // Retrieve and restore the FCSR.
166 __ cfc1(scratch, FCSR);
167 __ ctc1(scratch2, FCSR);
169 // Check for overflow and NaNs.
172 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
173 | kFCSRInvalidOpFlagMask);
174 // If we had no exceptions then set result_reg and we are done.
176 __ Branch(&error, ne, scratch, Operand(zero_reg));
177 __ Move(result_reg, scratch3);
182 // Load the double value and perform a manual truncation.
183 Register input_high = scratch2;
184 Register input_low = scratch3;
187 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
189 MemOperand(input_reg, double_offset + Register::kExponentOffset));
191 Label normal_exponent, restore_sign;
192 // Extract the biased exponent in result.
195 HeapNumber::kExponentShift,
196 HeapNumber::kExponentBits);
198 // Check for Infinity and NaNs, which should return 0.
199 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
200 __ Movz(result_reg, zero_reg, scratch);
201 __ Branch(&done, eq, scratch, Operand(zero_reg));
203 // Express exponent as delta to (number of mantissa bits + 31).
206 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
208 // If the delta is strictly positive, all bits would be shifted away,
209 // which means that we can return 0.
210 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
211 __ mov(result_reg, zero_reg);
214 __ bind(&normal_exponent);
215 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
217 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
220 Register sign = result_reg;
222 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
224 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
225 // to check for this specific case.
226 Label high_shift_needed, high_shift_done;
227 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
228 __ mov(input_high, zero_reg);
229 __ Branch(&high_shift_done);
230 __ bind(&high_shift_needed);
232 // Set the implicit 1 before the mantissa part in input_high.
235 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
236 // Shift the mantissa bits to the correct position.
237 // We don't need to clear non-mantissa bits as they will be shifted away.
238 // If they weren't, it would mean that the answer is in the 32bit range.
239 __ sllv(input_high, input_high, scratch);
241 __ bind(&high_shift_done);
243 // Replace the shifted bits with bits from the lower mantissa word.
244 Label pos_shift, shift_done;
246 __ subu(scratch, at, scratch);
247 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
250 __ Subu(scratch, zero_reg, scratch);
251 __ sllv(input_low, input_low, scratch);
252 __ Branch(&shift_done);
255 __ srlv(input_low, input_low, scratch);
257 __ bind(&shift_done);
258 __ Or(input_high, input_high, Operand(input_low));
259 // Restore sign if necessary.
260 __ mov(scratch, sign);
263 __ Subu(result_reg, zero_reg, input_high);
264 __ Movz(result_reg, input_high, scratch);
268 __ Pop(scratch, scratch2, scratch3);
273 // Handle the case where the lhs and rhs are the same object.
274 // Equality is almost reflexive (everything but NaN), so this is a test
275 // for "identity and not NaN".
276 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
277 Condition cc, Strength strength) {
279 Label heap_number, return_equal;
280 Register exp_mask_reg = t5;
282 __ Branch(¬_identical, ne, a0, Operand(a1));
284 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
286 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
287 // so we do the second best thing - test it ourselves.
288 // They are both equal and they are not both Smis so both of them are not
289 // Smis. If it's not a heap number, then return equal.
290 __ GetObjectType(a0, t4, t4);
291 if (cc == less || cc == greater) {
292 // Call runtime on identical JSObjects.
293 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
294 // Call runtime on identical symbols since we need to throw a TypeError.
295 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
296 // Call runtime on identical SIMD values since we must throw a TypeError.
297 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
298 if (is_strong(strength)) {
299 // Call the runtime on anything that is converted in the semantics, since
300 // we need to throw a TypeError. Smis have already been ruled out.
301 __ Branch(&return_equal, eq, t4, Operand(HEAP_NUMBER_TYPE));
302 __ And(t4, t4, Operand(kIsNotStringMask));
303 __ Branch(slow, ne, t4, Operand(zero_reg));
306 __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE));
307 // Comparing JS objects with <=, >= is complicated.
309 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
310 // Call runtime on identical symbols since we need to throw a TypeError.
311 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
312 // Call runtime on identical SIMD values since we must throw a TypeError.
313 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
314 if (is_strong(strength)) {
315 // Call the runtime on anything that is converted in the semantics,
316 // since we need to throw a TypeError. Smis and heap numbers have
317 // already been ruled out.
318 __ And(t4, t4, Operand(kIsNotStringMask));
319 __ Branch(slow, ne, t4, Operand(zero_reg));
321 // Normally here we fall through to return_equal, but undefined is
322 // special: (undefined == undefined) == true, but
323 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
324 if (cc == less_equal || cc == greater_equal) {
325 __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE));
326 __ LoadRoot(t2, Heap::kUndefinedValueRootIndex);
327 __ Branch(&return_equal, ne, a0, Operand(t2));
328 DCHECK(is_int16(GREATER) && is_int16(LESS));
329 __ Ret(USE_DELAY_SLOT);
331 // undefined <= undefined should fail.
332 __ li(v0, Operand(GREATER));
334 // undefined >= undefined should fail.
335 __ li(v0, Operand(LESS));
341 __ bind(&return_equal);
342 DCHECK(is_int16(GREATER) && is_int16(LESS));
343 __ Ret(USE_DELAY_SLOT);
345 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
346 } else if (cc == greater) {
347 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
349 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
352 // For less and greater we don't have to check for NaN since the result of
353 // x < x is false regardless. For the others here is some code to check
355 if (cc != lt && cc != gt) {
356 __ bind(&heap_number);
357 // It is a heap number, so return non-equal if it's NaN and equal if it's
360 // The representation of NaN values has all exponent bits (52..62) set,
361 // and not all mantissa bits (0..51) clear.
362 // Read top bits of double representation (second word of value).
363 __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset));
364 // Test that exponent bits are all set.
365 __ And(t3, t2, Operand(exp_mask_reg));
366 // If all bits not set (ne cond), then not a NaN, objects are equal.
367 __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg));
369 // Shift out flag and all exponent bits, retaining only mantissa.
370 __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord);
371 // Or with all low-bits of mantissa.
372 __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
373 __ Or(v0, t3, Operand(t2));
374 // For equal we already have the right value in v0: Return zero (equal)
375 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
376 // not (it's a NaN). For <= and >= we need to load v0 with the failing
377 // value if it's a NaN.
379 // All-zero means Infinity means equal.
380 __ Ret(eq, v0, Operand(zero_reg));
381 DCHECK(is_int16(GREATER) && is_int16(LESS));
382 __ Ret(USE_DELAY_SLOT);
384 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
386 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
390 // No fall through here.
392 __ bind(¬_identical);
396 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
399 Label* both_loaded_as_doubles,
402 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
403 (lhs.is(a1) && rhs.is(a0)));
406 __ JumpIfSmi(lhs, &lhs_is_smi);
408 // Check whether the non-smi is a heap number.
409 __ GetObjectType(lhs, t4, t4);
411 // If lhs was not a number and rhs was a Smi then strict equality cannot
412 // succeed. Return non-equal (lhs is already not zero).
413 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
416 // Smi compared non-strictly with a non-Smi non-heap-number. Call
418 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
421 // Rhs is a smi, lhs is a number.
422 // Convert smi rhs to double.
423 __ sra(at, rhs, kSmiTagSize);
425 __ cvt_d_w(f14, f14);
426 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
428 // We now have both loaded as doubles.
429 __ jmp(both_loaded_as_doubles);
431 __ bind(&lhs_is_smi);
432 // Lhs is a Smi. Check whether the non-smi is a heap number.
433 __ GetObjectType(rhs, t4, t4);
435 // If lhs was not a number and rhs was a Smi then strict equality cannot
436 // succeed. Return non-equal.
437 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
438 __ li(v0, Operand(1));
440 // Smi compared non-strictly with a non-Smi non-heap-number. Call
442 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
445 // Lhs is a smi, rhs is a number.
446 // Convert smi lhs to double.
447 __ sra(at, lhs, kSmiTagSize);
449 __ cvt_d_w(f12, f12);
450 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
451 // Fall through to both_loaded_as_doubles.
455 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
458 // If either operand is a JS object or an oddball value, then they are
459 // not equal since their pointers are different.
460 // There is no test for undetectability in strict equality.
461 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
462 Label first_non_object;
463 // Get the type of the first operand into a2 and compare it with
464 // FIRST_SPEC_OBJECT_TYPE.
465 __ GetObjectType(lhs, a2, a2);
466 __ Branch(&first_non_object, less, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
469 Label return_not_equal;
470 __ bind(&return_not_equal);
471 __ Ret(USE_DELAY_SLOT);
472 __ li(v0, Operand(1));
474 __ bind(&first_non_object);
475 // Check for oddballs: true, false, null, undefined.
476 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
478 __ GetObjectType(rhs, a3, a3);
479 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
481 // Check for oddballs: true, false, null, undefined.
482 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
484 // Now that we have the types we might as well check for
485 // internalized-internalized.
486 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
487 __ Or(a2, a2, Operand(a3));
488 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
489 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
493 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
496 Label* both_loaded_as_doubles,
497 Label* not_heap_numbers,
499 __ GetObjectType(lhs, a3, a2);
500 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
501 __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
502 // If first was a heap number & second wasn't, go to slow case.
503 __ Branch(slow, ne, a3, Operand(a2));
505 // Both are heap numbers. Load them up then jump to the code we have
507 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
508 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
510 __ jmp(both_loaded_as_doubles);
514 // Fast negative check for internalized-to-internalized equality.
515 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
518 Label* possible_strings,
519 Label* not_both_strings) {
520 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
521 (lhs.is(a1) && rhs.is(a0)));
523 // a2 is object type of rhs.
525 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
526 __ And(at, a2, Operand(kIsNotStringMask));
527 __ Branch(&object_test, ne, at, Operand(zero_reg));
528 __ And(at, a2, Operand(kIsNotInternalizedMask));
529 __ Branch(possible_strings, ne, at, Operand(zero_reg));
530 __ GetObjectType(rhs, a3, a3);
531 __ Branch(not_both_strings, ge, a3, Operand(FIRST_NONSTRING_TYPE));
532 __ And(at, a3, Operand(kIsNotInternalizedMask));
533 __ Branch(possible_strings, ne, at, Operand(zero_reg));
535 // Both are internalized strings. We already checked they weren't the same
536 // pointer so they are not equal.
537 __ Ret(USE_DELAY_SLOT);
538 __ li(v0, Operand(1)); // Non-zero indicates not equal.
540 __ bind(&object_test);
541 __ Branch(not_both_strings, lt, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
542 __ GetObjectType(rhs, a2, a3);
543 __ Branch(not_both_strings, lt, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
545 // If both objects are undetectable, they are equal. Otherwise, they
546 // are not equal, since they are different objects and an object is not
547 // equal to undefined.
548 __ lw(a3, FieldMemOperand(lhs, HeapObject::kMapOffset));
549 __ lbu(a2, FieldMemOperand(a2, Map::kBitFieldOffset));
550 __ lbu(a3, FieldMemOperand(a3, Map::kBitFieldOffset));
552 __ And(a0, a0, Operand(1 << Map::kIsUndetectable));
553 __ Ret(USE_DELAY_SLOT);
554 __ xori(v0, a0, 1 << Map::kIsUndetectable);
558 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
560 CompareICState::State expected,
563 if (expected == CompareICState::SMI) {
564 __ JumpIfNotSmi(input, fail);
565 } else if (expected == CompareICState::NUMBER) {
566 __ JumpIfSmi(input, &ok);
567 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
570 // We could be strict about internalized/string here, but as long as
571 // hydrogen doesn't care, the stub doesn't have to care either.
576 // On entry a1 and a2 are the values to be compared.
577 // On exit a0 is 0, positive or negative to indicate the result of
579 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
582 Condition cc = GetCondition();
585 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
586 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
588 Label slow; // Call builtin.
589 Label not_smis, both_loaded_as_doubles;
591 Label not_two_smis, smi_done;
593 __ JumpIfNotSmi(a2, ¬_two_smis);
596 __ Ret(USE_DELAY_SLOT);
598 __ bind(¬_two_smis);
600 // NOTICE! This code is only reached after a smi-fast-case check, so
601 // it is certain that at least one operand isn't a smi.
603 // Handle the case where the objects are identical. Either returns the answer
604 // or goes to slow. Only falls through if the objects were not identical.
605 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
607 // If either is a Smi (we know that not both are), then they can only
608 // be strictly equal if the other is a HeapNumber.
609 STATIC_ASSERT(kSmiTag == 0);
610 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
611 __ And(t2, lhs, Operand(rhs));
612 __ JumpIfNotSmi(t2, ¬_smis, t0);
613 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
614 // 1) Return the answer.
616 // 3) Fall through to both_loaded_as_doubles.
617 // 4) Jump to rhs_not_nan.
618 // In cases 3 and 4 we have found out we were dealing with a number-number
619 // comparison and the numbers have been loaded into f12 and f14 as doubles,
620 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
621 EmitSmiNonsmiComparison(masm, lhs, rhs,
622 &both_loaded_as_doubles, &slow, strict());
624 __ bind(&both_loaded_as_doubles);
625 // f12, f14 are the double representations of the left hand side
626 // and the right hand side if we have FPU. Otherwise a2, a3 represent
627 // left hand side and a0, a1 represent right hand side.
629 __ li(t0, Operand(LESS));
630 __ li(t1, Operand(GREATER));
631 __ li(t2, Operand(EQUAL));
633 // Check if either rhs or lhs is NaN.
634 __ BranchF(NULL, &nan, eq, f12, f14);
636 // Check if LESS condition is satisfied. If true, move conditionally
638 if (!IsMipsArchVariant(kMips32r6)) {
639 __ c(OLT, D, f12, f14);
641 // Use previous check to store conditionally to v0 oposite condition
642 // (GREATER). If rhs is equal to lhs, this will be corrected in next
645 // Check if EQUAL condition is satisfied. If true, move conditionally
647 __ c(EQ, D, f12, f14);
651 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
652 __ mov(v0, t0); // Return LESS as result.
654 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
655 __ mov(v0, t2); // Return EQUAL as result.
657 __ mov(v0, t1); // Return GREATER as result.
664 // NaN comparisons always fail.
665 // Load whatever we need in v0 to make the comparison fail.
666 DCHECK(is_int16(GREATER) && is_int16(LESS));
667 __ Ret(USE_DELAY_SLOT);
668 if (cc == lt || cc == le) {
669 __ li(v0, Operand(GREATER));
671 __ li(v0, Operand(LESS));
676 // At this point we know we are dealing with two different objects,
677 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
679 // This returns non-equal for some object types, or falls through if it
681 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
684 Label check_for_internalized_strings;
685 Label flat_string_check;
686 // Check for heap-number-heap-number comparison. Can jump to slow case,
687 // or load both doubles and jump to the code that handles
688 // that case. If the inputs are not doubles then jumps to
689 // check_for_internalized_strings.
690 // In this case a2 will contain the type of lhs_.
691 EmitCheckForTwoHeapNumbers(masm,
694 &both_loaded_as_doubles,
695 &check_for_internalized_strings,
698 __ bind(&check_for_internalized_strings);
699 if (cc == eq && !strict()) {
700 // Returns an answer for two internalized strings or two
701 // detectable objects.
702 // Otherwise jumps to string case or not both strings case.
703 // Assumes that a2 is the type of lhs_ on entry.
704 EmitCheckForInternalizedStringsOrObjects(
705 masm, lhs, rhs, &flat_string_check, &slow);
708 // Check for both being sequential one-byte strings,
709 // and inline if that is the case.
710 __ bind(&flat_string_check);
712 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
714 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
717 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0);
719 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0,
722 // Never falls through to here.
725 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
728 // Figure out which native to call and setup the arguments.
729 if (cc == eq && strict()) {
730 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
734 context_index = Context::EQUALS_BUILTIN_INDEX;
736 context_index = is_strong(strength())
737 ? Context::COMPARE_STRONG_BUILTIN_INDEX
738 : Context::COMPARE_BUILTIN_INDEX;
739 int ncr; // NaN compare result.
740 if (cc == lt || cc == le) {
743 DCHECK(cc == gt || cc == ge); // Remaining cases.
746 __ li(a0, Operand(Smi::FromInt(ncr)));
750 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
751 // tagged as a small integer.
752 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
760 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
763 __ PushSafepointRegisters();
768 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
771 __ PopSafepointRegisters();
776 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
777 // We don't allow a GC during a store buffer overflow so there is no need to
778 // store the registers in any particular way, but we do have to store and
780 __ MultiPush(kJSCallerSaved | ra.bit());
781 if (save_doubles()) {
782 __ MultiPushFPU(kCallerSavedFPU);
784 const int argument_count = 1;
785 const int fp_argument_count = 0;
786 const Register scratch = a1;
788 AllowExternalCallThatCantCauseGC scope(masm);
789 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
790 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
792 ExternalReference::store_buffer_overflow_function(isolate()),
794 if (save_doubles()) {
795 __ MultiPopFPU(kCallerSavedFPU);
798 __ MultiPop(kJSCallerSaved | ra.bit());
803 void MathPowStub::Generate(MacroAssembler* masm) {
804 const Register base = a1;
805 const Register exponent = MathPowTaggedDescriptor::exponent();
806 DCHECK(exponent.is(a2));
807 const Register heapnumbermap = t1;
808 const Register heapnumber = v0;
809 const DoubleRegister double_base = f2;
810 const DoubleRegister double_exponent = f4;
811 const DoubleRegister double_result = f0;
812 const DoubleRegister double_scratch = f6;
813 const FPURegister single_scratch = f8;
814 const Register scratch = t5;
815 const Register scratch2 = t3;
817 Label call_runtime, done, int_exponent;
818 if (exponent_type() == ON_STACK) {
819 Label base_is_smi, unpack_exponent;
820 // The exponent and base are supplied as arguments on the stack.
821 // This can only happen if the stub is called from non-optimized code.
822 // Load input parameters from stack to double registers.
823 __ lw(base, MemOperand(sp, 1 * kPointerSize));
824 __ lw(exponent, MemOperand(sp, 0 * kPointerSize));
826 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
828 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
829 __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset));
830 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
832 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
833 __ jmp(&unpack_exponent);
835 __ bind(&base_is_smi);
836 __ mtc1(scratch, single_scratch);
837 __ cvt_d_w(double_base, single_scratch);
838 __ bind(&unpack_exponent);
840 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
842 __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
843 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
844 __ ldc1(double_exponent,
845 FieldMemOperand(exponent, HeapNumber::kValueOffset));
846 } else if (exponent_type() == TAGGED) {
847 // Base is already in double_base.
848 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
850 __ ldc1(double_exponent,
851 FieldMemOperand(exponent, HeapNumber::kValueOffset));
854 if (exponent_type() != INTEGER) {
855 Label int_exponent_convert;
856 // Detect integer exponents stored as double.
857 __ EmitFPUTruncate(kRoundToMinusInf,
863 kCheckForInexactConversion);
864 // scratch2 == 0 means there was no conversion error.
865 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
867 if (exponent_type() == ON_STACK) {
868 // Detect square root case. Crankshaft detects constant +/-0.5 at
869 // compile time and uses DoMathPowHalf instead. We then skip this check
870 // for non-constant cases of +/-0.5 as these hardly occur.
873 __ Move(double_scratch, 0.5);
874 __ BranchF(USE_DELAY_SLOT,
880 // double_scratch can be overwritten in the delay slot.
881 // Calculates square root of base. Check for the special case of
882 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
883 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
884 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
885 __ neg_d(double_result, double_scratch);
887 // Add +0 to convert -0 to +0.
888 __ add_d(double_scratch, double_base, kDoubleRegZero);
889 __ sqrt_d(double_result, double_scratch);
892 __ bind(¬_plus_half);
893 __ Move(double_scratch, -0.5);
894 __ BranchF(USE_DELAY_SLOT,
900 // double_scratch can be overwritten in the delay slot.
901 // Calculates square root of base. Check for the special case of
902 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
903 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
904 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
905 __ Move(double_result, kDoubleRegZero);
907 // Add +0 to convert -0 to +0.
908 __ add_d(double_scratch, double_base, kDoubleRegZero);
909 __ Move(double_result, 1.);
910 __ sqrt_d(double_scratch, double_scratch);
911 __ div_d(double_result, double_result, double_scratch);
917 AllowExternalCallThatCantCauseGC scope(masm);
918 __ PrepareCallCFunction(0, 2, scratch2);
919 __ MovToFloatParameters(double_base, double_exponent);
921 ExternalReference::power_double_double_function(isolate()),
925 __ MovFromFloatResult(double_result);
928 __ bind(&int_exponent_convert);
931 // Calculate power with integer exponent.
932 __ bind(&int_exponent);
934 // Get two copies of exponent in the registers scratch and exponent.
935 if (exponent_type() == INTEGER) {
936 __ mov(scratch, exponent);
938 // Exponent has previously been stored into scratch as untagged integer.
939 __ mov(exponent, scratch);
942 __ mov_d(double_scratch, double_base); // Back up base.
943 __ Move(double_result, 1.0);
945 // Get absolute value of exponent.
946 Label positive_exponent;
947 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
948 __ Subu(scratch, zero_reg, scratch);
949 __ bind(&positive_exponent);
951 Label while_true, no_carry, loop_end;
952 __ bind(&while_true);
954 __ And(scratch2, scratch, 1);
956 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
957 __ mul_d(double_result, double_result, double_scratch);
960 __ sra(scratch, scratch, 1);
962 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
963 __ mul_d(double_scratch, double_scratch, double_scratch);
965 __ Branch(&while_true);
969 __ Branch(&done, ge, exponent, Operand(zero_reg));
970 __ Move(double_scratch, 1.0);
971 __ div_d(double_result, double_scratch, double_result);
972 // Test whether result is zero. Bail out to check for subnormal result.
973 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
974 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
976 // double_exponent may not contain the exponent value if the input was a
977 // smi. We set it with exponent value before bailing out.
978 __ mtc1(exponent, single_scratch);
979 __ cvt_d_w(double_exponent, single_scratch);
981 // Returning or bailing out.
982 Counters* counters = isolate()->counters();
983 if (exponent_type() == ON_STACK) {
984 // The arguments are still on the stack.
985 __ bind(&call_runtime);
986 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
988 // The stub is called from non-optimized code, which expects the result
989 // as heap number in exponent.
991 __ AllocateHeapNumber(
992 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
993 __ sdc1(double_result,
994 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
995 DCHECK(heapnumber.is(v0));
996 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1001 AllowExternalCallThatCantCauseGC scope(masm);
1002 __ PrepareCallCFunction(0, 2, scratch);
1003 __ MovToFloatParameters(double_base, double_exponent);
1005 ExternalReference::power_double_double_function(isolate()),
1009 __ MovFromFloatResult(double_result);
1012 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1018 bool CEntryStub::NeedsImmovableCode() {
1023 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1024 CEntryStub::GenerateAheadOfTime(isolate);
1025 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1026 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1027 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1028 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1029 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1030 BinaryOpICStub::GenerateAheadOfTime(isolate);
1031 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1032 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1033 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1034 StoreFastElementStub::GenerateAheadOfTime(isolate);
1035 TypeofStub::GenerateAheadOfTime(isolate);
1039 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1040 StoreRegistersStateStub stub(isolate);
1045 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1046 RestoreRegistersStateStub stub(isolate);
1051 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1052 // Generate if not already in cache.
1053 SaveFPRegsMode mode = kSaveFPRegs;
1054 CEntryStub(isolate, 1, mode).GetCode();
1055 StoreBufferOverflowStub(isolate, mode).GetCode();
1056 isolate->set_fp_stubs_generated(true);
1060 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1061 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1066 void CEntryStub::Generate(MacroAssembler* masm) {
1067 // Called from JavaScript; parameters are on stack as if calling JS function
1068 // a0: number of arguments including receiver
1069 // a1: pointer to builtin function
1070 // fp: frame pointer (restored after C call)
1071 // sp: stack pointer (restored as callee's sp after C call)
1072 // cp: current context (C callee-saved)
1074 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1076 // Compute the argv pointer in a callee-saved register.
1077 __ sll(s1, a0, kPointerSizeLog2);
1078 __ Addu(s1, sp, s1);
1079 __ Subu(s1, s1, kPointerSize);
1081 // Enter the exit frame that transitions from JavaScript to C++.
1082 FrameScope scope(masm, StackFrame::MANUAL);
1083 __ EnterExitFrame(save_doubles());
1085 // s0: number of arguments including receiver (C callee-saved)
1086 // s1: pointer to first argument (C callee-saved)
1087 // s2: pointer to builtin function (C callee-saved)
1089 // Prepare arguments for C routine.
1093 // a1 = argv (set in the delay slot after find_ra below).
1095 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1096 // also need to reserve the 4 argument slots on the stack.
1098 __ AssertStackIsAligned();
1100 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1102 // To let the GC traverse the return address of the exit frames, we need to
1103 // know where the return address is. The CEntryStub is unmovable, so
1104 // we can store the address on the stack to be able to find it again and
1105 // we never have to restore it, because it will not change.
1106 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1107 // This branch-and-link sequence is needed to find the current PC on mips,
1108 // saved to the ra register.
1109 // Use masm-> here instead of the double-underscore macro since extra
1110 // coverage code can interfere with the proper calculation of ra.
1112 masm->bal(&find_ra); // bal exposes branch delay slot.
1114 masm->bind(&find_ra);
1116 // Adjust the value in ra to point to the correct return location, 2nd
1117 // instruction past the real call into C code (the jalr(t9)), and push it.
1118 // This is the return address of the exit frame.
1119 const int kNumInstructionsToJump = 5;
1120 masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize);
1121 masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1122 // Stack space reservation moved to the branch delay slot below.
1123 // Stack is still aligned.
1125 // Call the C routine.
1126 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1128 // Set up sp in the delay slot.
1129 masm->addiu(sp, sp, -kCArgsSlotsSize);
1130 // Make sure the stored 'ra' points to this position.
1131 DCHECK_EQ(kNumInstructionsToJump,
1132 masm->InstructionsGeneratedSince(&find_ra));
1136 // Check result for exception sentinel.
1137 Label exception_returned;
1138 __ LoadRoot(t0, Heap::kExceptionRootIndex);
1139 __ Branch(&exception_returned, eq, t0, Operand(v0));
1141 // Check that there is no pending exception, otherwise we
1142 // should have returned the exception sentinel.
1143 if (FLAG_debug_code) {
1145 ExternalReference pending_exception_address(
1146 Isolate::kPendingExceptionAddress, isolate());
1147 __ li(a2, Operand(pending_exception_address));
1148 __ lw(a2, MemOperand(a2));
1149 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1150 // Cannot use check here as it attempts to generate call into runtime.
1151 __ Branch(&okay, eq, t0, Operand(a2));
1152 __ stop("Unexpected pending exception");
1156 // Exit C frame and return.
1158 // sp: stack pointer
1159 // fp: frame pointer
1160 // s0: still holds argc (callee-saved).
1161 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1163 // Handling of exception.
1164 __ bind(&exception_returned);
1166 ExternalReference pending_handler_context_address(
1167 Isolate::kPendingHandlerContextAddress, isolate());
1168 ExternalReference pending_handler_code_address(
1169 Isolate::kPendingHandlerCodeAddress, isolate());
1170 ExternalReference pending_handler_offset_address(
1171 Isolate::kPendingHandlerOffsetAddress, isolate());
1172 ExternalReference pending_handler_fp_address(
1173 Isolate::kPendingHandlerFPAddress, isolate());
1174 ExternalReference pending_handler_sp_address(
1175 Isolate::kPendingHandlerSPAddress, isolate());
1177 // Ask the runtime for help to determine the handler. This will set v0 to
1178 // contain the current pending exception, don't clobber it.
1179 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1182 FrameScope scope(masm, StackFrame::MANUAL);
1183 __ PrepareCallCFunction(3, 0, a0);
1184 __ mov(a0, zero_reg);
1185 __ mov(a1, zero_reg);
1186 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1187 __ CallCFunction(find_handler, 3);
1190 // Retrieve the handler context, SP and FP.
1191 __ li(cp, Operand(pending_handler_context_address));
1192 __ lw(cp, MemOperand(cp));
1193 __ li(sp, Operand(pending_handler_sp_address));
1194 __ lw(sp, MemOperand(sp));
1195 __ li(fp, Operand(pending_handler_fp_address));
1196 __ lw(fp, MemOperand(fp));
1198 // If the handler is a JS frame, restore the context to the frame. Note that
1199 // the context will be set to (cp == 0) for non-JS frames.
1201 __ Branch(&zero, eq, cp, Operand(zero_reg));
1202 __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1205 // Compute the handler entry address and jump to it.
1206 __ li(a1, Operand(pending_handler_code_address));
1207 __ lw(a1, MemOperand(a1));
1208 __ li(a2, Operand(pending_handler_offset_address));
1209 __ lw(a2, MemOperand(a2));
1210 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1211 __ Addu(t9, a1, a2);
1216 void JSEntryStub::Generate(MacroAssembler* masm) {
1217 Label invoke, handler_entry, exit;
1218 Isolate* isolate = masm->isolate();
1221 // a0: entry address
1230 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1232 // Save callee saved registers on the stack.
1233 __ MultiPush(kCalleeSaved | ra.bit());
1235 // Save callee-saved FPU registers.
1236 __ MultiPushFPU(kCalleeSavedFPU);
1237 // Set up the reserved register for 0.0.
1238 __ Move(kDoubleRegZero, 0.0);
1241 // Load argv in s0 register.
1242 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1243 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1245 __ InitializeRootRegister();
1246 __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1248 // We build an EntryFrame.
1249 __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1250 int marker = type();
1251 __ li(t2, Operand(Smi::FromInt(marker)));
1252 __ li(t1, Operand(Smi::FromInt(marker)));
1253 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1255 __ lw(t0, MemOperand(t0));
1256 __ Push(t3, t2, t1, t0);
1257 // Set up frame pointer for the frame to be pushed.
1258 __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1261 // a0: entry_address
1263 // a2: receiver_pointer
1269 // function slot | entry frame
1271 // bad fp (0xff...f) |
1272 // callee saved registers + ra
1276 // If this is the outermost JS call, set js_entry_sp value.
1277 Label non_outermost_js;
1278 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1279 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1280 __ lw(t2, MemOperand(t1));
1281 __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
1282 __ sw(fp, MemOperand(t1));
1283 __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1286 __ nop(); // Branch delay slot nop.
1287 __ bind(&non_outermost_js);
1288 __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1292 // Jump to a faked try block that does the invoke, with a faked catch
1293 // block that sets the pending exception.
1295 __ bind(&handler_entry);
1296 handler_offset_ = handler_entry.pos();
1297 // Caught exception: Store result (exception) in the pending exception
1298 // field in the JSEnv and return a failure sentinel. Coming in here the
1299 // fp will be invalid because the PushStackHandler below sets it to 0 to
1300 // signal the existence of the JSEntry frame.
1301 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1303 __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
1304 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1305 __ b(&exit); // b exposes branch delay slot.
1306 __ nop(); // Branch delay slot nop.
1308 // Invoke: Link this frame into the handler chain.
1310 __ PushStackHandler();
1311 // If an exception not caught by another handler occurs, this handler
1312 // returns control to the code after the bal(&invoke) above, which
1313 // restores all kCalleeSaved registers (including cp and fp) to their
1314 // saved values before returning a failure to C.
1316 // Clear any pending exceptions.
1317 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
1318 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1320 __ sw(t1, MemOperand(t0));
1322 // Invoke the function by calling through JS entry trampoline builtin.
1323 // Notice that we cannot store a reference to the trampoline code directly in
1324 // this stub, because runtime stubs are not traversed when doing GC.
1327 // a0: entry_address
1329 // a2: receiver_pointer
1336 // callee saved registers + ra
1340 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1341 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1343 __ li(t0, Operand(construct_entry));
1345 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1346 __ li(t0, Operand(entry));
1348 __ lw(t9, MemOperand(t0)); // Deref address.
1350 // Call JSEntryTrampoline.
1351 __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1354 // Unlink this frame from the handler chain.
1355 __ PopStackHandler();
1357 __ bind(&exit); // v0 holds result
1358 // Check if the current stack frame is marked as the outermost JS frame.
1359 Label non_outermost_js_2;
1361 __ Branch(&non_outermost_js_2,
1364 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1365 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1366 __ sw(zero_reg, MemOperand(t1));
1367 __ bind(&non_outermost_js_2);
1369 // Restore the top frame descriptors from the stack.
1371 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1373 __ sw(t1, MemOperand(t0));
1375 // Reset the stack to the callee saved registers.
1376 __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1378 // Restore callee-saved fpu registers.
1379 __ MultiPopFPU(kCalleeSavedFPU);
1381 // Restore callee saved registers from the stack.
1382 __ MultiPop(kCalleeSaved | ra.bit());
1388 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1389 // Return address is in ra.
1392 Register receiver = LoadDescriptor::ReceiverRegister();
1393 Register index = LoadDescriptor::NameRegister();
1394 Register scratch = t1;
1395 Register result = v0;
1396 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1397 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1399 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1400 &miss, // When not a string.
1401 &miss, // When not a number.
1402 &miss, // When index out of range.
1403 STRING_INDEX_IS_ARRAY_INDEX,
1404 RECEIVER_IS_STRING);
1405 char_at_generator.GenerateFast(masm);
1408 StubRuntimeCallHelper call_helper;
1409 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1412 PropertyAccessCompiler::TailCallBuiltin(
1413 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1417 void InstanceOfStub::Generate(MacroAssembler* masm) {
1418 Register const object = a1; // Object (lhs).
1419 Register const function = a0; // Function (rhs).
1420 Register const object_map = a2; // Map of {object}.
1421 Register const function_map = a3; // Map of {function}.
1422 Register const function_prototype = t0; // Prototype of {function}.
1423 Register const scratch = t1;
1425 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1426 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1428 // Check if {object} is a smi.
1429 Label object_is_smi;
1430 __ JumpIfSmi(object, &object_is_smi);
1432 // Lookup the {function} and the {object} map in the global instanceof cache.
1433 // Note: This is safe because we clear the global instanceof cache whenever
1434 // we change the prototype of any object.
1435 Label fast_case, slow_case;
1436 __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1437 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1438 __ Branch(&fast_case, ne, function, Operand(at));
1439 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1440 __ Branch(&fast_case, ne, object_map, Operand(at));
1441 __ Ret(USE_DELAY_SLOT);
1442 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1444 // If {object} is a smi we can safely return false if {function} is a JS
1445 // function, otherwise we have to miss to the runtime and throw an exception.
1446 __ bind(&object_is_smi);
1447 __ JumpIfSmi(function, &slow_case);
1448 __ GetObjectType(function, function_map, scratch);
1449 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1450 __ Ret(USE_DELAY_SLOT);
1451 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
1453 // Fast-case: The {function} must be a valid JSFunction.
1454 __ bind(&fast_case);
1455 __ JumpIfSmi(function, &slow_case);
1456 __ GetObjectType(function, function_map, scratch);
1457 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1459 // Ensure that {function} has an instance prototype.
1460 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1461 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1462 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1464 // Ensure that {function} is not bound.
1465 Register const shared_info = scratch;
1467 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1469 FieldMemOperand(shared_info, SharedFunctionInfo::kBoundByteOffset));
1470 __ And(at, scratch, Operand(1 << SharedFunctionInfo::kBoundBitWithinByte));
1471 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1473 // Get the "prototype" (or initial map) of the {function}.
1474 __ lw(function_prototype,
1475 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1476 __ AssertNotSmi(function_prototype);
1478 // Resolve the prototype if the {function} has an initial map. Afterwards the
1479 // {function_prototype} will be either the JSReceiver prototype object or the
1480 // hole value, which means that no instances of the {function} were created so
1481 // far and hence we should return false.
1482 Label function_prototype_valid;
1483 __ GetObjectType(function_prototype, scratch, scratch);
1484 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1485 __ lw(function_prototype,
1486 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1487 __ bind(&function_prototype_valid);
1488 __ AssertNotSmi(function_prototype);
1490 // Update the global instanceof cache with the current {object} map and
1491 // {function}. The cached answer will be set when it is known below.
1492 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1493 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1495 // Loop through the prototype chain looking for the {function} prototype.
1496 // Assume true, and change to false if not found.
1497 Register const object_prototype = object_map;
1498 Register const null = scratch;
1500 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1501 __ LoadRoot(null, Heap::kNullValueRootIndex);
1503 __ lw(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1504 __ Branch(&done, eq, object_prototype, Operand(function_prototype));
1505 __ Branch(USE_DELAY_SLOT, &loop, ne, object_prototype, Operand(null));
1506 __ lw(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1507 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1509 __ Ret(USE_DELAY_SLOT);
1510 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1512 // Slow-case: Call the runtime function.
1513 __ bind(&slow_case);
1514 __ Push(object, function);
1515 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1519 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1521 Register receiver = LoadDescriptor::ReceiverRegister();
1522 // Ensure that the vector and slot registers won't be clobbered before
1523 // calling the miss handler.
1524 DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(),
1525 LoadWithVectorDescriptor::SlotRegister()));
1527 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0,
1530 PropertyAccessCompiler::TailCallBuiltin(
1531 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1535 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1536 // The displacement is the offset of the last parameter (if any)
1537 // relative to the frame pointer.
1538 const int kDisplacement =
1539 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1540 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1541 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1543 // Check that the key is a smiGenerateReadElement.
1545 __ JumpIfNotSmi(a1, &slow);
1547 // Check if the calling frame is an arguments adaptor frame.
1549 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1550 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1554 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1556 // Check index (a1) against formal parameters count limit passed in
1557 // through register a0. Use unsigned comparison to get negative
1559 __ Branch(&slow, hs, a1, Operand(a0));
1561 // Read the argument from the stack and return it.
1562 __ subu(a3, a0, a1);
1563 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1564 __ Addu(a3, fp, Operand(t3));
1565 __ Ret(USE_DELAY_SLOT);
1566 __ lw(v0, MemOperand(a3, kDisplacement));
1568 // Arguments adaptor case: Check index (a1) against actual arguments
1569 // limit found in the arguments adaptor frame. Use unsigned
1570 // comparison to get negative check for free.
1572 __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1573 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1575 // Read the argument from the adaptor frame and return it.
1576 __ subu(a3, a0, a1);
1577 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1578 __ Addu(a3, a2, Operand(t3));
1579 __ Ret(USE_DELAY_SLOT);
1580 __ lw(v0, MemOperand(a3, kDisplacement));
1582 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1583 // by calling the runtime system.
1586 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1590 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1591 // sp[0] : number of parameters
1592 // sp[4] : receiver displacement
1595 // Check if the calling frame is an arguments adaptor frame.
1597 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1598 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1602 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1604 // Patch the arguments.length and the parameters pointer in the current frame.
1605 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1606 __ sw(a2, MemOperand(sp, 0 * kPointerSize));
1608 __ Addu(a3, a3, Operand(t3));
1609 __ addiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1610 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1613 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1617 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1619 // sp[0] : number of parameters (tagged)
1620 // sp[4] : address of receiver argument
1622 // Registers used over whole function:
1623 // t2 : allocated object (tagged)
1624 // t5 : mapped parameter count (tagged)
1626 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1627 // a1 = parameter count (tagged)
1629 // Check if the calling frame is an arguments adaptor frame.
1631 Label adaptor_frame, try_allocate;
1632 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1633 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1634 __ Branch(&adaptor_frame,
1637 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1639 // No adaptor, parameter count = argument count.
1641 __ b(&try_allocate);
1642 __ nop(); // Branch delay slot nop.
1644 // We have an adaptor frame. Patch the parameters pointer.
1645 __ bind(&adaptor_frame);
1646 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1648 __ Addu(a3, a3, Operand(t6));
1649 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1650 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1652 // a1 = parameter count (tagged)
1653 // a2 = argument count (tagged)
1654 // Compute the mapped parameter count = min(a1, a2) in a1.
1656 __ Branch(&skip_min, lt, a1, Operand(a2));
1660 __ bind(&try_allocate);
1662 // Compute the sizes of backing store, parameter map, and arguments object.
1663 // 1. Parameter map, has 2 extra words containing context and backing store.
1664 const int kParameterMapHeaderSize =
1665 FixedArray::kHeaderSize + 2 * kPointerSize;
1666 // If there are no mapped parameters, we do not need the parameter_map.
1667 Label param_map_size;
1668 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1669 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1670 __ mov(t5, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1672 __ addiu(t5, t5, kParameterMapHeaderSize);
1673 __ bind(¶m_map_size);
1675 // 2. Backing store.
1677 __ Addu(t5, t5, Operand(t6));
1678 __ Addu(t5, t5, Operand(FixedArray::kHeaderSize));
1680 // 3. Arguments object.
1681 __ Addu(t5, t5, Operand(Heap::kSloppyArgumentsObjectSize));
1683 // Do the allocation of all three objects in one go.
1684 __ Allocate(t5, v0, a3, t0, &runtime, TAG_OBJECT);
1686 // v0 = address of new object(s) (tagged)
1687 // a2 = argument count (smi-tagged)
1688 // Get the arguments boilerplate from the current native context into t0.
1689 const int kNormalOffset =
1690 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1691 const int kAliasedOffset =
1692 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1694 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1695 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1696 Label skip2_ne, skip2_eq;
1697 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1698 __ lw(t0, MemOperand(t0, kNormalOffset));
1701 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1702 __ lw(t0, MemOperand(t0, kAliasedOffset));
1705 // v0 = address of new object (tagged)
1706 // a1 = mapped parameter count (tagged)
1707 // a2 = argument count (smi-tagged)
1708 // t0 = address of arguments map (tagged)
1709 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1710 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1711 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1712 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1714 // Set up the callee in-object property.
1715 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1716 __ lw(a3, MemOperand(sp, 2 * kPointerSize));
1717 __ AssertNotSmi(a3);
1718 const int kCalleeOffset = JSObject::kHeaderSize +
1719 Heap::kArgumentsCalleeIndex * kPointerSize;
1720 __ sw(a3, FieldMemOperand(v0, kCalleeOffset));
1722 // Use the length (smi tagged) and set that as an in-object property too.
1724 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1725 const int kLengthOffset = JSObject::kHeaderSize +
1726 Heap::kArgumentsLengthIndex * kPointerSize;
1727 __ sw(a2, FieldMemOperand(v0, kLengthOffset));
1729 // Set up the elements pointer in the allocated arguments object.
1730 // If we allocated a parameter map, t0 will point there, otherwise
1731 // it will point to the backing store.
1732 __ Addu(t0, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1733 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1735 // v0 = address of new object (tagged)
1736 // a1 = mapped parameter count (tagged)
1737 // a2 = argument count (tagged)
1738 // t0 = address of parameter map or backing store (tagged)
1739 // Initialize parameter map. If there are no mapped arguments, we're done.
1740 Label skip_parameter_map;
1742 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1743 // Move backing store address to a3, because it is
1744 // expected there when filling in the unmapped arguments.
1748 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1750 __ LoadRoot(t2, Heap::kSloppyArgumentsElementsMapRootIndex);
1751 __ sw(t2, FieldMemOperand(t0, FixedArray::kMapOffset));
1752 __ Addu(t2, a1, Operand(Smi::FromInt(2)));
1753 __ sw(t2, FieldMemOperand(t0, FixedArray::kLengthOffset));
1754 __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize));
1756 __ Addu(t2, t0, Operand(t6));
1757 __ Addu(t2, t2, Operand(kParameterMapHeaderSize));
1758 __ sw(t2, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize));
1760 // Copy the parameter slots and the holes in the arguments.
1761 // We need to fill in mapped_parameter_count slots. They index the context,
1762 // where parameters are stored in reverse order, at
1763 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1764 // The mapped parameter thus need to get indices
1765 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1766 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1767 // We loop from right to left.
1768 Label parameters_loop, parameters_test;
1770 __ lw(t5, MemOperand(sp, 0 * kPointerSize));
1771 __ Addu(t5, t5, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1772 __ Subu(t5, t5, Operand(a1));
1773 __ LoadRoot(t3, Heap::kTheHoleValueRootIndex);
1775 __ Addu(a3, t0, Operand(t6));
1776 __ Addu(a3, a3, Operand(kParameterMapHeaderSize));
1778 // t2 = loop variable (tagged)
1779 // a1 = mapping index (tagged)
1780 // a3 = address of backing store (tagged)
1781 // t0 = address of parameter map (tagged)
1782 // t1 = temporary scratch (a.o., for address calculation)
1783 // t3 = the hole value
1784 __ jmp(¶meters_test);
1786 __ bind(¶meters_loop);
1787 __ Subu(t2, t2, Operand(Smi::FromInt(1)));
1789 __ Addu(t1, t1, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1790 __ Addu(t6, t0, t1);
1791 __ sw(t5, MemOperand(t6));
1792 __ Subu(t1, t1, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1793 __ Addu(t6, a3, t1);
1794 __ sw(t3, MemOperand(t6));
1795 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1796 __ bind(¶meters_test);
1797 __ Branch(¶meters_loop, ne, t2, Operand(Smi::FromInt(0)));
1799 __ bind(&skip_parameter_map);
1800 // a2 = argument count (tagged)
1801 // a3 = address of backing store (tagged)
1803 // Copy arguments header and remaining slots (if there are any).
1804 __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex);
1805 __ sw(t1, FieldMemOperand(a3, FixedArray::kMapOffset));
1806 __ sw(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1808 Label arguments_loop, arguments_test;
1810 __ lw(t0, MemOperand(sp, 1 * kPointerSize));
1812 __ Subu(t0, t0, Operand(t6));
1813 __ jmp(&arguments_test);
1815 __ bind(&arguments_loop);
1816 __ Subu(t0, t0, Operand(kPointerSize));
1817 __ lw(t2, MemOperand(t0, 0));
1819 __ Addu(t1, a3, Operand(t6));
1820 __ sw(t2, FieldMemOperand(t1, FixedArray::kHeaderSize));
1821 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1823 __ bind(&arguments_test);
1824 __ Branch(&arguments_loop, lt, t5, Operand(a2));
1826 // Return and remove the on-stack parameters.
1829 // Do the runtime call to allocate the arguments object.
1830 // a2 = argument count (tagged)
1832 __ sw(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1833 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1837 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1838 // Return address is in ra.
1841 Register receiver = LoadDescriptor::ReceiverRegister();
1842 Register key = LoadDescriptor::NameRegister();
1844 // Check that the key is an array index, that is Uint32.
1845 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1846 __ Branch(&slow, ne, t0, Operand(zero_reg));
1848 // Everything is fine, call runtime.
1849 __ Push(receiver, key); // Receiver, key.
1851 // Perform tail call to the entry.
1852 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1855 PropertyAccessCompiler::TailCallBuiltin(
1856 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1860 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1861 // sp[0] : number of parameters
1862 // sp[4] : receiver displacement
1864 // Check if the calling frame is an arguments adaptor frame.
1865 Label adaptor_frame, try_allocate, runtime;
1866 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1867 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1868 __ Branch(&adaptor_frame,
1871 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1873 // Get the length from the frame.
1874 __ lw(a1, MemOperand(sp, 0));
1875 __ Branch(&try_allocate);
1877 // Patch the arguments.length and the parameters pointer.
1878 __ bind(&adaptor_frame);
1879 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1880 __ sw(a1, MemOperand(sp, 0));
1881 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1882 __ Addu(a3, a2, Operand(at));
1884 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1885 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1887 // Try the new space allocation. Start out with computing the size
1888 // of the arguments object and the elements array in words.
1889 Label add_arguments_object;
1890 __ bind(&try_allocate);
1891 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1892 __ srl(a1, a1, kSmiTagSize);
1894 __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1895 __ bind(&add_arguments_object);
1896 __ Addu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1898 // Do the allocation of both objects in one go.
1899 __ Allocate(a1, v0, a2, a3, &runtime,
1900 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1902 // Get the arguments boilerplate from the current native context.
1903 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1904 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1905 __ lw(t0, MemOperand(
1906 t0, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1908 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1909 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1910 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1911 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1913 // Get the length (smi tagged) and set that as an in-object property too.
1914 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1915 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1917 __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
1918 Heap::kArgumentsLengthIndex * kPointerSize));
1921 __ Branch(&done, eq, a1, Operand(zero_reg));
1923 // Get the parameters pointer from the stack.
1924 __ lw(a2, MemOperand(sp, 1 * kPointerSize));
1926 // Set up the elements pointer in the allocated arguments object and
1927 // initialize the header in the elements fixed array.
1928 __ Addu(t0, v0, Operand(Heap::kStrictArgumentsObjectSize));
1929 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1930 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
1931 __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset));
1932 __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset));
1933 // Untag the length for the loop.
1934 __ srl(a1, a1, kSmiTagSize);
1936 // Copy the fixed array slots.
1938 // Set up t0 to point to the first array slot.
1939 __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1941 // Pre-decrement a2 with kPointerSize on each iteration.
1942 // Pre-decrement in order to skip receiver.
1943 __ Addu(a2, a2, Operand(-kPointerSize));
1944 __ lw(a3, MemOperand(a2));
1945 // Post-increment t0 with kPointerSize on each iteration.
1946 __ sw(a3, MemOperand(t0));
1947 __ Addu(t0, t0, Operand(kPointerSize));
1948 __ Subu(a1, a1, Operand(1));
1949 __ Branch(&loop, ne, a1, Operand(zero_reg));
1951 // Return and remove the on-stack parameters.
1955 // Do the runtime call to allocate the arguments object.
1957 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1961 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
1962 // sp[0] : language mode
1963 // sp[4] : index of rest parameter
1964 // sp[8] : number of parameters
1965 // sp[12] : receiver displacement
1966 // Check if the calling frame is an arguments adaptor frame.
1969 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1970 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1971 __ Branch(&runtime, ne, a3,
1972 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1974 // Patch the arguments.length and the parameters pointer.
1975 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1976 __ sw(a1, MemOperand(sp, 2 * kPointerSize));
1977 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1978 __ Addu(a3, a2, Operand(at));
1980 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1981 __ sw(a3, MemOperand(sp, 3 * kPointerSize));
1983 // Do the runtime call to allocate the arguments object.
1985 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
1989 void RegExpExecStub::Generate(MacroAssembler* masm) {
1990 // Just jump directly to runtime if native RegExp is not selected at compile
1991 // time or if regexp entry in generated code is turned off runtime switch or
1993 #ifdef V8_INTERPRETED_REGEXP
1994 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1995 #else // V8_INTERPRETED_REGEXP
1997 // Stack frame on entry.
1998 // sp[0]: last_match_info (expected JSArray)
1999 // sp[4]: previous index
2000 // sp[8]: subject string
2001 // sp[12]: JSRegExp object
2003 const int kLastMatchInfoOffset = 0 * kPointerSize;
2004 const int kPreviousIndexOffset = 1 * kPointerSize;
2005 const int kSubjectOffset = 2 * kPointerSize;
2006 const int kJSRegExpOffset = 3 * kPointerSize;
2009 // Allocation of registers for this function. These are in callee save
2010 // registers and will be preserved by the call to the native RegExp code, as
2011 // this code is called using the normal C calling convention. When calling
2012 // directly from generated code the native RegExp code will not do a GC and
2013 // therefore the content of these registers are safe to use after the call.
2014 // MIPS - using s0..s2, since we are not using CEntry Stub.
2015 Register subject = s0;
2016 Register regexp_data = s1;
2017 Register last_match_info_elements = s2;
2019 // Ensure that a RegExp stack is allocated.
2020 ExternalReference address_of_regexp_stack_memory_address =
2021 ExternalReference::address_of_regexp_stack_memory_address(
2023 ExternalReference address_of_regexp_stack_memory_size =
2024 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2025 __ li(a0, Operand(address_of_regexp_stack_memory_size));
2026 __ lw(a0, MemOperand(a0, 0));
2027 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2029 // Check that the first argument is a JSRegExp object.
2030 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
2031 STATIC_ASSERT(kSmiTag == 0);
2032 __ JumpIfSmi(a0, &runtime);
2033 __ GetObjectType(a0, a1, a1);
2034 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2036 // Check that the RegExp has been compiled (data contains a fixed array).
2037 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2038 if (FLAG_debug_code) {
2039 __ SmiTst(regexp_data, t0);
2041 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2044 __ GetObjectType(regexp_data, a0, a0);
2046 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2048 Operand(FIXED_ARRAY_TYPE));
2051 // regexp_data: RegExp data (FixedArray)
2052 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2053 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2054 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2056 // regexp_data: RegExp data (FixedArray)
2057 // Check that the number of captures fit in the static offsets vector buffer.
2059 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2060 // Check (number_of_captures + 1) * 2 <= offsets vector size
2061 // Or number_of_captures * 2 <= offsets vector size - 2
2062 // Multiplying by 2 comes for free since a2 is smi-tagged.
2063 STATIC_ASSERT(kSmiTag == 0);
2064 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2065 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2067 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2069 // Reset offset for possibly sliced string.
2070 __ mov(t0, zero_reg);
2071 __ lw(subject, MemOperand(sp, kSubjectOffset));
2072 __ JumpIfSmi(subject, &runtime);
2073 __ mov(a3, subject); // Make a copy of the original subject string.
2074 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2075 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2076 // subject: subject string
2077 // a3: subject string
2078 // a0: subject string instance type
2079 // regexp_data: RegExp data (FixedArray)
2080 // Handle subject string according to its encoding and representation:
2081 // (1) Sequential string? If yes, go to (5).
2082 // (2) Anything but sequential or cons? If yes, go to (6).
2083 // (3) Cons string. If the string is flat, replace subject with first string.
2084 // Otherwise bailout.
2085 // (4) Is subject external? If yes, go to (7).
2086 // (5) Sequential string. Load regexp code according to encoding.
2090 // Deferred code at the end of the stub:
2091 // (6) Not a long external string? If yes, go to (8).
2092 // (7) External string. Make it, offset-wise, look like a sequential string.
2094 // (8) Short external string or not a string? If yes, bail out to runtime.
2095 // (9) Sliced string. Replace subject with parent. Go to (4).
2097 Label seq_string /* 5 */, external_string /* 7 */,
2098 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2099 not_long_external /* 8 */;
2101 // (1) Sequential string? If yes, go to (5).
2104 Operand(kIsNotStringMask |
2105 kStringRepresentationMask |
2106 kShortExternalStringMask));
2107 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2108 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2110 // (2) Anything but sequential or cons? If yes, go to (6).
2111 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2112 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2113 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2114 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2116 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2118 // (3) Cons string. Check that it's flat.
2119 // Replace subject with first string and reload instance type.
2120 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2121 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2122 __ Branch(&runtime, ne, a0, Operand(a1));
2123 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2125 // (4) Is subject external? If yes, go to (7).
2126 __ bind(&check_underlying);
2127 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2128 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2129 STATIC_ASSERT(kSeqStringTag == 0);
2130 __ And(at, a0, Operand(kStringRepresentationMask));
2131 // The underlying external string is never a short external string.
2132 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2133 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2134 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2136 // (5) Sequential string. Load regexp code according to encoding.
2137 __ bind(&seq_string);
2138 // subject: sequential subject string (or look-alike, external string)
2139 // a3: original subject string
2140 // Load previous index and check range before a3 is overwritten. We have to
2141 // use a3 instead of subject here because subject might have been only made
2142 // to look like a sequential string when it actually is an external string.
2143 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
2144 __ JumpIfNotSmi(a1, &runtime);
2145 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
2146 __ Branch(&runtime, ls, a3, Operand(a1));
2147 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
2149 STATIC_ASSERT(kStringEncodingMask == 4);
2150 STATIC_ASSERT(kOneByteStringTag == 4);
2151 STATIC_ASSERT(kTwoByteStringTag == 0);
2152 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
2153 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2154 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
2155 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2156 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2158 // (E) Carry on. String handling is done.
2159 // t9: irregexp code
2160 // Check that the irregexp code has been generated for the actual string
2161 // encoding. If it has, the field contains a code object otherwise it contains
2162 // a smi (code flushing support).
2163 __ JumpIfSmi(t9, &runtime);
2165 // a1: previous index
2166 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2168 // subject: Subject string
2169 // regexp_data: RegExp data (FixedArray)
2170 // All checks done. Now push arguments for native regexp code.
2171 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2174 // Isolates: note we add an additional parameter here (isolate pointer).
2175 const int kRegExpExecuteArguments = 9;
2176 const int kParameterRegisters = 4;
2177 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2179 // Stack pointer now points to cell where return address is to be written.
2180 // Arguments are before that on the stack or in registers, meaning we
2181 // treat the return address as argument 5. Thus every argument after that
2182 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2183 // allocating space for the c argument slots, we don't need to calculate
2184 // that into the argument positions on the stack. This is how the stack will
2185 // look (sp meaning the value of sp at this moment):
2186 // [sp + 5] - Argument 9
2187 // [sp + 4] - Argument 8
2188 // [sp + 3] - Argument 7
2189 // [sp + 2] - Argument 6
2190 // [sp + 1] - Argument 5
2191 // [sp + 0] - saved ra
2193 // Argument 9: Pass current isolate address.
2194 // CFunctionArgumentOperand handles MIPS stack argument slots.
2195 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2196 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
2198 // Argument 8: Indicate that this is a direct call from JavaScript.
2199 __ li(a0, Operand(1));
2200 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
2202 // Argument 7: Start (high end) of backtracking stack memory area.
2203 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2204 __ lw(a0, MemOperand(a0, 0));
2205 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2206 __ lw(a2, MemOperand(a2, 0));
2207 __ addu(a0, a0, a2);
2208 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
2210 // Argument 6: Set the number of capture registers to zero to force global
2211 // regexps to behave as non-global. This does not affect non-global regexps.
2212 __ mov(a0, zero_reg);
2213 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
2215 // Argument 5: static offsets vector buffer.
2217 ExternalReference::address_of_static_offsets_vector(isolate())));
2218 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
2220 // For arguments 4 and 3 get string length, calculate start of string data
2221 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2222 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2223 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2224 // Load the length from the original subject string from the previous stack
2225 // frame. Therefore we have to use fp, which points exactly to two pointer
2226 // sizes below the previous sp. (Because creating a new stack frame pushes
2227 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2228 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2229 // If slice offset is not 0, load the length from the original sliced string.
2230 // Argument 4, a3: End of string data
2231 // Argument 3, a2: Start of string data
2232 // Prepare start and end index of the input.
2233 __ sllv(t1, t0, a3);
2234 __ addu(t0, t2, t1);
2235 __ sllv(t1, a1, a3);
2236 __ addu(a2, t0, t1);
2238 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
2239 __ sra(t2, t2, kSmiTagSize);
2240 __ sllv(t1, t2, a3);
2241 __ addu(a3, t0, t1);
2242 // Argument 2 (a1): Previous index.
2245 // Argument 1 (a0): Subject string.
2246 __ mov(a0, subject);
2248 // Locate the code entry and call it.
2249 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2250 DirectCEntryStub stub(isolate());
2251 stub.GenerateCall(masm, t9);
2253 __ LeaveExitFrame(false, no_reg, true);
2256 // subject: subject string (callee saved)
2257 // regexp_data: RegExp data (callee saved)
2258 // last_match_info_elements: Last match info elements (callee saved)
2259 // Check the result.
2261 __ Branch(&success, eq, v0, Operand(1));
2262 // We expect exactly one result since we force the called regexp to behave
2265 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2266 // If not exception it can only be retry. Handle that in the runtime system.
2267 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2268 // Result must now be exception. If there is no pending exception already a
2269 // stack overflow (on the backtrack stack) was detected in RegExp code but
2270 // haven't created the exception yet. Handle that in the runtime system.
2271 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2272 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2273 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2275 __ lw(v0, MemOperand(a2, 0));
2276 __ Branch(&runtime, eq, v0, Operand(a1));
2278 // For exception, throw the exception again.
2279 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2282 // For failure and exception return null.
2283 __ li(v0, Operand(isolate()->factory()->null_value()));
2286 // Process the result from the native regexp code.
2289 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2290 // Calculate number of capture registers (number_of_captures + 1) * 2.
2291 // Multiplying by 2 comes for free since r1 is smi-tagged.
2292 STATIC_ASSERT(kSmiTag == 0);
2293 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2294 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
2296 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
2297 __ JumpIfSmi(a0, &runtime);
2298 __ GetObjectType(a0, a2, a2);
2299 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2300 // Check that the JSArray is in fast case.
2301 __ lw(last_match_info_elements,
2302 FieldMemOperand(a0, JSArray::kElementsOffset));
2303 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2304 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2305 __ Branch(&runtime, ne, a0, Operand(at));
2306 // Check that the last match info has space for the capture registers and the
2307 // additional information.
2309 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2310 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2311 __ sra(at, a0, kSmiTagSize);
2312 __ Branch(&runtime, gt, a2, Operand(at));
2314 // a1: number of capture registers
2315 // subject: subject string
2316 // Store the capture count.
2317 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
2318 __ sw(a2, FieldMemOperand(last_match_info_elements,
2319 RegExpImpl::kLastCaptureCountOffset));
2320 // Store last subject and last input.
2322 FieldMemOperand(last_match_info_elements,
2323 RegExpImpl::kLastSubjectOffset));
2324 __ mov(a2, subject);
2325 __ RecordWriteField(last_match_info_elements,
2326 RegExpImpl::kLastSubjectOffset,
2331 __ mov(subject, a2);
2333 FieldMemOperand(last_match_info_elements,
2334 RegExpImpl::kLastInputOffset));
2335 __ RecordWriteField(last_match_info_elements,
2336 RegExpImpl::kLastInputOffset,
2342 // Get the static offsets vector filled by the native regexp code.
2343 ExternalReference address_of_static_offsets_vector =
2344 ExternalReference::address_of_static_offsets_vector(isolate());
2345 __ li(a2, Operand(address_of_static_offsets_vector));
2347 // a1: number of capture registers
2348 // a2: offsets vector
2349 Label next_capture, done;
2350 // Capture register counter starts from number of capture registers and
2351 // counts down until wrapping after zero.
2353 last_match_info_elements,
2354 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2355 __ bind(&next_capture);
2356 __ Subu(a1, a1, Operand(1));
2357 __ Branch(&done, lt, a1, Operand(zero_reg));
2358 // Read the value from the static offsets vector buffer.
2359 __ lw(a3, MemOperand(a2, 0));
2360 __ addiu(a2, a2, kPointerSize);
2361 // Store the smi value in the last match info.
2362 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
2363 __ sw(a3, MemOperand(a0, 0));
2364 __ Branch(&next_capture, USE_DELAY_SLOT);
2365 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
2369 // Return last match info.
2370 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
2373 // Do the runtime call to execute the regexp.
2375 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2377 // Deferred code for string handling.
2378 // (6) Not a long external string? If yes, go to (8).
2379 __ bind(¬_seq_nor_cons);
2381 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2383 // (7) External string. Make it, offset-wise, look like a sequential string.
2384 __ bind(&external_string);
2385 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2386 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2387 if (FLAG_debug_code) {
2388 // Assert that we do not have a cons or slice (indirect strings) here.
2389 // Sequential strings have already been ruled out.
2390 __ And(at, a0, Operand(kIsIndirectStringMask));
2392 kExternalStringExpectedButNotFound,
2397 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2398 // Move the pointer so that offset-wise, it looks like a sequential string.
2399 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2402 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2403 __ jmp(&seq_string); // Go to (5).
2405 // (8) Short external string or not a string? If yes, bail out to runtime.
2406 __ bind(¬_long_external);
2407 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2408 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2409 __ Branch(&runtime, ne, at, Operand(zero_reg));
2411 // (9) Sliced string. Replace subject with parent. Go to (4).
2412 // Load offset into t0 and replace subject string with parent.
2413 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2414 __ sra(t0, t0, kSmiTagSize);
2415 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2416 __ jmp(&check_underlying); // Go to (4).
2417 #endif // V8_INTERPRETED_REGEXP
2421 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2423 // a0 : number of arguments to the construct function
2424 // a2 : feedback vector
2425 // a3 : slot in feedback vector (Smi)
2426 // a1 : the function to call
2427 // t0 : original constructor (for IsSuperConstructorCall)
2428 FrameScope scope(masm, StackFrame::INTERNAL);
2429 const RegList kSavedRegs = 1 << 4 | // a0
2433 BoolToInt(is_super) << 8; // t0
2435 // Number-of-arguments register must be smi-tagged to call out.
2437 __ MultiPush(kSavedRegs);
2441 __ MultiPop(kSavedRegs);
2446 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2447 // Cache the called function in a feedback vector slot. Cache states
2448 // are uninitialized, monomorphic (indicated by a JSFunction), and
2450 // a0 : number of arguments to the construct function
2451 // a1 : the function to call
2452 // a2 : feedback vector
2453 // a3 : slot in feedback vector (Smi)
2454 // t0 : original constructor (for IsSuperConstructorCall)
2455 Label initialize, done, miss, megamorphic, not_array_function;
2457 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2458 masm->isolate()->heap()->megamorphic_symbol());
2459 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2460 masm->isolate()->heap()->uninitialized_symbol());
2462 // Load the cache state into t2.
2463 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2464 __ Addu(t2, a2, Operand(t2));
2465 __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize));
2467 // A monomorphic cache hit or an already megamorphic state: invoke the
2468 // function without changing the state.
2469 // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at
2470 // this position in a symbol (see static asserts in type-feedback-vector.h).
2471 Label check_allocation_site;
2472 Register feedback_map = t1;
2473 Register weak_value = t4;
2474 __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset));
2475 __ Branch(&done, eq, a1, Operand(weak_value));
2476 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2477 __ Branch(&done, eq, t2, Operand(at));
2478 __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset));
2479 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2480 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2481 feedback_map, Operand(at));
2483 // If the weak cell is cleared, we have a new chance to become monomorphic.
2484 __ JumpIfSmi(weak_value, &initialize);
2485 __ jmp(&megamorphic);
2487 if (!FLAG_pretenuring_call_new) {
2488 __ bind(&check_allocation_site);
2489 // If we came here, we need to see if we are the array function.
2490 // If we didn't have a matching function, and we didn't find the megamorph
2491 // sentinel, then we have in the slot either some other function or an
2493 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2494 __ Branch(&miss, ne, feedback_map, Operand(at));
2496 // Make sure the function is the Array() function
2497 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2498 __ Branch(&megamorphic, ne, a1, Operand(t2));
2504 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2506 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2507 __ Branch(&initialize, eq, t2, Operand(at));
2508 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2509 // write-barrier is needed.
2510 __ bind(&megamorphic);
2511 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2512 __ Addu(t2, a2, Operand(t2));
2513 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2514 __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize));
2517 // An uninitialized cache is patched with the function.
2518 __ bind(&initialize);
2519 if (!FLAG_pretenuring_call_new) {
2520 // Make sure the function is the Array() function.
2521 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2522 __ Branch(¬_array_function, ne, a1, Operand(t2));
2524 // The target function is the Array constructor,
2525 // Create an AllocationSite if we don't already have it, store it in the
2527 CreateAllocationSiteStub create_stub(masm->isolate());
2528 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2531 __ bind(¬_array_function);
2534 CreateWeakCellStub create_stub(masm->isolate());
2535 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2540 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2541 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2542 __ lw(t0, FieldMemOperand(a3, SharedFunctionInfo::kCompilerHintsOffset));
2544 // Do not transform the receiver for strict mode functions.
2545 int32_t strict_mode_function_mask =
2546 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
2547 // Do not transform the receiver for native (Compilerhints already in a3).
2548 int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize);
2549 __ And(at, t0, Operand(strict_mode_function_mask | native_mask));
2550 __ Branch(cont, ne, at, Operand(zero_reg));
2554 static void EmitSlowCase(MacroAssembler* masm,
2556 Label* non_function) {
2557 // Check for function proxy.
2558 __ Branch(non_function, ne, t0, Operand(JS_FUNCTION_PROXY_TYPE));
2559 __ push(a1); // put proxy as additional argument
2560 __ li(a0, Operand(argc + 1, RelocInfo::NONE32));
2561 __ mov(a2, zero_reg);
2562 __ GetBuiltinFunction(a1, Context::CALL_FUNCTION_PROXY_BUILTIN_INDEX);
2564 Handle<Code> adaptor =
2565 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2566 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2569 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2570 // of the original receiver from the call site).
2571 __ bind(non_function);
2572 __ sw(a1, MemOperand(sp, argc * kPointerSize));
2573 __ li(a0, Operand(argc)); // Set up the number of arguments.
2574 __ mov(a2, zero_reg);
2575 __ GetBuiltinFunction(a1, Context::CALL_NON_FUNCTION_BUILTIN_INDEX);
2576 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2577 RelocInfo::CODE_TARGET);
2581 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2582 // Wrap the receiver and patch it back onto the stack.
2583 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2586 ToObjectStub stub(masm->isolate());
2590 __ Branch(USE_DELAY_SLOT, cont);
2591 __ sw(v0, MemOperand(sp, argc * kPointerSize));
2595 static void CallFunctionNoFeedback(MacroAssembler* masm,
2596 int argc, bool needs_checks,
2597 bool call_as_method) {
2598 // a1 : the function to call
2599 Label slow, non_function, wrap, cont;
2602 // Check that the function is really a JavaScript function.
2603 // a1: pushed function (to be verified)
2604 __ JumpIfSmi(a1, &non_function);
2606 // Goto slow case if we do not have a function.
2607 __ GetObjectType(a1, t0, t0);
2608 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2611 // Fast-case: Invoke the function now.
2612 // a1: pushed function
2613 ParameterCount actual(argc);
2615 if (call_as_method) {
2617 EmitContinueIfStrictOrNative(masm, &cont);
2620 // Compute the receiver in sloppy mode.
2621 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2624 __ JumpIfSmi(a3, &wrap);
2625 __ GetObjectType(a3, t0, t0);
2626 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2634 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2637 // Slow-case: Non-function called.
2639 EmitSlowCase(masm, argc, &non_function);
2642 if (call_as_method) {
2644 // Wrap the receiver and patch it back onto the stack.
2645 EmitWrapCase(masm, argc, &cont);
2650 void CallFunctionStub::Generate(MacroAssembler* masm) {
2651 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2655 void CallConstructStub::Generate(MacroAssembler* masm) {
2656 // a0 : number of arguments
2657 // a1 : the function to call
2658 // a2 : feedback vector
2659 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2660 // t0 : original constructor (for IsSuperConstructorCall)
2661 Label slow, non_function_call;
2663 // Check that the function is not a smi.
2664 __ JumpIfSmi(a1, &non_function_call);
2665 // Check that the function is a JSFunction.
2666 __ GetObjectType(a1, t1, t1);
2667 __ Branch(&slow, ne, t1, Operand(JS_FUNCTION_TYPE));
2669 if (RecordCallTarget()) {
2670 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2672 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2673 __ Addu(t1, a2, at);
2674 if (FLAG_pretenuring_call_new) {
2675 // Put the AllocationSite from the feedback vector into a2.
2676 // By adding kPointerSize we encode that we know the AllocationSite
2677 // entry is at the feedback vector slot given by a3 + 1.
2678 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize + kPointerSize));
2680 Label feedback_register_initialized;
2681 // Put the AllocationSite from the feedback vector into a2, or undefined.
2682 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
2683 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
2684 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2685 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
2686 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2687 __ bind(&feedback_register_initialized);
2690 __ AssertUndefinedOrAllocationSite(a2, t1);
2693 // Pass function as original constructor.
2694 if (IsSuperConstructorCall()) {
2700 // Jump to the function-specific construct stub.
2701 Register jmp_reg = t0;
2702 __ lw(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2703 __ lw(jmp_reg, FieldMemOperand(jmp_reg,
2704 SharedFunctionInfo::kConstructStubOffset));
2705 __ Addu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2708 // a0: number of arguments
2709 // a1: called object
2713 __ Branch(&non_function_call, ne, t1, Operand(JS_FUNCTION_PROXY_TYPE));
2714 __ GetBuiltinFunction(
2715 a1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2718 __ bind(&non_function_call);
2719 __ GetBuiltinFunction(
2720 a1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2722 // Set expected number of arguments to zero (not changing r0).
2723 __ li(a2, Operand(0, RelocInfo::NONE32));
2724 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2725 RelocInfo::CODE_TARGET);
2729 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2730 __ lw(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2731 __ lw(vector, FieldMemOperand(vector,
2732 JSFunction::kSharedFunctionInfoOffset));
2733 __ lw(vector, FieldMemOperand(vector,
2734 SharedFunctionInfo::kFeedbackVectorOffset));
2738 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2744 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2745 __ Branch(&miss, ne, a1, Operand(at));
2747 __ li(a0, Operand(arg_count()));
2748 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2749 __ Addu(at, a2, Operand(at));
2750 __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize));
2752 // Verify that t0 contains an AllocationSite
2753 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2754 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2755 __ Branch(&miss, ne, t1, Operand(at));
2757 // Increment the call count for monomorphic function calls.
2758 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2759 __ Addu(at, a2, Operand(at));
2760 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2761 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2762 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2766 ArrayConstructorStub stub(masm->isolate(), arg_count());
2767 __ TailCallStub(&stub);
2772 // The slow case, we need this no matter what to complete a call after a miss.
2773 CallFunctionNoFeedback(masm,
2779 __ stop("Unexpected code address");
2783 void CallICStub::Generate(MacroAssembler* masm) {
2785 // a3 - slot id (Smi)
2787 const int with_types_offset =
2788 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2789 const int generic_offset =
2790 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2791 Label extra_checks_or_miss, slow_start;
2792 Label slow, non_function, wrap, cont;
2793 Label have_js_function;
2794 int argc = arg_count();
2795 ParameterCount actual(argc);
2797 // The checks. First, does r1 match the recorded monomorphic target?
2798 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2799 __ Addu(t0, a2, Operand(t0));
2800 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2802 // We don't know that we have a weak cell. We might have a private symbol
2803 // or an AllocationSite, but the memory is safe to examine.
2804 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2806 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2807 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2808 // computed, meaning that it can't appear to be a pointer. If the low bit is
2809 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2811 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2812 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2813 WeakCell::kValueOffset &&
2814 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2816 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2817 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
2819 // The compare above could have been a SMI/SMI comparison. Guard against this
2820 // convincing us that we have a monomorphic JSFunction.
2821 __ JumpIfSmi(a1, &extra_checks_or_miss);
2823 // Increment the call count for monomorphic function calls.
2824 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2825 __ Addu(at, a2, Operand(at));
2826 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2827 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2828 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2830 __ bind(&have_js_function);
2831 if (CallAsMethod()) {
2832 EmitContinueIfStrictOrNative(masm, &cont);
2833 // Compute the receiver in sloppy mode.
2834 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2836 __ JumpIfSmi(a3, &wrap);
2837 __ GetObjectType(a3, t0, t0);
2838 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2843 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2846 EmitSlowCase(masm, argc, &non_function);
2848 if (CallAsMethod()) {
2850 EmitWrapCase(masm, argc, &cont);
2853 __ bind(&extra_checks_or_miss);
2854 Label uninitialized, miss;
2856 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2857 __ Branch(&slow_start, eq, t0, Operand(at));
2859 // The following cases attempt to handle MISS cases without going to the
2861 if (FLAG_trace_ic) {
2865 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2866 __ Branch(&uninitialized, eq, t0, Operand(at));
2868 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2869 // to handle it here. More complex cases are dealt with in the runtime.
2870 __ AssertNotSmi(t0);
2871 __ GetObjectType(t0, t1, t1);
2872 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
2873 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2874 __ Addu(t0, a2, Operand(t0));
2875 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2876 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2877 // We have to update statistics for runtime profiling.
2878 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2879 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
2880 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2881 __ lw(t0, FieldMemOperand(a2, generic_offset));
2882 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2883 __ Branch(USE_DELAY_SLOT, &slow_start);
2884 __ sw(t0, FieldMemOperand(a2, generic_offset)); // In delay slot.
2886 __ bind(&uninitialized);
2888 // We are going monomorphic, provided we actually have a JSFunction.
2889 __ JumpIfSmi(a1, &miss);
2891 // Goto miss case if we do not have a function.
2892 __ GetObjectType(a1, t0, t0);
2893 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2895 // Make sure the function is not the Array() function, which requires special
2896 // behavior on MISS.
2897 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2898 __ Branch(&miss, eq, a1, Operand(t0));
2901 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2902 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2903 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2905 // Initialize the call counter.
2906 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2907 __ Addu(at, a2, Operand(at));
2908 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2909 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2911 // Store the function. Use a stub since we need a frame for allocation.
2916 FrameScope scope(masm, StackFrame::INTERNAL);
2917 CreateWeakCellStub create_stub(masm->isolate());
2919 __ CallStub(&create_stub);
2923 __ Branch(&have_js_function);
2925 // We are here because tracing is on or we encountered a MISS case we can't
2931 __ bind(&slow_start);
2932 // Check that the function is really a JavaScript function.
2933 // r1: pushed function (to be verified)
2934 __ JumpIfSmi(a1, &non_function);
2936 // Goto slow case if we do not have a function.
2937 __ GetObjectType(a1, t0, t0);
2938 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2939 __ Branch(&have_js_function);
2943 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2944 FrameScope scope(masm, StackFrame::INTERNAL);
2946 // Push the receiver and the function and feedback info.
2947 __ Push(a1, a2, a3);
2950 Runtime::FunctionId id = GetICState() == DEFAULT
2951 ? Runtime::kCallIC_Miss
2952 : Runtime::kCallIC_Customization_Miss;
2953 __ CallRuntime(id, 3);
2955 // Move result to a1 and exit the internal frame.
2960 // StringCharCodeAtGenerator.
2961 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2962 DCHECK(!t0.is(index_));
2963 DCHECK(!t0.is(result_));
2964 DCHECK(!t0.is(object_));
2965 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2966 // If the receiver is a smi trigger the non-string case.
2967 __ JumpIfSmi(object_, receiver_not_string_);
2969 // Fetch the instance type of the receiver into result register.
2970 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2971 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2972 // If the receiver is not a string trigger the non-string case.
2973 __ And(t0, result_, Operand(kIsNotStringMask));
2974 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
2977 // If the index is non-smi trigger the non-smi case.
2978 __ JumpIfNotSmi(index_, &index_not_smi_);
2980 __ bind(&got_smi_index_);
2982 // Check for index out of range.
2983 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
2984 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
2986 __ sra(index_, index_, kSmiTagSize);
2988 StringCharLoadGenerator::Generate(masm,
2994 __ sll(result_, result_, kSmiTagSize);
2999 void StringCharCodeAtGenerator::GenerateSlow(
3000 MacroAssembler* masm, EmbedMode embed_mode,
3001 const RuntimeCallHelper& call_helper) {
3002 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3004 // Index is not a smi.
3005 __ bind(&index_not_smi_);
3006 // If index is a heap number, try converting it to an integer.
3009 Heap::kHeapNumberMapRootIndex,
3012 call_helper.BeforeCall(masm);
3013 // Consumed by runtime conversion function:
3014 if (embed_mode == PART_OF_IC_HANDLER) {
3015 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3016 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3018 __ Push(object_, index_);
3020 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3021 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3023 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3024 // NumberToSmi discards numbers that are not exact integers.
3025 __ CallRuntime(Runtime::kNumberToSmi, 1);
3028 // Save the conversion result before the pop instructions below
3029 // have a chance to overwrite it.
3030 __ Move(index_, v0);
3031 if (embed_mode == PART_OF_IC_HANDLER) {
3032 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3033 LoadWithVectorDescriptor::SlotRegister(), object_);
3037 // Reload the instance type.
3038 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3039 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3040 call_helper.AfterCall(masm);
3041 // If index is still not a smi, it must be out of range.
3042 __ JumpIfNotSmi(index_, index_out_of_range_);
3043 // Otherwise, return to the fast path.
3044 __ Branch(&got_smi_index_);
3046 // Call runtime. We get here when the receiver is a string and the
3047 // index is a number, but the code of getting the actual character
3048 // is too complex (e.g., when the string needs to be flattened).
3049 __ bind(&call_runtime_);
3050 call_helper.BeforeCall(masm);
3051 __ sll(index_, index_, kSmiTagSize);
3052 __ Push(object_, index_);
3053 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3055 __ Move(result_, v0);
3057 call_helper.AfterCall(masm);
3060 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3064 // -------------------------------------------------------------------------
3065 // StringCharFromCodeGenerator
3067 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3068 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3070 DCHECK(!t0.is(result_));
3071 DCHECK(!t0.is(code_));
3073 STATIC_ASSERT(kSmiTag == 0);
3074 STATIC_ASSERT(kSmiShiftSize == 0);
3075 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3076 __ And(t0, code_, Operand(kSmiTagMask |
3077 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3078 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
3080 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3081 // At this point code register contains smi tagged one-byte char code.
3082 STATIC_ASSERT(kSmiTag == 0);
3083 __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize);
3084 __ Addu(result_, result_, t0);
3085 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3086 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
3087 __ Branch(&slow_case_, eq, result_, Operand(t0));
3092 void StringCharFromCodeGenerator::GenerateSlow(
3093 MacroAssembler* masm,
3094 const RuntimeCallHelper& call_helper) {
3095 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3097 __ bind(&slow_case_);
3098 call_helper.BeforeCall(masm);
3100 __ CallRuntime(Runtime::kCharFromCode, 1);
3101 __ Move(result_, v0);
3103 call_helper.AfterCall(masm);
3106 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3110 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3113 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3118 String::Encoding encoding) {
3119 if (FLAG_debug_code) {
3120 // Check that destination is word aligned.
3121 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3123 kDestinationOfCopyNotAligned,
3128 // Assumes word reads and writes are little endian.
3129 // Nothing to do for zero characters.
3132 if (encoding == String::TWO_BYTE_ENCODING) {
3133 __ Addu(count, count, count);
3136 Register limit = count; // Read until dest equals this.
3137 __ Addu(limit, dest, Operand(count));
3139 Label loop_entry, loop;
3140 // Copy bytes from src to dest until dest hits limit.
3141 __ Branch(&loop_entry);
3143 __ lbu(scratch, MemOperand(src));
3144 __ Addu(src, src, Operand(1));
3145 __ sb(scratch, MemOperand(dest));
3146 __ Addu(dest, dest, Operand(1));
3147 __ bind(&loop_entry);
3148 __ Branch(&loop, lt, dest, Operand(limit));
3154 void SubStringStub::Generate(MacroAssembler* masm) {
3156 // Stack frame on entry.
3157 // ra: return address
3162 // This stub is called from the native-call %_SubString(...), so
3163 // nothing can be assumed about the arguments. It is tested that:
3164 // "string" is a sequential string,
3165 // both "from" and "to" are smis, and
3166 // 0 <= from <= to <= string.length.
3167 // If any of these assumptions fail, we call the runtime system.
3169 const int kToOffset = 0 * kPointerSize;
3170 const int kFromOffset = 1 * kPointerSize;
3171 const int kStringOffset = 2 * kPointerSize;
3173 __ lw(a2, MemOperand(sp, kToOffset));
3174 __ lw(a3, MemOperand(sp, kFromOffset));
3175 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3176 STATIC_ASSERT(kSmiTag == 0);
3177 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3179 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3180 // safe in this case.
3181 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
3182 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
3183 // Both a2 and a3 are untagged integers.
3185 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3187 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3188 __ Subu(a2, a2, a3);
3190 // Make sure first argument is a string.
3191 __ lw(v0, MemOperand(sp, kStringOffset));
3192 __ JumpIfSmi(v0, &runtime);
3193 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3194 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3195 __ And(t0, a1, Operand(kIsNotStringMask));
3197 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3200 __ Branch(&single_char, eq, a2, Operand(1));
3202 // Short-cut for the case of trivial substring.
3204 // v0: original string
3205 // a2: result string length
3206 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
3208 // Return original string.
3209 __ Branch(&return_v0, eq, a2, Operand(t0));
3210 // Longer than original string's length or negative: unsafe arguments.
3211 __ Branch(&runtime, hi, a2, Operand(t0));
3212 // Shorter than original string's length: an actual substring.
3214 // Deal with different string types: update the index if necessary
3215 // and put the underlying string into t1.
3216 // v0: original string
3217 // a1: instance type
3219 // a3: from index (untagged)
3220 Label underlying_unpacked, sliced_string, seq_or_external_string;
3221 // If the string is not indirect, it can only be sequential or external.
3222 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3223 STATIC_ASSERT(kIsIndirectStringMask != 0);
3224 __ And(t0, a1, Operand(kIsIndirectStringMask));
3225 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
3226 // t0 is used as a scratch register and can be overwritten in either case.
3227 __ And(t0, a1, Operand(kSlicedNotConsMask));
3228 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
3229 // Cons string. Check whether it is flat, then fetch first part.
3230 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
3231 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
3232 __ Branch(&runtime, ne, t1, Operand(t0));
3233 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
3234 // Update instance type.
3235 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3236 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3237 __ jmp(&underlying_unpacked);
3239 __ bind(&sliced_string);
3240 // Sliced string. Fetch parent and correct start index by offset.
3241 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3242 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3243 __ sra(t0, t0, 1); // Add offset to index.
3244 __ Addu(a3, a3, t0);
3245 // Update instance type.
3246 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3247 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3248 __ jmp(&underlying_unpacked);
3250 __ bind(&seq_or_external_string);
3251 // Sequential or external string. Just move string to the expected register.
3254 __ bind(&underlying_unpacked);
3256 if (FLAG_string_slices) {
3258 // t1: underlying subject string
3259 // a1: instance type of underlying subject string
3261 // a3: adjusted start index (untagged)
3262 // Short slice. Copy instead of slicing.
3263 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3264 // Allocate new sliced string. At this point we do not reload the instance
3265 // type including the string encoding because we simply rely on the info
3266 // provided by the original string. It does not matter if the original
3267 // string's encoding is wrong because we always have to recheck encoding of
3268 // the newly created string's parent anyways due to externalized strings.
3269 Label two_byte_slice, set_slice_header;
3270 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3271 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3272 __ And(t0, a1, Operand(kStringEncodingMask));
3273 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
3274 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
3275 __ jmp(&set_slice_header);
3276 __ bind(&two_byte_slice);
3277 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
3278 __ bind(&set_slice_header);
3280 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3281 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3284 __ bind(©_routine);
3287 // t1: underlying subject string
3288 // a1: instance type of underlying subject string
3290 // a3: adjusted start index (untagged)
3291 Label two_byte_sequential, sequential_string, allocate_result;
3292 STATIC_ASSERT(kExternalStringTag != 0);
3293 STATIC_ASSERT(kSeqStringTag == 0);
3294 __ And(t0, a1, Operand(kExternalStringTag));
3295 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
3297 // Handle external string.
3298 // Rule out short external strings.
3299 STATIC_ASSERT(kShortExternalStringTag != 0);
3300 __ And(t0, a1, Operand(kShortExternalStringTag));
3301 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3302 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
3303 // t1 already points to the first character of underlying string.
3304 __ jmp(&allocate_result);
3306 __ bind(&sequential_string);
3307 // Locate first character of underlying subject string.
3308 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3309 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3311 __ bind(&allocate_result);
3312 // Sequential acii string. Allocate the result.
3313 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3314 __ And(t0, a1, Operand(kStringEncodingMask));
3315 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
3317 // Allocate and copy the resulting ASCII string.
3318 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
3320 // Locate first character of substring to copy.
3321 __ Addu(t1, t1, a3);
3323 // Locate first character of result.
3324 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3326 // v0: result string
3327 // a1: first character of result string
3328 // a2: result string length
3329 // t1: first character of substring to copy
3330 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3331 StringHelper::GenerateCopyCharacters(
3332 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
3335 // Allocate and copy the resulting two-byte string.
3336 __ bind(&two_byte_sequential);
3337 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
3339 // Locate first character of substring to copy.
3340 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3342 __ Addu(t1, t1, t0);
3343 // Locate first character of result.
3344 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3346 // v0: result string.
3347 // a1: first character of result.
3348 // a2: result length.
3349 // t1: first character of substring to copy.
3350 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3351 StringHelper::GenerateCopyCharacters(
3352 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
3354 __ bind(&return_v0);
3355 Counters* counters = isolate()->counters();
3356 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
3359 // Just jump to runtime to create the sub string.
3361 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3363 __ bind(&single_char);
3364 // v0: original string
3365 // a1: instance type
3367 // a3: from index (untagged)
3369 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3370 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3371 generator.GenerateFast(masm);
3373 generator.SkipSlow(masm, &runtime);
3377 void ToNumberStub::Generate(MacroAssembler* masm) {
3378 // The ToNumber stub takes one argument in a0.
3380 __ JumpIfNotSmi(a0, ¬_smi);
3381 __ Ret(USE_DELAY_SLOT);
3385 Label not_heap_number;
3386 __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3387 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3389 // a1: instance type.
3390 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3391 __ Ret(USE_DELAY_SLOT);
3393 __ bind(¬_heap_number);
3395 Label not_string, slow_string;
3396 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3397 // Check if string has a cached array index.
3398 __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3399 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3400 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3401 __ IndexFromHash(a2, a0);
3402 __ Ret(USE_DELAY_SLOT);
3404 __ bind(&slow_string);
3405 __ push(a0); // Push argument.
3406 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3407 __ bind(¬_string);
3410 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3411 __ Ret(USE_DELAY_SLOT);
3412 __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3413 __ bind(¬_oddball);
3415 __ push(a0); // Push argument.
3416 __ InvokeBuiltin(Context::TO_NUMBER_BUILTIN_INDEX, JUMP_FUNCTION);
3420 void StringHelper::GenerateFlatOneByteStringEquals(
3421 MacroAssembler* masm, Register left, Register right, Register scratch1,
3422 Register scratch2, Register scratch3) {
3423 Register length = scratch1;
3426 Label strings_not_equal, check_zero_length;
3427 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
3428 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3429 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3430 __ bind(&strings_not_equal);
3431 DCHECK(is_int16(NOT_EQUAL));
3432 __ Ret(USE_DELAY_SLOT);
3433 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3435 // Check if the length is zero.
3436 Label compare_chars;
3437 __ bind(&check_zero_length);
3438 STATIC_ASSERT(kSmiTag == 0);
3439 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3440 DCHECK(is_int16(EQUAL));
3441 __ Ret(USE_DELAY_SLOT);
3442 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3444 // Compare characters.
3445 __ bind(&compare_chars);
3447 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3448 v0, &strings_not_equal);
3450 // Characters are equal.
3451 __ Ret(USE_DELAY_SLOT);
3452 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3456 void StringHelper::GenerateCompareFlatOneByteStrings(
3457 MacroAssembler* masm, Register left, Register right, Register scratch1,
3458 Register scratch2, Register scratch3, Register scratch4) {
3459 Label result_not_equal, compare_lengths;
3460 // Find minimum length and length difference.
3461 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
3462 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3463 __ Subu(scratch3, scratch1, Operand(scratch2));
3464 Register length_delta = scratch3;
3465 __ slt(scratch4, scratch2, scratch1);
3466 __ Movn(scratch1, scratch2, scratch4);
3467 Register min_length = scratch1;
3468 STATIC_ASSERT(kSmiTag == 0);
3469 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3472 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3473 scratch4, v0, &result_not_equal);
3475 // Compare lengths - strings up to min-length are equal.
3476 __ bind(&compare_lengths);
3477 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3478 // Use length_delta as result if it's zero.
3479 __ mov(scratch2, length_delta);
3480 __ mov(scratch4, zero_reg);
3481 __ mov(v0, zero_reg);
3483 __ bind(&result_not_equal);
3484 // Conditionally update the result based either on length_delta or
3485 // the last comparion performed in the loop above.
3487 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3488 __ li(v0, Operand(Smi::FromInt(GREATER)));
3489 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3490 __ li(v0, Operand(Smi::FromInt(LESS)));
3496 void StringHelper::GenerateOneByteCharsCompareLoop(
3497 MacroAssembler* masm, Register left, Register right, Register length,
3498 Register scratch1, Register scratch2, Register scratch3,
3499 Label* chars_not_equal) {
3500 // Change index to run from -length to -1 by adding length to string
3501 // start. This means that loop ends when index reaches zero, which
3502 // doesn't need an additional compare.
3503 __ SmiUntag(length);
3504 __ Addu(scratch1, length,
3505 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3506 __ Addu(left, left, Operand(scratch1));
3507 __ Addu(right, right, Operand(scratch1));
3508 __ Subu(length, zero_reg, length);
3509 Register index = length; // index = -length;
3515 __ Addu(scratch3, left, index);
3516 __ lbu(scratch1, MemOperand(scratch3));
3517 __ Addu(scratch3, right, index);
3518 __ lbu(scratch2, MemOperand(scratch3));
3519 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3520 __ Addu(index, index, 1);
3521 __ Branch(&loop, ne, index, Operand(zero_reg));
3525 void StringCompareStub::Generate(MacroAssembler* masm) {
3528 Counters* counters = isolate()->counters();
3530 // Stack frame on entry.
3531 // sp[0]: right string
3532 // sp[4]: left string
3533 __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3534 __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3537 __ Branch(¬_same, ne, a0, Operand(a1));
3538 STATIC_ASSERT(EQUAL == 0);
3539 STATIC_ASSERT(kSmiTag == 0);
3540 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3541 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3546 // Check that both objects are sequential one-byte strings.
3547 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3549 // Compare flat ASCII strings natively. Remove arguments from stack first.
3550 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3551 __ Addu(sp, sp, Operand(2 * kPointerSize));
3552 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3555 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3559 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3560 // ----------- S t a t e -------------
3563 // -- ra : return address
3564 // -----------------------------------
3566 // Load a2 with the allocation site. We stick an undefined dummy value here
3567 // and replace it with the real allocation site later when we instantiate this
3568 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3569 __ li(a2, handle(isolate()->heap()->undefined_value()));
3571 // Make sure that we actually patched the allocation site.
3572 if (FLAG_debug_code) {
3573 __ And(at, a2, Operand(kSmiTagMask));
3574 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3575 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
3576 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3577 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
3580 // Tail call into the stub that handles binary operations with allocation
3582 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3583 __ TailCallStub(&stub);
3587 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3588 DCHECK(state() == CompareICState::SMI);
3591 __ JumpIfNotSmi(a2, &miss);
3593 if (GetCondition() == eq) {
3594 // For equality we do not care about the sign of the result.
3595 __ Ret(USE_DELAY_SLOT);
3596 __ Subu(v0, a0, a1);
3598 // Untag before subtracting to avoid handling overflow.
3601 __ Ret(USE_DELAY_SLOT);
3602 __ Subu(v0, a1, a0);
3610 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3611 DCHECK(state() == CompareICState::NUMBER);
3614 Label unordered, maybe_undefined1, maybe_undefined2;
3617 if (left() == CompareICState::SMI) {
3618 __ JumpIfNotSmi(a1, &miss);
3620 if (right() == CompareICState::SMI) {
3621 __ JumpIfNotSmi(a0, &miss);
3624 // Inlining the double comparison and falling back to the general compare
3625 // stub if NaN is involved.
3626 // Load left and right operand.
3627 Label done, left, left_smi, right_smi;
3628 __ JumpIfSmi(a0, &right_smi);
3629 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3631 __ Subu(a2, a0, Operand(kHeapObjectTag));
3632 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3634 __ bind(&right_smi);
3635 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3636 FPURegister single_scratch = f6;
3637 __ mtc1(a2, single_scratch);
3638 __ cvt_d_w(f2, single_scratch);
3641 __ JumpIfSmi(a1, &left_smi);
3642 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3644 __ Subu(a2, a1, Operand(kHeapObjectTag));
3645 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3648 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3649 single_scratch = f8;
3650 __ mtc1(a2, single_scratch);
3651 __ cvt_d_w(f0, single_scratch);
3655 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3656 Label fpu_eq, fpu_lt;
3657 // Test if equal, and also handle the unordered/NaN case.
3658 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3660 // Test if less (unordered case is already handled).
3661 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3663 // Otherwise it's greater, so just fall thru, and return.
3664 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3665 __ Ret(USE_DELAY_SLOT);
3666 __ li(v0, Operand(GREATER));
3669 __ Ret(USE_DELAY_SLOT);
3670 __ li(v0, Operand(EQUAL));
3673 __ Ret(USE_DELAY_SLOT);
3674 __ li(v0, Operand(LESS));
3676 __ bind(&unordered);
3677 __ bind(&generic_stub);
3678 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3679 CompareICState::GENERIC, CompareICState::GENERIC);
3680 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3682 __ bind(&maybe_undefined1);
3683 if (Token::IsOrderedRelationalCompareOp(op())) {
3684 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3685 __ Branch(&miss, ne, a0, Operand(at));
3686 __ JumpIfSmi(a1, &unordered);
3687 __ GetObjectType(a1, a2, a2);
3688 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3692 __ bind(&maybe_undefined2);
3693 if (Token::IsOrderedRelationalCompareOp(op())) {
3694 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3695 __ Branch(&unordered, eq, a1, Operand(at));
3703 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3704 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3707 // Registers containing left and right operands respectively.
3709 Register right = a0;
3713 // Check that both operands are heap objects.
3714 __ JumpIfEitherSmi(left, right, &miss);
3716 // Check that both operands are internalized strings.
3717 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3718 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3719 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3720 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3721 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3722 __ Or(tmp1, tmp1, Operand(tmp2));
3723 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3724 __ Branch(&miss, ne, at, Operand(zero_reg));
3726 // Make sure a0 is non-zero. At this point input operands are
3727 // guaranteed to be non-zero.
3728 DCHECK(right.is(a0));
3729 STATIC_ASSERT(EQUAL == 0);
3730 STATIC_ASSERT(kSmiTag == 0);
3732 // Internalized strings are compared by identity.
3733 __ Ret(ne, left, Operand(right));
3734 DCHECK(is_int16(EQUAL));
3735 __ Ret(USE_DELAY_SLOT);
3736 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3743 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3744 DCHECK(state() == CompareICState::UNIQUE_NAME);
3745 DCHECK(GetCondition() == eq);
3748 // Registers containing left and right operands respectively.
3750 Register right = a0;
3754 // Check that both operands are heap objects.
3755 __ JumpIfEitherSmi(left, right, &miss);
3757 // Check that both operands are unique names. This leaves the instance
3758 // types loaded in tmp1 and tmp2.
3759 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3760 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3761 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3762 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3764 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3765 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3770 // Unique names are compared by identity.
3772 __ Branch(&done, ne, left, Operand(right));
3773 // Make sure a0 is non-zero. At this point input operands are
3774 // guaranteed to be non-zero.
3775 DCHECK(right.is(a0));
3776 STATIC_ASSERT(EQUAL == 0);
3777 STATIC_ASSERT(kSmiTag == 0);
3778 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3787 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3788 DCHECK(state() == CompareICState::STRING);
3791 bool equality = Token::IsEqualityOp(op());
3793 // Registers containing left and right operands respectively.
3795 Register right = a0;
3802 // Check that both operands are heap objects.
3803 __ JumpIfEitherSmi(left, right, &miss);
3805 // Check that both operands are strings. This leaves the instance
3806 // types loaded in tmp1 and tmp2.
3807 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3808 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3809 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3810 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3811 STATIC_ASSERT(kNotStringTag != 0);
3812 __ Or(tmp3, tmp1, tmp2);
3813 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3814 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3816 // Fast check for identical strings.
3817 Label left_ne_right;
3818 STATIC_ASSERT(EQUAL == 0);
3819 STATIC_ASSERT(kSmiTag == 0);
3820 __ Branch(&left_ne_right, ne, left, Operand(right));
3821 __ Ret(USE_DELAY_SLOT);
3822 __ mov(v0, zero_reg); // In the delay slot.
3823 __ bind(&left_ne_right);
3825 // Handle not identical strings.
3827 // Check that both strings are internalized strings. If they are, we're done
3828 // because we already know they are not identical. We know they are both
3831 DCHECK(GetCondition() == eq);
3832 STATIC_ASSERT(kInternalizedTag == 0);
3833 __ Or(tmp3, tmp1, Operand(tmp2));
3834 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3836 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3837 // Make sure a0 is non-zero. At this point input operands are
3838 // guaranteed to be non-zero.
3839 DCHECK(right.is(a0));
3840 __ Ret(USE_DELAY_SLOT);
3841 __ mov(v0, a0); // In the delay slot.
3842 __ bind(&is_symbol);
3845 // Check that both strings are sequential one-byte.
3847 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3850 // Compare flat one-byte strings. Returns when done.
3852 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3855 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3859 // Handle more complex cases in runtime.
3861 __ Push(left, right);
3863 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3865 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3873 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3874 DCHECK(state() == CompareICState::OBJECT);
3876 __ And(a2, a1, Operand(a0));
3877 __ JumpIfSmi(a2, &miss);
3879 __ GetObjectType(a0, a2, a2);
3880 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3881 __ GetObjectType(a1, a2, a2);
3882 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3884 DCHECK(GetCondition() == eq);
3885 __ Ret(USE_DELAY_SLOT);
3886 __ subu(v0, a0, a1);
3893 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3895 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3897 __ JumpIfSmi(a2, &miss);
3898 __ GetWeakValue(t0, cell);
3899 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3900 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3901 __ Branch(&miss, ne, a2, Operand(t0));
3902 __ Branch(&miss, ne, a3, Operand(t0));
3904 __ Ret(USE_DELAY_SLOT);
3905 __ subu(v0, a0, a1);
3912 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3914 // Call the runtime system in a fresh internal frame.
3915 FrameScope scope(masm, StackFrame::INTERNAL);
3917 __ Push(ra, a1, a0);
3918 __ li(t0, Operand(Smi::FromInt(op())));
3919 __ addiu(sp, sp, -kPointerSize);
3920 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3922 __ sw(t0, MemOperand(sp)); // In the delay slot.
3923 // Compute the entry point of the rewritten stub.
3924 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3925 // Restore registers.
3932 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3933 // Make place for arguments to fit C calling convention. Most of the callers
3934 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3935 // so they handle stack restoring and we don't have to do that here.
3936 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3937 // kCArgsSlotsSize stack space after the call.
3938 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
3939 // Place the return address on the stack, making the call
3940 // GC safe. The RegExp backend also relies on this.
3941 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
3942 __ Call(t9); // Call the C++ function.
3943 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
3945 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3946 // In case of an error the return address may point to a memory area
3947 // filled with kZapValue by the GC.
3948 // Dereference the address and check for this.
3949 __ lw(t0, MemOperand(t9));
3950 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
3951 Operand(reinterpret_cast<uint32_t>(kZapValue)));
3957 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3960 reinterpret_cast<intptr_t>(GetCode().location());
3961 __ Move(t9, target);
3962 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3967 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3971 Register properties,
3973 Register scratch0) {
3974 DCHECK(name->IsUniqueName());
3975 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3976 // not equal to the name and kProbes-th slot is not used (its name is the
3977 // undefined value), it guarantees the hash table doesn't contain the
3978 // property. It's true even if some slots represent deleted properties
3979 // (their names are the hole value).
3980 for (int i = 0; i < kInlinedProbes; i++) {
3981 // scratch0 points to properties hash.
3982 // Compute the masked index: (hash + i + i * i) & mask.
3983 Register index = scratch0;
3984 // Capacity is smi 2^n.
3985 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
3986 __ Subu(index, index, Operand(1));
3987 __ And(index, index, Operand(
3988 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3990 // Scale the index by multiplying by the entry size.
3991 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3992 __ sll(at, index, 1);
3993 __ Addu(index, index, at);
3995 Register entity_name = scratch0;
3996 // Having undefined at this place means the name is not contained.
3997 STATIC_ASSERT(kSmiTagSize == 1);
3998 Register tmp = properties;
3999 __ sll(scratch0, index, 1);
4000 __ Addu(tmp, properties, scratch0);
4001 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4003 DCHECK(!tmp.is(entity_name));
4004 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4005 __ Branch(done, eq, entity_name, Operand(tmp));
4007 // Load the hole ready for use below:
4008 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4010 // Stop if found the property.
4011 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4014 __ Branch(&good, eq, entity_name, Operand(tmp));
4016 // Check if the entry name is not a unique name.
4017 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4019 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4020 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4023 // Restore the properties.
4025 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4028 const int spill_mask =
4029 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
4030 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4032 __ MultiPush(spill_mask);
4033 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4034 __ li(a1, Operand(Handle<Name>(name)));
4035 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4038 __ MultiPop(spill_mask);
4040 __ Branch(done, eq, at, Operand(zero_reg));
4041 __ Branch(miss, ne, at, Operand(zero_reg));
4045 // Probe the name dictionary in the |elements| register. Jump to the
4046 // |done| label if a property with the given name is found. Jump to
4047 // the |miss| label otherwise.
4048 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4049 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4055 Register scratch2) {
4056 DCHECK(!elements.is(scratch1));
4057 DCHECK(!elements.is(scratch2));
4058 DCHECK(!name.is(scratch1));
4059 DCHECK(!name.is(scratch2));
4061 __ AssertName(name);
4063 // Compute the capacity mask.
4064 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
4065 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
4066 __ Subu(scratch1, scratch1, Operand(1));
4068 // Generate an unrolled loop that performs a few probes before
4069 // giving up. Measurements done on Gmail indicate that 2 probes
4070 // cover ~93% of loads from dictionaries.
4071 for (int i = 0; i < kInlinedProbes; i++) {
4072 // Compute the masked index: (hash + i + i * i) & mask.
4073 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4075 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4076 // the hash in a separate instruction. The value hash + i + i * i is right
4077 // shifted in the following and instruction.
4078 DCHECK(NameDictionary::GetProbeOffset(i) <
4079 1 << (32 - Name::kHashFieldOffset));
4080 __ Addu(scratch2, scratch2, Operand(
4081 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4083 __ srl(scratch2, scratch2, Name::kHashShift);
4084 __ And(scratch2, scratch1, scratch2);
4086 // Scale the index by multiplying by the element size.
4087 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4088 // scratch2 = scratch2 * 3.
4090 __ sll(at, scratch2, 1);
4091 __ Addu(scratch2, scratch2, at);
4093 // Check if the key is identical to the name.
4094 __ sll(at, scratch2, 2);
4095 __ Addu(scratch2, elements, at);
4096 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
4097 __ Branch(done, eq, name, Operand(at));
4100 const int spill_mask =
4101 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
4102 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4103 ~(scratch1.bit() | scratch2.bit());
4105 __ MultiPush(spill_mask);
4107 DCHECK(!elements.is(a1));
4109 __ Move(a0, elements);
4111 __ Move(a0, elements);
4114 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4116 __ mov(scratch2, a2);
4118 __ MultiPop(spill_mask);
4120 __ Branch(done, ne, at, Operand(zero_reg));
4121 __ Branch(miss, eq, at, Operand(zero_reg));
4125 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4126 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4127 // we cannot call anything that could cause a GC from this stub.
4129 // result: NameDictionary to probe
4131 // dictionary: NameDictionary to probe.
4132 // index: will hold an index of entry if lookup is successful.
4133 // might alias with result_.
4135 // result_ is zero if lookup failed, non zero otherwise.
4137 Register result = v0;
4138 Register dictionary = a0;
4140 Register index = a2;
4143 Register undefined = t1;
4144 Register entry_key = t2;
4146 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4148 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
4149 __ sra(mask, mask, kSmiTagSize);
4150 __ Subu(mask, mask, Operand(1));
4152 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4154 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4156 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4157 // Compute the masked index: (hash + i + i * i) & mask.
4158 // Capacity is smi 2^n.
4160 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4161 // the hash in a separate instruction. The value hash + i + i * i is right
4162 // shifted in the following and instruction.
4163 DCHECK(NameDictionary::GetProbeOffset(i) <
4164 1 << (32 - Name::kHashFieldOffset));
4165 __ Addu(index, hash, Operand(
4166 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4168 __ mov(index, hash);
4170 __ srl(index, index, Name::kHashShift);
4171 __ And(index, mask, index);
4173 // Scale the index by multiplying by the entry size.
4174 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4177 __ sll(index, index, 1);
4178 __ Addu(index, index, at);
4181 STATIC_ASSERT(kSmiTagSize == 1);
4182 __ sll(index, index, 2);
4183 __ Addu(index, index, dictionary);
4184 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
4186 // Having undefined at this place means the name is not contained.
4187 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4189 // Stop if found the property.
4190 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4192 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4193 // Check if the entry name is not a unique name.
4194 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4196 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4197 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4201 __ bind(&maybe_in_dictionary);
4202 // If we are doing negative lookup then probing failure should be
4203 // treated as a lookup success. For positive lookup probing failure
4204 // should be treated as lookup failure.
4205 if (mode() == POSITIVE_LOOKUP) {
4206 __ Ret(USE_DELAY_SLOT);
4207 __ mov(result, zero_reg);
4210 __ bind(&in_dictionary);
4211 __ Ret(USE_DELAY_SLOT);
4214 __ bind(¬_in_dictionary);
4215 __ Ret(USE_DELAY_SLOT);
4216 __ mov(result, zero_reg);
4220 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4222 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4224 // Hydrogen code stubs need stub2 at snapshot time.
4225 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4230 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4231 // the value has just been written into the object, now this stub makes sure
4232 // we keep the GC informed. The word in the object where the value has been
4233 // written is in the address register.
4234 void RecordWriteStub::Generate(MacroAssembler* masm) {
4235 Label skip_to_incremental_noncompacting;
4236 Label skip_to_incremental_compacting;
4238 // The first two branch+nop instructions are generated with labels so as to
4239 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4240 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4241 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4242 // incremental heap marking.
4243 // See RecordWriteStub::Patch for details.
4244 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4246 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4249 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4250 __ RememberedSetHelper(object(),
4253 save_fp_regs_mode(),
4254 MacroAssembler::kReturnAtEnd);
4258 __ bind(&skip_to_incremental_noncompacting);
4259 GenerateIncremental(masm, INCREMENTAL);
4261 __ bind(&skip_to_incremental_compacting);
4262 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4264 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4265 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4267 PatchBranchIntoNop(masm, 0);
4268 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4272 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4275 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4276 Label dont_need_remembered_set;
4278 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4279 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4281 &dont_need_remembered_set);
4283 __ CheckPageFlag(regs_.object(),
4285 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4287 &dont_need_remembered_set);
4289 // First notify the incremental marker if necessary, then update the
4291 CheckNeedsToInformIncrementalMarker(
4292 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4293 InformIncrementalMarker(masm);
4294 regs_.Restore(masm);
4295 __ RememberedSetHelper(object(),
4298 save_fp_regs_mode(),
4299 MacroAssembler::kReturnAtEnd);
4301 __ bind(&dont_need_remembered_set);
4304 CheckNeedsToInformIncrementalMarker(
4305 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4306 InformIncrementalMarker(masm);
4307 regs_.Restore(masm);
4312 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4313 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4314 int argument_count = 3;
4315 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4317 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4318 DCHECK(!address.is(regs_.object()));
4319 DCHECK(!address.is(a0));
4320 __ Move(address, regs_.address());
4321 __ Move(a0, regs_.object());
4322 __ Move(a1, address);
4323 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4325 AllowExternalCallThatCantCauseGC scope(masm);
4327 ExternalReference::incremental_marking_record_write_function(isolate()),
4329 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4333 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4334 MacroAssembler* masm,
4335 OnNoNeedToInformIncrementalMarker on_no_need,
4338 Label need_incremental;
4339 Label need_incremental_pop_scratch;
4341 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4342 __ lw(regs_.scratch1(),
4343 MemOperand(regs_.scratch0(),
4344 MemoryChunk::kWriteBarrierCounterOffset));
4345 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4346 __ sw(regs_.scratch1(),
4347 MemOperand(regs_.scratch0(),
4348 MemoryChunk::kWriteBarrierCounterOffset));
4349 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4351 // Let's look at the color of the object: If it is not black we don't have
4352 // to inform the incremental marker.
4353 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4355 regs_.Restore(masm);
4356 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4357 __ RememberedSetHelper(object(),
4360 save_fp_regs_mode(),
4361 MacroAssembler::kReturnAtEnd);
4368 // Get the value from the slot.
4369 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4371 if (mode == INCREMENTAL_COMPACTION) {
4372 Label ensure_not_white;
4374 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4375 regs_.scratch1(), // Scratch.
4376 MemoryChunk::kEvacuationCandidateMask,
4380 __ CheckPageFlag(regs_.object(),
4381 regs_.scratch1(), // Scratch.
4382 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4386 __ bind(&ensure_not_white);
4389 // We need extra registers for this, so we push the object and the address
4390 // register temporarily.
4391 __ Push(regs_.object(), regs_.address());
4392 __ EnsureNotWhite(regs_.scratch0(), // The value.
4393 regs_.scratch1(), // Scratch.
4394 regs_.object(), // Scratch.
4395 regs_.address(), // Scratch.
4396 &need_incremental_pop_scratch);
4397 __ Pop(regs_.object(), regs_.address());
4399 regs_.Restore(masm);
4400 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4401 __ RememberedSetHelper(object(),
4404 save_fp_regs_mode(),
4405 MacroAssembler::kReturnAtEnd);
4410 __ bind(&need_incremental_pop_scratch);
4411 __ Pop(regs_.object(), regs_.address());
4413 __ bind(&need_incremental);
4415 // Fall through when we need to inform the incremental marker.
4419 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4420 // ----------- S t a t e -------------
4421 // -- a0 : element value to store
4422 // -- a3 : element index as smi
4423 // -- sp[0] : array literal index in function as smi
4424 // -- sp[4] : array literal
4425 // clobbers a1, a2, t0
4426 // -----------------------------------
4429 Label double_elements;
4431 Label slow_elements;
4432 Label fast_elements;
4434 // Get array literal index, array literal and its map.
4435 __ lw(t0, MemOperand(sp, 0 * kPointerSize));
4436 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
4437 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4439 __ CheckFastElements(a2, t1, &double_elements);
4440 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4441 __ JumpIfSmi(a0, &smi_element);
4442 __ CheckFastSmiElements(a2, t1, &fast_elements);
4444 // Store into the array literal requires a elements transition. Call into
4446 __ bind(&slow_elements);
4448 __ Push(a1, a3, a0);
4449 __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4450 __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset));
4452 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4454 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4455 __ bind(&fast_elements);
4456 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4457 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4458 __ Addu(t2, t1, t2);
4459 __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4460 __ sw(a0, MemOperand(t2, 0));
4461 // Update the write barrier for the array store.
4462 __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4463 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4464 __ Ret(USE_DELAY_SLOT);
4467 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4468 // and value is Smi.
4469 __ bind(&smi_element);
4470 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4471 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4472 __ Addu(t2, t1, t2);
4473 __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize));
4474 __ Ret(USE_DELAY_SLOT);
4477 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4478 __ bind(&double_elements);
4479 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4480 __ StoreNumberToDoubleElements(a0, a3, t1, t3, t5, a2, &slow_elements);
4481 __ Ret(USE_DELAY_SLOT);
4486 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4487 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4488 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4489 int parameter_count_offset =
4490 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4491 __ lw(a1, MemOperand(fp, parameter_count_offset));
4492 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4493 __ Addu(a1, a1, Operand(1));
4495 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4496 __ sll(a1, a1, kPointerSizeLog2);
4497 __ Ret(USE_DELAY_SLOT);
4498 __ Addu(sp, sp, a1);
4502 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4503 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4504 LoadICStub stub(isolate(), state());
4505 stub.GenerateForTrampoline(masm);
4509 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4510 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4511 KeyedLoadICStub stub(isolate(), state());
4512 stub.GenerateForTrampoline(masm);
4516 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4517 EmitLoadTypeFeedbackVector(masm, a2);
4518 CallICStub stub(isolate(), state());
4519 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4523 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4524 EmitLoadTypeFeedbackVector(masm, a2);
4525 CallIC_ArrayStub stub(isolate(), state());
4526 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4530 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4533 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4534 GenerateImpl(masm, true);
4538 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4539 Register key, Register vector, Register slot,
4540 Register feedback, Register receiver_map,
4541 Register scratch1, Register scratch2,
4542 bool is_polymorphic, Label* miss) {
4543 // feedback initially contains the feedback array
4544 Label next_loop, prepare_next;
4545 Label start_polymorphic;
4547 Register cached_map = scratch1;
4550 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4551 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4552 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4553 // found, now call handler.
4554 Register handler = feedback;
4555 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4556 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4560 Register length = scratch2;
4561 __ bind(&start_polymorphic);
4562 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4563 if (!is_polymorphic) {
4564 // If the IC could be monomorphic we have to make sure we don't go past the
4565 // end of the feedback array.
4566 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4569 Register too_far = length;
4570 Register pointer_reg = feedback;
4572 // +-----+------+------+-----+-----+ ... ----+
4573 // | map | len | wm0 | h0 | wm1 | hN |
4574 // +-----+------+------+-----+-----+ ... ----+
4578 // pointer_reg too_far
4579 // aka feedback scratch2
4580 // also need receiver_map
4581 // use cached_map (scratch1) to look in the weak map values.
4582 __ sll(at, length, kPointerSizeLog2 - kSmiTagSize);
4583 __ Addu(too_far, feedback, Operand(at));
4584 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4585 __ Addu(pointer_reg, feedback,
4586 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4588 __ bind(&next_loop);
4589 __ lw(cached_map, MemOperand(pointer_reg));
4590 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4591 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4592 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
4593 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4596 __ bind(&prepare_next);
4597 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4598 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4600 // We exhausted our array of map handler pairs.
4605 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4606 Register receiver_map, Register feedback,
4607 Register vector, Register slot,
4608 Register scratch, Label* compare_map,
4609 Label* load_smi_map, Label* try_array) {
4610 __ JumpIfSmi(receiver, load_smi_map);
4611 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4612 __ bind(compare_map);
4613 Register cached_map = scratch;
4614 // Move the weak map into the weak_cell register.
4615 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4616 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4617 Register handler = feedback;
4619 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4620 __ Addu(handler, vector, Operand(at));
4622 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4623 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4628 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4629 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4630 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4631 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4632 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4633 Register feedback = t0;
4634 Register receiver_map = t1;
4635 Register scratch1 = t4;
4637 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4638 __ Addu(feedback, vector, Operand(at));
4639 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4641 // Try to quickly handle the monomorphic case without knowing for sure
4642 // if we have a weak cell in feedback. We do know it's safe to look
4643 // at WeakCell::kValueOffset.
4644 Label try_array, load_smi_map, compare_map;
4645 Label not_array, miss;
4646 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4647 scratch1, &compare_map, &load_smi_map, &try_array);
4649 // Is it a fixed array?
4650 __ bind(&try_array);
4651 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4652 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4653 __ Branch(¬_array, ne, at, Operand(scratch1));
4654 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4655 scratch1, t5, true, &miss);
4657 __ bind(¬_array);
4658 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4659 __ Branch(&miss, ne, at, Operand(feedback));
4660 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4661 Code::ComputeHandlerFlags(Code::LOAD_IC));
4662 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4663 receiver, name, feedback,
4664 receiver_map, scratch1, t5);
4667 LoadIC::GenerateMiss(masm);
4669 __ bind(&load_smi_map);
4670 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4671 __ jmp(&compare_map);
4675 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4676 GenerateImpl(masm, false);
4680 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4681 GenerateImpl(masm, true);
4685 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4686 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4687 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4688 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4689 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4690 Register feedback = t0;
4691 Register receiver_map = t1;
4692 Register scratch1 = t4;
4694 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4695 __ Addu(feedback, vector, Operand(at));
4696 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4698 // Try to quickly handle the monomorphic case without knowing for sure
4699 // if we have a weak cell in feedback. We do know it's safe to look
4700 // at WeakCell::kValueOffset.
4701 Label try_array, load_smi_map, compare_map;
4702 Label not_array, miss;
4703 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4704 scratch1, &compare_map, &load_smi_map, &try_array);
4706 __ bind(&try_array);
4707 // Is it a fixed array?
4708 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4709 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4710 __ Branch(¬_array, ne, at, Operand(scratch1));
4711 // We have a polymorphic element handler.
4712 __ JumpIfNotSmi(key, &miss);
4714 Label polymorphic, try_poly_name;
4715 __ bind(&polymorphic);
4716 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4717 scratch1, t5, true, &miss);
4719 __ bind(¬_array);
4721 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4722 __ Branch(&try_poly_name, ne, at, Operand(feedback));
4723 Handle<Code> megamorphic_stub =
4724 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4725 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4727 __ bind(&try_poly_name);
4728 // We might have a name in feedback, and a fixed array in the next slot.
4729 __ Branch(&miss, ne, key, Operand(feedback));
4730 // If the name comparison succeeded, we know we have a fixed array with
4731 // at least one map/handler pair.
4732 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4733 __ Addu(feedback, vector, Operand(at));
4735 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4736 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4737 scratch1, t5, false, &miss);
4740 KeyedLoadIC::GenerateMiss(masm);
4742 __ bind(&load_smi_map);
4743 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4744 __ jmp(&compare_map);
4748 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4749 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4750 VectorStoreICStub stub(isolate(), state());
4751 stub.GenerateForTrampoline(masm);
4755 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4756 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4757 VectorKeyedStoreICStub stub(isolate(), state());
4758 stub.GenerateForTrampoline(masm);
4762 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4763 GenerateImpl(masm, false);
4767 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4768 GenerateImpl(masm, true);
4772 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4775 // TODO(mvstanton): Implement.
4777 StoreIC::GenerateMiss(masm);
4781 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4782 GenerateImpl(masm, false);
4786 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4787 GenerateImpl(masm, true);
4791 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4794 // TODO(mvstanton): Implement.
4796 KeyedStoreIC::GenerateMiss(masm);
4800 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4801 if (masm->isolate()->function_entry_hook() != NULL) {
4802 ProfileEntryHookStub stub(masm->isolate());
4810 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4811 // The entry hook is a "push ra" instruction, followed by a call.
4812 // Note: on MIPS "push" is 2 instruction
4813 const int32_t kReturnAddressDistanceFromFunctionStart =
4814 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4816 // This should contain all kJSCallerSaved registers.
4817 const RegList kSavedRegs =
4818 kJSCallerSaved | // Caller saved registers.
4819 s5.bit(); // Saved stack pointer.
4821 // We also save ra, so the count here is one higher than the mask indicates.
4822 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4824 // Save all caller-save registers as this may be called from anywhere.
4825 __ MultiPush(kSavedRegs | ra.bit());
4827 // Compute the function's address for the first argument.
4828 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4830 // The caller's return address is above the saved temporaries.
4831 // Grab that for the second argument to the hook.
4832 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4834 // Align the stack if necessary.
4835 int frame_alignment = masm->ActivationFrameAlignment();
4836 if (frame_alignment > kPointerSize) {
4838 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4839 __ And(sp, sp, Operand(-frame_alignment));
4841 __ Subu(sp, sp, kCArgsSlotsSize);
4842 #if defined(V8_HOST_ARCH_MIPS)
4843 int32_t entry_hook =
4844 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4845 __ li(t9, Operand(entry_hook));
4847 // Under the simulator we need to indirect the entry hook through a
4848 // trampoline function at a known address.
4849 // It additionally takes an isolate as a third parameter.
4850 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4852 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4853 __ li(t9, Operand(ExternalReference(&dispatcher,
4854 ExternalReference::BUILTIN_CALL,
4857 // Call C function through t9 to conform ABI for PIC.
4860 // Restore the stack pointer if needed.
4861 if (frame_alignment > kPointerSize) {
4864 __ Addu(sp, sp, kCArgsSlotsSize);
4867 // Also pop ra to get Ret(0).
4868 __ MultiPop(kSavedRegs | ra.bit());
4874 static void CreateArrayDispatch(MacroAssembler* masm,
4875 AllocationSiteOverrideMode mode) {
4876 if (mode == DISABLE_ALLOCATION_SITES) {
4877 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4878 __ TailCallStub(&stub);
4879 } else if (mode == DONT_OVERRIDE) {
4880 int last_index = GetSequenceIndexFromFastElementsKind(
4881 TERMINAL_FAST_ELEMENTS_KIND);
4882 for (int i = 0; i <= last_index; ++i) {
4883 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4884 T stub(masm->isolate(), kind);
4885 __ TailCallStub(&stub, eq, a3, Operand(kind));
4888 // If we reached this point there is a problem.
4889 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4896 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4897 AllocationSiteOverrideMode mode) {
4898 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4899 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4900 // a0 - number of arguments
4901 // a1 - constructor?
4902 // sp[0] - last argument
4903 Label normal_sequence;
4904 if (mode == DONT_OVERRIDE) {
4905 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4906 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4907 STATIC_ASSERT(FAST_ELEMENTS == 2);
4908 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4909 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4910 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4912 // is the low bit set? If so, we are holey and that is good.
4913 __ And(at, a3, Operand(1));
4914 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
4917 // look at the first argument
4918 __ lw(t1, MemOperand(sp, 0));
4919 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
4921 if (mode == DISABLE_ALLOCATION_SITES) {
4922 ElementsKind initial = GetInitialFastElementsKind();
4923 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4925 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4927 DISABLE_ALLOCATION_SITES);
4928 __ TailCallStub(&stub_holey);
4930 __ bind(&normal_sequence);
4931 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4933 DISABLE_ALLOCATION_SITES);
4934 __ TailCallStub(&stub);
4935 } else if (mode == DONT_OVERRIDE) {
4936 // We are going to create a holey array, but our kind is non-holey.
4937 // Fix kind and retry (only if we have an allocation site in the slot).
4938 __ Addu(a3, a3, Operand(1));
4940 if (FLAG_debug_code) {
4941 __ lw(t1, FieldMemOperand(a2, 0));
4942 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
4943 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
4946 // Save the resulting elements kind in type info. We can't just store a3
4947 // in the AllocationSite::transition_info field because elements kind is
4948 // restricted to a portion of the field...upper bits need to be left alone.
4949 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4950 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4951 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4952 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4955 __ bind(&normal_sequence);
4956 int last_index = GetSequenceIndexFromFastElementsKind(
4957 TERMINAL_FAST_ELEMENTS_KIND);
4958 for (int i = 0; i <= last_index; ++i) {
4959 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4960 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4961 __ TailCallStub(&stub, eq, a3, Operand(kind));
4964 // If we reached this point there is a problem.
4965 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4973 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4974 int to_index = GetSequenceIndexFromFastElementsKind(
4975 TERMINAL_FAST_ELEMENTS_KIND);
4976 for (int i = 0; i <= to_index; ++i) {
4977 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4978 T stub(isolate, kind);
4980 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4981 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4988 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4989 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4991 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4993 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4998 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5000 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5001 for (int i = 0; i < 2; i++) {
5002 // For internal arrays we only need a few things.
5003 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5005 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5007 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5013 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5014 MacroAssembler* masm,
5015 AllocationSiteOverrideMode mode) {
5016 if (argument_count() == ANY) {
5017 Label not_zero_case, not_one_case;
5019 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5020 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5022 __ bind(¬_zero_case);
5023 __ Branch(¬_one_case, gt, a0, Operand(1));
5024 CreateArrayDispatchOneArgument(masm, mode);
5026 __ bind(¬_one_case);
5027 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5028 } else if (argument_count() == NONE) {
5029 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5030 } else if (argument_count() == ONE) {
5031 CreateArrayDispatchOneArgument(masm, mode);
5032 } else if (argument_count() == MORE_THAN_ONE) {
5033 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5040 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5041 // ----------- S t a t e -------------
5042 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5043 // -- a1 : constructor
5044 // -- a2 : AllocationSite or undefined
5045 // -- a3 : Original constructor
5046 // -- sp[0] : last argument
5047 // -----------------------------------
5049 if (FLAG_debug_code) {
5050 // The array construct code is only set for the global and natives
5051 // builtin Array functions which always have maps.
5053 // Initial map for the builtin Array function should be a map.
5054 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5055 // Will both indicate a NULL and a Smi.
5057 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5058 at, Operand(zero_reg));
5059 __ GetObjectType(t0, t0, t1);
5060 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5061 t1, Operand(MAP_TYPE));
5063 // We should either have undefined in a2 or a valid AllocationSite
5064 __ AssertUndefinedOrAllocationSite(a2, t0);
5068 __ Branch(&subclassing, ne, a1, Operand(a3));
5071 // Get the elements kind and case on that.
5072 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5073 __ Branch(&no_info, eq, a2, Operand(at));
5075 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5077 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5078 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5079 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5082 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5085 __ bind(&subclassing);
5090 switch (argument_count()) {
5093 __ li(at, Operand(2));
5094 __ addu(a0, a0, at);
5097 __ li(a0, Operand(2));
5100 __ li(a0, Operand(3));
5104 __ JumpToExternalReference(
5105 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5109 void InternalArrayConstructorStub::GenerateCase(
5110 MacroAssembler* masm, ElementsKind kind) {
5112 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5113 __ TailCallStub(&stub0, lo, a0, Operand(1));
5115 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5116 __ TailCallStub(&stubN, hi, a0, Operand(1));
5118 if (IsFastPackedElementsKind(kind)) {
5119 // We might need to create a holey array
5120 // look at the first argument.
5121 __ lw(at, MemOperand(sp, 0));
5123 InternalArraySingleArgumentConstructorStub
5124 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5125 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5128 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5129 __ TailCallStub(&stub1);
5133 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5134 // ----------- S t a t e -------------
5136 // -- a1 : constructor
5137 // -- sp[0] : return address
5138 // -- sp[4] : last argument
5139 // -----------------------------------
5141 if (FLAG_debug_code) {
5142 // The array construct code is only set for the global and natives
5143 // builtin Array functions which always have maps.
5145 // Initial map for the builtin Array function should be a map.
5146 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5147 // Will both indicate a NULL and a Smi.
5149 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5150 at, Operand(zero_reg));
5151 __ GetObjectType(a3, a3, t0);
5152 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5153 t0, Operand(MAP_TYPE));
5156 // Figure out the right elements kind.
5157 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5159 // Load the map's "bit field 2" into a3. We only need the first byte,
5160 // but the following bit field extraction takes care of that anyway.
5161 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5162 // Retrieve elements_kind from bit field 2.
5163 __ DecodeField<Map::ElementsKindBits>(a3);
5165 if (FLAG_debug_code) {
5167 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5169 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5170 a3, Operand(FAST_HOLEY_ELEMENTS));
5174 Label fast_elements_case;
5175 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5176 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5178 __ bind(&fast_elements_case);
5179 GenerateCase(masm, FAST_ELEMENTS);
5183 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5184 Register context_reg = cp;
5185 Register slot_reg = a2;
5186 Register result_reg = v0;
5189 // Go up context chain to the script context.
5190 for (int i = 0; i < depth(); ++i) {
5191 __ lw(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5192 context_reg = result_reg;
5195 // Load the PropertyCell value at the specified slot.
5196 __ sll(at, slot_reg, kPointerSizeLog2);
5197 __ Addu(at, at, Operand(context_reg));
5198 __ lw(result_reg, ContextOperand(at, 0));
5199 __ lw(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5201 // Check that value is not the_hole.
5202 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5203 __ Branch(&slow_case, eq, result_reg, Operand(at));
5206 // Fallback to the runtime.
5207 __ bind(&slow_case);
5208 __ SmiTag(slot_reg);
5210 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5214 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5215 Register context_reg = cp;
5216 Register slot_reg = a2;
5217 Register value_reg = a0;
5218 Register cell_reg = t0;
5219 Register cell_value_reg = t1;
5220 Register cell_details_reg = t2;
5221 Label fast_heapobject_case, fast_smi_case, slow_case;
5223 if (FLAG_debug_code) {
5224 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5225 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5228 // Go up context chain to the script context.
5229 for (int i = 0; i < depth(); ++i) {
5230 __ lw(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5231 context_reg = cell_reg;
5234 // Load the PropertyCell at the specified slot.
5235 __ sll(at, slot_reg, kPointerSizeLog2);
5236 __ Addu(at, at, Operand(context_reg));
5237 __ lw(cell_reg, ContextOperand(at, 0));
5239 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5240 __ lw(cell_details_reg,
5241 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5242 __ SmiUntag(cell_details_reg);
5243 __ And(cell_details_reg, cell_details_reg,
5244 PropertyDetails::PropertyCellTypeField::kMask |
5245 PropertyDetails::KindField::kMask |
5246 PropertyDetails::kAttributesReadOnlyMask);
5248 // Check if PropertyCell holds mutable data.
5249 Label not_mutable_data;
5250 __ Branch(¬_mutable_data, ne, cell_details_reg,
5251 Operand(PropertyDetails::PropertyCellTypeField::encode(
5252 PropertyCellType::kMutable) |
5253 PropertyDetails::KindField::encode(kData)));
5254 __ JumpIfSmi(value_reg, &fast_smi_case);
5255 __ bind(&fast_heapobject_case);
5256 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5257 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5258 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5259 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5260 // RecordWriteField clobbers the value register, so we need to reload.
5261 __ Ret(USE_DELAY_SLOT);
5262 __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5263 __ bind(¬_mutable_data);
5265 // Check if PropertyCell value matches the new value (relevant for Constant,
5266 // ConstantType and Undefined cells).
5267 Label not_same_value;
5268 __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5269 __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg));
5270 // Make sure the PropertyCell is not marked READ_ONLY.
5271 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5272 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5273 if (FLAG_debug_code) {
5275 // This can only be true for Constant, ConstantType and Undefined cells,
5276 // because we never store the_hole via this stub.
5277 __ Branch(&done, eq, cell_details_reg,
5278 Operand(PropertyDetails::PropertyCellTypeField::encode(
5279 PropertyCellType::kConstant) |
5280 PropertyDetails::KindField::encode(kData)));
5281 __ Branch(&done, eq, cell_details_reg,
5282 Operand(PropertyDetails::PropertyCellTypeField::encode(
5283 PropertyCellType::kConstantType) |
5284 PropertyDetails::KindField::encode(kData)));
5285 __ Check(eq, kUnexpectedValue, cell_details_reg,
5286 Operand(PropertyDetails::PropertyCellTypeField::encode(
5287 PropertyCellType::kUndefined) |
5288 PropertyDetails::KindField::encode(kData)));
5292 __ bind(¬_same_value);
5294 // Check if PropertyCell contains data with constant type (and is not
5296 __ Branch(&slow_case, ne, cell_details_reg,
5297 Operand(PropertyDetails::PropertyCellTypeField::encode(
5298 PropertyCellType::kConstantType) |
5299 PropertyDetails::KindField::encode(kData)));
5301 // Now either both old and new values must be SMIs or both must be heap
5302 // objects with same map.
5303 Label value_is_heap_object;
5304 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5305 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5306 // Old and new values are SMIs, no need for a write barrier here.
5307 __ bind(&fast_smi_case);
5308 __ Ret(USE_DELAY_SLOT);
5309 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5310 __ bind(&value_is_heap_object);
5311 __ JumpIfSmi(cell_value_reg, &slow_case);
5312 Register cell_value_map_reg = cell_value_reg;
5313 __ lw(cell_value_map_reg,
5314 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5315 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5316 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5318 // Fallback to the runtime.
5319 __ bind(&slow_case);
5320 __ SmiTag(slot_reg);
5321 __ Push(slot_reg, value_reg);
5322 __ TailCallRuntime(is_strict(language_mode())
5323 ? Runtime::kStoreGlobalViaContext_Strict
5324 : Runtime::kStoreGlobalViaContext_Sloppy,
5329 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5330 return ref0.address() - ref1.address();
5334 // Calls an API function. Allocates HandleScope, extracts returned value
5335 // from handle and propagates exceptions. Restores context. stack_space
5336 // - space to be unwound on exit (includes the call JS arguments space and
5337 // the additional space allocated for the fast call).
5338 static void CallApiFunctionAndReturn(
5339 MacroAssembler* masm, Register function_address,
5340 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5341 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5342 Isolate* isolate = masm->isolate();
5343 ExternalReference next_address =
5344 ExternalReference::handle_scope_next_address(isolate);
5345 const int kNextOffset = 0;
5346 const int kLimitOffset = AddressOffset(
5347 ExternalReference::handle_scope_limit_address(isolate), next_address);
5348 const int kLevelOffset = AddressOffset(
5349 ExternalReference::handle_scope_level_address(isolate), next_address);
5351 DCHECK(function_address.is(a1) || function_address.is(a2));
5353 Label profiler_disabled;
5354 Label end_profiler_check;
5355 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5356 __ lb(t9, MemOperand(t9, 0));
5357 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5359 // Additional parameter is the address of the actual callback.
5360 __ li(t9, Operand(thunk_ref));
5361 __ jmp(&end_profiler_check);
5363 __ bind(&profiler_disabled);
5364 __ mov(t9, function_address);
5365 __ bind(&end_profiler_check);
5367 // Allocate HandleScope in callee-save registers.
5368 __ li(s3, Operand(next_address));
5369 __ lw(s0, MemOperand(s3, kNextOffset));
5370 __ lw(s1, MemOperand(s3, kLimitOffset));
5371 __ lw(s2, MemOperand(s3, kLevelOffset));
5372 __ Addu(s2, s2, Operand(1));
5373 __ sw(s2, MemOperand(s3, kLevelOffset));
5375 if (FLAG_log_timer_events) {
5376 FrameScope frame(masm, StackFrame::MANUAL);
5377 __ PushSafepointRegisters();
5378 __ PrepareCallCFunction(1, a0);
5379 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5380 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5382 __ PopSafepointRegisters();
5385 // Native call returns to the DirectCEntry stub which redirects to the
5386 // return address pushed on stack (could have moved after GC).
5387 // DirectCEntry stub itself is generated early and never moves.
5388 DirectCEntryStub stub(isolate);
5389 stub.GenerateCall(masm, t9);
5391 if (FLAG_log_timer_events) {
5392 FrameScope frame(masm, StackFrame::MANUAL);
5393 __ PushSafepointRegisters();
5394 __ PrepareCallCFunction(1, a0);
5395 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5396 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5398 __ PopSafepointRegisters();
5401 Label promote_scheduled_exception;
5402 Label delete_allocated_handles;
5403 Label leave_exit_frame;
5404 Label return_value_loaded;
5406 // Load value from ReturnValue.
5407 __ lw(v0, return_value_operand);
5408 __ bind(&return_value_loaded);
5410 // No more valid handles (the result handle was the last one). Restore
5411 // previous handle scope.
5412 __ sw(s0, MemOperand(s3, kNextOffset));
5413 if (__ emit_debug_code()) {
5414 __ lw(a1, MemOperand(s3, kLevelOffset));
5415 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5417 __ Subu(s2, s2, Operand(1));
5418 __ sw(s2, MemOperand(s3, kLevelOffset));
5419 __ lw(at, MemOperand(s3, kLimitOffset));
5420 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5422 // Leave the API exit frame.
5423 __ bind(&leave_exit_frame);
5425 bool restore_context = context_restore_operand != NULL;
5426 if (restore_context) {
5427 __ lw(cp, *context_restore_operand);
5429 if (stack_space_offset != kInvalidStackOffset) {
5430 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5431 // so this must be accounted for.
5432 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5434 __ li(s0, Operand(stack_space));
5436 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5437 stack_space_offset != kInvalidStackOffset);
5439 // Check if the function scheduled an exception.
5440 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5441 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5442 __ lw(t1, MemOperand(at));
5443 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5447 // Re-throw by promoting a scheduled exception.
5448 __ bind(&promote_scheduled_exception);
5449 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5451 // HandleScope limit has changed. Delete allocated extensions.
5452 __ bind(&delete_allocated_handles);
5453 __ sw(s1, MemOperand(s3, kLimitOffset));
5456 __ PrepareCallCFunction(1, s1);
5457 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5458 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5461 __ jmp(&leave_exit_frame);
5465 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5466 const ParameterCount& argc,
5467 bool return_first_arg,
5468 bool call_data_undefined) {
5469 // ----------- S t a t e -------------
5471 // -- t0 : call_data
5473 // -- a1 : api_function_address
5474 // -- a3 : number of arguments if argc is a register
5477 // -- sp[0] : last argument
5479 // -- sp[(argc - 1)* 4] : first argument
5480 // -- sp[argc * 4] : receiver
5481 // -----------------------------------
5483 Register callee = a0;
5484 Register call_data = t0;
5485 Register holder = a2;
5486 Register api_function_address = a1;
5487 Register context = cp;
5489 typedef FunctionCallbackArguments FCA;
5491 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5492 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5493 STATIC_ASSERT(FCA::kDataIndex == 4);
5494 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5495 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5496 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5497 STATIC_ASSERT(FCA::kHolderIndex == 0);
5498 STATIC_ASSERT(FCA::kArgsLength == 7);
5500 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5502 // Save context, callee and call data.
5503 __ Push(context, callee, call_data);
5504 // Load context from callee.
5505 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5507 Register scratch = call_data;
5508 if (!call_data_undefined) {
5509 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5511 // Push return value and default return value.
5512 __ Push(scratch, scratch);
5513 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5514 // Push isolate and holder.
5515 __ Push(scratch, holder);
5517 // Prepare arguments.
5518 __ mov(scratch, sp);
5520 // Allocate the v8::Arguments structure in the arguments' space since
5521 // it's not controlled by GC.
5522 const int kApiStackSpace = 4;
5524 FrameScope frame_scope(masm, StackFrame::MANUAL);
5525 __ EnterExitFrame(false, kApiStackSpace);
5527 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5528 // a0 = FunctionCallbackInfo&
5529 // Arguments is after the return address.
5530 __ Addu(a0, sp, Operand(1 * kPointerSize));
5531 // FunctionCallbackInfo::implicit_args_
5532 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
5533 if (argc.is_immediate()) {
5534 // FunctionCallbackInfo::values_
5535 __ Addu(at, scratch,
5536 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5537 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5538 // FunctionCallbackInfo::length_ = argc
5539 __ li(at, Operand(argc.immediate()));
5540 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5541 // FunctionCallbackInfo::is_construct_call_ = 0
5542 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
5544 // FunctionCallbackInfo::values_
5545 __ sll(at, argc.reg(), kPointerSizeLog2);
5546 __ Addu(at, at, scratch);
5547 __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5548 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5549 // FunctionCallbackInfo::length_ = argc
5550 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5551 // FunctionCallbackInfo::is_construct_call_
5552 __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5553 __ sll(at, argc.reg(), kPointerSizeLog2);
5554 __ sw(at, MemOperand(a0, 3 * kPointerSize));
5557 ExternalReference thunk_ref =
5558 ExternalReference::invoke_function_callback(masm->isolate());
5560 AllowExternalCallThatCantCauseGC scope(masm);
5561 MemOperand context_restore_operand(
5562 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5563 // Stores return the first js argument.
5564 int return_value_offset = 0;
5565 if (return_first_arg) {
5566 return_value_offset = 2 + FCA::kArgsLength;
5568 return_value_offset = 2 + FCA::kReturnValueOffset;
5570 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5571 int stack_space = 0;
5572 int32_t stack_space_offset = 4 * kPointerSize;
5573 if (argc.is_immediate()) {
5574 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5575 stack_space_offset = kInvalidStackOffset;
5577 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5578 stack_space_offset, return_value_operand,
5579 &context_restore_operand);
5583 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5584 bool call_data_undefined = this->call_data_undefined();
5585 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5586 call_data_undefined);
5590 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5591 bool is_store = this->is_store();
5592 int argc = this->argc();
5593 bool call_data_undefined = this->call_data_undefined();
5594 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5595 call_data_undefined);
5599 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5600 // ----------- S t a t e -------------
5602 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5604 // -- a2 : api_function_address
5605 // -----------------------------------
5607 Register api_function_address = ApiGetterDescriptor::function_address();
5608 DCHECK(api_function_address.is(a2));
5610 __ mov(a0, sp); // a0 = Handle<Name>
5611 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5613 const int kApiStackSpace = 1;
5614 FrameScope frame_scope(masm, StackFrame::MANUAL);
5615 __ EnterExitFrame(false, kApiStackSpace);
5617 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5618 // a1 (internal::Object** args_) as the data.
5619 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
5620 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5622 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5624 ExternalReference thunk_ref =
5625 ExternalReference::invoke_accessor_getter_callback(isolate());
5626 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5627 kStackUnwindSpace, kInvalidStackOffset,
5628 MemOperand(fp, 6 * kPointerSize), NULL);
5634 } // namespace internal
5637 #endif // V8_TARGET_ARCH_MIPS