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);
732 Builtins::JavaScript native;
734 native = Builtins::EQUALS;
737 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
738 int ncr; // NaN compare result.
739 if (cc == lt || cc == le) {
742 DCHECK(cc == gt || cc == ge); // Remaining cases.
745 __ li(a0, Operand(Smi::FromInt(ncr)));
749 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
750 // tagged as a small integer.
751 __ InvokeBuiltin(native, JUMP_FUNCTION);
759 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
762 __ PushSafepointRegisters();
767 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
770 __ PopSafepointRegisters();
775 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
776 // We don't allow a GC during a store buffer overflow so there is no need to
777 // store the registers in any particular way, but we do have to store and
779 __ MultiPush(kJSCallerSaved | ra.bit());
780 if (save_doubles()) {
781 __ MultiPushFPU(kCallerSavedFPU);
783 const int argument_count = 1;
784 const int fp_argument_count = 0;
785 const Register scratch = a1;
787 AllowExternalCallThatCantCauseGC scope(masm);
788 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
789 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
791 ExternalReference::store_buffer_overflow_function(isolate()),
793 if (save_doubles()) {
794 __ MultiPopFPU(kCallerSavedFPU);
797 __ MultiPop(kJSCallerSaved | ra.bit());
802 void MathPowStub::Generate(MacroAssembler* masm) {
803 const Register base = a1;
804 const Register exponent = MathPowTaggedDescriptor::exponent();
805 DCHECK(exponent.is(a2));
806 const Register heapnumbermap = t1;
807 const Register heapnumber = v0;
808 const DoubleRegister double_base = f2;
809 const DoubleRegister double_exponent = f4;
810 const DoubleRegister double_result = f0;
811 const DoubleRegister double_scratch = f6;
812 const FPURegister single_scratch = f8;
813 const Register scratch = t5;
814 const Register scratch2 = t3;
816 Label call_runtime, done, int_exponent;
817 if (exponent_type() == ON_STACK) {
818 Label base_is_smi, unpack_exponent;
819 // The exponent and base are supplied as arguments on the stack.
820 // This can only happen if the stub is called from non-optimized code.
821 // Load input parameters from stack to double registers.
822 __ lw(base, MemOperand(sp, 1 * kPointerSize));
823 __ lw(exponent, MemOperand(sp, 0 * kPointerSize));
825 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
827 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
828 __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset));
829 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
831 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
832 __ jmp(&unpack_exponent);
834 __ bind(&base_is_smi);
835 __ mtc1(scratch, single_scratch);
836 __ cvt_d_w(double_base, single_scratch);
837 __ bind(&unpack_exponent);
839 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
841 __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
842 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
843 __ ldc1(double_exponent,
844 FieldMemOperand(exponent, HeapNumber::kValueOffset));
845 } else if (exponent_type() == TAGGED) {
846 // Base is already in double_base.
847 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
849 __ ldc1(double_exponent,
850 FieldMemOperand(exponent, HeapNumber::kValueOffset));
853 if (exponent_type() != INTEGER) {
854 Label int_exponent_convert;
855 // Detect integer exponents stored as double.
856 __ EmitFPUTruncate(kRoundToMinusInf,
862 kCheckForInexactConversion);
863 // scratch2 == 0 means there was no conversion error.
864 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
866 if (exponent_type() == ON_STACK) {
867 // Detect square root case. Crankshaft detects constant +/-0.5 at
868 // compile time and uses DoMathPowHalf instead. We then skip this check
869 // for non-constant cases of +/-0.5 as these hardly occur.
872 __ Move(double_scratch, 0.5);
873 __ BranchF(USE_DELAY_SLOT,
879 // double_scratch can be overwritten in the delay slot.
880 // Calculates square root of base. Check for the special case of
881 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
882 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
883 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
884 __ neg_d(double_result, double_scratch);
886 // Add +0 to convert -0 to +0.
887 __ add_d(double_scratch, double_base, kDoubleRegZero);
888 __ sqrt_d(double_result, double_scratch);
891 __ bind(¬_plus_half);
892 __ Move(double_scratch, -0.5);
893 __ BranchF(USE_DELAY_SLOT,
899 // double_scratch can be overwritten in the delay slot.
900 // Calculates square root of base. Check for the special case of
901 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
902 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
903 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
904 __ Move(double_result, kDoubleRegZero);
906 // Add +0 to convert -0 to +0.
907 __ add_d(double_scratch, double_base, kDoubleRegZero);
908 __ Move(double_result, 1.);
909 __ sqrt_d(double_scratch, double_scratch);
910 __ div_d(double_result, double_result, double_scratch);
916 AllowExternalCallThatCantCauseGC scope(masm);
917 __ PrepareCallCFunction(0, 2, scratch2);
918 __ MovToFloatParameters(double_base, double_exponent);
920 ExternalReference::power_double_double_function(isolate()),
924 __ MovFromFloatResult(double_result);
927 __ bind(&int_exponent_convert);
930 // Calculate power with integer exponent.
931 __ bind(&int_exponent);
933 // Get two copies of exponent in the registers scratch and exponent.
934 if (exponent_type() == INTEGER) {
935 __ mov(scratch, exponent);
937 // Exponent has previously been stored into scratch as untagged integer.
938 __ mov(exponent, scratch);
941 __ mov_d(double_scratch, double_base); // Back up base.
942 __ Move(double_result, 1.0);
944 // Get absolute value of exponent.
945 Label positive_exponent;
946 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
947 __ Subu(scratch, zero_reg, scratch);
948 __ bind(&positive_exponent);
950 Label while_true, no_carry, loop_end;
951 __ bind(&while_true);
953 __ And(scratch2, scratch, 1);
955 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
956 __ mul_d(double_result, double_result, double_scratch);
959 __ sra(scratch, scratch, 1);
961 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
962 __ mul_d(double_scratch, double_scratch, double_scratch);
964 __ Branch(&while_true);
968 __ Branch(&done, ge, exponent, Operand(zero_reg));
969 __ Move(double_scratch, 1.0);
970 __ div_d(double_result, double_scratch, double_result);
971 // Test whether result is zero. Bail out to check for subnormal result.
972 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
973 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
975 // double_exponent may not contain the exponent value if the input was a
976 // smi. We set it with exponent value before bailing out.
977 __ mtc1(exponent, single_scratch);
978 __ cvt_d_w(double_exponent, single_scratch);
980 // Returning or bailing out.
981 Counters* counters = isolate()->counters();
982 if (exponent_type() == ON_STACK) {
983 // The arguments are still on the stack.
984 __ bind(&call_runtime);
985 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
987 // The stub is called from non-optimized code, which expects the result
988 // as heap number in exponent.
990 __ AllocateHeapNumber(
991 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
992 __ sdc1(double_result,
993 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
994 DCHECK(heapnumber.is(v0));
995 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1000 AllowExternalCallThatCantCauseGC scope(masm);
1001 __ PrepareCallCFunction(0, 2, scratch);
1002 __ MovToFloatParameters(double_base, double_exponent);
1004 ExternalReference::power_double_double_function(isolate()),
1008 __ MovFromFloatResult(double_result);
1011 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1017 bool CEntryStub::NeedsImmovableCode() {
1022 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1023 CEntryStub::GenerateAheadOfTime(isolate);
1024 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1025 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1026 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1027 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1028 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1029 BinaryOpICStub::GenerateAheadOfTime(isolate);
1030 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1031 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1032 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1033 StoreFastElementStub::GenerateAheadOfTime(isolate);
1034 TypeofStub::GenerateAheadOfTime(isolate);
1038 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1039 StoreRegistersStateStub stub(isolate);
1044 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1045 RestoreRegistersStateStub stub(isolate);
1050 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1051 // Generate if not already in cache.
1052 SaveFPRegsMode mode = kSaveFPRegs;
1053 CEntryStub(isolate, 1, mode).GetCode();
1054 StoreBufferOverflowStub(isolate, mode).GetCode();
1055 isolate->set_fp_stubs_generated(true);
1059 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1060 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1065 void CEntryStub::Generate(MacroAssembler* masm) {
1066 // Called from JavaScript; parameters are on stack as if calling JS function
1067 // a0: number of arguments including receiver
1068 // a1: pointer to builtin function
1069 // fp: frame pointer (restored after C call)
1070 // sp: stack pointer (restored as callee's sp after C call)
1071 // cp: current context (C callee-saved)
1073 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1075 // Compute the argv pointer in a callee-saved register.
1076 __ sll(s1, a0, kPointerSizeLog2);
1077 __ Addu(s1, sp, s1);
1078 __ Subu(s1, s1, kPointerSize);
1080 // Enter the exit frame that transitions from JavaScript to C++.
1081 FrameScope scope(masm, StackFrame::MANUAL);
1082 __ EnterExitFrame(save_doubles());
1084 // s0: number of arguments including receiver (C callee-saved)
1085 // s1: pointer to first argument (C callee-saved)
1086 // s2: pointer to builtin function (C callee-saved)
1088 // Prepare arguments for C routine.
1092 // a1 = argv (set in the delay slot after find_ra below).
1094 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1095 // also need to reserve the 4 argument slots on the stack.
1097 __ AssertStackIsAligned();
1099 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1101 // To let the GC traverse the return address of the exit frames, we need to
1102 // know where the return address is. The CEntryStub is unmovable, so
1103 // we can store the address on the stack to be able to find it again and
1104 // we never have to restore it, because it will not change.
1105 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1106 // This branch-and-link sequence is needed to find the current PC on mips,
1107 // saved to the ra register.
1108 // Use masm-> here instead of the double-underscore macro since extra
1109 // coverage code can interfere with the proper calculation of ra.
1111 masm->bal(&find_ra); // bal exposes branch delay slot.
1113 masm->bind(&find_ra);
1115 // Adjust the value in ra to point to the correct return location, 2nd
1116 // instruction past the real call into C code (the jalr(t9)), and push it.
1117 // This is the return address of the exit frame.
1118 const int kNumInstructionsToJump = 5;
1119 masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize);
1120 masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1121 // Stack space reservation moved to the branch delay slot below.
1122 // Stack is still aligned.
1124 // Call the C routine.
1125 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1127 // Set up sp in the delay slot.
1128 masm->addiu(sp, sp, -kCArgsSlotsSize);
1129 // Make sure the stored 'ra' points to this position.
1130 DCHECK_EQ(kNumInstructionsToJump,
1131 masm->InstructionsGeneratedSince(&find_ra));
1135 // Check result for exception sentinel.
1136 Label exception_returned;
1137 __ LoadRoot(t0, Heap::kExceptionRootIndex);
1138 __ Branch(&exception_returned, eq, t0, Operand(v0));
1140 // Check that there is no pending exception, otherwise we
1141 // should have returned the exception sentinel.
1142 if (FLAG_debug_code) {
1144 ExternalReference pending_exception_address(
1145 Isolate::kPendingExceptionAddress, isolate());
1146 __ li(a2, Operand(pending_exception_address));
1147 __ lw(a2, MemOperand(a2));
1148 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1149 // Cannot use check here as it attempts to generate call into runtime.
1150 __ Branch(&okay, eq, t0, Operand(a2));
1151 __ stop("Unexpected pending exception");
1155 // Exit C frame and return.
1157 // sp: stack pointer
1158 // fp: frame pointer
1159 // s0: still holds argc (callee-saved).
1160 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1162 // Handling of exception.
1163 __ bind(&exception_returned);
1165 ExternalReference pending_handler_context_address(
1166 Isolate::kPendingHandlerContextAddress, isolate());
1167 ExternalReference pending_handler_code_address(
1168 Isolate::kPendingHandlerCodeAddress, isolate());
1169 ExternalReference pending_handler_offset_address(
1170 Isolate::kPendingHandlerOffsetAddress, isolate());
1171 ExternalReference pending_handler_fp_address(
1172 Isolate::kPendingHandlerFPAddress, isolate());
1173 ExternalReference pending_handler_sp_address(
1174 Isolate::kPendingHandlerSPAddress, isolate());
1176 // Ask the runtime for help to determine the handler. This will set v0 to
1177 // contain the current pending exception, don't clobber it.
1178 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1181 FrameScope scope(masm, StackFrame::MANUAL);
1182 __ PrepareCallCFunction(3, 0, a0);
1183 __ mov(a0, zero_reg);
1184 __ mov(a1, zero_reg);
1185 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1186 __ CallCFunction(find_handler, 3);
1189 // Retrieve the handler context, SP and FP.
1190 __ li(cp, Operand(pending_handler_context_address));
1191 __ lw(cp, MemOperand(cp));
1192 __ li(sp, Operand(pending_handler_sp_address));
1193 __ lw(sp, MemOperand(sp));
1194 __ li(fp, Operand(pending_handler_fp_address));
1195 __ lw(fp, MemOperand(fp));
1197 // If the handler is a JS frame, restore the context to the frame. Note that
1198 // the context will be set to (cp == 0) for non-JS frames.
1200 __ Branch(&zero, eq, cp, Operand(zero_reg));
1201 __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1204 // Compute the handler entry address and jump to it.
1205 __ li(a1, Operand(pending_handler_code_address));
1206 __ lw(a1, MemOperand(a1));
1207 __ li(a2, Operand(pending_handler_offset_address));
1208 __ lw(a2, MemOperand(a2));
1209 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1210 __ Addu(t9, a1, a2);
1215 void JSEntryStub::Generate(MacroAssembler* masm) {
1216 Label invoke, handler_entry, exit;
1217 Isolate* isolate = masm->isolate();
1220 // a0: entry address
1229 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1231 // Save callee saved registers on the stack.
1232 __ MultiPush(kCalleeSaved | ra.bit());
1234 // Save callee-saved FPU registers.
1235 __ MultiPushFPU(kCalleeSavedFPU);
1236 // Set up the reserved register for 0.0.
1237 __ Move(kDoubleRegZero, 0.0);
1240 // Load argv in s0 register.
1241 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1242 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1244 __ InitializeRootRegister();
1245 __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1247 // We build an EntryFrame.
1248 __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1249 int marker = type();
1250 __ li(t2, Operand(Smi::FromInt(marker)));
1251 __ li(t1, Operand(Smi::FromInt(marker)));
1252 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1254 __ lw(t0, MemOperand(t0));
1255 __ Push(t3, t2, t1, t0);
1256 // Set up frame pointer for the frame to be pushed.
1257 __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1260 // a0: entry_address
1262 // a2: receiver_pointer
1268 // function slot | entry frame
1270 // bad fp (0xff...f) |
1271 // callee saved registers + ra
1275 // If this is the outermost JS call, set js_entry_sp value.
1276 Label non_outermost_js;
1277 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1278 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1279 __ lw(t2, MemOperand(t1));
1280 __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
1281 __ sw(fp, MemOperand(t1));
1282 __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1285 __ nop(); // Branch delay slot nop.
1286 __ bind(&non_outermost_js);
1287 __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1291 // Jump to a faked try block that does the invoke, with a faked catch
1292 // block that sets the pending exception.
1294 __ bind(&handler_entry);
1295 handler_offset_ = handler_entry.pos();
1296 // Caught exception: Store result (exception) in the pending exception
1297 // field in the JSEnv and return a failure sentinel. Coming in here the
1298 // fp will be invalid because the PushStackHandler below sets it to 0 to
1299 // signal the existence of the JSEntry frame.
1300 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1302 __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
1303 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1304 __ b(&exit); // b exposes branch delay slot.
1305 __ nop(); // Branch delay slot nop.
1307 // Invoke: Link this frame into the handler chain.
1309 __ PushStackHandler();
1310 // If an exception not caught by another handler occurs, this handler
1311 // returns control to the code after the bal(&invoke) above, which
1312 // restores all kCalleeSaved registers (including cp and fp) to their
1313 // saved values before returning a failure to C.
1315 // Clear any pending exceptions.
1316 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
1317 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1319 __ sw(t1, MemOperand(t0));
1321 // Invoke the function by calling through JS entry trampoline builtin.
1322 // Notice that we cannot store a reference to the trampoline code directly in
1323 // this stub, because runtime stubs are not traversed when doing GC.
1326 // a0: entry_address
1328 // a2: receiver_pointer
1335 // callee saved registers + ra
1339 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1340 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1342 __ li(t0, Operand(construct_entry));
1344 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1345 __ li(t0, Operand(entry));
1347 __ lw(t9, MemOperand(t0)); // Deref address.
1349 // Call JSEntryTrampoline.
1350 __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1353 // Unlink this frame from the handler chain.
1354 __ PopStackHandler();
1356 __ bind(&exit); // v0 holds result
1357 // Check if the current stack frame is marked as the outermost JS frame.
1358 Label non_outermost_js_2;
1360 __ Branch(&non_outermost_js_2,
1363 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1364 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1365 __ sw(zero_reg, MemOperand(t1));
1366 __ bind(&non_outermost_js_2);
1368 // Restore the top frame descriptors from the stack.
1370 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1372 __ sw(t1, MemOperand(t0));
1374 // Reset the stack to the callee saved registers.
1375 __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1377 // Restore callee-saved fpu registers.
1378 __ MultiPopFPU(kCalleeSavedFPU);
1380 // Restore callee saved registers from the stack.
1381 __ MultiPop(kCalleeSaved | ra.bit());
1387 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1388 // Return address is in ra.
1391 Register receiver = LoadDescriptor::ReceiverRegister();
1392 Register index = LoadDescriptor::NameRegister();
1393 Register scratch = t1;
1394 Register result = v0;
1395 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1396 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1398 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1399 &miss, // When not a string.
1400 &miss, // When not a number.
1401 &miss, // When index out of range.
1402 STRING_INDEX_IS_ARRAY_INDEX,
1403 RECEIVER_IS_STRING);
1404 char_at_generator.GenerateFast(masm);
1407 StubRuntimeCallHelper call_helper;
1408 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1411 PropertyAccessCompiler::TailCallBuiltin(
1412 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1416 void InstanceOfStub::Generate(MacroAssembler* masm) {
1417 Register const object = a1; // Object (lhs).
1418 Register const function = a0; // Function (rhs).
1419 Register const object_map = a2; // Map of {object}.
1420 Register const function_map = a3; // Map of {function}.
1421 Register const function_prototype = t0; // Prototype of {function}.
1422 Register const scratch = t1;
1424 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1425 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1427 // Check if {object} is a smi.
1428 Label object_is_smi;
1429 __ JumpIfSmi(object, &object_is_smi);
1431 // Lookup the {function} and the {object} map in the global instanceof cache.
1432 // Note: This is safe because we clear the global instanceof cache whenever
1433 // we change the prototype of any object.
1434 Label fast_case, slow_case;
1435 __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1436 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1437 __ Branch(&fast_case, ne, function, Operand(at));
1438 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1439 __ Branch(&fast_case, ne, object_map, Operand(at));
1440 __ Ret(USE_DELAY_SLOT);
1441 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1443 // If {object} is a smi we can safely return false if {function} is a JS
1444 // function, otherwise we have to miss to the runtime and throw an exception.
1445 __ bind(&object_is_smi);
1446 __ JumpIfSmi(function, &slow_case);
1447 __ GetObjectType(function, function_map, scratch);
1448 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1449 __ Ret(USE_DELAY_SLOT);
1450 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
1452 // Fast-case: The {function} must be a valid JSFunction.
1453 __ bind(&fast_case);
1454 __ JumpIfSmi(function, &slow_case);
1455 __ GetObjectType(function, function_map, scratch);
1456 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1458 // Ensure that {function} has an instance prototype.
1459 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1460 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1461 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1463 // Ensure that {function} is not bound.
1464 Register const shared_info = scratch;
1466 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1468 FieldMemOperand(shared_info, SharedFunctionInfo::kBoundByteOffset));
1469 __ And(at, scratch, Operand(1 << SharedFunctionInfo::kBoundBitWithinByte));
1470 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1472 // Get the "prototype" (or initial map) of the {function}.
1473 __ lw(function_prototype,
1474 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1475 __ AssertNotSmi(function_prototype);
1477 // Resolve the prototype if the {function} has an initial map. Afterwards the
1478 // {function_prototype} will be either the JSReceiver prototype object or the
1479 // hole value, which means that no instances of the {function} were created so
1480 // far and hence we should return false.
1481 Label function_prototype_valid;
1482 __ GetObjectType(function_prototype, scratch, scratch);
1483 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1484 __ lw(function_prototype,
1485 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1486 __ bind(&function_prototype_valid);
1487 __ AssertNotSmi(function_prototype);
1489 // Update the global instanceof cache with the current {object} map and
1490 // {function}. The cached answer will be set when it is known below.
1491 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1492 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1494 // Loop through the prototype chain looking for the {function} prototype.
1495 // Assume true, and change to false if not found.
1496 Register const object_prototype = object_map;
1497 Register const null = scratch;
1499 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1500 __ LoadRoot(null, Heap::kNullValueRootIndex);
1502 __ lw(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1503 __ Branch(&done, eq, object_prototype, Operand(function_prototype));
1504 __ Branch(USE_DELAY_SLOT, &loop, ne, object_prototype, Operand(null));
1505 __ lw(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1506 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1508 __ Ret(USE_DELAY_SLOT);
1509 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1511 // Slow-case: Call the runtime function.
1512 __ bind(&slow_case);
1513 __ Push(object, function);
1514 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1518 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1520 Register receiver = LoadDescriptor::ReceiverRegister();
1521 // Ensure that the vector and slot registers won't be clobbered before
1522 // calling the miss handler.
1523 DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(),
1524 LoadWithVectorDescriptor::SlotRegister()));
1526 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0,
1529 PropertyAccessCompiler::TailCallBuiltin(
1530 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1534 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1535 // The displacement is the offset of the last parameter (if any)
1536 // relative to the frame pointer.
1537 const int kDisplacement =
1538 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1539 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1540 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1542 // Check that the key is a smiGenerateReadElement.
1544 __ JumpIfNotSmi(a1, &slow);
1546 // Check if the calling frame is an arguments adaptor frame.
1548 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1549 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1553 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1555 // Check index (a1) against formal parameters count limit passed in
1556 // through register a0. Use unsigned comparison to get negative
1558 __ Branch(&slow, hs, a1, Operand(a0));
1560 // Read the argument from the stack and return it.
1561 __ subu(a3, a0, a1);
1562 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1563 __ Addu(a3, fp, Operand(t3));
1564 __ Ret(USE_DELAY_SLOT);
1565 __ lw(v0, MemOperand(a3, kDisplacement));
1567 // Arguments adaptor case: Check index (a1) against actual arguments
1568 // limit found in the arguments adaptor frame. Use unsigned
1569 // comparison to get negative check for free.
1571 __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1572 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1574 // Read the argument from the adaptor frame and return it.
1575 __ subu(a3, a0, a1);
1576 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1577 __ Addu(a3, a2, Operand(t3));
1578 __ Ret(USE_DELAY_SLOT);
1579 __ lw(v0, MemOperand(a3, kDisplacement));
1581 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1582 // by calling the runtime system.
1585 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1589 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1590 // sp[0] : number of parameters
1591 // sp[4] : receiver displacement
1594 // Check if the calling frame is an arguments adaptor frame.
1596 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1597 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1601 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1603 // Patch the arguments.length and the parameters pointer in the current frame.
1604 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1605 __ sw(a2, MemOperand(sp, 0 * kPointerSize));
1607 __ Addu(a3, a3, Operand(t3));
1608 __ addiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1609 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1612 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1616 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1618 // sp[0] : number of parameters (tagged)
1619 // sp[4] : address of receiver argument
1621 // Registers used over whole function:
1622 // t2 : allocated object (tagged)
1623 // t5 : mapped parameter count (tagged)
1625 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1626 // a1 = parameter count (tagged)
1628 // Check if the calling frame is an arguments adaptor frame.
1630 Label adaptor_frame, try_allocate;
1631 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1632 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1633 __ Branch(&adaptor_frame,
1636 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1638 // No adaptor, parameter count = argument count.
1640 __ b(&try_allocate);
1641 __ nop(); // Branch delay slot nop.
1643 // We have an adaptor frame. Patch the parameters pointer.
1644 __ bind(&adaptor_frame);
1645 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1647 __ Addu(a3, a3, Operand(t6));
1648 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1649 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1651 // a1 = parameter count (tagged)
1652 // a2 = argument count (tagged)
1653 // Compute the mapped parameter count = min(a1, a2) in a1.
1655 __ Branch(&skip_min, lt, a1, Operand(a2));
1659 __ bind(&try_allocate);
1661 // Compute the sizes of backing store, parameter map, and arguments object.
1662 // 1. Parameter map, has 2 extra words containing context and backing store.
1663 const int kParameterMapHeaderSize =
1664 FixedArray::kHeaderSize + 2 * kPointerSize;
1665 // If there are no mapped parameters, we do not need the parameter_map.
1666 Label param_map_size;
1667 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1668 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1669 __ mov(t5, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1671 __ addiu(t5, t5, kParameterMapHeaderSize);
1672 __ bind(¶m_map_size);
1674 // 2. Backing store.
1676 __ Addu(t5, t5, Operand(t6));
1677 __ Addu(t5, t5, Operand(FixedArray::kHeaderSize));
1679 // 3. Arguments object.
1680 __ Addu(t5, t5, Operand(Heap::kSloppyArgumentsObjectSize));
1682 // Do the allocation of all three objects in one go.
1683 __ Allocate(t5, v0, a3, t0, &runtime, TAG_OBJECT);
1685 // v0 = address of new object(s) (tagged)
1686 // a2 = argument count (smi-tagged)
1687 // Get the arguments boilerplate from the current native context into t0.
1688 const int kNormalOffset =
1689 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1690 const int kAliasedOffset =
1691 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1693 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1694 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1695 Label skip2_ne, skip2_eq;
1696 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1697 __ lw(t0, MemOperand(t0, kNormalOffset));
1700 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1701 __ lw(t0, MemOperand(t0, kAliasedOffset));
1704 // v0 = address of new object (tagged)
1705 // a1 = mapped parameter count (tagged)
1706 // a2 = argument count (smi-tagged)
1707 // t0 = address of arguments map (tagged)
1708 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1709 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1710 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1711 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1713 // Set up the callee in-object property.
1714 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1715 __ lw(a3, MemOperand(sp, 2 * kPointerSize));
1716 __ AssertNotSmi(a3);
1717 const int kCalleeOffset = JSObject::kHeaderSize +
1718 Heap::kArgumentsCalleeIndex * kPointerSize;
1719 __ sw(a3, FieldMemOperand(v0, kCalleeOffset));
1721 // Use the length (smi tagged) and set that as an in-object property too.
1723 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1724 const int kLengthOffset = JSObject::kHeaderSize +
1725 Heap::kArgumentsLengthIndex * kPointerSize;
1726 __ sw(a2, FieldMemOperand(v0, kLengthOffset));
1728 // Set up the elements pointer in the allocated arguments object.
1729 // If we allocated a parameter map, t0 will point there, otherwise
1730 // it will point to the backing store.
1731 __ Addu(t0, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1732 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1734 // v0 = address of new object (tagged)
1735 // a1 = mapped parameter count (tagged)
1736 // a2 = argument count (tagged)
1737 // t0 = address of parameter map or backing store (tagged)
1738 // Initialize parameter map. If there are no mapped arguments, we're done.
1739 Label skip_parameter_map;
1741 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1742 // Move backing store address to a3, because it is
1743 // expected there when filling in the unmapped arguments.
1747 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1749 __ LoadRoot(t2, Heap::kSloppyArgumentsElementsMapRootIndex);
1750 __ sw(t2, FieldMemOperand(t0, FixedArray::kMapOffset));
1751 __ Addu(t2, a1, Operand(Smi::FromInt(2)));
1752 __ sw(t2, FieldMemOperand(t0, FixedArray::kLengthOffset));
1753 __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize));
1755 __ Addu(t2, t0, Operand(t6));
1756 __ Addu(t2, t2, Operand(kParameterMapHeaderSize));
1757 __ sw(t2, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize));
1759 // Copy the parameter slots and the holes in the arguments.
1760 // We need to fill in mapped_parameter_count slots. They index the context,
1761 // where parameters are stored in reverse order, at
1762 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1763 // The mapped parameter thus need to get indices
1764 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1765 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1766 // We loop from right to left.
1767 Label parameters_loop, parameters_test;
1769 __ lw(t5, MemOperand(sp, 0 * kPointerSize));
1770 __ Addu(t5, t5, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1771 __ Subu(t5, t5, Operand(a1));
1772 __ LoadRoot(t3, Heap::kTheHoleValueRootIndex);
1774 __ Addu(a3, t0, Operand(t6));
1775 __ Addu(a3, a3, Operand(kParameterMapHeaderSize));
1777 // t2 = loop variable (tagged)
1778 // a1 = mapping index (tagged)
1779 // a3 = address of backing store (tagged)
1780 // t0 = address of parameter map (tagged)
1781 // t1 = temporary scratch (a.o., for address calculation)
1782 // t3 = the hole value
1783 __ jmp(¶meters_test);
1785 __ bind(¶meters_loop);
1786 __ Subu(t2, t2, Operand(Smi::FromInt(1)));
1788 __ Addu(t1, t1, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1789 __ Addu(t6, t0, t1);
1790 __ sw(t5, MemOperand(t6));
1791 __ Subu(t1, t1, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1792 __ Addu(t6, a3, t1);
1793 __ sw(t3, MemOperand(t6));
1794 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1795 __ bind(¶meters_test);
1796 __ Branch(¶meters_loop, ne, t2, Operand(Smi::FromInt(0)));
1798 __ bind(&skip_parameter_map);
1799 // a2 = argument count (tagged)
1800 // a3 = address of backing store (tagged)
1802 // Copy arguments header and remaining slots (if there are any).
1803 __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex);
1804 __ sw(t1, FieldMemOperand(a3, FixedArray::kMapOffset));
1805 __ sw(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1807 Label arguments_loop, arguments_test;
1809 __ lw(t0, MemOperand(sp, 1 * kPointerSize));
1811 __ Subu(t0, t0, Operand(t6));
1812 __ jmp(&arguments_test);
1814 __ bind(&arguments_loop);
1815 __ Subu(t0, t0, Operand(kPointerSize));
1816 __ lw(t2, MemOperand(t0, 0));
1818 __ Addu(t1, a3, Operand(t6));
1819 __ sw(t2, FieldMemOperand(t1, FixedArray::kHeaderSize));
1820 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1822 __ bind(&arguments_test);
1823 __ Branch(&arguments_loop, lt, t5, Operand(a2));
1825 // Return and remove the on-stack parameters.
1828 // Do the runtime call to allocate the arguments object.
1829 // a2 = argument count (tagged)
1831 __ sw(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1832 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1836 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1837 // Return address is in ra.
1840 Register receiver = LoadDescriptor::ReceiverRegister();
1841 Register key = LoadDescriptor::NameRegister();
1843 // Check that the key is an array index, that is Uint32.
1844 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1845 __ Branch(&slow, ne, t0, Operand(zero_reg));
1847 // Everything is fine, call runtime.
1848 __ Push(receiver, key); // Receiver, key.
1850 // Perform tail call to the entry.
1851 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1854 PropertyAccessCompiler::TailCallBuiltin(
1855 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1859 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1860 // sp[0] : number of parameters
1861 // sp[4] : receiver displacement
1863 // Check if the calling frame is an arguments adaptor frame.
1864 Label adaptor_frame, try_allocate, runtime;
1865 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1866 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1867 __ Branch(&adaptor_frame,
1870 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1872 // Get the length from the frame.
1873 __ lw(a1, MemOperand(sp, 0));
1874 __ Branch(&try_allocate);
1876 // Patch the arguments.length and the parameters pointer.
1877 __ bind(&adaptor_frame);
1878 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1879 __ sw(a1, MemOperand(sp, 0));
1880 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1881 __ Addu(a3, a2, Operand(at));
1883 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1884 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1886 // Try the new space allocation. Start out with computing the size
1887 // of the arguments object and the elements array in words.
1888 Label add_arguments_object;
1889 __ bind(&try_allocate);
1890 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1891 __ srl(a1, a1, kSmiTagSize);
1893 __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1894 __ bind(&add_arguments_object);
1895 __ Addu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1897 // Do the allocation of both objects in one go.
1898 __ Allocate(a1, v0, a2, a3, &runtime,
1899 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1901 // Get the arguments boilerplate from the current native context.
1902 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1903 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1904 __ lw(t0, MemOperand(
1905 t0, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1907 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1908 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1909 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1910 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1912 // Get the length (smi tagged) and set that as an in-object property too.
1913 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1914 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1916 __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
1917 Heap::kArgumentsLengthIndex * kPointerSize));
1920 __ Branch(&done, eq, a1, Operand(zero_reg));
1922 // Get the parameters pointer from the stack.
1923 __ lw(a2, MemOperand(sp, 1 * kPointerSize));
1925 // Set up the elements pointer in the allocated arguments object and
1926 // initialize the header in the elements fixed array.
1927 __ Addu(t0, v0, Operand(Heap::kStrictArgumentsObjectSize));
1928 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1929 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
1930 __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset));
1931 __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset));
1932 // Untag the length for the loop.
1933 __ srl(a1, a1, kSmiTagSize);
1935 // Copy the fixed array slots.
1937 // Set up t0 to point to the first array slot.
1938 __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1940 // Pre-decrement a2 with kPointerSize on each iteration.
1941 // Pre-decrement in order to skip receiver.
1942 __ Addu(a2, a2, Operand(-kPointerSize));
1943 __ lw(a3, MemOperand(a2));
1944 // Post-increment t0 with kPointerSize on each iteration.
1945 __ sw(a3, MemOperand(t0));
1946 __ Addu(t0, t0, Operand(kPointerSize));
1947 __ Subu(a1, a1, Operand(1));
1948 __ Branch(&loop, ne, a1, Operand(zero_reg));
1950 // Return and remove the on-stack parameters.
1954 // Do the runtime call to allocate the arguments object.
1956 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1960 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
1961 // sp[0] : language mode
1962 // sp[4] : index of rest parameter
1963 // sp[8] : number of parameters
1964 // sp[12] : receiver displacement
1965 // Check if the calling frame is an arguments adaptor frame.
1968 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1969 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1970 __ Branch(&runtime, ne, a3,
1971 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1973 // Patch the arguments.length and the parameters pointer.
1974 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1975 __ sw(a1, MemOperand(sp, 2 * kPointerSize));
1976 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1977 __ Addu(a3, a2, Operand(at));
1979 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1980 __ sw(a3, MemOperand(sp, 3 * kPointerSize));
1982 // Do the runtime call to allocate the arguments object.
1984 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
1988 void RegExpExecStub::Generate(MacroAssembler* masm) {
1989 // Just jump directly to runtime if native RegExp is not selected at compile
1990 // time or if regexp entry in generated code is turned off runtime switch or
1992 #ifdef V8_INTERPRETED_REGEXP
1993 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1994 #else // V8_INTERPRETED_REGEXP
1996 // Stack frame on entry.
1997 // sp[0]: last_match_info (expected JSArray)
1998 // sp[4]: previous index
1999 // sp[8]: subject string
2000 // sp[12]: JSRegExp object
2002 const int kLastMatchInfoOffset = 0 * kPointerSize;
2003 const int kPreviousIndexOffset = 1 * kPointerSize;
2004 const int kSubjectOffset = 2 * kPointerSize;
2005 const int kJSRegExpOffset = 3 * kPointerSize;
2008 // Allocation of registers for this function. These are in callee save
2009 // registers and will be preserved by the call to the native RegExp code, as
2010 // this code is called using the normal C calling convention. When calling
2011 // directly from generated code the native RegExp code will not do a GC and
2012 // therefore the content of these registers are safe to use after the call.
2013 // MIPS - using s0..s2, since we are not using CEntry Stub.
2014 Register subject = s0;
2015 Register regexp_data = s1;
2016 Register last_match_info_elements = s2;
2018 // Ensure that a RegExp stack is allocated.
2019 ExternalReference address_of_regexp_stack_memory_address =
2020 ExternalReference::address_of_regexp_stack_memory_address(
2022 ExternalReference address_of_regexp_stack_memory_size =
2023 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2024 __ li(a0, Operand(address_of_regexp_stack_memory_size));
2025 __ lw(a0, MemOperand(a0, 0));
2026 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2028 // Check that the first argument is a JSRegExp object.
2029 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
2030 STATIC_ASSERT(kSmiTag == 0);
2031 __ JumpIfSmi(a0, &runtime);
2032 __ GetObjectType(a0, a1, a1);
2033 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2035 // Check that the RegExp has been compiled (data contains a fixed array).
2036 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2037 if (FLAG_debug_code) {
2038 __ SmiTst(regexp_data, t0);
2040 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2043 __ GetObjectType(regexp_data, a0, a0);
2045 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2047 Operand(FIXED_ARRAY_TYPE));
2050 // regexp_data: RegExp data (FixedArray)
2051 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2052 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2053 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2055 // regexp_data: RegExp data (FixedArray)
2056 // Check that the number of captures fit in the static offsets vector buffer.
2058 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2059 // Check (number_of_captures + 1) * 2 <= offsets vector size
2060 // Or number_of_captures * 2 <= offsets vector size - 2
2061 // Multiplying by 2 comes for free since a2 is smi-tagged.
2062 STATIC_ASSERT(kSmiTag == 0);
2063 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2064 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2066 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2068 // Reset offset for possibly sliced string.
2069 __ mov(t0, zero_reg);
2070 __ lw(subject, MemOperand(sp, kSubjectOffset));
2071 __ JumpIfSmi(subject, &runtime);
2072 __ mov(a3, subject); // Make a copy of the original subject string.
2073 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2074 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2075 // subject: subject string
2076 // a3: subject string
2077 // a0: subject string instance type
2078 // regexp_data: RegExp data (FixedArray)
2079 // Handle subject string according to its encoding and representation:
2080 // (1) Sequential string? If yes, go to (5).
2081 // (2) Anything but sequential or cons? If yes, go to (6).
2082 // (3) Cons string. If the string is flat, replace subject with first string.
2083 // Otherwise bailout.
2084 // (4) Is subject external? If yes, go to (7).
2085 // (5) Sequential string. Load regexp code according to encoding.
2089 // Deferred code at the end of the stub:
2090 // (6) Not a long external string? If yes, go to (8).
2091 // (7) External string. Make it, offset-wise, look like a sequential string.
2093 // (8) Short external string or not a string? If yes, bail out to runtime.
2094 // (9) Sliced string. Replace subject with parent. Go to (4).
2096 Label seq_string /* 5 */, external_string /* 7 */,
2097 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2098 not_long_external /* 8 */;
2100 // (1) Sequential string? If yes, go to (5).
2103 Operand(kIsNotStringMask |
2104 kStringRepresentationMask |
2105 kShortExternalStringMask));
2106 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2107 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2109 // (2) Anything but sequential or cons? If yes, go to (6).
2110 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2111 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2112 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2113 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2115 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2117 // (3) Cons string. Check that it's flat.
2118 // Replace subject with first string and reload instance type.
2119 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2120 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2121 __ Branch(&runtime, ne, a0, Operand(a1));
2122 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2124 // (4) Is subject external? If yes, go to (7).
2125 __ bind(&check_underlying);
2126 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2127 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2128 STATIC_ASSERT(kSeqStringTag == 0);
2129 __ And(at, a0, Operand(kStringRepresentationMask));
2130 // The underlying external string is never a short external string.
2131 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2132 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2133 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2135 // (5) Sequential string. Load regexp code according to encoding.
2136 __ bind(&seq_string);
2137 // subject: sequential subject string (or look-alike, external string)
2138 // a3: original subject string
2139 // Load previous index and check range before a3 is overwritten. We have to
2140 // use a3 instead of subject here because subject might have been only made
2141 // to look like a sequential string when it actually is an external string.
2142 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
2143 __ JumpIfNotSmi(a1, &runtime);
2144 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
2145 __ Branch(&runtime, ls, a3, Operand(a1));
2146 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
2148 STATIC_ASSERT(kStringEncodingMask == 4);
2149 STATIC_ASSERT(kOneByteStringTag == 4);
2150 STATIC_ASSERT(kTwoByteStringTag == 0);
2151 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
2152 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2153 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
2154 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2155 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2157 // (E) Carry on. String handling is done.
2158 // t9: irregexp code
2159 // Check that the irregexp code has been generated for the actual string
2160 // encoding. If it has, the field contains a code object otherwise it contains
2161 // a smi (code flushing support).
2162 __ JumpIfSmi(t9, &runtime);
2164 // a1: previous index
2165 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2167 // subject: Subject string
2168 // regexp_data: RegExp data (FixedArray)
2169 // All checks done. Now push arguments for native regexp code.
2170 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2173 // Isolates: note we add an additional parameter here (isolate pointer).
2174 const int kRegExpExecuteArguments = 9;
2175 const int kParameterRegisters = 4;
2176 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2178 // Stack pointer now points to cell where return address is to be written.
2179 // Arguments are before that on the stack or in registers, meaning we
2180 // treat the return address as argument 5. Thus every argument after that
2181 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2182 // allocating space for the c argument slots, we don't need to calculate
2183 // that into the argument positions on the stack. This is how the stack will
2184 // look (sp meaning the value of sp at this moment):
2185 // [sp + 5] - Argument 9
2186 // [sp + 4] - Argument 8
2187 // [sp + 3] - Argument 7
2188 // [sp + 2] - Argument 6
2189 // [sp + 1] - Argument 5
2190 // [sp + 0] - saved ra
2192 // Argument 9: Pass current isolate address.
2193 // CFunctionArgumentOperand handles MIPS stack argument slots.
2194 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2195 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
2197 // Argument 8: Indicate that this is a direct call from JavaScript.
2198 __ li(a0, Operand(1));
2199 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
2201 // Argument 7: Start (high end) of backtracking stack memory area.
2202 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2203 __ lw(a0, MemOperand(a0, 0));
2204 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2205 __ lw(a2, MemOperand(a2, 0));
2206 __ addu(a0, a0, a2);
2207 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
2209 // Argument 6: Set the number of capture registers to zero to force global
2210 // regexps to behave as non-global. This does not affect non-global regexps.
2211 __ mov(a0, zero_reg);
2212 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
2214 // Argument 5: static offsets vector buffer.
2216 ExternalReference::address_of_static_offsets_vector(isolate())));
2217 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
2219 // For arguments 4 and 3 get string length, calculate start of string data
2220 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2221 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2222 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2223 // Load the length from the original subject string from the previous stack
2224 // frame. Therefore we have to use fp, which points exactly to two pointer
2225 // sizes below the previous sp. (Because creating a new stack frame pushes
2226 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2227 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2228 // If slice offset is not 0, load the length from the original sliced string.
2229 // Argument 4, a3: End of string data
2230 // Argument 3, a2: Start of string data
2231 // Prepare start and end index of the input.
2232 __ sllv(t1, t0, a3);
2233 __ addu(t0, t2, t1);
2234 __ sllv(t1, a1, a3);
2235 __ addu(a2, t0, t1);
2237 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
2238 __ sra(t2, t2, kSmiTagSize);
2239 __ sllv(t1, t2, a3);
2240 __ addu(a3, t0, t1);
2241 // Argument 2 (a1): Previous index.
2244 // Argument 1 (a0): Subject string.
2245 __ mov(a0, subject);
2247 // Locate the code entry and call it.
2248 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2249 DirectCEntryStub stub(isolate());
2250 stub.GenerateCall(masm, t9);
2252 __ LeaveExitFrame(false, no_reg, true);
2255 // subject: subject string (callee saved)
2256 // regexp_data: RegExp data (callee saved)
2257 // last_match_info_elements: Last match info elements (callee saved)
2258 // Check the result.
2260 __ Branch(&success, eq, v0, Operand(1));
2261 // We expect exactly one result since we force the called regexp to behave
2264 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2265 // If not exception it can only be retry. Handle that in the runtime system.
2266 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2267 // Result must now be exception. If there is no pending exception already a
2268 // stack overflow (on the backtrack stack) was detected in RegExp code but
2269 // haven't created the exception yet. Handle that in the runtime system.
2270 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2271 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2272 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2274 __ lw(v0, MemOperand(a2, 0));
2275 __ Branch(&runtime, eq, v0, Operand(a1));
2277 // For exception, throw the exception again.
2278 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2281 // For failure and exception return null.
2282 __ li(v0, Operand(isolate()->factory()->null_value()));
2285 // Process the result from the native regexp code.
2288 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2289 // Calculate number of capture registers (number_of_captures + 1) * 2.
2290 // Multiplying by 2 comes for free since r1 is smi-tagged.
2291 STATIC_ASSERT(kSmiTag == 0);
2292 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2293 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
2295 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
2296 __ JumpIfSmi(a0, &runtime);
2297 __ GetObjectType(a0, a2, a2);
2298 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2299 // Check that the JSArray is in fast case.
2300 __ lw(last_match_info_elements,
2301 FieldMemOperand(a0, JSArray::kElementsOffset));
2302 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2303 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2304 __ Branch(&runtime, ne, a0, Operand(at));
2305 // Check that the last match info has space for the capture registers and the
2306 // additional information.
2308 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2309 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2310 __ sra(at, a0, kSmiTagSize);
2311 __ Branch(&runtime, gt, a2, Operand(at));
2313 // a1: number of capture registers
2314 // subject: subject string
2315 // Store the capture count.
2316 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
2317 __ sw(a2, FieldMemOperand(last_match_info_elements,
2318 RegExpImpl::kLastCaptureCountOffset));
2319 // Store last subject and last input.
2321 FieldMemOperand(last_match_info_elements,
2322 RegExpImpl::kLastSubjectOffset));
2323 __ mov(a2, subject);
2324 __ RecordWriteField(last_match_info_elements,
2325 RegExpImpl::kLastSubjectOffset,
2330 __ mov(subject, a2);
2332 FieldMemOperand(last_match_info_elements,
2333 RegExpImpl::kLastInputOffset));
2334 __ RecordWriteField(last_match_info_elements,
2335 RegExpImpl::kLastInputOffset,
2341 // Get the static offsets vector filled by the native regexp code.
2342 ExternalReference address_of_static_offsets_vector =
2343 ExternalReference::address_of_static_offsets_vector(isolate());
2344 __ li(a2, Operand(address_of_static_offsets_vector));
2346 // a1: number of capture registers
2347 // a2: offsets vector
2348 Label next_capture, done;
2349 // Capture register counter starts from number of capture registers and
2350 // counts down until wrapping after zero.
2352 last_match_info_elements,
2353 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2354 __ bind(&next_capture);
2355 __ Subu(a1, a1, Operand(1));
2356 __ Branch(&done, lt, a1, Operand(zero_reg));
2357 // Read the value from the static offsets vector buffer.
2358 __ lw(a3, MemOperand(a2, 0));
2359 __ addiu(a2, a2, kPointerSize);
2360 // Store the smi value in the last match info.
2361 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
2362 __ sw(a3, MemOperand(a0, 0));
2363 __ Branch(&next_capture, USE_DELAY_SLOT);
2364 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
2368 // Return last match info.
2369 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
2372 // Do the runtime call to execute the regexp.
2374 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2376 // Deferred code for string handling.
2377 // (6) Not a long external string? If yes, go to (8).
2378 __ bind(¬_seq_nor_cons);
2380 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2382 // (7) External string. Make it, offset-wise, look like a sequential string.
2383 __ bind(&external_string);
2384 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2385 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2386 if (FLAG_debug_code) {
2387 // Assert that we do not have a cons or slice (indirect strings) here.
2388 // Sequential strings have already been ruled out.
2389 __ And(at, a0, Operand(kIsIndirectStringMask));
2391 kExternalStringExpectedButNotFound,
2396 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2397 // Move the pointer so that offset-wise, it looks like a sequential string.
2398 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2401 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2402 __ jmp(&seq_string); // Go to (5).
2404 // (8) Short external string or not a string? If yes, bail out to runtime.
2405 __ bind(¬_long_external);
2406 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2407 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2408 __ Branch(&runtime, ne, at, Operand(zero_reg));
2410 // (9) Sliced string. Replace subject with parent. Go to (4).
2411 // Load offset into t0 and replace subject string with parent.
2412 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2413 __ sra(t0, t0, kSmiTagSize);
2414 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2415 __ jmp(&check_underlying); // Go to (4).
2416 #endif // V8_INTERPRETED_REGEXP
2420 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2422 // a0 : number of arguments to the construct function
2423 // a2 : feedback vector
2424 // a3 : slot in feedback vector (Smi)
2425 // a1 : the function to call
2426 // t0 : original constructor (for IsSuperConstructorCall)
2427 FrameScope scope(masm, StackFrame::INTERNAL);
2428 const RegList kSavedRegs = 1 << 4 | // a0
2432 BoolToInt(is_super) << 8; // t0
2434 // Number-of-arguments register must be smi-tagged to call out.
2436 __ MultiPush(kSavedRegs);
2440 __ MultiPop(kSavedRegs);
2445 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2446 // Cache the called function in a feedback vector slot. Cache states
2447 // are uninitialized, monomorphic (indicated by a JSFunction), and
2449 // a0 : number of arguments to the construct function
2450 // a1 : the function to call
2451 // a2 : feedback vector
2452 // a3 : slot in feedback vector (Smi)
2453 // t0 : original constructor (for IsSuperConstructorCall)
2454 Label initialize, done, miss, megamorphic, not_array_function;
2456 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2457 masm->isolate()->heap()->megamorphic_symbol());
2458 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2459 masm->isolate()->heap()->uninitialized_symbol());
2461 // Load the cache state into t2.
2462 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2463 __ Addu(t2, a2, Operand(t2));
2464 __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize));
2466 // A monomorphic cache hit or an already megamorphic state: invoke the
2467 // function without changing the state.
2468 // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at
2469 // this position in a symbol (see static asserts in type-feedback-vector.h).
2470 Label check_allocation_site;
2471 Register feedback_map = t1;
2472 Register weak_value = t4;
2473 __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset));
2474 __ Branch(&done, eq, a1, Operand(weak_value));
2475 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2476 __ Branch(&done, eq, t2, Operand(at));
2477 __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset));
2478 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2479 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2480 feedback_map, Operand(at));
2482 // If the weak cell is cleared, we have a new chance to become monomorphic.
2483 __ JumpIfSmi(weak_value, &initialize);
2484 __ jmp(&megamorphic);
2486 if (!FLAG_pretenuring_call_new) {
2487 __ bind(&check_allocation_site);
2488 // If we came here, we need to see if we are the array function.
2489 // If we didn't have a matching function, and we didn't find the megamorph
2490 // sentinel, then we have in the slot either some other function or an
2492 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2493 __ Branch(&miss, ne, feedback_map, Operand(at));
2495 // Make sure the function is the Array() function
2496 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2497 __ Branch(&megamorphic, ne, a1, Operand(t2));
2503 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2505 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2506 __ Branch(&initialize, eq, t2, Operand(at));
2507 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2508 // write-barrier is needed.
2509 __ bind(&megamorphic);
2510 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2511 __ Addu(t2, a2, Operand(t2));
2512 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2513 __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize));
2516 // An uninitialized cache is patched with the function.
2517 __ bind(&initialize);
2518 if (!FLAG_pretenuring_call_new) {
2519 // Make sure the function is the Array() function.
2520 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2521 __ Branch(¬_array_function, ne, a1, Operand(t2));
2523 // The target function is the Array constructor,
2524 // Create an AllocationSite if we don't already have it, store it in the
2526 CreateAllocationSiteStub create_stub(masm->isolate());
2527 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2530 __ bind(¬_array_function);
2533 CreateWeakCellStub create_stub(masm->isolate());
2534 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2539 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2540 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2541 __ lw(t0, FieldMemOperand(a3, SharedFunctionInfo::kCompilerHintsOffset));
2543 // Do not transform the receiver for strict mode functions.
2544 int32_t strict_mode_function_mask =
2545 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
2546 // Do not transform the receiver for native (Compilerhints already in a3).
2547 int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize);
2548 __ And(at, t0, Operand(strict_mode_function_mask | native_mask));
2549 __ Branch(cont, ne, at, Operand(zero_reg));
2553 static void EmitSlowCase(MacroAssembler* masm,
2555 Label* non_function) {
2556 // Check for function proxy.
2557 __ Branch(non_function, ne, t0, Operand(JS_FUNCTION_PROXY_TYPE));
2558 __ push(a1); // put proxy as additional argument
2559 __ li(a0, Operand(argc + 1, RelocInfo::NONE32));
2560 __ mov(a2, zero_reg);
2561 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY);
2563 Handle<Code> adaptor =
2564 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2565 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2568 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2569 // of the original receiver from the call site).
2570 __ bind(non_function);
2571 __ sw(a1, MemOperand(sp, argc * kPointerSize));
2572 __ li(a0, Operand(argc)); // Set up the number of arguments.
2573 __ mov(a2, zero_reg);
2574 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION);
2575 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2576 RelocInfo::CODE_TARGET);
2580 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2581 // Wrap the receiver and patch it back onto the stack.
2582 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2585 ToObjectStub stub(masm->isolate());
2589 __ Branch(USE_DELAY_SLOT, cont);
2590 __ sw(v0, MemOperand(sp, argc * kPointerSize));
2594 static void CallFunctionNoFeedback(MacroAssembler* masm,
2595 int argc, bool needs_checks,
2596 bool call_as_method) {
2597 // a1 : the function to call
2598 Label slow, non_function, wrap, cont;
2601 // Check that the function is really a JavaScript function.
2602 // a1: pushed function (to be verified)
2603 __ JumpIfSmi(a1, &non_function);
2605 // Goto slow case if we do not have a function.
2606 __ GetObjectType(a1, t0, t0);
2607 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2610 // Fast-case: Invoke the function now.
2611 // a1: pushed function
2612 ParameterCount actual(argc);
2614 if (call_as_method) {
2616 EmitContinueIfStrictOrNative(masm, &cont);
2619 // Compute the receiver in sloppy mode.
2620 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2623 __ JumpIfSmi(a3, &wrap);
2624 __ GetObjectType(a3, t0, t0);
2625 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2633 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2636 // Slow-case: Non-function called.
2638 EmitSlowCase(masm, argc, &non_function);
2641 if (call_as_method) {
2643 // Wrap the receiver and patch it back onto the stack.
2644 EmitWrapCase(masm, argc, &cont);
2649 void CallFunctionStub::Generate(MacroAssembler* masm) {
2650 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2654 void CallConstructStub::Generate(MacroAssembler* masm) {
2655 // a0 : number of arguments
2656 // a1 : the function to call
2657 // a2 : feedback vector
2658 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2659 // t0 : original constructor (for IsSuperConstructorCall)
2660 Label slow, non_function_call;
2662 // Check that the function is not a smi.
2663 __ JumpIfSmi(a1, &non_function_call);
2664 // Check that the function is a JSFunction.
2665 __ GetObjectType(a1, t1, t1);
2666 __ Branch(&slow, ne, t1, Operand(JS_FUNCTION_TYPE));
2668 if (RecordCallTarget()) {
2669 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2671 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2672 __ Addu(t1, a2, at);
2673 if (FLAG_pretenuring_call_new) {
2674 // Put the AllocationSite from the feedback vector into a2.
2675 // By adding kPointerSize we encode that we know the AllocationSite
2676 // entry is at the feedback vector slot given by a3 + 1.
2677 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize + kPointerSize));
2679 Label feedback_register_initialized;
2680 // Put the AllocationSite from the feedback vector into a2, or undefined.
2681 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
2682 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
2683 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2684 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
2685 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2686 __ bind(&feedback_register_initialized);
2689 __ AssertUndefinedOrAllocationSite(a2, t1);
2692 // Pass function as original constructor.
2693 if (IsSuperConstructorCall()) {
2699 // Jump to the function-specific construct stub.
2700 Register jmp_reg = t0;
2701 __ lw(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2702 __ lw(jmp_reg, FieldMemOperand(jmp_reg,
2703 SharedFunctionInfo::kConstructStubOffset));
2704 __ Addu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2707 // a0: number of arguments
2708 // a1: called object
2712 __ Branch(&non_function_call, ne, t1, Operand(JS_FUNCTION_PROXY_TYPE));
2713 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2716 __ bind(&non_function_call);
2717 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2719 // Set expected number of arguments to zero (not changing r0).
2720 __ li(a2, Operand(0, RelocInfo::NONE32));
2721 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2722 RelocInfo::CODE_TARGET);
2726 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2727 __ lw(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2728 __ lw(vector, FieldMemOperand(vector,
2729 JSFunction::kSharedFunctionInfoOffset));
2730 __ lw(vector, FieldMemOperand(vector,
2731 SharedFunctionInfo::kFeedbackVectorOffset));
2735 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2741 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2742 __ Branch(&miss, ne, a1, Operand(at));
2744 __ li(a0, Operand(arg_count()));
2745 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2746 __ Addu(at, a2, Operand(at));
2747 __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize));
2749 // Verify that t0 contains an AllocationSite
2750 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2751 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2752 __ Branch(&miss, ne, t1, Operand(at));
2754 // Increment the call count for monomorphic function calls.
2755 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2756 __ Addu(at, a2, Operand(at));
2757 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2758 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2759 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2763 ArrayConstructorStub stub(masm->isolate(), arg_count());
2764 __ TailCallStub(&stub);
2769 // The slow case, we need this no matter what to complete a call after a miss.
2770 CallFunctionNoFeedback(masm,
2776 __ stop("Unexpected code address");
2780 void CallICStub::Generate(MacroAssembler* masm) {
2782 // a3 - slot id (Smi)
2784 const int with_types_offset =
2785 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2786 const int generic_offset =
2787 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2788 Label extra_checks_or_miss, slow_start;
2789 Label slow, non_function, wrap, cont;
2790 Label have_js_function;
2791 int argc = arg_count();
2792 ParameterCount actual(argc);
2794 // The checks. First, does r1 match the recorded monomorphic target?
2795 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2796 __ Addu(t0, a2, Operand(t0));
2797 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2799 // We don't know that we have a weak cell. We might have a private symbol
2800 // or an AllocationSite, but the memory is safe to examine.
2801 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2803 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2804 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2805 // computed, meaning that it can't appear to be a pointer. If the low bit is
2806 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2808 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2809 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2810 WeakCell::kValueOffset &&
2811 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2813 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2814 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
2816 // The compare above could have been a SMI/SMI comparison. Guard against this
2817 // convincing us that we have a monomorphic JSFunction.
2818 __ JumpIfSmi(a1, &extra_checks_or_miss);
2820 // Increment the call count for monomorphic function calls.
2821 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2822 __ Addu(at, a2, Operand(at));
2823 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2824 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2825 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2827 __ bind(&have_js_function);
2828 if (CallAsMethod()) {
2829 EmitContinueIfStrictOrNative(masm, &cont);
2830 // Compute the receiver in sloppy mode.
2831 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2833 __ JumpIfSmi(a3, &wrap);
2834 __ GetObjectType(a3, t0, t0);
2835 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2840 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2843 EmitSlowCase(masm, argc, &non_function);
2845 if (CallAsMethod()) {
2847 EmitWrapCase(masm, argc, &cont);
2850 __ bind(&extra_checks_or_miss);
2851 Label uninitialized, miss;
2853 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2854 __ Branch(&slow_start, eq, t0, Operand(at));
2856 // The following cases attempt to handle MISS cases without going to the
2858 if (FLAG_trace_ic) {
2862 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2863 __ Branch(&uninitialized, eq, t0, Operand(at));
2865 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2866 // to handle it here. More complex cases are dealt with in the runtime.
2867 __ AssertNotSmi(t0);
2868 __ GetObjectType(t0, t1, t1);
2869 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
2870 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2871 __ Addu(t0, a2, Operand(t0));
2872 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2873 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2874 // We have to update statistics for runtime profiling.
2875 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2876 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
2877 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2878 __ lw(t0, FieldMemOperand(a2, generic_offset));
2879 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2880 __ Branch(USE_DELAY_SLOT, &slow_start);
2881 __ sw(t0, FieldMemOperand(a2, generic_offset)); // In delay slot.
2883 __ bind(&uninitialized);
2885 // We are going monomorphic, provided we actually have a JSFunction.
2886 __ JumpIfSmi(a1, &miss);
2888 // Goto miss case if we do not have a function.
2889 __ GetObjectType(a1, t0, t0);
2890 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2892 // Make sure the function is not the Array() function, which requires special
2893 // behavior on MISS.
2894 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2895 __ Branch(&miss, eq, a1, Operand(t0));
2898 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2899 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2900 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2902 // Initialize the call counter.
2903 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2904 __ Addu(at, a2, Operand(at));
2905 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2906 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2908 // Store the function. Use a stub since we need a frame for allocation.
2913 FrameScope scope(masm, StackFrame::INTERNAL);
2914 CreateWeakCellStub create_stub(masm->isolate());
2916 __ CallStub(&create_stub);
2920 __ Branch(&have_js_function);
2922 // We are here because tracing is on or we encountered a MISS case we can't
2928 __ bind(&slow_start);
2929 // Check that the function is really a JavaScript function.
2930 // r1: pushed function (to be verified)
2931 __ JumpIfSmi(a1, &non_function);
2933 // Goto slow case if we do not have a function.
2934 __ GetObjectType(a1, t0, t0);
2935 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2936 __ Branch(&have_js_function);
2940 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2941 FrameScope scope(masm, StackFrame::INTERNAL);
2943 // Push the receiver and the function and feedback info.
2944 __ Push(a1, a2, a3);
2947 Runtime::FunctionId id = GetICState() == DEFAULT
2948 ? Runtime::kCallIC_Miss
2949 : Runtime::kCallIC_Customization_Miss;
2950 __ CallRuntime(id, 3);
2952 // Move result to a1 and exit the internal frame.
2957 // StringCharCodeAtGenerator.
2958 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2959 DCHECK(!t0.is(index_));
2960 DCHECK(!t0.is(result_));
2961 DCHECK(!t0.is(object_));
2962 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2963 // If the receiver is a smi trigger the non-string case.
2964 __ JumpIfSmi(object_, receiver_not_string_);
2966 // Fetch the instance type of the receiver into result register.
2967 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2968 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2969 // If the receiver is not a string trigger the non-string case.
2970 __ And(t0, result_, Operand(kIsNotStringMask));
2971 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
2974 // If the index is non-smi trigger the non-smi case.
2975 __ JumpIfNotSmi(index_, &index_not_smi_);
2977 __ bind(&got_smi_index_);
2979 // Check for index out of range.
2980 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
2981 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
2983 __ sra(index_, index_, kSmiTagSize);
2985 StringCharLoadGenerator::Generate(masm,
2991 __ sll(result_, result_, kSmiTagSize);
2996 void StringCharCodeAtGenerator::GenerateSlow(
2997 MacroAssembler* masm, EmbedMode embed_mode,
2998 const RuntimeCallHelper& call_helper) {
2999 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3001 // Index is not a smi.
3002 __ bind(&index_not_smi_);
3003 // If index is a heap number, try converting it to an integer.
3006 Heap::kHeapNumberMapRootIndex,
3009 call_helper.BeforeCall(masm);
3010 // Consumed by runtime conversion function:
3011 if (embed_mode == PART_OF_IC_HANDLER) {
3012 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3013 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3015 __ Push(object_, index_);
3017 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3018 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3020 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3021 // NumberToSmi discards numbers that are not exact integers.
3022 __ CallRuntime(Runtime::kNumberToSmi, 1);
3025 // Save the conversion result before the pop instructions below
3026 // have a chance to overwrite it.
3027 __ Move(index_, v0);
3028 if (embed_mode == PART_OF_IC_HANDLER) {
3029 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3030 LoadWithVectorDescriptor::SlotRegister(), object_);
3034 // Reload the instance type.
3035 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3036 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3037 call_helper.AfterCall(masm);
3038 // If index is still not a smi, it must be out of range.
3039 __ JumpIfNotSmi(index_, index_out_of_range_);
3040 // Otherwise, return to the fast path.
3041 __ Branch(&got_smi_index_);
3043 // Call runtime. We get here when the receiver is a string and the
3044 // index is a number, but the code of getting the actual character
3045 // is too complex (e.g., when the string needs to be flattened).
3046 __ bind(&call_runtime_);
3047 call_helper.BeforeCall(masm);
3048 __ sll(index_, index_, kSmiTagSize);
3049 __ Push(object_, index_);
3050 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3052 __ Move(result_, v0);
3054 call_helper.AfterCall(masm);
3057 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3061 // -------------------------------------------------------------------------
3062 // StringCharFromCodeGenerator
3064 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3065 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3067 DCHECK(!t0.is(result_));
3068 DCHECK(!t0.is(code_));
3070 STATIC_ASSERT(kSmiTag == 0);
3071 STATIC_ASSERT(kSmiShiftSize == 0);
3072 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3073 __ And(t0, code_, Operand(kSmiTagMask |
3074 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3075 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
3077 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3078 // At this point code register contains smi tagged one-byte char code.
3079 STATIC_ASSERT(kSmiTag == 0);
3080 __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize);
3081 __ Addu(result_, result_, t0);
3082 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3083 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
3084 __ Branch(&slow_case_, eq, result_, Operand(t0));
3089 void StringCharFromCodeGenerator::GenerateSlow(
3090 MacroAssembler* masm,
3091 const RuntimeCallHelper& call_helper) {
3092 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3094 __ bind(&slow_case_);
3095 call_helper.BeforeCall(masm);
3097 __ CallRuntime(Runtime::kCharFromCode, 1);
3098 __ Move(result_, v0);
3100 call_helper.AfterCall(masm);
3103 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3107 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3110 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3115 String::Encoding encoding) {
3116 if (FLAG_debug_code) {
3117 // Check that destination is word aligned.
3118 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3120 kDestinationOfCopyNotAligned,
3125 // Assumes word reads and writes are little endian.
3126 // Nothing to do for zero characters.
3129 if (encoding == String::TWO_BYTE_ENCODING) {
3130 __ Addu(count, count, count);
3133 Register limit = count; // Read until dest equals this.
3134 __ Addu(limit, dest, Operand(count));
3136 Label loop_entry, loop;
3137 // Copy bytes from src to dest until dest hits limit.
3138 __ Branch(&loop_entry);
3140 __ lbu(scratch, MemOperand(src));
3141 __ Addu(src, src, Operand(1));
3142 __ sb(scratch, MemOperand(dest));
3143 __ Addu(dest, dest, Operand(1));
3144 __ bind(&loop_entry);
3145 __ Branch(&loop, lt, dest, Operand(limit));
3151 void SubStringStub::Generate(MacroAssembler* masm) {
3153 // Stack frame on entry.
3154 // ra: return address
3159 // This stub is called from the native-call %_SubString(...), so
3160 // nothing can be assumed about the arguments. It is tested that:
3161 // "string" is a sequential string,
3162 // both "from" and "to" are smis, and
3163 // 0 <= from <= to <= string.length.
3164 // If any of these assumptions fail, we call the runtime system.
3166 const int kToOffset = 0 * kPointerSize;
3167 const int kFromOffset = 1 * kPointerSize;
3168 const int kStringOffset = 2 * kPointerSize;
3170 __ lw(a2, MemOperand(sp, kToOffset));
3171 __ lw(a3, MemOperand(sp, kFromOffset));
3172 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3173 STATIC_ASSERT(kSmiTag == 0);
3174 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3176 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3177 // safe in this case.
3178 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
3179 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
3180 // Both a2 and a3 are untagged integers.
3182 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3184 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3185 __ Subu(a2, a2, a3);
3187 // Make sure first argument is a string.
3188 __ lw(v0, MemOperand(sp, kStringOffset));
3189 __ JumpIfSmi(v0, &runtime);
3190 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3191 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3192 __ And(t0, a1, Operand(kIsNotStringMask));
3194 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3197 __ Branch(&single_char, eq, a2, Operand(1));
3199 // Short-cut for the case of trivial substring.
3201 // v0: original string
3202 // a2: result string length
3203 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
3205 // Return original string.
3206 __ Branch(&return_v0, eq, a2, Operand(t0));
3207 // Longer than original string's length or negative: unsafe arguments.
3208 __ Branch(&runtime, hi, a2, Operand(t0));
3209 // Shorter than original string's length: an actual substring.
3211 // Deal with different string types: update the index if necessary
3212 // and put the underlying string into t1.
3213 // v0: original string
3214 // a1: instance type
3216 // a3: from index (untagged)
3217 Label underlying_unpacked, sliced_string, seq_or_external_string;
3218 // If the string is not indirect, it can only be sequential or external.
3219 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3220 STATIC_ASSERT(kIsIndirectStringMask != 0);
3221 __ And(t0, a1, Operand(kIsIndirectStringMask));
3222 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
3223 // t0 is used as a scratch register and can be overwritten in either case.
3224 __ And(t0, a1, Operand(kSlicedNotConsMask));
3225 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
3226 // Cons string. Check whether it is flat, then fetch first part.
3227 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
3228 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
3229 __ Branch(&runtime, ne, t1, Operand(t0));
3230 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
3231 // Update instance type.
3232 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3233 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3234 __ jmp(&underlying_unpacked);
3236 __ bind(&sliced_string);
3237 // Sliced string. Fetch parent and correct start index by offset.
3238 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3239 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3240 __ sra(t0, t0, 1); // Add offset to index.
3241 __ Addu(a3, a3, t0);
3242 // Update instance type.
3243 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3244 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3245 __ jmp(&underlying_unpacked);
3247 __ bind(&seq_or_external_string);
3248 // Sequential or external string. Just move string to the expected register.
3251 __ bind(&underlying_unpacked);
3253 if (FLAG_string_slices) {
3255 // t1: underlying subject string
3256 // a1: instance type of underlying subject string
3258 // a3: adjusted start index (untagged)
3259 // Short slice. Copy instead of slicing.
3260 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3261 // Allocate new sliced string. At this point we do not reload the instance
3262 // type including the string encoding because we simply rely on the info
3263 // provided by the original string. It does not matter if the original
3264 // string's encoding is wrong because we always have to recheck encoding of
3265 // the newly created string's parent anyways due to externalized strings.
3266 Label two_byte_slice, set_slice_header;
3267 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3268 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3269 __ And(t0, a1, Operand(kStringEncodingMask));
3270 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
3271 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
3272 __ jmp(&set_slice_header);
3273 __ bind(&two_byte_slice);
3274 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
3275 __ bind(&set_slice_header);
3277 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3278 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3281 __ bind(©_routine);
3284 // t1: underlying subject string
3285 // a1: instance type of underlying subject string
3287 // a3: adjusted start index (untagged)
3288 Label two_byte_sequential, sequential_string, allocate_result;
3289 STATIC_ASSERT(kExternalStringTag != 0);
3290 STATIC_ASSERT(kSeqStringTag == 0);
3291 __ And(t0, a1, Operand(kExternalStringTag));
3292 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
3294 // Handle external string.
3295 // Rule out short external strings.
3296 STATIC_ASSERT(kShortExternalStringTag != 0);
3297 __ And(t0, a1, Operand(kShortExternalStringTag));
3298 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3299 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
3300 // t1 already points to the first character of underlying string.
3301 __ jmp(&allocate_result);
3303 __ bind(&sequential_string);
3304 // Locate first character of underlying subject string.
3305 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3306 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3308 __ bind(&allocate_result);
3309 // Sequential acii string. Allocate the result.
3310 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3311 __ And(t0, a1, Operand(kStringEncodingMask));
3312 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
3314 // Allocate and copy the resulting ASCII string.
3315 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
3317 // Locate first character of substring to copy.
3318 __ Addu(t1, t1, a3);
3320 // Locate first character of result.
3321 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3323 // v0: result string
3324 // a1: first character of result string
3325 // a2: result string length
3326 // t1: first character of substring to copy
3327 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3328 StringHelper::GenerateCopyCharacters(
3329 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
3332 // Allocate and copy the resulting two-byte string.
3333 __ bind(&two_byte_sequential);
3334 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
3336 // Locate first character of substring to copy.
3337 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3339 __ Addu(t1, t1, t0);
3340 // Locate first character of result.
3341 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3343 // v0: result string.
3344 // a1: first character of result.
3345 // a2: result length.
3346 // t1: first character of substring to copy.
3347 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3348 StringHelper::GenerateCopyCharacters(
3349 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
3351 __ bind(&return_v0);
3352 Counters* counters = isolate()->counters();
3353 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
3356 // Just jump to runtime to create the sub string.
3358 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3360 __ bind(&single_char);
3361 // v0: original string
3362 // a1: instance type
3364 // a3: from index (untagged)
3366 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3367 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3368 generator.GenerateFast(masm);
3370 generator.SkipSlow(masm, &runtime);
3374 void ToNumberStub::Generate(MacroAssembler* masm) {
3375 // The ToNumber stub takes one argument in a0.
3377 __ JumpIfNotSmi(a0, ¬_smi);
3378 __ Ret(USE_DELAY_SLOT);
3382 Label not_heap_number;
3383 __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3384 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3386 // a1: instance type.
3387 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3388 __ Ret(USE_DELAY_SLOT);
3390 __ bind(¬_heap_number);
3392 Label not_string, slow_string;
3393 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3394 // Check if string has a cached array index.
3395 __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3396 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3397 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3398 __ IndexFromHash(a2, a0);
3399 __ Ret(USE_DELAY_SLOT);
3401 __ bind(&slow_string);
3402 __ push(a0); // Push argument.
3403 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3404 __ bind(¬_string);
3407 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3408 __ Ret(USE_DELAY_SLOT);
3409 __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3410 __ bind(¬_oddball);
3412 __ push(a0); // Push argument.
3413 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3417 void StringHelper::GenerateFlatOneByteStringEquals(
3418 MacroAssembler* masm, Register left, Register right, Register scratch1,
3419 Register scratch2, Register scratch3) {
3420 Register length = scratch1;
3423 Label strings_not_equal, check_zero_length;
3424 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
3425 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3426 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3427 __ bind(&strings_not_equal);
3428 DCHECK(is_int16(NOT_EQUAL));
3429 __ Ret(USE_DELAY_SLOT);
3430 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3432 // Check if the length is zero.
3433 Label compare_chars;
3434 __ bind(&check_zero_length);
3435 STATIC_ASSERT(kSmiTag == 0);
3436 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3437 DCHECK(is_int16(EQUAL));
3438 __ Ret(USE_DELAY_SLOT);
3439 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3441 // Compare characters.
3442 __ bind(&compare_chars);
3444 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3445 v0, &strings_not_equal);
3447 // Characters are equal.
3448 __ Ret(USE_DELAY_SLOT);
3449 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3453 void StringHelper::GenerateCompareFlatOneByteStrings(
3454 MacroAssembler* masm, Register left, Register right, Register scratch1,
3455 Register scratch2, Register scratch3, Register scratch4) {
3456 Label result_not_equal, compare_lengths;
3457 // Find minimum length and length difference.
3458 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
3459 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3460 __ Subu(scratch3, scratch1, Operand(scratch2));
3461 Register length_delta = scratch3;
3462 __ slt(scratch4, scratch2, scratch1);
3463 __ Movn(scratch1, scratch2, scratch4);
3464 Register min_length = scratch1;
3465 STATIC_ASSERT(kSmiTag == 0);
3466 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3469 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3470 scratch4, v0, &result_not_equal);
3472 // Compare lengths - strings up to min-length are equal.
3473 __ bind(&compare_lengths);
3474 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3475 // Use length_delta as result if it's zero.
3476 __ mov(scratch2, length_delta);
3477 __ mov(scratch4, zero_reg);
3478 __ mov(v0, zero_reg);
3480 __ bind(&result_not_equal);
3481 // Conditionally update the result based either on length_delta or
3482 // the last comparion performed in the loop above.
3484 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3485 __ li(v0, Operand(Smi::FromInt(GREATER)));
3486 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3487 __ li(v0, Operand(Smi::FromInt(LESS)));
3493 void StringHelper::GenerateOneByteCharsCompareLoop(
3494 MacroAssembler* masm, Register left, Register right, Register length,
3495 Register scratch1, Register scratch2, Register scratch3,
3496 Label* chars_not_equal) {
3497 // Change index to run from -length to -1 by adding length to string
3498 // start. This means that loop ends when index reaches zero, which
3499 // doesn't need an additional compare.
3500 __ SmiUntag(length);
3501 __ Addu(scratch1, length,
3502 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3503 __ Addu(left, left, Operand(scratch1));
3504 __ Addu(right, right, Operand(scratch1));
3505 __ Subu(length, zero_reg, length);
3506 Register index = length; // index = -length;
3512 __ Addu(scratch3, left, index);
3513 __ lbu(scratch1, MemOperand(scratch3));
3514 __ Addu(scratch3, right, index);
3515 __ lbu(scratch2, MemOperand(scratch3));
3516 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3517 __ Addu(index, index, 1);
3518 __ Branch(&loop, ne, index, Operand(zero_reg));
3522 void StringCompareStub::Generate(MacroAssembler* masm) {
3525 Counters* counters = isolate()->counters();
3527 // Stack frame on entry.
3528 // sp[0]: right string
3529 // sp[4]: left string
3530 __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3531 __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3534 __ Branch(¬_same, ne, a0, Operand(a1));
3535 STATIC_ASSERT(EQUAL == 0);
3536 STATIC_ASSERT(kSmiTag == 0);
3537 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3538 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3543 // Check that both objects are sequential one-byte strings.
3544 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3546 // Compare flat ASCII strings natively. Remove arguments from stack first.
3547 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3548 __ Addu(sp, sp, Operand(2 * kPointerSize));
3549 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3552 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3556 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3557 // ----------- S t a t e -------------
3560 // -- ra : return address
3561 // -----------------------------------
3563 // Load a2 with the allocation site. We stick an undefined dummy value here
3564 // and replace it with the real allocation site later when we instantiate this
3565 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3566 __ li(a2, handle(isolate()->heap()->undefined_value()));
3568 // Make sure that we actually patched the allocation site.
3569 if (FLAG_debug_code) {
3570 __ And(at, a2, Operand(kSmiTagMask));
3571 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3572 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
3573 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3574 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
3577 // Tail call into the stub that handles binary operations with allocation
3579 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3580 __ TailCallStub(&stub);
3584 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3585 DCHECK(state() == CompareICState::SMI);
3588 __ JumpIfNotSmi(a2, &miss);
3590 if (GetCondition() == eq) {
3591 // For equality we do not care about the sign of the result.
3592 __ Ret(USE_DELAY_SLOT);
3593 __ Subu(v0, a0, a1);
3595 // Untag before subtracting to avoid handling overflow.
3598 __ Ret(USE_DELAY_SLOT);
3599 __ Subu(v0, a1, a0);
3607 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3608 DCHECK(state() == CompareICState::NUMBER);
3611 Label unordered, maybe_undefined1, maybe_undefined2;
3614 if (left() == CompareICState::SMI) {
3615 __ JumpIfNotSmi(a1, &miss);
3617 if (right() == CompareICState::SMI) {
3618 __ JumpIfNotSmi(a0, &miss);
3621 // Inlining the double comparison and falling back to the general compare
3622 // stub if NaN is involved.
3623 // Load left and right operand.
3624 Label done, left, left_smi, right_smi;
3625 __ JumpIfSmi(a0, &right_smi);
3626 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3628 __ Subu(a2, a0, Operand(kHeapObjectTag));
3629 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3631 __ bind(&right_smi);
3632 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3633 FPURegister single_scratch = f6;
3634 __ mtc1(a2, single_scratch);
3635 __ cvt_d_w(f2, single_scratch);
3638 __ JumpIfSmi(a1, &left_smi);
3639 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3641 __ Subu(a2, a1, Operand(kHeapObjectTag));
3642 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3645 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3646 single_scratch = f8;
3647 __ mtc1(a2, single_scratch);
3648 __ cvt_d_w(f0, single_scratch);
3652 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3653 Label fpu_eq, fpu_lt;
3654 // Test if equal, and also handle the unordered/NaN case.
3655 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3657 // Test if less (unordered case is already handled).
3658 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3660 // Otherwise it's greater, so just fall thru, and return.
3661 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3662 __ Ret(USE_DELAY_SLOT);
3663 __ li(v0, Operand(GREATER));
3666 __ Ret(USE_DELAY_SLOT);
3667 __ li(v0, Operand(EQUAL));
3670 __ Ret(USE_DELAY_SLOT);
3671 __ li(v0, Operand(LESS));
3673 __ bind(&unordered);
3674 __ bind(&generic_stub);
3675 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3676 CompareICState::GENERIC, CompareICState::GENERIC);
3677 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3679 __ bind(&maybe_undefined1);
3680 if (Token::IsOrderedRelationalCompareOp(op())) {
3681 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3682 __ Branch(&miss, ne, a0, Operand(at));
3683 __ JumpIfSmi(a1, &unordered);
3684 __ GetObjectType(a1, a2, a2);
3685 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3689 __ bind(&maybe_undefined2);
3690 if (Token::IsOrderedRelationalCompareOp(op())) {
3691 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3692 __ Branch(&unordered, eq, a1, Operand(at));
3700 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3701 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3704 // Registers containing left and right operands respectively.
3706 Register right = a0;
3710 // Check that both operands are heap objects.
3711 __ JumpIfEitherSmi(left, right, &miss);
3713 // Check that both operands are internalized strings.
3714 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3715 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3716 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3717 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3718 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3719 __ Or(tmp1, tmp1, Operand(tmp2));
3720 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3721 __ Branch(&miss, ne, at, Operand(zero_reg));
3723 // Make sure a0 is non-zero. At this point input operands are
3724 // guaranteed to be non-zero.
3725 DCHECK(right.is(a0));
3726 STATIC_ASSERT(EQUAL == 0);
3727 STATIC_ASSERT(kSmiTag == 0);
3729 // Internalized strings are compared by identity.
3730 __ Ret(ne, left, Operand(right));
3731 DCHECK(is_int16(EQUAL));
3732 __ Ret(USE_DELAY_SLOT);
3733 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3740 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3741 DCHECK(state() == CompareICState::UNIQUE_NAME);
3742 DCHECK(GetCondition() == eq);
3745 // Registers containing left and right operands respectively.
3747 Register right = a0;
3751 // Check that both operands are heap objects.
3752 __ JumpIfEitherSmi(left, right, &miss);
3754 // Check that both operands are unique names. This leaves the instance
3755 // types loaded in tmp1 and tmp2.
3756 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3757 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3758 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3759 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3761 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3762 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3767 // Unique names are compared by identity.
3769 __ Branch(&done, ne, left, Operand(right));
3770 // Make sure a0 is non-zero. At this point input operands are
3771 // guaranteed to be non-zero.
3772 DCHECK(right.is(a0));
3773 STATIC_ASSERT(EQUAL == 0);
3774 STATIC_ASSERT(kSmiTag == 0);
3775 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3784 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3785 DCHECK(state() == CompareICState::STRING);
3788 bool equality = Token::IsEqualityOp(op());
3790 // Registers containing left and right operands respectively.
3792 Register right = a0;
3799 // Check that both operands are heap objects.
3800 __ JumpIfEitherSmi(left, right, &miss);
3802 // Check that both operands are strings. This leaves the instance
3803 // types loaded in tmp1 and tmp2.
3804 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3805 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3806 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3807 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3808 STATIC_ASSERT(kNotStringTag != 0);
3809 __ Or(tmp3, tmp1, tmp2);
3810 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3811 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3813 // Fast check for identical strings.
3814 Label left_ne_right;
3815 STATIC_ASSERT(EQUAL == 0);
3816 STATIC_ASSERT(kSmiTag == 0);
3817 __ Branch(&left_ne_right, ne, left, Operand(right));
3818 __ Ret(USE_DELAY_SLOT);
3819 __ mov(v0, zero_reg); // In the delay slot.
3820 __ bind(&left_ne_right);
3822 // Handle not identical strings.
3824 // Check that both strings are internalized strings. If they are, we're done
3825 // because we already know they are not identical. We know they are both
3828 DCHECK(GetCondition() == eq);
3829 STATIC_ASSERT(kInternalizedTag == 0);
3830 __ Or(tmp3, tmp1, Operand(tmp2));
3831 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3833 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3834 // Make sure a0 is non-zero. At this point input operands are
3835 // guaranteed to be non-zero.
3836 DCHECK(right.is(a0));
3837 __ Ret(USE_DELAY_SLOT);
3838 __ mov(v0, a0); // In the delay slot.
3839 __ bind(&is_symbol);
3842 // Check that both strings are sequential one-byte.
3844 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3847 // Compare flat one-byte strings. Returns when done.
3849 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3852 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3856 // Handle more complex cases in runtime.
3858 __ Push(left, right);
3860 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3862 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3870 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3871 DCHECK(state() == CompareICState::OBJECT);
3873 __ And(a2, a1, Operand(a0));
3874 __ JumpIfSmi(a2, &miss);
3876 __ GetObjectType(a0, a2, a2);
3877 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3878 __ GetObjectType(a1, a2, a2);
3879 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3881 DCHECK(GetCondition() == eq);
3882 __ Ret(USE_DELAY_SLOT);
3883 __ subu(v0, a0, a1);
3890 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3892 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3894 __ JumpIfSmi(a2, &miss);
3895 __ GetWeakValue(t0, cell);
3896 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3897 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3898 __ Branch(&miss, ne, a2, Operand(t0));
3899 __ Branch(&miss, ne, a3, Operand(t0));
3901 __ Ret(USE_DELAY_SLOT);
3902 __ subu(v0, a0, a1);
3909 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3911 // Call the runtime system in a fresh internal frame.
3912 FrameScope scope(masm, StackFrame::INTERNAL);
3914 __ Push(ra, a1, a0);
3915 __ li(t0, Operand(Smi::FromInt(op())));
3916 __ addiu(sp, sp, -kPointerSize);
3917 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3919 __ sw(t0, MemOperand(sp)); // In the delay slot.
3920 // Compute the entry point of the rewritten stub.
3921 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3922 // Restore registers.
3929 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3930 // Make place for arguments to fit C calling convention. Most of the callers
3931 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3932 // so they handle stack restoring and we don't have to do that here.
3933 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3934 // kCArgsSlotsSize stack space after the call.
3935 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
3936 // Place the return address on the stack, making the call
3937 // GC safe. The RegExp backend also relies on this.
3938 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
3939 __ Call(t9); // Call the C++ function.
3940 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
3942 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3943 // In case of an error the return address may point to a memory area
3944 // filled with kZapValue by the GC.
3945 // Dereference the address and check for this.
3946 __ lw(t0, MemOperand(t9));
3947 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
3948 Operand(reinterpret_cast<uint32_t>(kZapValue)));
3954 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3957 reinterpret_cast<intptr_t>(GetCode().location());
3958 __ Move(t9, target);
3959 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3964 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3968 Register properties,
3970 Register scratch0) {
3971 DCHECK(name->IsUniqueName());
3972 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3973 // not equal to the name and kProbes-th slot is not used (its name is the
3974 // undefined value), it guarantees the hash table doesn't contain the
3975 // property. It's true even if some slots represent deleted properties
3976 // (their names are the hole value).
3977 for (int i = 0; i < kInlinedProbes; i++) {
3978 // scratch0 points to properties hash.
3979 // Compute the masked index: (hash + i + i * i) & mask.
3980 Register index = scratch0;
3981 // Capacity is smi 2^n.
3982 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
3983 __ Subu(index, index, Operand(1));
3984 __ And(index, index, Operand(
3985 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3987 // Scale the index by multiplying by the entry size.
3988 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3989 __ sll(at, index, 1);
3990 __ Addu(index, index, at);
3992 Register entity_name = scratch0;
3993 // Having undefined at this place means the name is not contained.
3994 STATIC_ASSERT(kSmiTagSize == 1);
3995 Register tmp = properties;
3996 __ sll(scratch0, index, 1);
3997 __ Addu(tmp, properties, scratch0);
3998 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4000 DCHECK(!tmp.is(entity_name));
4001 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4002 __ Branch(done, eq, entity_name, Operand(tmp));
4004 // Load the hole ready for use below:
4005 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4007 // Stop if found the property.
4008 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4011 __ Branch(&good, eq, entity_name, Operand(tmp));
4013 // Check if the entry name is not a unique name.
4014 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4016 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4017 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4020 // Restore the properties.
4022 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4025 const int spill_mask =
4026 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
4027 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4029 __ MultiPush(spill_mask);
4030 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4031 __ li(a1, Operand(Handle<Name>(name)));
4032 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4035 __ MultiPop(spill_mask);
4037 __ Branch(done, eq, at, Operand(zero_reg));
4038 __ Branch(miss, ne, at, Operand(zero_reg));
4042 // Probe the name dictionary in the |elements| register. Jump to the
4043 // |done| label if a property with the given name is found. Jump to
4044 // the |miss| label otherwise.
4045 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4046 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4052 Register scratch2) {
4053 DCHECK(!elements.is(scratch1));
4054 DCHECK(!elements.is(scratch2));
4055 DCHECK(!name.is(scratch1));
4056 DCHECK(!name.is(scratch2));
4058 __ AssertName(name);
4060 // Compute the capacity mask.
4061 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
4062 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
4063 __ Subu(scratch1, scratch1, Operand(1));
4065 // Generate an unrolled loop that performs a few probes before
4066 // giving up. Measurements done on Gmail indicate that 2 probes
4067 // cover ~93% of loads from dictionaries.
4068 for (int i = 0; i < kInlinedProbes; i++) {
4069 // Compute the masked index: (hash + i + i * i) & mask.
4070 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4072 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4073 // the hash in a separate instruction. The value hash + i + i * i is right
4074 // shifted in the following and instruction.
4075 DCHECK(NameDictionary::GetProbeOffset(i) <
4076 1 << (32 - Name::kHashFieldOffset));
4077 __ Addu(scratch2, scratch2, Operand(
4078 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4080 __ srl(scratch2, scratch2, Name::kHashShift);
4081 __ And(scratch2, scratch1, scratch2);
4083 // Scale the index by multiplying by the element size.
4084 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4085 // scratch2 = scratch2 * 3.
4087 __ sll(at, scratch2, 1);
4088 __ Addu(scratch2, scratch2, at);
4090 // Check if the key is identical to the name.
4091 __ sll(at, scratch2, 2);
4092 __ Addu(scratch2, elements, at);
4093 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
4094 __ Branch(done, eq, name, Operand(at));
4097 const int spill_mask =
4098 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
4099 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4100 ~(scratch1.bit() | scratch2.bit());
4102 __ MultiPush(spill_mask);
4104 DCHECK(!elements.is(a1));
4106 __ Move(a0, elements);
4108 __ Move(a0, elements);
4111 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4113 __ mov(scratch2, a2);
4115 __ MultiPop(spill_mask);
4117 __ Branch(done, ne, at, Operand(zero_reg));
4118 __ Branch(miss, eq, at, Operand(zero_reg));
4122 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4123 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4124 // we cannot call anything that could cause a GC from this stub.
4126 // result: NameDictionary to probe
4128 // dictionary: NameDictionary to probe.
4129 // index: will hold an index of entry if lookup is successful.
4130 // might alias with result_.
4132 // result_ is zero if lookup failed, non zero otherwise.
4134 Register result = v0;
4135 Register dictionary = a0;
4137 Register index = a2;
4140 Register undefined = t1;
4141 Register entry_key = t2;
4143 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4145 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
4146 __ sra(mask, mask, kSmiTagSize);
4147 __ Subu(mask, mask, Operand(1));
4149 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4151 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4153 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4154 // Compute the masked index: (hash + i + i * i) & mask.
4155 // Capacity is smi 2^n.
4157 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4158 // the hash in a separate instruction. The value hash + i + i * i is right
4159 // shifted in the following and instruction.
4160 DCHECK(NameDictionary::GetProbeOffset(i) <
4161 1 << (32 - Name::kHashFieldOffset));
4162 __ Addu(index, hash, Operand(
4163 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4165 __ mov(index, hash);
4167 __ srl(index, index, Name::kHashShift);
4168 __ And(index, mask, index);
4170 // Scale the index by multiplying by the entry size.
4171 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4174 __ sll(index, index, 1);
4175 __ Addu(index, index, at);
4178 STATIC_ASSERT(kSmiTagSize == 1);
4179 __ sll(index, index, 2);
4180 __ Addu(index, index, dictionary);
4181 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
4183 // Having undefined at this place means the name is not contained.
4184 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4186 // Stop if found the property.
4187 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4189 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4190 // Check if the entry name is not a unique name.
4191 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4193 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4194 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4198 __ bind(&maybe_in_dictionary);
4199 // If we are doing negative lookup then probing failure should be
4200 // treated as a lookup success. For positive lookup probing failure
4201 // should be treated as lookup failure.
4202 if (mode() == POSITIVE_LOOKUP) {
4203 __ Ret(USE_DELAY_SLOT);
4204 __ mov(result, zero_reg);
4207 __ bind(&in_dictionary);
4208 __ Ret(USE_DELAY_SLOT);
4211 __ bind(¬_in_dictionary);
4212 __ Ret(USE_DELAY_SLOT);
4213 __ mov(result, zero_reg);
4217 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4219 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4221 // Hydrogen code stubs need stub2 at snapshot time.
4222 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4227 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4228 // the value has just been written into the object, now this stub makes sure
4229 // we keep the GC informed. The word in the object where the value has been
4230 // written is in the address register.
4231 void RecordWriteStub::Generate(MacroAssembler* masm) {
4232 Label skip_to_incremental_noncompacting;
4233 Label skip_to_incremental_compacting;
4235 // The first two branch+nop instructions are generated with labels so as to
4236 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4237 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4238 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4239 // incremental heap marking.
4240 // See RecordWriteStub::Patch for details.
4241 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4243 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4246 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4247 __ RememberedSetHelper(object(),
4250 save_fp_regs_mode(),
4251 MacroAssembler::kReturnAtEnd);
4255 __ bind(&skip_to_incremental_noncompacting);
4256 GenerateIncremental(masm, INCREMENTAL);
4258 __ bind(&skip_to_incremental_compacting);
4259 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4261 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4262 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4264 PatchBranchIntoNop(masm, 0);
4265 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4269 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4272 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4273 Label dont_need_remembered_set;
4275 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4276 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4278 &dont_need_remembered_set);
4280 __ CheckPageFlag(regs_.object(),
4282 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4284 &dont_need_remembered_set);
4286 // First notify the incremental marker if necessary, then update the
4288 CheckNeedsToInformIncrementalMarker(
4289 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4290 InformIncrementalMarker(masm);
4291 regs_.Restore(masm);
4292 __ RememberedSetHelper(object(),
4295 save_fp_regs_mode(),
4296 MacroAssembler::kReturnAtEnd);
4298 __ bind(&dont_need_remembered_set);
4301 CheckNeedsToInformIncrementalMarker(
4302 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4303 InformIncrementalMarker(masm);
4304 regs_.Restore(masm);
4309 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4310 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4311 int argument_count = 3;
4312 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4314 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4315 DCHECK(!address.is(regs_.object()));
4316 DCHECK(!address.is(a0));
4317 __ Move(address, regs_.address());
4318 __ Move(a0, regs_.object());
4319 __ Move(a1, address);
4320 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4322 AllowExternalCallThatCantCauseGC scope(masm);
4324 ExternalReference::incremental_marking_record_write_function(isolate()),
4326 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4330 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4331 MacroAssembler* masm,
4332 OnNoNeedToInformIncrementalMarker on_no_need,
4335 Label need_incremental;
4336 Label need_incremental_pop_scratch;
4338 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4339 __ lw(regs_.scratch1(),
4340 MemOperand(regs_.scratch0(),
4341 MemoryChunk::kWriteBarrierCounterOffset));
4342 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4343 __ sw(regs_.scratch1(),
4344 MemOperand(regs_.scratch0(),
4345 MemoryChunk::kWriteBarrierCounterOffset));
4346 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4348 // Let's look at the color of the object: If it is not black we don't have
4349 // to inform the incremental marker.
4350 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4352 regs_.Restore(masm);
4353 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4354 __ RememberedSetHelper(object(),
4357 save_fp_regs_mode(),
4358 MacroAssembler::kReturnAtEnd);
4365 // Get the value from the slot.
4366 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4368 if (mode == INCREMENTAL_COMPACTION) {
4369 Label ensure_not_white;
4371 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4372 regs_.scratch1(), // Scratch.
4373 MemoryChunk::kEvacuationCandidateMask,
4377 __ CheckPageFlag(regs_.object(),
4378 regs_.scratch1(), // Scratch.
4379 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4383 __ bind(&ensure_not_white);
4386 // We need extra registers for this, so we push the object and the address
4387 // register temporarily.
4388 __ Push(regs_.object(), regs_.address());
4389 __ EnsureNotWhite(regs_.scratch0(), // The value.
4390 regs_.scratch1(), // Scratch.
4391 regs_.object(), // Scratch.
4392 regs_.address(), // Scratch.
4393 &need_incremental_pop_scratch);
4394 __ Pop(regs_.object(), regs_.address());
4396 regs_.Restore(masm);
4397 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4398 __ RememberedSetHelper(object(),
4401 save_fp_regs_mode(),
4402 MacroAssembler::kReturnAtEnd);
4407 __ bind(&need_incremental_pop_scratch);
4408 __ Pop(regs_.object(), regs_.address());
4410 __ bind(&need_incremental);
4412 // Fall through when we need to inform the incremental marker.
4416 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4417 // ----------- S t a t e -------------
4418 // -- a0 : element value to store
4419 // -- a3 : element index as smi
4420 // -- sp[0] : array literal index in function as smi
4421 // -- sp[4] : array literal
4422 // clobbers a1, a2, t0
4423 // -----------------------------------
4426 Label double_elements;
4428 Label slow_elements;
4429 Label fast_elements;
4431 // Get array literal index, array literal and its map.
4432 __ lw(t0, MemOperand(sp, 0 * kPointerSize));
4433 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
4434 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4436 __ CheckFastElements(a2, t1, &double_elements);
4437 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4438 __ JumpIfSmi(a0, &smi_element);
4439 __ CheckFastSmiElements(a2, t1, &fast_elements);
4441 // Store into the array literal requires a elements transition. Call into
4443 __ bind(&slow_elements);
4445 __ Push(a1, a3, a0);
4446 __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4447 __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset));
4449 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4451 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4452 __ bind(&fast_elements);
4453 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4454 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4455 __ Addu(t2, t1, t2);
4456 __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4457 __ sw(a0, MemOperand(t2, 0));
4458 // Update the write barrier for the array store.
4459 __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4460 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4461 __ Ret(USE_DELAY_SLOT);
4464 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4465 // and value is Smi.
4466 __ bind(&smi_element);
4467 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4468 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4469 __ Addu(t2, t1, t2);
4470 __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize));
4471 __ Ret(USE_DELAY_SLOT);
4474 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4475 __ bind(&double_elements);
4476 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4477 __ StoreNumberToDoubleElements(a0, a3, t1, t3, t5, a2, &slow_elements);
4478 __ Ret(USE_DELAY_SLOT);
4483 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4484 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4485 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4486 int parameter_count_offset =
4487 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4488 __ lw(a1, MemOperand(fp, parameter_count_offset));
4489 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4490 __ Addu(a1, a1, Operand(1));
4492 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4493 __ sll(a1, a1, kPointerSizeLog2);
4494 __ Ret(USE_DELAY_SLOT);
4495 __ Addu(sp, sp, a1);
4499 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4500 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4501 LoadICStub stub(isolate(), state());
4502 stub.GenerateForTrampoline(masm);
4506 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4507 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4508 KeyedLoadICStub stub(isolate(), state());
4509 stub.GenerateForTrampoline(masm);
4513 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4514 EmitLoadTypeFeedbackVector(masm, a2);
4515 CallICStub stub(isolate(), state());
4516 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4520 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4521 EmitLoadTypeFeedbackVector(masm, a2);
4522 CallIC_ArrayStub stub(isolate(), state());
4523 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4527 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4530 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4531 GenerateImpl(masm, true);
4535 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4536 Register key, Register vector, Register slot,
4537 Register feedback, Register receiver_map,
4538 Register scratch1, Register scratch2,
4539 bool is_polymorphic, Label* miss) {
4540 // feedback initially contains the feedback array
4541 Label next_loop, prepare_next;
4542 Label start_polymorphic;
4544 Register cached_map = scratch1;
4547 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4548 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4549 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4550 // found, now call handler.
4551 Register handler = feedback;
4552 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4553 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4557 Register length = scratch2;
4558 __ bind(&start_polymorphic);
4559 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4560 if (!is_polymorphic) {
4561 // If the IC could be monomorphic we have to make sure we don't go past the
4562 // end of the feedback array.
4563 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4566 Register too_far = length;
4567 Register pointer_reg = feedback;
4569 // +-----+------+------+-----+-----+ ... ----+
4570 // | map | len | wm0 | h0 | wm1 | hN |
4571 // +-----+------+------+-----+-----+ ... ----+
4575 // pointer_reg too_far
4576 // aka feedback scratch2
4577 // also need receiver_map
4578 // use cached_map (scratch1) to look in the weak map values.
4579 __ sll(at, length, kPointerSizeLog2 - kSmiTagSize);
4580 __ Addu(too_far, feedback, Operand(at));
4581 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4582 __ Addu(pointer_reg, feedback,
4583 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4585 __ bind(&next_loop);
4586 __ lw(cached_map, MemOperand(pointer_reg));
4587 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4588 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4589 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
4590 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4593 __ bind(&prepare_next);
4594 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4595 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4597 // We exhausted our array of map handler pairs.
4602 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4603 Register receiver_map, Register feedback,
4604 Register vector, Register slot,
4605 Register scratch, Label* compare_map,
4606 Label* load_smi_map, Label* try_array) {
4607 __ JumpIfSmi(receiver, load_smi_map);
4608 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4609 __ bind(compare_map);
4610 Register cached_map = scratch;
4611 // Move the weak map into the weak_cell register.
4612 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4613 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4614 Register handler = feedback;
4616 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4617 __ Addu(handler, vector, Operand(at));
4619 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4620 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4625 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4626 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4627 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4628 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4629 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4630 Register feedback = t0;
4631 Register receiver_map = t1;
4632 Register scratch1 = t4;
4634 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4635 __ Addu(feedback, vector, Operand(at));
4636 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4638 // Try to quickly handle the monomorphic case without knowing for sure
4639 // if we have a weak cell in feedback. We do know it's safe to look
4640 // at WeakCell::kValueOffset.
4641 Label try_array, load_smi_map, compare_map;
4642 Label not_array, miss;
4643 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4644 scratch1, &compare_map, &load_smi_map, &try_array);
4646 // Is it a fixed array?
4647 __ bind(&try_array);
4648 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4649 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4650 __ Branch(¬_array, ne, at, Operand(scratch1));
4651 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4652 scratch1, t5, true, &miss);
4654 __ bind(¬_array);
4655 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4656 __ Branch(&miss, ne, at, Operand(feedback));
4657 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4658 Code::ComputeHandlerFlags(Code::LOAD_IC));
4659 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4660 receiver, name, feedback,
4661 receiver_map, scratch1, t5);
4664 LoadIC::GenerateMiss(masm);
4666 __ bind(&load_smi_map);
4667 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4668 __ jmp(&compare_map);
4672 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4673 GenerateImpl(masm, false);
4677 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4678 GenerateImpl(masm, true);
4682 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4683 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4684 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4685 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4686 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4687 Register feedback = t0;
4688 Register receiver_map = t1;
4689 Register scratch1 = t4;
4691 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4692 __ Addu(feedback, vector, Operand(at));
4693 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4695 // Try to quickly handle the monomorphic case without knowing for sure
4696 // if we have a weak cell in feedback. We do know it's safe to look
4697 // at WeakCell::kValueOffset.
4698 Label try_array, load_smi_map, compare_map;
4699 Label not_array, miss;
4700 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4701 scratch1, &compare_map, &load_smi_map, &try_array);
4703 __ bind(&try_array);
4704 // Is it a fixed array?
4705 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4706 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4707 __ Branch(¬_array, ne, at, Operand(scratch1));
4708 // We have a polymorphic element handler.
4709 __ JumpIfNotSmi(key, &miss);
4711 Label polymorphic, try_poly_name;
4712 __ bind(&polymorphic);
4713 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4714 scratch1, t5, true, &miss);
4716 __ bind(¬_array);
4718 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4719 __ Branch(&try_poly_name, ne, at, Operand(feedback));
4720 Handle<Code> megamorphic_stub =
4721 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4722 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4724 __ bind(&try_poly_name);
4725 // We might have a name in feedback, and a fixed array in the next slot.
4726 __ Branch(&miss, ne, key, Operand(feedback));
4727 // If the name comparison succeeded, we know we have a fixed array with
4728 // at least one map/handler pair.
4729 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4730 __ Addu(feedback, vector, Operand(at));
4732 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4733 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4734 scratch1, t5, false, &miss);
4737 KeyedLoadIC::GenerateMiss(masm);
4739 __ bind(&load_smi_map);
4740 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4741 __ jmp(&compare_map);
4745 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4746 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4747 VectorStoreICStub stub(isolate(), state());
4748 stub.GenerateForTrampoline(masm);
4752 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4753 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4754 VectorKeyedStoreICStub stub(isolate(), state());
4755 stub.GenerateForTrampoline(masm);
4759 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4760 GenerateImpl(masm, false);
4764 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4765 GenerateImpl(masm, true);
4769 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4772 // TODO(mvstanton): Implement.
4774 StoreIC::GenerateMiss(masm);
4778 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4779 GenerateImpl(masm, false);
4783 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4784 GenerateImpl(masm, true);
4788 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4791 // TODO(mvstanton): Implement.
4793 KeyedStoreIC::GenerateMiss(masm);
4797 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4798 if (masm->isolate()->function_entry_hook() != NULL) {
4799 ProfileEntryHookStub stub(masm->isolate());
4807 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4808 // The entry hook is a "push ra" instruction, followed by a call.
4809 // Note: on MIPS "push" is 2 instruction
4810 const int32_t kReturnAddressDistanceFromFunctionStart =
4811 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4813 // This should contain all kJSCallerSaved registers.
4814 const RegList kSavedRegs =
4815 kJSCallerSaved | // Caller saved registers.
4816 s5.bit(); // Saved stack pointer.
4818 // We also save ra, so the count here is one higher than the mask indicates.
4819 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4821 // Save all caller-save registers as this may be called from anywhere.
4822 __ MultiPush(kSavedRegs | ra.bit());
4824 // Compute the function's address for the first argument.
4825 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4827 // The caller's return address is above the saved temporaries.
4828 // Grab that for the second argument to the hook.
4829 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4831 // Align the stack if necessary.
4832 int frame_alignment = masm->ActivationFrameAlignment();
4833 if (frame_alignment > kPointerSize) {
4835 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4836 __ And(sp, sp, Operand(-frame_alignment));
4838 __ Subu(sp, sp, kCArgsSlotsSize);
4839 #if defined(V8_HOST_ARCH_MIPS)
4840 int32_t entry_hook =
4841 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4842 __ li(t9, Operand(entry_hook));
4844 // Under the simulator we need to indirect the entry hook through a
4845 // trampoline function at a known address.
4846 // It additionally takes an isolate as a third parameter.
4847 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4849 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4850 __ li(t9, Operand(ExternalReference(&dispatcher,
4851 ExternalReference::BUILTIN_CALL,
4854 // Call C function through t9 to conform ABI for PIC.
4857 // Restore the stack pointer if needed.
4858 if (frame_alignment > kPointerSize) {
4861 __ Addu(sp, sp, kCArgsSlotsSize);
4864 // Also pop ra to get Ret(0).
4865 __ MultiPop(kSavedRegs | ra.bit());
4871 static void CreateArrayDispatch(MacroAssembler* masm,
4872 AllocationSiteOverrideMode mode) {
4873 if (mode == DISABLE_ALLOCATION_SITES) {
4874 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4875 __ TailCallStub(&stub);
4876 } else if (mode == DONT_OVERRIDE) {
4877 int last_index = GetSequenceIndexFromFastElementsKind(
4878 TERMINAL_FAST_ELEMENTS_KIND);
4879 for (int i = 0; i <= last_index; ++i) {
4880 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4881 T stub(masm->isolate(), kind);
4882 __ TailCallStub(&stub, eq, a3, Operand(kind));
4885 // If we reached this point there is a problem.
4886 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4893 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4894 AllocationSiteOverrideMode mode) {
4895 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4896 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4897 // a0 - number of arguments
4898 // a1 - constructor?
4899 // sp[0] - last argument
4900 Label normal_sequence;
4901 if (mode == DONT_OVERRIDE) {
4902 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4903 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4904 STATIC_ASSERT(FAST_ELEMENTS == 2);
4905 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4906 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
4907 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4909 // is the low bit set? If so, we are holey and that is good.
4910 __ And(at, a3, Operand(1));
4911 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
4914 // look at the first argument
4915 __ lw(t1, MemOperand(sp, 0));
4916 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
4918 if (mode == DISABLE_ALLOCATION_SITES) {
4919 ElementsKind initial = GetInitialFastElementsKind();
4920 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4922 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4924 DISABLE_ALLOCATION_SITES);
4925 __ TailCallStub(&stub_holey);
4927 __ bind(&normal_sequence);
4928 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4930 DISABLE_ALLOCATION_SITES);
4931 __ TailCallStub(&stub);
4932 } else if (mode == DONT_OVERRIDE) {
4933 // We are going to create a holey array, but our kind is non-holey.
4934 // Fix kind and retry (only if we have an allocation site in the slot).
4935 __ Addu(a3, a3, Operand(1));
4937 if (FLAG_debug_code) {
4938 __ lw(t1, FieldMemOperand(a2, 0));
4939 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
4940 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
4943 // Save the resulting elements kind in type info. We can't just store a3
4944 // in the AllocationSite::transition_info field because elements kind is
4945 // restricted to a portion of the field...upper bits need to be left alone.
4946 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4947 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4948 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
4949 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
4952 __ bind(&normal_sequence);
4953 int last_index = GetSequenceIndexFromFastElementsKind(
4954 TERMINAL_FAST_ELEMENTS_KIND);
4955 for (int i = 0; i <= last_index; ++i) {
4956 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4957 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4958 __ TailCallStub(&stub, eq, a3, Operand(kind));
4961 // If we reached this point there is a problem.
4962 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4970 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4971 int to_index = GetSequenceIndexFromFastElementsKind(
4972 TERMINAL_FAST_ELEMENTS_KIND);
4973 for (int i = 0; i <= to_index; ++i) {
4974 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4975 T stub(isolate, kind);
4977 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4978 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4985 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4986 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4988 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4990 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4995 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4997 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4998 for (int i = 0; i < 2; i++) {
4999 // For internal arrays we only need a few things.
5000 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5002 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5004 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5010 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5011 MacroAssembler* masm,
5012 AllocationSiteOverrideMode mode) {
5013 if (argument_count() == ANY) {
5014 Label not_zero_case, not_one_case;
5016 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5017 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5019 __ bind(¬_zero_case);
5020 __ Branch(¬_one_case, gt, a0, Operand(1));
5021 CreateArrayDispatchOneArgument(masm, mode);
5023 __ bind(¬_one_case);
5024 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5025 } else if (argument_count() == NONE) {
5026 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5027 } else if (argument_count() == ONE) {
5028 CreateArrayDispatchOneArgument(masm, mode);
5029 } else if (argument_count() == MORE_THAN_ONE) {
5030 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5037 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5038 // ----------- S t a t e -------------
5039 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5040 // -- a1 : constructor
5041 // -- a2 : AllocationSite or undefined
5042 // -- a3 : Original constructor
5043 // -- sp[0] : last argument
5044 // -----------------------------------
5046 if (FLAG_debug_code) {
5047 // The array construct code is only set for the global and natives
5048 // builtin Array functions which always have maps.
5050 // Initial map for the builtin Array function should be a map.
5051 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5052 // Will both indicate a NULL and a Smi.
5054 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5055 at, Operand(zero_reg));
5056 __ GetObjectType(t0, t0, t1);
5057 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5058 t1, Operand(MAP_TYPE));
5060 // We should either have undefined in a2 or a valid AllocationSite
5061 __ AssertUndefinedOrAllocationSite(a2, t0);
5065 __ Branch(&subclassing, ne, a1, Operand(a3));
5068 // Get the elements kind and case on that.
5069 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5070 __ Branch(&no_info, eq, a2, Operand(at));
5072 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5074 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5075 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5076 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5079 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5082 __ bind(&subclassing);
5087 switch (argument_count()) {
5090 __ li(at, Operand(2));
5091 __ addu(a0, a0, at);
5094 __ li(a0, Operand(2));
5097 __ li(a0, Operand(3));
5101 __ JumpToExternalReference(
5102 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5106 void InternalArrayConstructorStub::GenerateCase(
5107 MacroAssembler* masm, ElementsKind kind) {
5109 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5110 __ TailCallStub(&stub0, lo, a0, Operand(1));
5112 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5113 __ TailCallStub(&stubN, hi, a0, Operand(1));
5115 if (IsFastPackedElementsKind(kind)) {
5116 // We might need to create a holey array
5117 // look at the first argument.
5118 __ lw(at, MemOperand(sp, 0));
5120 InternalArraySingleArgumentConstructorStub
5121 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5122 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5125 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5126 __ TailCallStub(&stub1);
5130 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5131 // ----------- S t a t e -------------
5133 // -- a1 : constructor
5134 // -- sp[0] : return address
5135 // -- sp[4] : last argument
5136 // -----------------------------------
5138 if (FLAG_debug_code) {
5139 // The array construct code is only set for the global and natives
5140 // builtin Array functions which always have maps.
5142 // Initial map for the builtin Array function should be a map.
5143 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5144 // Will both indicate a NULL and a Smi.
5146 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5147 at, Operand(zero_reg));
5148 __ GetObjectType(a3, a3, t0);
5149 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5150 t0, Operand(MAP_TYPE));
5153 // Figure out the right elements kind.
5154 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5156 // Load the map's "bit field 2" into a3. We only need the first byte,
5157 // but the following bit field extraction takes care of that anyway.
5158 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5159 // Retrieve elements_kind from bit field 2.
5160 __ DecodeField<Map::ElementsKindBits>(a3);
5162 if (FLAG_debug_code) {
5164 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5166 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5167 a3, Operand(FAST_HOLEY_ELEMENTS));
5171 Label fast_elements_case;
5172 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5173 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5175 __ bind(&fast_elements_case);
5176 GenerateCase(masm, FAST_ELEMENTS);
5180 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5181 Register context_reg = cp;
5182 Register slot_reg = a2;
5183 Register result_reg = v0;
5186 // Go up context chain to the script context.
5187 for (int i = 0; i < depth(); ++i) {
5188 __ lw(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5189 context_reg = result_reg;
5192 // Load the PropertyCell value at the specified slot.
5193 __ sll(at, slot_reg, kPointerSizeLog2);
5194 __ Addu(at, at, Operand(context_reg));
5195 __ lw(result_reg, ContextOperand(at, 0));
5196 __ lw(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5198 // Check that value is not the_hole.
5199 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5200 __ Branch(&slow_case, eq, result_reg, Operand(at));
5203 // Fallback to the runtime.
5204 __ bind(&slow_case);
5205 __ SmiTag(slot_reg);
5207 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5211 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5212 Register context_reg = cp;
5213 Register slot_reg = a2;
5214 Register value_reg = a0;
5215 Register cell_reg = t0;
5216 Register cell_value_reg = t1;
5217 Register cell_details_reg = t2;
5218 Label fast_heapobject_case, fast_smi_case, slow_case;
5220 if (FLAG_debug_code) {
5221 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5222 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5225 // Go up context chain to the script context.
5226 for (int i = 0; i < depth(); ++i) {
5227 __ lw(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5228 context_reg = cell_reg;
5231 // Load the PropertyCell at the specified slot.
5232 __ sll(at, slot_reg, kPointerSizeLog2);
5233 __ Addu(at, at, Operand(context_reg));
5234 __ lw(cell_reg, ContextOperand(at, 0));
5236 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5237 __ lw(cell_details_reg,
5238 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5239 __ SmiUntag(cell_details_reg);
5240 __ And(cell_details_reg, cell_details_reg,
5241 PropertyDetails::PropertyCellTypeField::kMask |
5242 PropertyDetails::KindField::kMask |
5243 PropertyDetails::kAttributesReadOnlyMask);
5245 // Check if PropertyCell holds mutable data.
5246 Label not_mutable_data;
5247 __ Branch(¬_mutable_data, ne, cell_details_reg,
5248 Operand(PropertyDetails::PropertyCellTypeField::encode(
5249 PropertyCellType::kMutable) |
5250 PropertyDetails::KindField::encode(kData)));
5251 __ JumpIfSmi(value_reg, &fast_smi_case);
5252 __ bind(&fast_heapobject_case);
5253 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5254 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5255 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5256 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5257 // RecordWriteField clobbers the value register, so we need to reload.
5258 __ Ret(USE_DELAY_SLOT);
5259 __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5260 __ bind(¬_mutable_data);
5262 // Check if PropertyCell value matches the new value (relevant for Constant,
5263 // ConstantType and Undefined cells).
5264 Label not_same_value;
5265 __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5266 __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg));
5267 // Make sure the PropertyCell is not marked READ_ONLY.
5268 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5269 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5270 if (FLAG_debug_code) {
5272 // This can only be true for Constant, ConstantType and Undefined cells,
5273 // because we never store the_hole via this stub.
5274 __ Branch(&done, eq, cell_details_reg,
5275 Operand(PropertyDetails::PropertyCellTypeField::encode(
5276 PropertyCellType::kConstant) |
5277 PropertyDetails::KindField::encode(kData)));
5278 __ Branch(&done, eq, cell_details_reg,
5279 Operand(PropertyDetails::PropertyCellTypeField::encode(
5280 PropertyCellType::kConstantType) |
5281 PropertyDetails::KindField::encode(kData)));
5282 __ Check(eq, kUnexpectedValue, cell_details_reg,
5283 Operand(PropertyDetails::PropertyCellTypeField::encode(
5284 PropertyCellType::kUndefined) |
5285 PropertyDetails::KindField::encode(kData)));
5289 __ bind(¬_same_value);
5291 // Check if PropertyCell contains data with constant type (and is not
5293 __ Branch(&slow_case, ne, cell_details_reg,
5294 Operand(PropertyDetails::PropertyCellTypeField::encode(
5295 PropertyCellType::kConstantType) |
5296 PropertyDetails::KindField::encode(kData)));
5298 // Now either both old and new values must be SMIs or both must be heap
5299 // objects with same map.
5300 Label value_is_heap_object;
5301 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5302 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5303 // Old and new values are SMIs, no need for a write barrier here.
5304 __ bind(&fast_smi_case);
5305 __ Ret(USE_DELAY_SLOT);
5306 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5307 __ bind(&value_is_heap_object);
5308 __ JumpIfSmi(cell_value_reg, &slow_case);
5309 Register cell_value_map_reg = cell_value_reg;
5310 __ lw(cell_value_map_reg,
5311 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5312 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5313 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5315 // Fallback to the runtime.
5316 __ bind(&slow_case);
5317 __ SmiTag(slot_reg);
5318 __ Push(slot_reg, value_reg);
5319 __ TailCallRuntime(is_strict(language_mode())
5320 ? Runtime::kStoreGlobalViaContext_Strict
5321 : Runtime::kStoreGlobalViaContext_Sloppy,
5326 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5327 return ref0.address() - ref1.address();
5331 // Calls an API function. Allocates HandleScope, extracts returned value
5332 // from handle and propagates exceptions. Restores context. stack_space
5333 // - space to be unwound on exit (includes the call JS arguments space and
5334 // the additional space allocated for the fast call).
5335 static void CallApiFunctionAndReturn(
5336 MacroAssembler* masm, Register function_address,
5337 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5338 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5339 Isolate* isolate = masm->isolate();
5340 ExternalReference next_address =
5341 ExternalReference::handle_scope_next_address(isolate);
5342 const int kNextOffset = 0;
5343 const int kLimitOffset = AddressOffset(
5344 ExternalReference::handle_scope_limit_address(isolate), next_address);
5345 const int kLevelOffset = AddressOffset(
5346 ExternalReference::handle_scope_level_address(isolate), next_address);
5348 DCHECK(function_address.is(a1) || function_address.is(a2));
5350 Label profiler_disabled;
5351 Label end_profiler_check;
5352 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5353 __ lb(t9, MemOperand(t9, 0));
5354 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5356 // Additional parameter is the address of the actual callback.
5357 __ li(t9, Operand(thunk_ref));
5358 __ jmp(&end_profiler_check);
5360 __ bind(&profiler_disabled);
5361 __ mov(t9, function_address);
5362 __ bind(&end_profiler_check);
5364 // Allocate HandleScope in callee-save registers.
5365 __ li(s3, Operand(next_address));
5366 __ lw(s0, MemOperand(s3, kNextOffset));
5367 __ lw(s1, MemOperand(s3, kLimitOffset));
5368 __ lw(s2, MemOperand(s3, kLevelOffset));
5369 __ Addu(s2, s2, Operand(1));
5370 __ sw(s2, MemOperand(s3, kLevelOffset));
5372 if (FLAG_log_timer_events) {
5373 FrameScope frame(masm, StackFrame::MANUAL);
5374 __ PushSafepointRegisters();
5375 __ PrepareCallCFunction(1, a0);
5376 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5377 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5379 __ PopSafepointRegisters();
5382 // Native call returns to the DirectCEntry stub which redirects to the
5383 // return address pushed on stack (could have moved after GC).
5384 // DirectCEntry stub itself is generated early and never moves.
5385 DirectCEntryStub stub(isolate);
5386 stub.GenerateCall(masm, t9);
5388 if (FLAG_log_timer_events) {
5389 FrameScope frame(masm, StackFrame::MANUAL);
5390 __ PushSafepointRegisters();
5391 __ PrepareCallCFunction(1, a0);
5392 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5393 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5395 __ PopSafepointRegisters();
5398 Label promote_scheduled_exception;
5399 Label delete_allocated_handles;
5400 Label leave_exit_frame;
5401 Label return_value_loaded;
5403 // Load value from ReturnValue.
5404 __ lw(v0, return_value_operand);
5405 __ bind(&return_value_loaded);
5407 // No more valid handles (the result handle was the last one). Restore
5408 // previous handle scope.
5409 __ sw(s0, MemOperand(s3, kNextOffset));
5410 if (__ emit_debug_code()) {
5411 __ lw(a1, MemOperand(s3, kLevelOffset));
5412 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5414 __ Subu(s2, s2, Operand(1));
5415 __ sw(s2, MemOperand(s3, kLevelOffset));
5416 __ lw(at, MemOperand(s3, kLimitOffset));
5417 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5419 // Leave the API exit frame.
5420 __ bind(&leave_exit_frame);
5422 bool restore_context = context_restore_operand != NULL;
5423 if (restore_context) {
5424 __ lw(cp, *context_restore_operand);
5426 if (stack_space_offset != kInvalidStackOffset) {
5427 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5428 // so this must be accounted for.
5429 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5431 __ li(s0, Operand(stack_space));
5433 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5434 stack_space_offset != kInvalidStackOffset);
5436 // Check if the function scheduled an exception.
5437 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5438 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5439 __ lw(t1, MemOperand(at));
5440 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5444 // Re-throw by promoting a scheduled exception.
5445 __ bind(&promote_scheduled_exception);
5446 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5448 // HandleScope limit has changed. Delete allocated extensions.
5449 __ bind(&delete_allocated_handles);
5450 __ sw(s1, MemOperand(s3, kLimitOffset));
5453 __ PrepareCallCFunction(1, s1);
5454 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5455 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5458 __ jmp(&leave_exit_frame);
5462 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5463 const ParameterCount& argc,
5464 bool return_first_arg,
5465 bool call_data_undefined) {
5466 // ----------- S t a t e -------------
5468 // -- t0 : call_data
5470 // -- a1 : api_function_address
5471 // -- a3 : number of arguments if argc is a register
5474 // -- sp[0] : last argument
5476 // -- sp[(argc - 1)* 4] : first argument
5477 // -- sp[argc * 4] : receiver
5478 // -----------------------------------
5480 Register callee = a0;
5481 Register call_data = t0;
5482 Register holder = a2;
5483 Register api_function_address = a1;
5484 Register context = cp;
5486 typedef FunctionCallbackArguments FCA;
5488 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5489 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5490 STATIC_ASSERT(FCA::kDataIndex == 4);
5491 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5492 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5493 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5494 STATIC_ASSERT(FCA::kHolderIndex == 0);
5495 STATIC_ASSERT(FCA::kArgsLength == 7);
5497 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5499 // Save context, callee and call data.
5500 __ Push(context, callee, call_data);
5501 // Load context from callee.
5502 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5504 Register scratch = call_data;
5505 if (!call_data_undefined) {
5506 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5508 // Push return value and default return value.
5509 __ Push(scratch, scratch);
5510 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5511 // Push isolate and holder.
5512 __ Push(scratch, holder);
5514 // Prepare arguments.
5515 __ mov(scratch, sp);
5517 // Allocate the v8::Arguments structure in the arguments' space since
5518 // it's not controlled by GC.
5519 const int kApiStackSpace = 4;
5521 FrameScope frame_scope(masm, StackFrame::MANUAL);
5522 __ EnterExitFrame(false, kApiStackSpace);
5524 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5525 // a0 = FunctionCallbackInfo&
5526 // Arguments is after the return address.
5527 __ Addu(a0, sp, Operand(1 * kPointerSize));
5528 // FunctionCallbackInfo::implicit_args_
5529 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
5530 if (argc.is_immediate()) {
5531 // FunctionCallbackInfo::values_
5532 __ Addu(at, scratch,
5533 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5534 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5535 // FunctionCallbackInfo::length_ = argc
5536 __ li(at, Operand(argc.immediate()));
5537 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5538 // FunctionCallbackInfo::is_construct_call_ = 0
5539 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
5541 // FunctionCallbackInfo::values_
5542 __ sll(at, argc.reg(), kPointerSizeLog2);
5543 __ Addu(at, at, scratch);
5544 __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5545 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5546 // FunctionCallbackInfo::length_ = argc
5547 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5548 // FunctionCallbackInfo::is_construct_call_
5549 __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5550 __ sll(at, argc.reg(), kPointerSizeLog2);
5551 __ sw(at, MemOperand(a0, 3 * kPointerSize));
5554 ExternalReference thunk_ref =
5555 ExternalReference::invoke_function_callback(masm->isolate());
5557 AllowExternalCallThatCantCauseGC scope(masm);
5558 MemOperand context_restore_operand(
5559 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5560 // Stores return the first js argument.
5561 int return_value_offset = 0;
5562 if (return_first_arg) {
5563 return_value_offset = 2 + FCA::kArgsLength;
5565 return_value_offset = 2 + FCA::kReturnValueOffset;
5567 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5568 int stack_space = 0;
5569 int32_t stack_space_offset = 4 * kPointerSize;
5570 if (argc.is_immediate()) {
5571 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5572 stack_space_offset = kInvalidStackOffset;
5574 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5575 stack_space_offset, return_value_operand,
5576 &context_restore_operand);
5580 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5581 bool call_data_undefined = this->call_data_undefined();
5582 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5583 call_data_undefined);
5587 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5588 bool is_store = this->is_store();
5589 int argc = this->argc();
5590 bool call_data_undefined = this->call_data_undefined();
5591 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5592 call_data_undefined);
5596 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5597 // ----------- S t a t e -------------
5599 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5601 // -- a2 : api_function_address
5602 // -----------------------------------
5604 Register api_function_address = ApiGetterDescriptor::function_address();
5605 DCHECK(api_function_address.is(a2));
5607 __ mov(a0, sp); // a0 = Handle<Name>
5608 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5610 const int kApiStackSpace = 1;
5611 FrameScope frame_scope(masm, StackFrame::MANUAL);
5612 __ EnterExitFrame(false, kApiStackSpace);
5614 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5615 // a1 (internal::Object** args_) as the data.
5616 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
5617 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5619 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5621 ExternalReference thunk_ref =
5622 ExternalReference::invoke_accessor_getter_callback(isolate());
5623 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5624 kStackUnwindSpace, kInvalidStackOffset,
5625 MemOperand(fp, 6 * kPointerSize), NULL);
5631 } // namespace internal
5634 #endif // V8_TARGET_ARCH_MIPS