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/mips/code-stubs-mips.h"
16 #include "src/regexp/jsregexp.h"
17 #include "src/regexp/regexp-macro-assembler.h"
18 #include "src/runtime/runtime.h"
24 static void InitializeArrayConstructorDescriptor(
25 Isolate* isolate, CodeStubDescriptor* descriptor,
26 int constant_stack_parameter_count) {
27 Address deopt_handler = Runtime::FunctionForId(
28 Runtime::kArrayConstructor)->entry;
30 if (constant_stack_parameter_count == 0) {
31 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
32 JS_FUNCTION_STUB_MODE);
34 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
35 JS_FUNCTION_STUB_MODE);
40 static void InitializeInternalArrayConstructorDescriptor(
41 Isolate* isolate, CodeStubDescriptor* descriptor,
42 int constant_stack_parameter_count) {
43 Address deopt_handler = Runtime::FunctionForId(
44 Runtime::kInternalArrayConstructor)->entry;
46 if (constant_stack_parameter_count == 0) {
47 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
48 JS_FUNCTION_STUB_MODE);
50 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
51 JS_FUNCTION_STUB_MODE);
56 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
57 CodeStubDescriptor* descriptor) {
58 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
62 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
63 CodeStubDescriptor* descriptor) {
64 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
68 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
69 CodeStubDescriptor* descriptor) {
70 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
74 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
75 CodeStubDescriptor* descriptor) {
76 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
80 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
81 CodeStubDescriptor* descriptor) {
82 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
86 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
87 CodeStubDescriptor* descriptor) {
88 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
92 #define __ ACCESS_MASM(masm)
95 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
96 Condition cc, Strength strength);
97 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
103 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
108 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
109 ExternalReference miss) {
110 // Update the static counter each time a new code stub is generated.
111 isolate()->counters()->code_stubs()->Increment();
113 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
114 int param_count = descriptor.GetRegisterParameterCount();
116 // Call the runtime system in a fresh internal frame.
117 FrameScope scope(masm, StackFrame::INTERNAL);
118 DCHECK(param_count == 0 ||
119 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
120 // Push arguments, adjust sp.
121 __ Subu(sp, sp, Operand(param_count * kPointerSize));
122 for (int i = 0; i < param_count; ++i) {
123 // Store argument to stack.
124 __ sw(descriptor.GetRegisterParameter(i),
125 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
127 __ CallExternalReference(miss, param_count);
134 void DoubleToIStub::Generate(MacroAssembler* masm) {
135 Label out_of_range, only_low, negate, done;
136 Register input_reg = source();
137 Register result_reg = destination();
139 int double_offset = offset();
140 // Account for saved regs if input is sp.
141 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
144 GetRegisterThatIsNotOneOf(input_reg, result_reg);
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
148 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
149 DoubleRegister double_scratch = kLithiumScratchDouble;
151 __ Push(scratch, scratch2, scratch3);
153 if (!skip_fastpath()) {
154 // Load double input.
155 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
157 // Clear cumulative exception flags and save the FCSR.
158 __ cfc1(scratch2, FCSR);
159 __ ctc1(zero_reg, FCSR);
161 // Try a conversion to a signed integer.
162 __ Trunc_w_d(double_scratch, double_scratch);
163 // Move the converted value into the result register.
164 __ mfc1(scratch3, double_scratch);
166 // Retrieve and restore the FCSR.
167 __ cfc1(scratch, FCSR);
168 __ ctc1(scratch2, FCSR);
170 // Check for overflow and NaNs.
173 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
174 | kFCSRInvalidOpFlagMask);
175 // If we had no exceptions then set result_reg and we are done.
177 __ Branch(&error, ne, scratch, Operand(zero_reg));
178 __ Move(result_reg, scratch3);
183 // Load the double value and perform a manual truncation.
184 Register input_high = scratch2;
185 Register input_low = scratch3;
188 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
190 MemOperand(input_reg, double_offset + Register::kExponentOffset));
192 Label normal_exponent, restore_sign;
193 // Extract the biased exponent in result.
196 HeapNumber::kExponentShift,
197 HeapNumber::kExponentBits);
199 // Check for Infinity and NaNs, which should return 0.
200 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
201 __ Movz(result_reg, zero_reg, scratch);
202 __ Branch(&done, eq, scratch, Operand(zero_reg));
204 // Express exponent as delta to (number of mantissa bits + 31).
207 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
209 // If the delta is strictly positive, all bits would be shifted away,
210 // which means that we can return 0.
211 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
212 __ mov(result_reg, zero_reg);
215 __ bind(&normal_exponent);
216 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
218 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
221 Register sign = result_reg;
223 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
225 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
226 // to check for this specific case.
227 Label high_shift_needed, high_shift_done;
228 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
229 __ mov(input_high, zero_reg);
230 __ Branch(&high_shift_done);
231 __ bind(&high_shift_needed);
233 // Set the implicit 1 before the mantissa part in input_high.
236 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
237 // Shift the mantissa bits to the correct position.
238 // We don't need to clear non-mantissa bits as they will be shifted away.
239 // If they weren't, it would mean that the answer is in the 32bit range.
240 __ sllv(input_high, input_high, scratch);
242 __ bind(&high_shift_done);
244 // Replace the shifted bits with bits from the lower mantissa word.
245 Label pos_shift, shift_done;
247 __ subu(scratch, at, scratch);
248 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
251 __ Subu(scratch, zero_reg, scratch);
252 __ sllv(input_low, input_low, scratch);
253 __ Branch(&shift_done);
256 __ srlv(input_low, input_low, scratch);
258 __ bind(&shift_done);
259 __ Or(input_high, input_high, Operand(input_low));
260 // Restore sign if necessary.
261 __ mov(scratch, sign);
264 __ Subu(result_reg, zero_reg, input_high);
265 __ Movz(result_reg, input_high, scratch);
269 __ Pop(scratch, scratch2, scratch3);
274 // Handle the case where the lhs and rhs are the same object.
275 // Equality is almost reflexive (everything but NaN), so this is a test
276 // for "identity and not NaN".
277 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
278 Condition cc, Strength strength) {
280 Label heap_number, return_equal;
281 Register exp_mask_reg = t5;
283 __ Branch(¬_identical, ne, a0, Operand(a1));
285 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
287 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
288 // so we do the second best thing - test it ourselves.
289 // They are both equal and they are not both Smis so both of them are not
290 // Smis. If it's not a heap number, then return equal.
291 __ GetObjectType(a0, t4, t4);
292 if (cc == less || cc == greater) {
293 // Call runtime on identical JSObjects.
294 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
295 // Call runtime on identical symbols since we need to throw a TypeError.
296 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
297 // Call runtime on identical SIMD values since we must throw a TypeError.
298 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
299 if (is_strong(strength)) {
300 // Call the runtime on anything that is converted in the semantics, since
301 // we need to throw a TypeError. Smis have already been ruled out.
302 __ Branch(&return_equal, eq, t4, Operand(HEAP_NUMBER_TYPE));
303 __ And(t4, t4, Operand(kIsNotStringMask));
304 __ Branch(slow, ne, t4, Operand(zero_reg));
307 __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE));
308 // Comparing JS objects with <=, >= is complicated.
310 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
311 // Call runtime on identical symbols since we need to throw a TypeError.
312 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
313 // Call runtime on identical SIMD values since we must throw a TypeError.
314 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
315 if (is_strong(strength)) {
316 // Call the runtime on anything that is converted in the semantics,
317 // since we need to throw a TypeError. Smis and heap numbers have
318 // already been ruled out.
319 __ And(t4, t4, Operand(kIsNotStringMask));
320 __ Branch(slow, ne, t4, Operand(zero_reg));
322 // Normally here we fall through to return_equal, but undefined is
323 // special: (undefined == undefined) == true, but
324 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
325 if (cc == less_equal || cc == greater_equal) {
326 __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE));
327 __ LoadRoot(t2, Heap::kUndefinedValueRootIndex);
328 __ Branch(&return_equal, ne, a0, Operand(t2));
329 DCHECK(is_int16(GREATER) && is_int16(LESS));
330 __ Ret(USE_DELAY_SLOT);
332 // undefined <= undefined should fail.
333 __ li(v0, Operand(GREATER));
335 // undefined >= undefined should fail.
336 __ li(v0, Operand(LESS));
342 __ bind(&return_equal);
343 DCHECK(is_int16(GREATER) && is_int16(LESS));
344 __ Ret(USE_DELAY_SLOT);
346 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
347 } else if (cc == greater) {
348 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
350 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
353 // For less and greater we don't have to check for NaN since the result of
354 // x < x is false regardless. For the others here is some code to check
356 if (cc != lt && cc != gt) {
357 __ bind(&heap_number);
358 // It is a heap number, so return non-equal if it's NaN and equal if it's
361 // The representation of NaN values has all exponent bits (52..62) set,
362 // and not all mantissa bits (0..51) clear.
363 // Read top bits of double representation (second word of value).
364 __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset));
365 // Test that exponent bits are all set.
366 __ And(t3, t2, Operand(exp_mask_reg));
367 // If all bits not set (ne cond), then not a NaN, objects are equal.
368 __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg));
370 // Shift out flag and all exponent bits, retaining only mantissa.
371 __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord);
372 // Or with all low-bits of mantissa.
373 __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
374 __ Or(v0, t3, Operand(t2));
375 // For equal we already have the right value in v0: Return zero (equal)
376 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
377 // not (it's a NaN). For <= and >= we need to load v0 with the failing
378 // value if it's a NaN.
380 // All-zero means Infinity means equal.
381 __ Ret(eq, v0, Operand(zero_reg));
382 DCHECK(is_int16(GREATER) && is_int16(LESS));
383 __ Ret(USE_DELAY_SLOT);
385 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
387 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
391 // No fall through here.
393 __ bind(¬_identical);
397 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
400 Label* both_loaded_as_doubles,
403 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
404 (lhs.is(a1) && rhs.is(a0)));
407 __ JumpIfSmi(lhs, &lhs_is_smi);
409 // Check whether the non-smi is a heap number.
410 __ GetObjectType(lhs, t4, t4);
412 // If lhs was not a number and rhs was a Smi then strict equality cannot
413 // succeed. Return non-equal (lhs is already not zero).
414 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
417 // Smi compared non-strictly with a non-Smi non-heap-number. Call
419 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
422 // Rhs is a smi, lhs is a number.
423 // Convert smi rhs to double.
424 __ sra(at, rhs, kSmiTagSize);
426 __ cvt_d_w(f14, f14);
427 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
429 // We now have both loaded as doubles.
430 __ jmp(both_loaded_as_doubles);
432 __ bind(&lhs_is_smi);
433 // Lhs is a Smi. Check whether the non-smi is a heap number.
434 __ GetObjectType(rhs, t4, t4);
436 // If lhs was not a number and rhs was a Smi then strict equality cannot
437 // succeed. Return non-equal.
438 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
439 __ li(v0, Operand(1));
441 // Smi compared non-strictly with a non-Smi non-heap-number. Call
443 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
446 // Lhs is a smi, rhs is a number.
447 // Convert smi lhs to double.
448 __ sra(at, lhs, kSmiTagSize);
450 __ cvt_d_w(f12, f12);
451 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
452 // Fall through to both_loaded_as_doubles.
456 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
459 // If either operand is a JS object or an oddball value, then they are
460 // not equal since their pointers are different.
461 // There is no test for undetectability in strict equality.
462 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
463 Label first_non_object;
464 // Get the type of the first operand into a2 and compare it with
465 // FIRST_SPEC_OBJECT_TYPE.
466 __ GetObjectType(lhs, a2, a2);
467 __ Branch(&first_non_object, less, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
470 Label return_not_equal;
471 __ bind(&return_not_equal);
472 __ Ret(USE_DELAY_SLOT);
473 __ li(v0, Operand(1));
475 __ bind(&first_non_object);
476 // Check for oddballs: true, false, null, undefined.
477 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
479 __ GetObjectType(rhs, a3, a3);
480 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
482 // Check for oddballs: true, false, null, undefined.
483 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
485 // Now that we have the types we might as well check for
486 // internalized-internalized.
487 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
488 __ Or(a2, a2, Operand(a3));
489 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
490 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
494 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
497 Label* both_loaded_as_doubles,
498 Label* not_heap_numbers,
500 __ GetObjectType(lhs, a3, a2);
501 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
502 __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
503 // If first was a heap number & second wasn't, go to slow case.
504 __ Branch(slow, ne, a3, Operand(a2));
506 // Both are heap numbers. Load them up then jump to the code we have
508 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
509 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
511 __ jmp(both_loaded_as_doubles);
515 // Fast negative check for internalized-to-internalized equality.
516 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
519 Label* possible_strings,
520 Label* not_both_strings) {
521 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
522 (lhs.is(a1) && rhs.is(a0)));
524 // a2 is object type of rhs.
526 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
527 __ And(at, a2, Operand(kIsNotStringMask));
528 __ Branch(&object_test, ne, at, Operand(zero_reg));
529 __ And(at, a2, Operand(kIsNotInternalizedMask));
530 __ Branch(possible_strings, ne, at, Operand(zero_reg));
531 __ GetObjectType(rhs, a3, a3);
532 __ Branch(not_both_strings, ge, a3, Operand(FIRST_NONSTRING_TYPE));
533 __ And(at, a3, Operand(kIsNotInternalizedMask));
534 __ Branch(possible_strings, ne, at, Operand(zero_reg));
536 // Both are internalized strings. We already checked they weren't the same
537 // pointer so they are not equal.
538 __ Ret(USE_DELAY_SLOT);
539 __ li(v0, Operand(1)); // Non-zero indicates not equal.
541 __ bind(&object_test);
542 __ Branch(not_both_strings, lt, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
543 __ GetObjectType(rhs, a2, a3);
544 __ Branch(not_both_strings, lt, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
546 // If both objects are undetectable, they are equal. Otherwise, they
547 // are not equal, since they are different objects and an object is not
548 // equal to undefined.
549 __ lw(a3, FieldMemOperand(lhs, HeapObject::kMapOffset));
550 __ lbu(a2, FieldMemOperand(a2, Map::kBitFieldOffset));
551 __ lbu(a3, FieldMemOperand(a3, Map::kBitFieldOffset));
553 __ And(a0, a0, Operand(1 << Map::kIsUndetectable));
554 __ Ret(USE_DELAY_SLOT);
555 __ xori(v0, a0, 1 << Map::kIsUndetectable);
559 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
561 CompareICState::State expected,
564 if (expected == CompareICState::SMI) {
565 __ JumpIfNotSmi(input, fail);
566 } else if (expected == CompareICState::NUMBER) {
567 __ JumpIfSmi(input, &ok);
568 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
571 // We could be strict about internalized/string here, but as long as
572 // hydrogen doesn't care, the stub doesn't have to care either.
577 // On entry a1 and a2 are the values to be compared.
578 // On exit a0 is 0, positive or negative to indicate the result of
580 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
583 Condition cc = GetCondition();
586 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
587 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
589 Label slow; // Call builtin.
590 Label not_smis, both_loaded_as_doubles;
592 Label not_two_smis, smi_done;
594 __ JumpIfNotSmi(a2, ¬_two_smis);
597 __ Ret(USE_DELAY_SLOT);
599 __ bind(¬_two_smis);
601 // NOTICE! This code is only reached after a smi-fast-case check, so
602 // it is certain that at least one operand isn't a smi.
604 // Handle the case where the objects are identical. Either returns the answer
605 // or goes to slow. Only falls through if the objects were not identical.
606 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
608 // If either is a Smi (we know that not both are), then they can only
609 // be strictly equal if the other is a HeapNumber.
610 STATIC_ASSERT(kSmiTag == 0);
611 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
612 __ And(t2, lhs, Operand(rhs));
613 __ JumpIfNotSmi(t2, ¬_smis, t0);
614 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
615 // 1) Return the answer.
617 // 3) Fall through to both_loaded_as_doubles.
618 // 4) Jump to rhs_not_nan.
619 // In cases 3 and 4 we have found out we were dealing with a number-number
620 // comparison and the numbers have been loaded into f12 and f14 as doubles,
621 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
622 EmitSmiNonsmiComparison(masm, lhs, rhs,
623 &both_loaded_as_doubles, &slow, strict());
625 __ bind(&both_loaded_as_doubles);
626 // f12, f14 are the double representations of the left hand side
627 // and the right hand side if we have FPU. Otherwise a2, a3 represent
628 // left hand side and a0, a1 represent right hand side.
630 __ li(t0, Operand(LESS));
631 __ li(t1, Operand(GREATER));
632 __ li(t2, Operand(EQUAL));
634 // Check if either rhs or lhs is NaN.
635 __ BranchF(NULL, &nan, eq, f12, f14);
637 // Check if LESS condition is satisfied. If true, move conditionally
639 if (!IsMipsArchVariant(kMips32r6)) {
640 __ c(OLT, D, f12, f14);
642 // Use previous check to store conditionally to v0 oposite condition
643 // (GREATER). If rhs is equal to lhs, this will be corrected in next
646 // Check if EQUAL condition is satisfied. If true, move conditionally
648 __ c(EQ, D, f12, f14);
652 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
653 __ mov(v0, t0); // Return LESS as result.
655 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
656 __ mov(v0, t2); // Return EQUAL as result.
658 __ mov(v0, t1); // Return GREATER as result.
665 // NaN comparisons always fail.
666 // Load whatever we need in v0 to make the comparison fail.
667 DCHECK(is_int16(GREATER) && is_int16(LESS));
668 __ Ret(USE_DELAY_SLOT);
669 if (cc == lt || cc == le) {
670 __ li(v0, Operand(GREATER));
672 __ li(v0, Operand(LESS));
677 // At this point we know we are dealing with two different objects,
678 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
680 // This returns non-equal for some object types, or falls through if it
682 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
685 Label check_for_internalized_strings;
686 Label flat_string_check;
687 // Check for heap-number-heap-number comparison. Can jump to slow case,
688 // or load both doubles and jump to the code that handles
689 // that case. If the inputs are not doubles then jumps to
690 // check_for_internalized_strings.
691 // In this case a2 will contain the type of lhs_.
692 EmitCheckForTwoHeapNumbers(masm,
695 &both_loaded_as_doubles,
696 &check_for_internalized_strings,
699 __ bind(&check_for_internalized_strings);
700 if (cc == eq && !strict()) {
701 // Returns an answer for two internalized strings or two
702 // detectable objects.
703 // Otherwise jumps to string case or not both strings case.
704 // Assumes that a2 is the type of lhs_ on entry.
705 EmitCheckForInternalizedStringsOrObjects(
706 masm, lhs, rhs, &flat_string_check, &slow);
709 // Check for both being sequential one-byte strings,
710 // and inline if that is the case.
711 __ bind(&flat_string_check);
713 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
715 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
718 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0);
720 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0,
723 // Never falls through to here.
726 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
729 // Figure out which native to call and setup the arguments.
730 if (cc == eq && strict()) {
731 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
735 context_index = Context::EQUALS_BUILTIN_INDEX;
737 context_index = is_strong(strength())
738 ? Context::COMPARE_STRONG_BUILTIN_INDEX
739 : Context::COMPARE_BUILTIN_INDEX;
740 int ncr; // NaN compare result.
741 if (cc == lt || cc == le) {
744 DCHECK(cc == gt || cc == ge); // Remaining cases.
747 __ li(a0, Operand(Smi::FromInt(ncr)));
751 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
752 // tagged as a small integer.
753 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
761 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
764 __ PushSafepointRegisters();
769 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
772 __ PopSafepointRegisters();
777 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
778 // We don't allow a GC during a store buffer overflow so there is no need to
779 // store the registers in any particular way, but we do have to store and
781 __ MultiPush(kJSCallerSaved | ra.bit());
782 if (save_doubles()) {
783 __ MultiPushFPU(kCallerSavedFPU);
785 const int argument_count = 1;
786 const int fp_argument_count = 0;
787 const Register scratch = a1;
789 AllowExternalCallThatCantCauseGC scope(masm);
790 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
791 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
793 ExternalReference::store_buffer_overflow_function(isolate()),
795 if (save_doubles()) {
796 __ MultiPopFPU(kCallerSavedFPU);
799 __ MultiPop(kJSCallerSaved | ra.bit());
804 void MathPowStub::Generate(MacroAssembler* masm) {
805 const Register base = a1;
806 const Register exponent = MathPowTaggedDescriptor::exponent();
807 DCHECK(exponent.is(a2));
808 const Register heapnumbermap = t1;
809 const Register heapnumber = v0;
810 const DoubleRegister double_base = f2;
811 const DoubleRegister double_exponent = f4;
812 const DoubleRegister double_result = f0;
813 const DoubleRegister double_scratch = f6;
814 const FPURegister single_scratch = f8;
815 const Register scratch = t5;
816 const Register scratch2 = t3;
818 Label call_runtime, done, int_exponent;
819 if (exponent_type() == ON_STACK) {
820 Label base_is_smi, unpack_exponent;
821 // The exponent and base are supplied as arguments on the stack.
822 // This can only happen if the stub is called from non-optimized code.
823 // Load input parameters from stack to double registers.
824 __ lw(base, MemOperand(sp, 1 * kPointerSize));
825 __ lw(exponent, MemOperand(sp, 0 * kPointerSize));
827 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
829 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
830 __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset));
831 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
833 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
834 __ jmp(&unpack_exponent);
836 __ bind(&base_is_smi);
837 __ mtc1(scratch, single_scratch);
838 __ cvt_d_w(double_base, single_scratch);
839 __ bind(&unpack_exponent);
841 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
843 __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
844 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
845 __ ldc1(double_exponent,
846 FieldMemOperand(exponent, HeapNumber::kValueOffset));
847 } else if (exponent_type() == TAGGED) {
848 // Base is already in double_base.
849 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
851 __ ldc1(double_exponent,
852 FieldMemOperand(exponent, HeapNumber::kValueOffset));
855 if (exponent_type() != INTEGER) {
856 Label int_exponent_convert;
857 // Detect integer exponents stored as double.
858 __ EmitFPUTruncate(kRoundToMinusInf,
864 kCheckForInexactConversion);
865 // scratch2 == 0 means there was no conversion error.
866 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
868 if (exponent_type() == ON_STACK) {
869 // Detect square root case. Crankshaft detects constant +/-0.5 at
870 // compile time and uses DoMathPowHalf instead. We then skip this check
871 // for non-constant cases of +/-0.5 as these hardly occur.
874 __ Move(double_scratch, 0.5);
875 __ BranchF(USE_DELAY_SLOT,
881 // double_scratch can be overwritten in the delay slot.
882 // Calculates square root of base. Check for the special case of
883 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
884 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
885 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
886 __ neg_d(double_result, double_scratch);
888 // Add +0 to convert -0 to +0.
889 __ add_d(double_scratch, double_base, kDoubleRegZero);
890 __ sqrt_d(double_result, double_scratch);
893 __ bind(¬_plus_half);
894 __ Move(double_scratch, -0.5);
895 __ BranchF(USE_DELAY_SLOT,
901 // double_scratch can be overwritten in the delay slot.
902 // Calculates square root of base. Check for the special case of
903 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
904 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
905 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
906 __ Move(double_result, kDoubleRegZero);
908 // Add +0 to convert -0 to +0.
909 __ add_d(double_scratch, double_base, kDoubleRegZero);
910 __ Move(double_result, 1.);
911 __ sqrt_d(double_scratch, double_scratch);
912 __ div_d(double_result, double_result, double_scratch);
918 AllowExternalCallThatCantCauseGC scope(masm);
919 __ PrepareCallCFunction(0, 2, scratch2);
920 __ MovToFloatParameters(double_base, double_exponent);
922 ExternalReference::power_double_double_function(isolate()),
926 __ MovFromFloatResult(double_result);
929 __ bind(&int_exponent_convert);
932 // Calculate power with integer exponent.
933 __ bind(&int_exponent);
935 // Get two copies of exponent in the registers scratch and exponent.
936 if (exponent_type() == INTEGER) {
937 __ mov(scratch, exponent);
939 // Exponent has previously been stored into scratch as untagged integer.
940 __ mov(exponent, scratch);
943 __ mov_d(double_scratch, double_base); // Back up base.
944 __ Move(double_result, 1.0);
946 // Get absolute value of exponent.
947 Label positive_exponent;
948 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
949 __ Subu(scratch, zero_reg, scratch);
950 __ bind(&positive_exponent);
952 Label while_true, no_carry, loop_end;
953 __ bind(&while_true);
955 __ And(scratch2, scratch, 1);
957 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
958 __ mul_d(double_result, double_result, double_scratch);
961 __ sra(scratch, scratch, 1);
963 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
964 __ mul_d(double_scratch, double_scratch, double_scratch);
966 __ Branch(&while_true);
970 __ Branch(&done, ge, exponent, Operand(zero_reg));
971 __ Move(double_scratch, 1.0);
972 __ div_d(double_result, double_scratch, double_result);
973 // Test whether result is zero. Bail out to check for subnormal result.
974 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
975 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
977 // double_exponent may not contain the exponent value if the input was a
978 // smi. We set it with exponent value before bailing out.
979 __ mtc1(exponent, single_scratch);
980 __ cvt_d_w(double_exponent, single_scratch);
982 // Returning or bailing out.
983 Counters* counters = isolate()->counters();
984 if (exponent_type() == ON_STACK) {
985 // The arguments are still on the stack.
986 __ bind(&call_runtime);
987 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
989 // The stub is called from non-optimized code, which expects the result
990 // as heap number in exponent.
992 __ AllocateHeapNumber(
993 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
994 __ sdc1(double_result,
995 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
996 DCHECK(heapnumber.is(v0));
997 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1002 AllowExternalCallThatCantCauseGC scope(masm);
1003 __ PrepareCallCFunction(0, 2, scratch);
1004 __ MovToFloatParameters(double_base, double_exponent);
1006 ExternalReference::power_double_double_function(isolate()),
1010 __ MovFromFloatResult(double_result);
1013 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1019 bool CEntryStub::NeedsImmovableCode() {
1024 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1025 CEntryStub::GenerateAheadOfTime(isolate);
1026 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1027 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1028 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1029 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1030 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1031 BinaryOpICStub::GenerateAheadOfTime(isolate);
1032 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1033 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1034 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1035 StoreFastElementStub::GenerateAheadOfTime(isolate);
1036 TypeofStub::GenerateAheadOfTime(isolate);
1040 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1041 StoreRegistersStateStub stub(isolate);
1046 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1047 RestoreRegistersStateStub stub(isolate);
1052 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1053 // Generate if not already in cache.
1054 SaveFPRegsMode mode = kSaveFPRegs;
1055 CEntryStub(isolate, 1, mode).GetCode();
1056 StoreBufferOverflowStub(isolate, mode).GetCode();
1057 isolate->set_fp_stubs_generated(true);
1061 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1062 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1067 void CEntryStub::Generate(MacroAssembler* masm) {
1068 // Called from JavaScript; parameters are on stack as if calling JS function
1069 // a0: number of arguments including receiver
1070 // a1: pointer to builtin function
1071 // fp: frame pointer (restored after C call)
1072 // sp: stack pointer (restored as callee's sp after C call)
1073 // cp: current context (C callee-saved)
1075 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1077 // Compute the argv pointer in a callee-saved register.
1078 __ sll(s1, a0, kPointerSizeLog2);
1079 __ Addu(s1, sp, s1);
1080 __ Subu(s1, s1, kPointerSize);
1082 // Enter the exit frame that transitions from JavaScript to C++.
1083 FrameScope scope(masm, StackFrame::MANUAL);
1084 __ EnterExitFrame(save_doubles());
1086 // s0: number of arguments including receiver (C callee-saved)
1087 // s1: pointer to first argument (C callee-saved)
1088 // s2: pointer to builtin function (C callee-saved)
1090 // Prepare arguments for C routine.
1094 // a1 = argv (set in the delay slot after find_ra below).
1096 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1097 // also need to reserve the 4 argument slots on the stack.
1099 __ AssertStackIsAligned();
1101 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1103 // To let the GC traverse the return address of the exit frames, we need to
1104 // know where the return address is. The CEntryStub is unmovable, so
1105 // we can store the address on the stack to be able to find it again and
1106 // we never have to restore it, because it will not change.
1107 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1108 // This branch-and-link sequence is needed to find the current PC on mips,
1109 // saved to the ra register.
1110 // Use masm-> here instead of the double-underscore macro since extra
1111 // coverage code can interfere with the proper calculation of ra.
1113 masm->bal(&find_ra); // bal exposes branch delay slot.
1115 masm->bind(&find_ra);
1117 // Adjust the value in ra to point to the correct return location, 2nd
1118 // instruction past the real call into C code (the jalr(t9)), and push it.
1119 // This is the return address of the exit frame.
1120 const int kNumInstructionsToJump = 5;
1121 masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize);
1122 masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1123 // Stack space reservation moved to the branch delay slot below.
1124 // Stack is still aligned.
1126 // Call the C routine.
1127 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1129 // Set up sp in the delay slot.
1130 masm->addiu(sp, sp, -kCArgsSlotsSize);
1131 // Make sure the stored 'ra' points to this position.
1132 DCHECK_EQ(kNumInstructionsToJump,
1133 masm->InstructionsGeneratedSince(&find_ra));
1137 // Check result for exception sentinel.
1138 Label exception_returned;
1139 __ LoadRoot(t0, Heap::kExceptionRootIndex);
1140 __ Branch(&exception_returned, eq, t0, Operand(v0));
1142 // Check that there is no pending exception, otherwise we
1143 // should have returned the exception sentinel.
1144 if (FLAG_debug_code) {
1146 ExternalReference pending_exception_address(
1147 Isolate::kPendingExceptionAddress, isolate());
1148 __ li(a2, Operand(pending_exception_address));
1149 __ lw(a2, MemOperand(a2));
1150 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1151 // Cannot use check here as it attempts to generate call into runtime.
1152 __ Branch(&okay, eq, t0, Operand(a2));
1153 __ stop("Unexpected pending exception");
1157 // Exit C frame and return.
1159 // sp: stack pointer
1160 // fp: frame pointer
1161 // s0: still holds argc (callee-saved).
1162 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1164 // Handling of exception.
1165 __ bind(&exception_returned);
1167 ExternalReference pending_handler_context_address(
1168 Isolate::kPendingHandlerContextAddress, isolate());
1169 ExternalReference pending_handler_code_address(
1170 Isolate::kPendingHandlerCodeAddress, isolate());
1171 ExternalReference pending_handler_offset_address(
1172 Isolate::kPendingHandlerOffsetAddress, isolate());
1173 ExternalReference pending_handler_fp_address(
1174 Isolate::kPendingHandlerFPAddress, isolate());
1175 ExternalReference pending_handler_sp_address(
1176 Isolate::kPendingHandlerSPAddress, isolate());
1178 // Ask the runtime for help to determine the handler. This will set v0 to
1179 // contain the current pending exception, don't clobber it.
1180 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1183 FrameScope scope(masm, StackFrame::MANUAL);
1184 __ PrepareCallCFunction(3, 0, a0);
1185 __ mov(a0, zero_reg);
1186 __ mov(a1, zero_reg);
1187 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1188 __ CallCFunction(find_handler, 3);
1191 // Retrieve the handler context, SP and FP.
1192 __ li(cp, Operand(pending_handler_context_address));
1193 __ lw(cp, MemOperand(cp));
1194 __ li(sp, Operand(pending_handler_sp_address));
1195 __ lw(sp, MemOperand(sp));
1196 __ li(fp, Operand(pending_handler_fp_address));
1197 __ lw(fp, MemOperand(fp));
1199 // If the handler is a JS frame, restore the context to the frame. Note that
1200 // the context will be set to (cp == 0) for non-JS frames.
1202 __ Branch(&zero, eq, cp, Operand(zero_reg));
1203 __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1206 // Compute the handler entry address and jump to it.
1207 __ li(a1, Operand(pending_handler_code_address));
1208 __ lw(a1, MemOperand(a1));
1209 __ li(a2, Operand(pending_handler_offset_address));
1210 __ lw(a2, MemOperand(a2));
1211 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1212 __ Addu(t9, a1, a2);
1217 void JSEntryStub::Generate(MacroAssembler* masm) {
1218 Label invoke, handler_entry, exit;
1219 Isolate* isolate = masm->isolate();
1222 // a0: entry address
1231 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1233 // Save callee saved registers on the stack.
1234 __ MultiPush(kCalleeSaved | ra.bit());
1236 // Save callee-saved FPU registers.
1237 __ MultiPushFPU(kCalleeSavedFPU);
1238 // Set up the reserved register for 0.0.
1239 __ Move(kDoubleRegZero, 0.0);
1242 // Load argv in s0 register.
1243 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1244 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1246 __ InitializeRootRegister();
1247 __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1249 // We build an EntryFrame.
1250 __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1251 int marker = type();
1252 __ li(t2, Operand(Smi::FromInt(marker)));
1253 __ li(t1, Operand(Smi::FromInt(marker)));
1254 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1256 __ lw(t0, MemOperand(t0));
1257 __ Push(t3, t2, t1, t0);
1258 // Set up frame pointer for the frame to be pushed.
1259 __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1262 // a0: entry_address
1264 // a2: receiver_pointer
1270 // function slot | entry frame
1272 // bad fp (0xff...f) |
1273 // callee saved registers + ra
1277 // If this is the outermost JS call, set js_entry_sp value.
1278 Label non_outermost_js;
1279 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1280 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1281 __ lw(t2, MemOperand(t1));
1282 __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
1283 __ sw(fp, MemOperand(t1));
1284 __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1287 __ nop(); // Branch delay slot nop.
1288 __ bind(&non_outermost_js);
1289 __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1293 // Jump to a faked try block that does the invoke, with a faked catch
1294 // block that sets the pending exception.
1296 __ bind(&handler_entry);
1297 handler_offset_ = handler_entry.pos();
1298 // Caught exception: Store result (exception) in the pending exception
1299 // field in the JSEnv and return a failure sentinel. Coming in here the
1300 // fp will be invalid because the PushStackHandler below sets it to 0 to
1301 // signal the existence of the JSEntry frame.
1302 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1304 __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
1305 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1306 __ b(&exit); // b exposes branch delay slot.
1307 __ nop(); // Branch delay slot nop.
1309 // Invoke: Link this frame into the handler chain.
1311 __ PushStackHandler();
1312 // If an exception not caught by another handler occurs, this handler
1313 // returns control to the code after the bal(&invoke) above, which
1314 // restores all kCalleeSaved registers (including cp and fp) to their
1315 // saved values before returning a failure to C.
1317 // Clear any pending exceptions.
1318 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
1319 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1321 __ sw(t1, MemOperand(t0));
1323 // Invoke the function by calling through JS entry trampoline builtin.
1324 // Notice that we cannot store a reference to the trampoline code directly in
1325 // this stub, because runtime stubs are not traversed when doing GC.
1328 // a0: entry_address
1330 // a2: receiver_pointer
1337 // callee saved registers + ra
1341 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1342 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1344 __ li(t0, Operand(construct_entry));
1346 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1347 __ li(t0, Operand(entry));
1349 __ lw(t9, MemOperand(t0)); // Deref address.
1351 // Call JSEntryTrampoline.
1352 __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1355 // Unlink this frame from the handler chain.
1356 __ PopStackHandler();
1358 __ bind(&exit); // v0 holds result
1359 // Check if the current stack frame is marked as the outermost JS frame.
1360 Label non_outermost_js_2;
1362 __ Branch(&non_outermost_js_2,
1365 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1366 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1367 __ sw(zero_reg, MemOperand(t1));
1368 __ bind(&non_outermost_js_2);
1370 // Restore the top frame descriptors from the stack.
1372 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1374 __ sw(t1, MemOperand(t0));
1376 // Reset the stack to the callee saved registers.
1377 __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1379 // Restore callee-saved fpu registers.
1380 __ MultiPopFPU(kCalleeSavedFPU);
1382 // Restore callee saved registers from the stack.
1383 __ MultiPop(kCalleeSaved | ra.bit());
1389 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1390 // Return address is in ra.
1393 Register receiver = LoadDescriptor::ReceiverRegister();
1394 Register index = LoadDescriptor::NameRegister();
1395 Register scratch = t1;
1396 Register result = v0;
1397 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1398 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1400 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1401 &miss, // When not a string.
1402 &miss, // When not a number.
1403 &miss, // When index out of range.
1404 STRING_INDEX_IS_ARRAY_INDEX,
1405 RECEIVER_IS_STRING);
1406 char_at_generator.GenerateFast(masm);
1409 StubRuntimeCallHelper call_helper;
1410 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1413 PropertyAccessCompiler::TailCallBuiltin(
1414 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1418 void InstanceOfStub::Generate(MacroAssembler* masm) {
1419 Register const object = a1; // Object (lhs).
1420 Register const function = a0; // Function (rhs).
1421 Register const object_map = a2; // Map of {object}.
1422 Register const function_map = a3; // Map of {function}.
1423 Register const function_prototype = t0; // Prototype of {function}.
1424 Register const scratch = t1;
1426 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1427 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1429 // Check if {object} is a smi.
1430 Label object_is_smi;
1431 __ JumpIfSmi(object, &object_is_smi);
1433 // Lookup the {function} and the {object} map in the global instanceof cache.
1434 // Note: This is safe because we clear the global instanceof cache whenever
1435 // we change the prototype of any object.
1436 Label fast_case, slow_case;
1437 __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1438 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1439 __ Branch(&fast_case, ne, function, Operand(at));
1440 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1441 __ Branch(&fast_case, ne, object_map, Operand(at));
1442 __ Ret(USE_DELAY_SLOT);
1443 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1445 // If {object} is a smi we can safely return false if {function} is a JS
1446 // function, otherwise we have to miss to the runtime and throw an exception.
1447 __ bind(&object_is_smi);
1448 __ JumpIfSmi(function, &slow_case);
1449 __ GetObjectType(function, function_map, scratch);
1450 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1451 __ Ret(USE_DELAY_SLOT);
1452 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
1454 // Fast-case: The {function} must be a valid JSFunction.
1455 __ bind(&fast_case);
1456 __ JumpIfSmi(function, &slow_case);
1457 __ GetObjectType(function, function_map, scratch);
1458 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1460 // Ensure that {function} has an instance prototype.
1461 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1462 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1463 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1465 // Ensure that {function} is not bound.
1466 Register const shared_info = scratch;
1468 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1470 FieldMemOperand(shared_info, SharedFunctionInfo::kBoundByteOffset));
1471 __ And(at, scratch, Operand(1 << SharedFunctionInfo::kBoundBitWithinByte));
1472 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1474 // Get the "prototype" (or initial map) of the {function}.
1475 __ lw(function_prototype,
1476 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1477 __ AssertNotSmi(function_prototype);
1479 // Resolve the prototype if the {function} has an initial map. Afterwards the
1480 // {function_prototype} will be either the JSReceiver prototype object or the
1481 // hole value, which means that no instances of the {function} were created so
1482 // far and hence we should return false.
1483 Label function_prototype_valid;
1484 __ GetObjectType(function_prototype, scratch, scratch);
1485 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1486 __ lw(function_prototype,
1487 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1488 __ bind(&function_prototype_valid);
1489 __ AssertNotSmi(function_prototype);
1491 // Update the global instanceof cache with the current {object} map and
1492 // {function}. The cached answer will be set when it is known below.
1493 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1494 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1496 // Loop through the prototype chain looking for the {function} prototype.
1497 // Assume true, and change to false if not found.
1498 Register const object_prototype = object_map;
1499 Register const null = scratch;
1501 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1502 __ LoadRoot(null, Heap::kNullValueRootIndex);
1504 __ lw(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1505 __ Branch(&done, eq, object_prototype, Operand(function_prototype));
1506 __ Branch(USE_DELAY_SLOT, &loop, ne, object_prototype, Operand(null));
1507 __ lw(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1508 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1510 __ Ret(USE_DELAY_SLOT);
1511 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1513 // Slow-case: Call the runtime function.
1514 __ bind(&slow_case);
1515 __ Push(object, function);
1516 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1520 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1522 Register receiver = LoadDescriptor::ReceiverRegister();
1523 // Ensure that the vector and slot registers won't be clobbered before
1524 // calling the miss handler.
1525 DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(),
1526 LoadWithVectorDescriptor::SlotRegister()));
1528 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0,
1531 PropertyAccessCompiler::TailCallBuiltin(
1532 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1536 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1537 // The displacement is the offset of the last parameter (if any)
1538 // relative to the frame pointer.
1539 const int kDisplacement =
1540 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1541 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1542 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1544 // Check that the key is a smiGenerateReadElement.
1546 __ JumpIfNotSmi(a1, &slow);
1548 // Check if the calling frame is an arguments adaptor frame.
1550 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1551 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1555 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1557 // Check index (a1) against formal parameters count limit passed in
1558 // through register a0. Use unsigned comparison to get negative
1560 __ Branch(&slow, hs, a1, Operand(a0));
1562 // Read the argument from the stack and return it.
1563 __ subu(a3, a0, a1);
1564 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1565 __ Addu(a3, fp, Operand(t3));
1566 __ Ret(USE_DELAY_SLOT);
1567 __ lw(v0, MemOperand(a3, kDisplacement));
1569 // Arguments adaptor case: Check index (a1) against actual arguments
1570 // limit found in the arguments adaptor frame. Use unsigned
1571 // comparison to get negative check for free.
1573 __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1574 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1576 // Read the argument from the adaptor frame and return it.
1577 __ subu(a3, a0, a1);
1578 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1579 __ Addu(a3, a2, Operand(t3));
1580 __ Ret(USE_DELAY_SLOT);
1581 __ lw(v0, MemOperand(a3, kDisplacement));
1583 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1584 // by calling the runtime system.
1587 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1591 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1592 // sp[0] : number of parameters
1593 // sp[4] : receiver displacement
1596 // Check if the calling frame is an arguments adaptor frame.
1598 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1599 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1603 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1605 // Patch the arguments.length and the parameters pointer in the current frame.
1606 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1607 __ sw(a2, MemOperand(sp, 0 * kPointerSize));
1609 __ Addu(a3, a3, Operand(t3));
1610 __ addiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1611 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1614 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1618 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1620 // sp[0] : number of parameters (tagged)
1621 // sp[4] : address of receiver argument
1623 // Registers used over whole function:
1624 // t2 : allocated object (tagged)
1625 // t5 : mapped parameter count (tagged)
1627 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1628 // a1 = parameter count (tagged)
1630 // Check if the calling frame is an arguments adaptor frame.
1632 Label adaptor_frame, try_allocate;
1633 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1634 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1635 __ Branch(&adaptor_frame,
1638 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1640 // No adaptor, parameter count = argument count.
1642 __ b(&try_allocate);
1643 __ nop(); // Branch delay slot nop.
1645 // We have an adaptor frame. Patch the parameters pointer.
1646 __ bind(&adaptor_frame);
1647 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1649 __ Addu(a3, a3, Operand(t6));
1650 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1651 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1653 // a1 = parameter count (tagged)
1654 // a2 = argument count (tagged)
1655 // Compute the mapped parameter count = min(a1, a2) in a1.
1657 __ Branch(&skip_min, lt, a1, Operand(a2));
1661 __ bind(&try_allocate);
1663 // Compute the sizes of backing store, parameter map, and arguments object.
1664 // 1. Parameter map, has 2 extra words containing context and backing store.
1665 const int kParameterMapHeaderSize =
1666 FixedArray::kHeaderSize + 2 * kPointerSize;
1667 // If there are no mapped parameters, we do not need the parameter_map.
1668 Label param_map_size;
1669 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1670 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1671 __ mov(t5, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1673 __ addiu(t5, t5, kParameterMapHeaderSize);
1674 __ bind(¶m_map_size);
1676 // 2. Backing store.
1678 __ Addu(t5, t5, Operand(t6));
1679 __ Addu(t5, t5, Operand(FixedArray::kHeaderSize));
1681 // 3. Arguments object.
1682 __ Addu(t5, t5, Operand(Heap::kSloppyArgumentsObjectSize));
1684 // Do the allocation of all three objects in one go.
1685 __ Allocate(t5, v0, a3, t0, &runtime, TAG_OBJECT);
1687 // v0 = address of new object(s) (tagged)
1688 // a2 = argument count (smi-tagged)
1689 // Get the arguments boilerplate from the current native context into t0.
1690 const int kNormalOffset =
1691 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1692 const int kAliasedOffset =
1693 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1695 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1696 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1697 Label skip2_ne, skip2_eq;
1698 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1699 __ lw(t0, MemOperand(t0, kNormalOffset));
1702 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1703 __ lw(t0, MemOperand(t0, kAliasedOffset));
1706 // v0 = address of new object (tagged)
1707 // a1 = mapped parameter count (tagged)
1708 // a2 = argument count (smi-tagged)
1709 // t0 = address of arguments map (tagged)
1710 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1711 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1712 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1713 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1715 // Set up the callee in-object property.
1716 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1717 __ lw(a3, MemOperand(sp, 2 * kPointerSize));
1718 __ AssertNotSmi(a3);
1719 const int kCalleeOffset = JSObject::kHeaderSize +
1720 Heap::kArgumentsCalleeIndex * kPointerSize;
1721 __ sw(a3, FieldMemOperand(v0, kCalleeOffset));
1723 // Use the length (smi tagged) and set that as an in-object property too.
1725 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1726 const int kLengthOffset = JSObject::kHeaderSize +
1727 Heap::kArgumentsLengthIndex * kPointerSize;
1728 __ sw(a2, FieldMemOperand(v0, kLengthOffset));
1730 // Set up the elements pointer in the allocated arguments object.
1731 // If we allocated a parameter map, t0 will point there, otherwise
1732 // it will point to the backing store.
1733 __ Addu(t0, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1734 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1736 // v0 = address of new object (tagged)
1737 // a1 = mapped parameter count (tagged)
1738 // a2 = argument count (tagged)
1739 // t0 = address of parameter map or backing store (tagged)
1740 // Initialize parameter map. If there are no mapped arguments, we're done.
1741 Label skip_parameter_map;
1743 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1744 // Move backing store address to a3, because it is
1745 // expected there when filling in the unmapped arguments.
1749 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1751 __ LoadRoot(t2, Heap::kSloppyArgumentsElementsMapRootIndex);
1752 __ sw(t2, FieldMemOperand(t0, FixedArray::kMapOffset));
1753 __ Addu(t2, a1, Operand(Smi::FromInt(2)));
1754 __ sw(t2, FieldMemOperand(t0, FixedArray::kLengthOffset));
1755 __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize));
1757 __ Addu(t2, t0, Operand(t6));
1758 __ Addu(t2, t2, Operand(kParameterMapHeaderSize));
1759 __ sw(t2, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize));
1761 // Copy the parameter slots and the holes in the arguments.
1762 // We need to fill in mapped_parameter_count slots. They index the context,
1763 // where parameters are stored in reverse order, at
1764 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1765 // The mapped parameter thus need to get indices
1766 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1767 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1768 // We loop from right to left.
1769 Label parameters_loop, parameters_test;
1771 __ lw(t5, MemOperand(sp, 0 * kPointerSize));
1772 __ Addu(t5, t5, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1773 __ Subu(t5, t5, Operand(a1));
1774 __ LoadRoot(t3, Heap::kTheHoleValueRootIndex);
1776 __ Addu(a3, t0, Operand(t6));
1777 __ Addu(a3, a3, Operand(kParameterMapHeaderSize));
1779 // t2 = loop variable (tagged)
1780 // a1 = mapping index (tagged)
1781 // a3 = address of backing store (tagged)
1782 // t0 = address of parameter map (tagged)
1783 // t1 = temporary scratch (a.o., for address calculation)
1784 // t3 = the hole value
1785 __ jmp(¶meters_test);
1787 __ bind(¶meters_loop);
1788 __ Subu(t2, t2, Operand(Smi::FromInt(1)));
1790 __ Addu(t1, t1, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1791 __ Addu(t6, t0, t1);
1792 __ sw(t5, MemOperand(t6));
1793 __ Subu(t1, t1, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1794 __ Addu(t6, a3, t1);
1795 __ sw(t3, MemOperand(t6));
1796 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1797 __ bind(¶meters_test);
1798 __ Branch(¶meters_loop, ne, t2, Operand(Smi::FromInt(0)));
1800 __ bind(&skip_parameter_map);
1801 // a2 = argument count (tagged)
1802 // a3 = address of backing store (tagged)
1804 // Copy arguments header and remaining slots (if there are any).
1805 __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex);
1806 __ sw(t1, FieldMemOperand(a3, FixedArray::kMapOffset));
1807 __ sw(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1809 Label arguments_loop, arguments_test;
1811 __ lw(t0, MemOperand(sp, 1 * kPointerSize));
1813 __ Subu(t0, t0, Operand(t6));
1814 __ jmp(&arguments_test);
1816 __ bind(&arguments_loop);
1817 __ Subu(t0, t0, Operand(kPointerSize));
1818 __ lw(t2, MemOperand(t0, 0));
1820 __ Addu(t1, a3, Operand(t6));
1821 __ sw(t2, FieldMemOperand(t1, FixedArray::kHeaderSize));
1822 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1824 __ bind(&arguments_test);
1825 __ Branch(&arguments_loop, lt, t5, Operand(a2));
1827 // Return and remove the on-stack parameters.
1830 // Do the runtime call to allocate the arguments object.
1831 // a2 = argument count (tagged)
1833 __ sw(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1834 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1838 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1839 // Return address is in ra.
1842 Register receiver = LoadDescriptor::ReceiverRegister();
1843 Register key = LoadDescriptor::NameRegister();
1845 // Check that the key is an array index, that is Uint32.
1846 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1847 __ Branch(&slow, ne, t0, Operand(zero_reg));
1849 // Everything is fine, call runtime.
1850 __ Push(receiver, key); // Receiver, key.
1852 // Perform tail call to the entry.
1853 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1856 PropertyAccessCompiler::TailCallBuiltin(
1857 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1861 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1862 // sp[0] : number of parameters
1863 // sp[4] : receiver displacement
1865 // Check if the calling frame is an arguments adaptor frame.
1866 Label adaptor_frame, try_allocate, runtime;
1867 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1868 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1869 __ Branch(&adaptor_frame,
1872 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1874 // Get the length from the frame.
1875 __ lw(a1, MemOperand(sp, 0));
1876 __ Branch(&try_allocate);
1878 // Patch the arguments.length and the parameters pointer.
1879 __ bind(&adaptor_frame);
1880 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1881 __ sw(a1, MemOperand(sp, 0));
1882 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1883 __ Addu(a3, a2, Operand(at));
1885 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1886 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1888 // Try the new space allocation. Start out with computing the size
1889 // of the arguments object and the elements array in words.
1890 Label add_arguments_object;
1891 __ bind(&try_allocate);
1892 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1893 __ srl(a1, a1, kSmiTagSize);
1895 __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1896 __ bind(&add_arguments_object);
1897 __ Addu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1899 // Do the allocation of both objects in one go.
1900 __ Allocate(a1, v0, a2, a3, &runtime,
1901 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1903 // Get the arguments boilerplate from the current native context.
1904 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1905 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1906 __ lw(t0, MemOperand(
1907 t0, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1909 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1910 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1911 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1912 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1914 // Get the length (smi tagged) and set that as an in-object property too.
1915 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1916 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1918 __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
1919 Heap::kArgumentsLengthIndex * kPointerSize));
1922 __ Branch(&done, eq, a1, Operand(zero_reg));
1924 // Get the parameters pointer from the stack.
1925 __ lw(a2, MemOperand(sp, 1 * kPointerSize));
1927 // Set up the elements pointer in the allocated arguments object and
1928 // initialize the header in the elements fixed array.
1929 __ Addu(t0, v0, Operand(Heap::kStrictArgumentsObjectSize));
1930 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1931 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
1932 __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset));
1933 __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset));
1934 // Untag the length for the loop.
1935 __ srl(a1, a1, kSmiTagSize);
1937 // Copy the fixed array slots.
1939 // Set up t0 to point to the first array slot.
1940 __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1942 // Pre-decrement a2 with kPointerSize on each iteration.
1943 // Pre-decrement in order to skip receiver.
1944 __ Addu(a2, a2, Operand(-kPointerSize));
1945 __ lw(a3, MemOperand(a2));
1946 // Post-increment t0 with kPointerSize on each iteration.
1947 __ sw(a3, MemOperand(t0));
1948 __ Addu(t0, t0, Operand(kPointerSize));
1949 __ Subu(a1, a1, Operand(1));
1950 __ Branch(&loop, ne, a1, Operand(zero_reg));
1952 // Return and remove the on-stack parameters.
1956 // Do the runtime call to allocate the arguments object.
1958 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1962 void RegExpExecStub::Generate(MacroAssembler* masm) {
1963 // Just jump directly to runtime if native RegExp is not selected at compile
1964 // time or if regexp entry in generated code is turned off runtime switch or
1966 #ifdef V8_INTERPRETED_REGEXP
1967 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1968 #else // V8_INTERPRETED_REGEXP
1970 // Stack frame on entry.
1971 // sp[0]: last_match_info (expected JSArray)
1972 // sp[4]: previous index
1973 // sp[8]: subject string
1974 // sp[12]: JSRegExp object
1976 const int kLastMatchInfoOffset = 0 * kPointerSize;
1977 const int kPreviousIndexOffset = 1 * kPointerSize;
1978 const int kSubjectOffset = 2 * kPointerSize;
1979 const int kJSRegExpOffset = 3 * kPointerSize;
1982 // Allocation of registers for this function. These are in callee save
1983 // registers and will be preserved by the call to the native RegExp code, as
1984 // this code is called using the normal C calling convention. When calling
1985 // directly from generated code the native RegExp code will not do a GC and
1986 // therefore the content of these registers are safe to use after the call.
1987 // MIPS - using s0..s2, since we are not using CEntry Stub.
1988 Register subject = s0;
1989 Register regexp_data = s1;
1990 Register last_match_info_elements = s2;
1992 // Ensure that a RegExp stack is allocated.
1993 ExternalReference address_of_regexp_stack_memory_address =
1994 ExternalReference::address_of_regexp_stack_memory_address(
1996 ExternalReference address_of_regexp_stack_memory_size =
1997 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1998 __ li(a0, Operand(address_of_regexp_stack_memory_size));
1999 __ lw(a0, MemOperand(a0, 0));
2000 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2002 // Check that the first argument is a JSRegExp object.
2003 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
2004 STATIC_ASSERT(kSmiTag == 0);
2005 __ JumpIfSmi(a0, &runtime);
2006 __ GetObjectType(a0, a1, a1);
2007 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2009 // Check that the RegExp has been compiled (data contains a fixed array).
2010 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2011 if (FLAG_debug_code) {
2012 __ SmiTst(regexp_data, t0);
2014 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2017 __ GetObjectType(regexp_data, a0, a0);
2019 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2021 Operand(FIXED_ARRAY_TYPE));
2024 // regexp_data: RegExp data (FixedArray)
2025 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2026 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2027 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2029 // regexp_data: RegExp data (FixedArray)
2030 // Check that the number of captures fit in the static offsets vector buffer.
2032 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2033 // Check (number_of_captures + 1) * 2 <= offsets vector size
2034 // Or number_of_captures * 2 <= offsets vector size - 2
2035 // Multiplying by 2 comes for free since a2 is smi-tagged.
2036 STATIC_ASSERT(kSmiTag == 0);
2037 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2038 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2040 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2042 // Reset offset for possibly sliced string.
2043 __ mov(t0, zero_reg);
2044 __ lw(subject, MemOperand(sp, kSubjectOffset));
2045 __ JumpIfSmi(subject, &runtime);
2046 __ mov(a3, subject); // Make a copy of the original subject string.
2047 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2048 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2049 // subject: subject string
2050 // a3: subject string
2051 // a0: subject string instance type
2052 // regexp_data: RegExp data (FixedArray)
2053 // Handle subject string according to its encoding and representation:
2054 // (1) Sequential string? If yes, go to (5).
2055 // (2) Anything but sequential or cons? If yes, go to (6).
2056 // (3) Cons string. If the string is flat, replace subject with first string.
2057 // Otherwise bailout.
2058 // (4) Is subject external? If yes, go to (7).
2059 // (5) Sequential string. Load regexp code according to encoding.
2063 // Deferred code at the end of the stub:
2064 // (6) Not a long external string? If yes, go to (8).
2065 // (7) External string. Make it, offset-wise, look like a sequential string.
2067 // (8) Short external string or not a string? If yes, bail out to runtime.
2068 // (9) Sliced string. Replace subject with parent. Go to (4).
2070 Label seq_string /* 5 */, external_string /* 7 */,
2071 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2072 not_long_external /* 8 */;
2074 // (1) Sequential string? If yes, go to (5).
2077 Operand(kIsNotStringMask |
2078 kStringRepresentationMask |
2079 kShortExternalStringMask));
2080 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2081 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2083 // (2) Anything but sequential or cons? If yes, go to (6).
2084 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2085 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2086 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2087 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2089 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2091 // (3) Cons string. Check that it's flat.
2092 // Replace subject with first string and reload instance type.
2093 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2094 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2095 __ Branch(&runtime, ne, a0, Operand(a1));
2096 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2098 // (4) Is subject external? If yes, go to (7).
2099 __ bind(&check_underlying);
2100 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2101 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2102 STATIC_ASSERT(kSeqStringTag == 0);
2103 __ And(at, a0, Operand(kStringRepresentationMask));
2104 // The underlying external string is never a short external string.
2105 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2106 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2107 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2109 // (5) Sequential string. Load regexp code according to encoding.
2110 __ bind(&seq_string);
2111 // subject: sequential subject string (or look-alike, external string)
2112 // a3: original subject string
2113 // Load previous index and check range before a3 is overwritten. We have to
2114 // use a3 instead of subject here because subject might have been only made
2115 // to look like a sequential string when it actually is an external string.
2116 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
2117 __ JumpIfNotSmi(a1, &runtime);
2118 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
2119 __ Branch(&runtime, ls, a3, Operand(a1));
2120 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
2122 STATIC_ASSERT(kStringEncodingMask == 4);
2123 STATIC_ASSERT(kOneByteStringTag == 4);
2124 STATIC_ASSERT(kTwoByteStringTag == 0);
2125 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
2126 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2127 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
2128 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2129 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2131 // (E) Carry on. String handling is done.
2132 // t9: irregexp code
2133 // Check that the irregexp code has been generated for the actual string
2134 // encoding. If it has, the field contains a code object otherwise it contains
2135 // a smi (code flushing support).
2136 __ JumpIfSmi(t9, &runtime);
2138 // a1: previous index
2139 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2141 // subject: Subject string
2142 // regexp_data: RegExp data (FixedArray)
2143 // All checks done. Now push arguments for native regexp code.
2144 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2147 // Isolates: note we add an additional parameter here (isolate pointer).
2148 const int kRegExpExecuteArguments = 9;
2149 const int kParameterRegisters = 4;
2150 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2152 // Stack pointer now points to cell where return address is to be written.
2153 // Arguments are before that on the stack or in registers, meaning we
2154 // treat the return address as argument 5. Thus every argument after that
2155 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2156 // allocating space for the c argument slots, we don't need to calculate
2157 // that into the argument positions on the stack. This is how the stack will
2158 // look (sp meaning the value of sp at this moment):
2159 // [sp + 5] - Argument 9
2160 // [sp + 4] - Argument 8
2161 // [sp + 3] - Argument 7
2162 // [sp + 2] - Argument 6
2163 // [sp + 1] - Argument 5
2164 // [sp + 0] - saved ra
2166 // Argument 9: Pass current isolate address.
2167 // CFunctionArgumentOperand handles MIPS stack argument slots.
2168 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2169 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
2171 // Argument 8: Indicate that this is a direct call from JavaScript.
2172 __ li(a0, Operand(1));
2173 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
2175 // Argument 7: Start (high end) of backtracking stack memory area.
2176 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2177 __ lw(a0, MemOperand(a0, 0));
2178 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2179 __ lw(a2, MemOperand(a2, 0));
2180 __ addu(a0, a0, a2);
2181 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
2183 // Argument 6: Set the number of capture registers to zero to force global
2184 // regexps to behave as non-global. This does not affect non-global regexps.
2185 __ mov(a0, zero_reg);
2186 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
2188 // Argument 5: static offsets vector buffer.
2190 ExternalReference::address_of_static_offsets_vector(isolate())));
2191 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
2193 // For arguments 4 and 3 get string length, calculate start of string data
2194 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2195 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2196 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2197 // Load the length from the original subject string from the previous stack
2198 // frame. Therefore we have to use fp, which points exactly to two pointer
2199 // sizes below the previous sp. (Because creating a new stack frame pushes
2200 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2201 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2202 // If slice offset is not 0, load the length from the original sliced string.
2203 // Argument 4, a3: End of string data
2204 // Argument 3, a2: Start of string data
2205 // Prepare start and end index of the input.
2206 __ sllv(t1, t0, a3);
2207 __ addu(t0, t2, t1);
2208 __ sllv(t1, a1, a3);
2209 __ addu(a2, t0, t1);
2211 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
2212 __ sra(t2, t2, kSmiTagSize);
2213 __ sllv(t1, t2, a3);
2214 __ addu(a3, t0, t1);
2215 // Argument 2 (a1): Previous index.
2218 // Argument 1 (a0): Subject string.
2219 __ mov(a0, subject);
2221 // Locate the code entry and call it.
2222 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2223 DirectCEntryStub stub(isolate());
2224 stub.GenerateCall(masm, t9);
2226 __ LeaveExitFrame(false, no_reg, true);
2229 // subject: subject string (callee saved)
2230 // regexp_data: RegExp data (callee saved)
2231 // last_match_info_elements: Last match info elements (callee saved)
2232 // Check the result.
2234 __ Branch(&success, eq, v0, Operand(1));
2235 // We expect exactly one result since we force the called regexp to behave
2238 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2239 // If not exception it can only be retry. Handle that in the runtime system.
2240 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2241 // Result must now be exception. If there is no pending exception already a
2242 // stack overflow (on the backtrack stack) was detected in RegExp code but
2243 // haven't created the exception yet. Handle that in the runtime system.
2244 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2245 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2246 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2248 __ lw(v0, MemOperand(a2, 0));
2249 __ Branch(&runtime, eq, v0, Operand(a1));
2251 // For exception, throw the exception again.
2252 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2255 // For failure and exception return null.
2256 __ li(v0, Operand(isolate()->factory()->null_value()));
2259 // Process the result from the native regexp code.
2262 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2263 // Calculate number of capture registers (number_of_captures + 1) * 2.
2264 // Multiplying by 2 comes for free since r1 is smi-tagged.
2265 STATIC_ASSERT(kSmiTag == 0);
2266 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2267 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
2269 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
2270 __ JumpIfSmi(a0, &runtime);
2271 __ GetObjectType(a0, a2, a2);
2272 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2273 // Check that the JSArray is in fast case.
2274 __ lw(last_match_info_elements,
2275 FieldMemOperand(a0, JSArray::kElementsOffset));
2276 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2277 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2278 __ Branch(&runtime, ne, a0, Operand(at));
2279 // Check that the last match info has space for the capture registers and the
2280 // additional information.
2282 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2283 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2284 __ sra(at, a0, kSmiTagSize);
2285 __ Branch(&runtime, gt, a2, Operand(at));
2287 // a1: number of capture registers
2288 // subject: subject string
2289 // Store the capture count.
2290 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
2291 __ sw(a2, FieldMemOperand(last_match_info_elements,
2292 RegExpImpl::kLastCaptureCountOffset));
2293 // Store last subject and last input.
2295 FieldMemOperand(last_match_info_elements,
2296 RegExpImpl::kLastSubjectOffset));
2297 __ mov(a2, subject);
2298 __ RecordWriteField(last_match_info_elements,
2299 RegExpImpl::kLastSubjectOffset,
2304 __ mov(subject, a2);
2306 FieldMemOperand(last_match_info_elements,
2307 RegExpImpl::kLastInputOffset));
2308 __ RecordWriteField(last_match_info_elements,
2309 RegExpImpl::kLastInputOffset,
2315 // Get the static offsets vector filled by the native regexp code.
2316 ExternalReference address_of_static_offsets_vector =
2317 ExternalReference::address_of_static_offsets_vector(isolate());
2318 __ li(a2, Operand(address_of_static_offsets_vector));
2320 // a1: number of capture registers
2321 // a2: offsets vector
2322 Label next_capture, done;
2323 // Capture register counter starts from number of capture registers and
2324 // counts down until wrapping after zero.
2326 last_match_info_elements,
2327 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2328 __ bind(&next_capture);
2329 __ Subu(a1, a1, Operand(1));
2330 __ Branch(&done, lt, a1, Operand(zero_reg));
2331 // Read the value from the static offsets vector buffer.
2332 __ lw(a3, MemOperand(a2, 0));
2333 __ addiu(a2, a2, kPointerSize);
2334 // Store the smi value in the last match info.
2335 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
2336 __ sw(a3, MemOperand(a0, 0));
2337 __ Branch(&next_capture, USE_DELAY_SLOT);
2338 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
2342 // Return last match info.
2343 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
2346 // Do the runtime call to execute the regexp.
2348 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2350 // Deferred code for string handling.
2351 // (6) Not a long external string? If yes, go to (8).
2352 __ bind(¬_seq_nor_cons);
2354 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2356 // (7) External string. Make it, offset-wise, look like a sequential string.
2357 __ bind(&external_string);
2358 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2359 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2360 if (FLAG_debug_code) {
2361 // Assert that we do not have a cons or slice (indirect strings) here.
2362 // Sequential strings have already been ruled out.
2363 __ And(at, a0, Operand(kIsIndirectStringMask));
2365 kExternalStringExpectedButNotFound,
2370 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2371 // Move the pointer so that offset-wise, it looks like a sequential string.
2372 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2375 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2376 __ jmp(&seq_string); // Go to (5).
2378 // (8) Short external string or not a string? If yes, bail out to runtime.
2379 __ bind(¬_long_external);
2380 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2381 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2382 __ Branch(&runtime, ne, at, Operand(zero_reg));
2384 // (9) Sliced string. Replace subject with parent. Go to (4).
2385 // Load offset into t0 and replace subject string with parent.
2386 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2387 __ sra(t0, t0, kSmiTagSize);
2388 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2389 __ jmp(&check_underlying); // Go to (4).
2390 #endif // V8_INTERPRETED_REGEXP
2394 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2396 // a0 : number of arguments to the construct function
2397 // a2 : feedback vector
2398 // a3 : slot in feedback vector (Smi)
2399 // a1 : the function to call
2400 // t0 : original constructor (for IsSuperConstructorCall)
2401 FrameScope scope(masm, StackFrame::INTERNAL);
2402 const RegList kSavedRegs = 1 << 4 | // a0
2406 BoolToInt(is_super) << 8; // t0
2408 // Number-of-arguments register must be smi-tagged to call out.
2410 __ MultiPush(kSavedRegs);
2414 __ MultiPop(kSavedRegs);
2419 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2420 // Cache the called function in a feedback vector slot. Cache states
2421 // are uninitialized, monomorphic (indicated by a JSFunction), and
2423 // a0 : number of arguments to the construct function
2424 // a1 : the function to call
2425 // a2 : feedback vector
2426 // a3 : slot in feedback vector (Smi)
2427 // t0 : original constructor (for IsSuperConstructorCall)
2428 Label initialize, done, miss, megamorphic, not_array_function;
2430 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2431 masm->isolate()->heap()->megamorphic_symbol());
2432 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2433 masm->isolate()->heap()->uninitialized_symbol());
2435 // Load the cache state into t2.
2436 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2437 __ Addu(t2, a2, Operand(t2));
2438 __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize));
2440 // A monomorphic cache hit or an already megamorphic state: invoke the
2441 // function without changing the state.
2442 // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at
2443 // this position in a symbol (see static asserts in type-feedback-vector.h).
2444 Label check_allocation_site;
2445 Register feedback_map = t1;
2446 Register weak_value = t4;
2447 __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset));
2448 __ Branch(&done, eq, a1, Operand(weak_value));
2449 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2450 __ Branch(&done, eq, t2, Operand(at));
2451 __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset));
2452 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2453 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2454 feedback_map, Operand(at));
2456 // If the weak cell is cleared, we have a new chance to become monomorphic.
2457 __ JumpIfSmi(weak_value, &initialize);
2458 __ jmp(&megamorphic);
2460 if (!FLAG_pretenuring_call_new) {
2461 __ bind(&check_allocation_site);
2462 // If we came here, we need to see if we are the array function.
2463 // If we didn't have a matching function, and we didn't find the megamorph
2464 // sentinel, then we have in the slot either some other function or an
2466 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2467 __ Branch(&miss, ne, feedback_map, Operand(at));
2469 // Make sure the function is the Array() function
2470 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2471 __ Branch(&megamorphic, ne, a1, Operand(t2));
2477 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2479 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2480 __ Branch(&initialize, eq, t2, Operand(at));
2481 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2482 // write-barrier is needed.
2483 __ bind(&megamorphic);
2484 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2485 __ Addu(t2, a2, Operand(t2));
2486 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2487 __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize));
2490 // An uninitialized cache is patched with the function.
2491 __ bind(&initialize);
2492 if (!FLAG_pretenuring_call_new) {
2493 // Make sure the function is the Array() function.
2494 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2495 __ Branch(¬_array_function, ne, a1, Operand(t2));
2497 // The target function is the Array constructor,
2498 // Create an AllocationSite if we don't already have it, store it in the
2500 CreateAllocationSiteStub create_stub(masm->isolate());
2501 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2504 __ bind(¬_array_function);
2507 CreateWeakCellStub create_stub(masm->isolate());
2508 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2513 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2514 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2515 __ lw(t0, FieldMemOperand(a3, SharedFunctionInfo::kCompilerHintsOffset));
2517 // Do not transform the receiver for strict mode functions.
2518 int32_t strict_mode_function_mask =
2519 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
2520 // Do not transform the receiver for native (Compilerhints already in a3).
2521 int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize);
2522 __ And(at, t0, Operand(strict_mode_function_mask | native_mask));
2523 __ Branch(cont, ne, at, Operand(zero_reg));
2527 static void EmitSlowCase(MacroAssembler* masm,
2529 Label* non_function) {
2530 // Check for function proxy.
2531 __ Branch(non_function, ne, t0, Operand(JS_FUNCTION_PROXY_TYPE));
2532 __ push(a1); // put proxy as additional argument
2533 __ li(a0, Operand(argc + 1, RelocInfo::NONE32));
2534 __ mov(a2, zero_reg);
2535 __ GetBuiltinFunction(a1, Context::CALL_FUNCTION_PROXY_BUILTIN_INDEX);
2537 Handle<Code> adaptor =
2538 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2539 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2542 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2543 // of the original receiver from the call site).
2544 __ bind(non_function);
2545 __ sw(a1, MemOperand(sp, argc * kPointerSize));
2546 __ li(a0, Operand(argc)); // Set up the number of arguments.
2547 __ mov(a2, zero_reg);
2548 __ GetBuiltinFunction(a1, Context::CALL_NON_FUNCTION_BUILTIN_INDEX);
2549 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2550 RelocInfo::CODE_TARGET);
2554 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2555 // Wrap the receiver and patch it back onto the stack.
2556 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2559 ToObjectStub stub(masm->isolate());
2563 __ Branch(USE_DELAY_SLOT, cont);
2564 __ sw(v0, MemOperand(sp, argc * kPointerSize));
2568 static void CallFunctionNoFeedback(MacroAssembler* masm,
2569 int argc, bool needs_checks,
2570 bool call_as_method) {
2571 // a1 : the function to call
2572 Label slow, non_function, wrap, cont;
2575 // Check that the function is really a JavaScript function.
2576 // a1: pushed function (to be verified)
2577 __ JumpIfSmi(a1, &non_function);
2579 // Goto slow case if we do not have a function.
2580 __ GetObjectType(a1, t0, t0);
2581 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2584 // Fast-case: Invoke the function now.
2585 // a1: pushed function
2586 ParameterCount actual(argc);
2588 if (call_as_method) {
2590 EmitContinueIfStrictOrNative(masm, &cont);
2593 // Compute the receiver in sloppy mode.
2594 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2597 __ JumpIfSmi(a3, &wrap);
2598 __ GetObjectType(a3, t0, t0);
2599 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2607 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2610 // Slow-case: Non-function called.
2612 EmitSlowCase(masm, argc, &non_function);
2615 if (call_as_method) {
2617 // Wrap the receiver and patch it back onto the stack.
2618 EmitWrapCase(masm, argc, &cont);
2623 void CallFunctionStub::Generate(MacroAssembler* masm) {
2624 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2628 void CallConstructStub::Generate(MacroAssembler* masm) {
2629 // a0 : number of arguments
2630 // a1 : the function to call
2631 // a2 : feedback vector
2632 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2633 // t0 : original constructor (for IsSuperConstructorCall)
2634 Label slow, non_function_call;
2636 // Check that the function is not a smi.
2637 __ JumpIfSmi(a1, &non_function_call);
2638 // Check that the function is a JSFunction.
2639 __ GetObjectType(a1, t1, t1);
2640 __ Branch(&slow, ne, t1, Operand(JS_FUNCTION_TYPE));
2642 if (RecordCallTarget()) {
2643 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2645 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2646 __ Addu(t1, a2, at);
2647 if (FLAG_pretenuring_call_new) {
2648 // Put the AllocationSite from the feedback vector into a2.
2649 // By adding kPointerSize we encode that we know the AllocationSite
2650 // entry is at the feedback vector slot given by a3 + 1.
2651 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize + kPointerSize));
2653 Label feedback_register_initialized;
2654 // Put the AllocationSite from the feedback vector into a2, or undefined.
2655 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
2656 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
2657 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2658 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
2659 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2660 __ bind(&feedback_register_initialized);
2663 __ AssertUndefinedOrAllocationSite(a2, t1);
2666 // Pass function as original constructor.
2667 if (IsSuperConstructorCall()) {
2673 // Jump to the function-specific construct stub.
2674 Register jmp_reg = t0;
2675 __ lw(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2676 __ lw(jmp_reg, FieldMemOperand(jmp_reg,
2677 SharedFunctionInfo::kConstructStubOffset));
2678 __ Addu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2681 // a0: number of arguments
2682 // a1: called object
2686 __ Branch(&non_function_call, ne, t1, Operand(JS_FUNCTION_PROXY_TYPE));
2687 __ GetBuiltinFunction(
2688 a1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2691 __ bind(&non_function_call);
2692 __ GetBuiltinFunction(
2693 a1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2695 // Set expected number of arguments to zero (not changing r0).
2696 __ li(a2, Operand(0, RelocInfo::NONE32));
2697 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2698 RelocInfo::CODE_TARGET);
2702 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2703 __ lw(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2704 __ lw(vector, FieldMemOperand(vector,
2705 JSFunction::kSharedFunctionInfoOffset));
2706 __ lw(vector, FieldMemOperand(vector,
2707 SharedFunctionInfo::kFeedbackVectorOffset));
2711 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2717 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2718 __ Branch(&miss, ne, a1, Operand(at));
2720 __ li(a0, Operand(arg_count()));
2721 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2722 __ Addu(at, a2, Operand(at));
2723 __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize));
2725 // Verify that t0 contains an AllocationSite
2726 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2727 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2728 __ Branch(&miss, ne, t1, Operand(at));
2730 // Increment the call count for monomorphic function calls.
2731 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2732 __ Addu(at, a2, Operand(at));
2733 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2734 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2735 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2739 ArrayConstructorStub stub(masm->isolate(), arg_count());
2740 __ TailCallStub(&stub);
2745 // The slow case, we need this no matter what to complete a call after a miss.
2746 CallFunctionNoFeedback(masm,
2752 __ stop("Unexpected code address");
2756 void CallICStub::Generate(MacroAssembler* masm) {
2758 // a3 - slot id (Smi)
2760 const int with_types_offset =
2761 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2762 const int generic_offset =
2763 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2764 Label extra_checks_or_miss, slow_start;
2765 Label slow, non_function, wrap, cont;
2766 Label have_js_function;
2767 int argc = arg_count();
2768 ParameterCount actual(argc);
2770 // The checks. First, does r1 match the recorded monomorphic target?
2771 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2772 __ Addu(t0, a2, Operand(t0));
2773 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2775 // We don't know that we have a weak cell. We might have a private symbol
2776 // or an AllocationSite, but the memory is safe to examine.
2777 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2779 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2780 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2781 // computed, meaning that it can't appear to be a pointer. If the low bit is
2782 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2784 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2785 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2786 WeakCell::kValueOffset &&
2787 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2789 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2790 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
2792 // The compare above could have been a SMI/SMI comparison. Guard against this
2793 // convincing us that we have a monomorphic JSFunction.
2794 __ JumpIfSmi(a1, &extra_checks_or_miss);
2796 // Increment the call count for monomorphic function calls.
2797 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2798 __ Addu(at, a2, Operand(at));
2799 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2800 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2801 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2803 __ bind(&have_js_function);
2804 if (CallAsMethod()) {
2805 EmitContinueIfStrictOrNative(masm, &cont);
2806 // Compute the receiver in sloppy mode.
2807 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2809 __ JumpIfSmi(a3, &wrap);
2810 __ GetObjectType(a3, t0, t0);
2811 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2816 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2819 EmitSlowCase(masm, argc, &non_function);
2821 if (CallAsMethod()) {
2823 EmitWrapCase(masm, argc, &cont);
2826 __ bind(&extra_checks_or_miss);
2827 Label uninitialized, miss;
2829 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2830 __ Branch(&slow_start, eq, t0, Operand(at));
2832 // The following cases attempt to handle MISS cases without going to the
2834 if (FLAG_trace_ic) {
2838 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2839 __ Branch(&uninitialized, eq, t0, Operand(at));
2841 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2842 // to handle it here. More complex cases are dealt with in the runtime.
2843 __ AssertNotSmi(t0);
2844 __ GetObjectType(t0, t1, t1);
2845 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
2846 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2847 __ Addu(t0, a2, Operand(t0));
2848 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2849 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2850 // We have to update statistics for runtime profiling.
2851 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2852 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
2853 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2854 __ lw(t0, FieldMemOperand(a2, generic_offset));
2855 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2856 __ Branch(USE_DELAY_SLOT, &slow_start);
2857 __ sw(t0, FieldMemOperand(a2, generic_offset)); // In delay slot.
2859 __ bind(&uninitialized);
2861 // We are going monomorphic, provided we actually have a JSFunction.
2862 __ JumpIfSmi(a1, &miss);
2864 // Goto miss case if we do not have a function.
2865 __ GetObjectType(a1, t0, t0);
2866 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2868 // Make sure the function is not the Array() function, which requires special
2869 // behavior on MISS.
2870 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2871 __ Branch(&miss, eq, a1, Operand(t0));
2874 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2875 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2876 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2878 // Initialize the call counter.
2879 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2880 __ Addu(at, a2, Operand(at));
2881 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2882 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2884 // Store the function. Use a stub since we need a frame for allocation.
2889 FrameScope scope(masm, StackFrame::INTERNAL);
2890 CreateWeakCellStub create_stub(masm->isolate());
2892 __ CallStub(&create_stub);
2896 __ Branch(&have_js_function);
2898 // We are here because tracing is on or we encountered a MISS case we can't
2904 __ bind(&slow_start);
2905 // Check that the function is really a JavaScript function.
2906 // r1: pushed function (to be verified)
2907 __ JumpIfSmi(a1, &non_function);
2909 // Goto slow case if we do not have a function.
2910 __ GetObjectType(a1, t0, t0);
2911 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2912 __ Branch(&have_js_function);
2916 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2917 FrameScope scope(masm, StackFrame::INTERNAL);
2919 // Push the receiver and the function and feedback info.
2920 __ Push(a1, a2, a3);
2923 Runtime::FunctionId id = GetICState() == DEFAULT
2924 ? Runtime::kCallIC_Miss
2925 : Runtime::kCallIC_Customization_Miss;
2926 __ CallRuntime(id, 3);
2928 // Move result to a1 and exit the internal frame.
2933 // StringCharCodeAtGenerator.
2934 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2935 DCHECK(!t0.is(index_));
2936 DCHECK(!t0.is(result_));
2937 DCHECK(!t0.is(object_));
2938 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2939 // If the receiver is a smi trigger the non-string case.
2940 __ JumpIfSmi(object_, receiver_not_string_);
2942 // Fetch the instance type of the receiver into result register.
2943 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2944 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2945 // If the receiver is not a string trigger the non-string case.
2946 __ And(t0, result_, Operand(kIsNotStringMask));
2947 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
2950 // If the index is non-smi trigger the non-smi case.
2951 __ JumpIfNotSmi(index_, &index_not_smi_);
2953 __ bind(&got_smi_index_);
2955 // Check for index out of range.
2956 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
2957 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
2959 __ sra(index_, index_, kSmiTagSize);
2961 StringCharLoadGenerator::Generate(masm,
2967 __ sll(result_, result_, kSmiTagSize);
2972 void StringCharCodeAtGenerator::GenerateSlow(
2973 MacroAssembler* masm, EmbedMode embed_mode,
2974 const RuntimeCallHelper& call_helper) {
2975 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2977 // Index is not a smi.
2978 __ bind(&index_not_smi_);
2979 // If index is a heap number, try converting it to an integer.
2982 Heap::kHeapNumberMapRootIndex,
2985 call_helper.BeforeCall(masm);
2986 // Consumed by runtime conversion function:
2987 if (embed_mode == PART_OF_IC_HANDLER) {
2988 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2989 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2991 __ Push(object_, index_);
2993 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2994 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2996 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2997 // NumberToSmi discards numbers that are not exact integers.
2998 __ CallRuntime(Runtime::kNumberToSmi, 1);
3001 // Save the conversion result before the pop instructions below
3002 // have a chance to overwrite it.
3003 __ Move(index_, v0);
3004 if (embed_mode == PART_OF_IC_HANDLER) {
3005 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3006 LoadWithVectorDescriptor::SlotRegister(), object_);
3010 // Reload the instance type.
3011 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3012 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3013 call_helper.AfterCall(masm);
3014 // If index is still not a smi, it must be out of range.
3015 __ JumpIfNotSmi(index_, index_out_of_range_);
3016 // Otherwise, return to the fast path.
3017 __ Branch(&got_smi_index_);
3019 // Call runtime. We get here when the receiver is a string and the
3020 // index is a number, but the code of getting the actual character
3021 // is too complex (e.g., when the string needs to be flattened).
3022 __ bind(&call_runtime_);
3023 call_helper.BeforeCall(masm);
3024 __ sll(index_, index_, kSmiTagSize);
3025 __ Push(object_, index_);
3026 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3028 __ Move(result_, v0);
3030 call_helper.AfterCall(masm);
3033 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3037 // -------------------------------------------------------------------------
3038 // StringCharFromCodeGenerator
3040 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3041 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3043 DCHECK(!t0.is(result_));
3044 DCHECK(!t0.is(code_));
3046 STATIC_ASSERT(kSmiTag == 0);
3047 STATIC_ASSERT(kSmiShiftSize == 0);
3048 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3049 __ And(t0, code_, Operand(kSmiTagMask |
3050 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3051 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
3053 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3054 // At this point code register contains smi tagged one-byte char code.
3055 STATIC_ASSERT(kSmiTag == 0);
3056 __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize);
3057 __ Addu(result_, result_, t0);
3058 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3059 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
3060 __ Branch(&slow_case_, eq, result_, Operand(t0));
3065 void StringCharFromCodeGenerator::GenerateSlow(
3066 MacroAssembler* masm,
3067 const RuntimeCallHelper& call_helper) {
3068 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3070 __ bind(&slow_case_);
3071 call_helper.BeforeCall(masm);
3073 __ CallRuntime(Runtime::kCharFromCode, 1);
3074 __ Move(result_, v0);
3076 call_helper.AfterCall(masm);
3079 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3083 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3086 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3091 String::Encoding encoding) {
3092 if (FLAG_debug_code) {
3093 // Check that destination is word aligned.
3094 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3096 kDestinationOfCopyNotAligned,
3101 // Assumes word reads and writes are little endian.
3102 // Nothing to do for zero characters.
3105 if (encoding == String::TWO_BYTE_ENCODING) {
3106 __ Addu(count, count, count);
3109 Register limit = count; // Read until dest equals this.
3110 __ Addu(limit, dest, Operand(count));
3112 Label loop_entry, loop;
3113 // Copy bytes from src to dest until dest hits limit.
3114 __ Branch(&loop_entry);
3116 __ lbu(scratch, MemOperand(src));
3117 __ Addu(src, src, Operand(1));
3118 __ sb(scratch, MemOperand(dest));
3119 __ Addu(dest, dest, Operand(1));
3120 __ bind(&loop_entry);
3121 __ Branch(&loop, lt, dest, Operand(limit));
3127 void SubStringStub::Generate(MacroAssembler* masm) {
3129 // Stack frame on entry.
3130 // ra: return address
3135 // This stub is called from the native-call %_SubString(...), so
3136 // nothing can be assumed about the arguments. It is tested that:
3137 // "string" is a sequential string,
3138 // both "from" and "to" are smis, and
3139 // 0 <= from <= to <= string.length.
3140 // If any of these assumptions fail, we call the runtime system.
3142 const int kToOffset = 0 * kPointerSize;
3143 const int kFromOffset = 1 * kPointerSize;
3144 const int kStringOffset = 2 * kPointerSize;
3146 __ lw(a2, MemOperand(sp, kToOffset));
3147 __ lw(a3, MemOperand(sp, kFromOffset));
3148 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3149 STATIC_ASSERT(kSmiTag == 0);
3150 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3152 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3153 // safe in this case.
3154 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
3155 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
3156 // Both a2 and a3 are untagged integers.
3158 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3160 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3161 __ Subu(a2, a2, a3);
3163 // Make sure first argument is a string.
3164 __ lw(v0, MemOperand(sp, kStringOffset));
3165 __ JumpIfSmi(v0, &runtime);
3166 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3167 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3168 __ And(t0, a1, Operand(kIsNotStringMask));
3170 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3173 __ Branch(&single_char, eq, a2, Operand(1));
3175 // Short-cut for the case of trivial substring.
3177 // v0: original string
3178 // a2: result string length
3179 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
3181 // Return original string.
3182 __ Branch(&return_v0, eq, a2, Operand(t0));
3183 // Longer than original string's length or negative: unsafe arguments.
3184 __ Branch(&runtime, hi, a2, Operand(t0));
3185 // Shorter than original string's length: an actual substring.
3187 // Deal with different string types: update the index if necessary
3188 // and put the underlying string into t1.
3189 // v0: original string
3190 // a1: instance type
3192 // a3: from index (untagged)
3193 Label underlying_unpacked, sliced_string, seq_or_external_string;
3194 // If the string is not indirect, it can only be sequential or external.
3195 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3196 STATIC_ASSERT(kIsIndirectStringMask != 0);
3197 __ And(t0, a1, Operand(kIsIndirectStringMask));
3198 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
3199 // t0 is used as a scratch register and can be overwritten in either case.
3200 __ And(t0, a1, Operand(kSlicedNotConsMask));
3201 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
3202 // Cons string. Check whether it is flat, then fetch first part.
3203 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
3204 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
3205 __ Branch(&runtime, ne, t1, Operand(t0));
3206 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
3207 // Update instance type.
3208 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3209 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3210 __ jmp(&underlying_unpacked);
3212 __ bind(&sliced_string);
3213 // Sliced string. Fetch parent and correct start index by offset.
3214 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3215 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3216 __ sra(t0, t0, 1); // Add offset to index.
3217 __ Addu(a3, a3, t0);
3218 // Update instance type.
3219 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3220 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3221 __ jmp(&underlying_unpacked);
3223 __ bind(&seq_or_external_string);
3224 // Sequential or external string. Just move string to the expected register.
3227 __ bind(&underlying_unpacked);
3229 if (FLAG_string_slices) {
3231 // t1: underlying subject string
3232 // a1: instance type of underlying subject string
3234 // a3: adjusted start index (untagged)
3235 // Short slice. Copy instead of slicing.
3236 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3237 // Allocate new sliced string. At this point we do not reload the instance
3238 // type including the string encoding because we simply rely on the info
3239 // provided by the original string. It does not matter if the original
3240 // string's encoding is wrong because we always have to recheck encoding of
3241 // the newly created string's parent anyways due to externalized strings.
3242 Label two_byte_slice, set_slice_header;
3243 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3244 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3245 __ And(t0, a1, Operand(kStringEncodingMask));
3246 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
3247 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
3248 __ jmp(&set_slice_header);
3249 __ bind(&two_byte_slice);
3250 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
3251 __ bind(&set_slice_header);
3253 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3254 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3257 __ bind(©_routine);
3260 // t1: underlying subject string
3261 // a1: instance type of underlying subject string
3263 // a3: adjusted start index (untagged)
3264 Label two_byte_sequential, sequential_string, allocate_result;
3265 STATIC_ASSERT(kExternalStringTag != 0);
3266 STATIC_ASSERT(kSeqStringTag == 0);
3267 __ And(t0, a1, Operand(kExternalStringTag));
3268 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
3270 // Handle external string.
3271 // Rule out short external strings.
3272 STATIC_ASSERT(kShortExternalStringTag != 0);
3273 __ And(t0, a1, Operand(kShortExternalStringTag));
3274 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3275 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
3276 // t1 already points to the first character of underlying string.
3277 __ jmp(&allocate_result);
3279 __ bind(&sequential_string);
3280 // Locate first character of underlying subject string.
3281 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3282 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3284 __ bind(&allocate_result);
3285 // Sequential acii string. Allocate the result.
3286 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3287 __ And(t0, a1, Operand(kStringEncodingMask));
3288 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
3290 // Allocate and copy the resulting ASCII string.
3291 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
3293 // Locate first character of substring to copy.
3294 __ Addu(t1, t1, a3);
3296 // Locate first character of result.
3297 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3299 // v0: result string
3300 // a1: first character of result string
3301 // a2: result string length
3302 // t1: first character of substring to copy
3303 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3304 StringHelper::GenerateCopyCharacters(
3305 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
3308 // Allocate and copy the resulting two-byte string.
3309 __ bind(&two_byte_sequential);
3310 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
3312 // Locate first character of substring to copy.
3313 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3315 __ Addu(t1, t1, t0);
3316 // Locate first character of result.
3317 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3319 // v0: result string.
3320 // a1: first character of result.
3321 // a2: result length.
3322 // t1: first character of substring to copy.
3323 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3324 StringHelper::GenerateCopyCharacters(
3325 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
3327 __ bind(&return_v0);
3328 Counters* counters = isolate()->counters();
3329 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
3332 // Just jump to runtime to create the sub string.
3334 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3336 __ bind(&single_char);
3337 // v0: original string
3338 // a1: instance type
3340 // a3: from index (untagged)
3342 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3343 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3344 generator.GenerateFast(masm);
3346 generator.SkipSlow(masm, &runtime);
3350 void ToNumberStub::Generate(MacroAssembler* masm) {
3351 // The ToNumber stub takes one argument in a0.
3353 __ JumpIfNotSmi(a0, ¬_smi);
3354 __ Ret(USE_DELAY_SLOT);
3358 Label not_heap_number;
3359 __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3360 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3362 // a1: instance type.
3363 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3364 __ Ret(USE_DELAY_SLOT);
3366 __ bind(¬_heap_number);
3368 Label not_string, slow_string;
3369 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3370 // Check if string has a cached array index.
3371 __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3372 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3373 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3374 __ IndexFromHash(a2, a0);
3375 __ Ret(USE_DELAY_SLOT);
3377 __ bind(&slow_string);
3378 __ push(a0); // Push argument.
3379 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3380 __ bind(¬_string);
3383 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3384 __ Ret(USE_DELAY_SLOT);
3385 __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3386 __ bind(¬_oddball);
3388 __ push(a0); // Push argument.
3389 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3393 void ToStringStub::Generate(MacroAssembler* masm) {
3394 // The ToString stub takes on argument in a0.
3396 __ JumpIfSmi(a0, &is_number);
3399 __ GetObjectType(a0, a1, a1);
3401 // a1: receiver instance type
3402 __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
3403 __ Ret(USE_DELAY_SLOT);
3405 __ bind(¬_string);
3407 Label not_heap_number;
3408 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3409 __ bind(&is_number);
3410 NumberToStringStub stub(isolate());
3411 __ TailCallStub(&stub);
3412 __ bind(¬_heap_number);
3415 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3416 __ Ret(USE_DELAY_SLOT);
3417 __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
3418 __ bind(¬_oddball);
3420 __ push(a0); // Push argument.
3421 __ TailCallRuntime(Runtime::kToString, 1, 1);
3425 void StringHelper::GenerateFlatOneByteStringEquals(
3426 MacroAssembler* masm, Register left, Register right, Register scratch1,
3427 Register scratch2, Register scratch3) {
3428 Register length = scratch1;
3431 Label strings_not_equal, check_zero_length;
3432 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
3433 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3434 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3435 __ bind(&strings_not_equal);
3436 DCHECK(is_int16(NOT_EQUAL));
3437 __ Ret(USE_DELAY_SLOT);
3438 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3440 // Check if the length is zero.
3441 Label compare_chars;
3442 __ bind(&check_zero_length);
3443 STATIC_ASSERT(kSmiTag == 0);
3444 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3445 DCHECK(is_int16(EQUAL));
3446 __ Ret(USE_DELAY_SLOT);
3447 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3449 // Compare characters.
3450 __ bind(&compare_chars);
3452 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3453 v0, &strings_not_equal);
3455 // Characters are equal.
3456 __ Ret(USE_DELAY_SLOT);
3457 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3461 void StringHelper::GenerateCompareFlatOneByteStrings(
3462 MacroAssembler* masm, Register left, Register right, Register scratch1,
3463 Register scratch2, Register scratch3, Register scratch4) {
3464 Label result_not_equal, compare_lengths;
3465 // Find minimum length and length difference.
3466 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
3467 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3468 __ Subu(scratch3, scratch1, Operand(scratch2));
3469 Register length_delta = scratch3;
3470 __ slt(scratch4, scratch2, scratch1);
3471 __ Movn(scratch1, scratch2, scratch4);
3472 Register min_length = scratch1;
3473 STATIC_ASSERT(kSmiTag == 0);
3474 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3477 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3478 scratch4, v0, &result_not_equal);
3480 // Compare lengths - strings up to min-length are equal.
3481 __ bind(&compare_lengths);
3482 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3483 // Use length_delta as result if it's zero.
3484 __ mov(scratch2, length_delta);
3485 __ mov(scratch4, zero_reg);
3486 __ mov(v0, zero_reg);
3488 __ bind(&result_not_equal);
3489 // Conditionally update the result based either on length_delta or
3490 // the last comparion performed in the loop above.
3492 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3493 __ li(v0, Operand(Smi::FromInt(GREATER)));
3494 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3495 __ li(v0, Operand(Smi::FromInt(LESS)));
3501 void StringHelper::GenerateOneByteCharsCompareLoop(
3502 MacroAssembler* masm, Register left, Register right, Register length,
3503 Register scratch1, Register scratch2, Register scratch3,
3504 Label* chars_not_equal) {
3505 // Change index to run from -length to -1 by adding length to string
3506 // start. This means that loop ends when index reaches zero, which
3507 // doesn't need an additional compare.
3508 __ SmiUntag(length);
3509 __ Addu(scratch1, length,
3510 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3511 __ Addu(left, left, Operand(scratch1));
3512 __ Addu(right, right, Operand(scratch1));
3513 __ Subu(length, zero_reg, length);
3514 Register index = length; // index = -length;
3520 __ Addu(scratch3, left, index);
3521 __ lbu(scratch1, MemOperand(scratch3));
3522 __ Addu(scratch3, right, index);
3523 __ lbu(scratch2, MemOperand(scratch3));
3524 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3525 __ Addu(index, index, 1);
3526 __ Branch(&loop, ne, index, Operand(zero_reg));
3530 void StringCompareStub::Generate(MacroAssembler* masm) {
3533 Counters* counters = isolate()->counters();
3535 // Stack frame on entry.
3536 // sp[0]: right string
3537 // sp[4]: left string
3538 __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3539 __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3542 __ Branch(¬_same, ne, a0, Operand(a1));
3543 STATIC_ASSERT(EQUAL == 0);
3544 STATIC_ASSERT(kSmiTag == 0);
3545 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3546 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3551 // Check that both objects are sequential one-byte strings.
3552 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3554 // Compare flat ASCII strings natively. Remove arguments from stack first.
3555 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3556 __ Addu(sp, sp, Operand(2 * kPointerSize));
3557 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3560 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3564 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3565 // ----------- S t a t e -------------
3568 // -- ra : return address
3569 // -----------------------------------
3571 // Load a2 with the allocation site. We stick an undefined dummy value here
3572 // and replace it with the real allocation site later when we instantiate this
3573 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3574 __ li(a2, handle(isolate()->heap()->undefined_value()));
3576 // Make sure that we actually patched the allocation site.
3577 if (FLAG_debug_code) {
3578 __ And(at, a2, Operand(kSmiTagMask));
3579 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3580 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
3581 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3582 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
3585 // Tail call into the stub that handles binary operations with allocation
3587 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3588 __ TailCallStub(&stub);
3592 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3593 DCHECK(state() == CompareICState::SMI);
3596 __ JumpIfNotSmi(a2, &miss);
3598 if (GetCondition() == eq) {
3599 // For equality we do not care about the sign of the result.
3600 __ Ret(USE_DELAY_SLOT);
3601 __ Subu(v0, a0, a1);
3603 // Untag before subtracting to avoid handling overflow.
3606 __ Ret(USE_DELAY_SLOT);
3607 __ Subu(v0, a1, a0);
3615 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3616 DCHECK(state() == CompareICState::NUMBER);
3619 Label unordered, maybe_undefined1, maybe_undefined2;
3622 if (left() == CompareICState::SMI) {
3623 __ JumpIfNotSmi(a1, &miss);
3625 if (right() == CompareICState::SMI) {
3626 __ JumpIfNotSmi(a0, &miss);
3629 // Inlining the double comparison and falling back to the general compare
3630 // stub if NaN is involved.
3631 // Load left and right operand.
3632 Label done, left, left_smi, right_smi;
3633 __ JumpIfSmi(a0, &right_smi);
3634 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3636 __ Subu(a2, a0, Operand(kHeapObjectTag));
3637 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3639 __ bind(&right_smi);
3640 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3641 FPURegister single_scratch = f6;
3642 __ mtc1(a2, single_scratch);
3643 __ cvt_d_w(f2, single_scratch);
3646 __ JumpIfSmi(a1, &left_smi);
3647 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3649 __ Subu(a2, a1, Operand(kHeapObjectTag));
3650 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3653 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3654 single_scratch = f8;
3655 __ mtc1(a2, single_scratch);
3656 __ cvt_d_w(f0, single_scratch);
3660 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3661 Label fpu_eq, fpu_lt;
3662 // Test if equal, and also handle the unordered/NaN case.
3663 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3665 // Test if less (unordered case is already handled).
3666 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3668 // Otherwise it's greater, so just fall thru, and return.
3669 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3670 __ Ret(USE_DELAY_SLOT);
3671 __ li(v0, Operand(GREATER));
3674 __ Ret(USE_DELAY_SLOT);
3675 __ li(v0, Operand(EQUAL));
3678 __ Ret(USE_DELAY_SLOT);
3679 __ li(v0, Operand(LESS));
3681 __ bind(&unordered);
3682 __ bind(&generic_stub);
3683 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3684 CompareICState::GENERIC, CompareICState::GENERIC);
3685 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3687 __ bind(&maybe_undefined1);
3688 if (Token::IsOrderedRelationalCompareOp(op())) {
3689 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3690 __ Branch(&miss, ne, a0, Operand(at));
3691 __ JumpIfSmi(a1, &unordered);
3692 __ GetObjectType(a1, a2, a2);
3693 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3697 __ bind(&maybe_undefined2);
3698 if (Token::IsOrderedRelationalCompareOp(op())) {
3699 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3700 __ Branch(&unordered, eq, a1, Operand(at));
3708 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3709 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3712 // Registers containing left and right operands respectively.
3714 Register right = a0;
3718 // Check that both operands are heap objects.
3719 __ JumpIfEitherSmi(left, right, &miss);
3721 // Check that both operands are internalized strings.
3722 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3723 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3724 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3725 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3726 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3727 __ Or(tmp1, tmp1, Operand(tmp2));
3728 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3729 __ Branch(&miss, ne, at, Operand(zero_reg));
3731 // Make sure a0 is non-zero. At this point input operands are
3732 // guaranteed to be non-zero.
3733 DCHECK(right.is(a0));
3734 STATIC_ASSERT(EQUAL == 0);
3735 STATIC_ASSERT(kSmiTag == 0);
3737 // Internalized strings are compared by identity.
3738 __ Ret(ne, left, Operand(right));
3739 DCHECK(is_int16(EQUAL));
3740 __ Ret(USE_DELAY_SLOT);
3741 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3748 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3749 DCHECK(state() == CompareICState::UNIQUE_NAME);
3750 DCHECK(GetCondition() == eq);
3753 // Registers containing left and right operands respectively.
3755 Register right = a0;
3759 // Check that both operands are heap objects.
3760 __ JumpIfEitherSmi(left, right, &miss);
3762 // Check that both operands are unique names. This leaves the instance
3763 // types loaded in tmp1 and tmp2.
3764 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3765 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3766 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3767 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3769 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3770 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3775 // Unique names are compared by identity.
3777 __ Branch(&done, ne, left, Operand(right));
3778 // Make sure a0 is non-zero. At this point input operands are
3779 // guaranteed to be non-zero.
3780 DCHECK(right.is(a0));
3781 STATIC_ASSERT(EQUAL == 0);
3782 STATIC_ASSERT(kSmiTag == 0);
3783 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3792 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3793 DCHECK(state() == CompareICState::STRING);
3796 bool equality = Token::IsEqualityOp(op());
3798 // Registers containing left and right operands respectively.
3800 Register right = a0;
3807 // Check that both operands are heap objects.
3808 __ JumpIfEitherSmi(left, right, &miss);
3810 // Check that both operands are strings. This leaves the instance
3811 // types loaded in tmp1 and tmp2.
3812 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3813 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3814 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3815 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3816 STATIC_ASSERT(kNotStringTag != 0);
3817 __ Or(tmp3, tmp1, tmp2);
3818 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3819 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3821 // Fast check for identical strings.
3822 Label left_ne_right;
3823 STATIC_ASSERT(EQUAL == 0);
3824 STATIC_ASSERT(kSmiTag == 0);
3825 __ Branch(&left_ne_right, ne, left, Operand(right));
3826 __ Ret(USE_DELAY_SLOT);
3827 __ mov(v0, zero_reg); // In the delay slot.
3828 __ bind(&left_ne_right);
3830 // Handle not identical strings.
3832 // Check that both strings are internalized strings. If they are, we're done
3833 // because we already know they are not identical. We know they are both
3836 DCHECK(GetCondition() == eq);
3837 STATIC_ASSERT(kInternalizedTag == 0);
3838 __ Or(tmp3, tmp1, Operand(tmp2));
3839 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3841 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3842 // Make sure a0 is non-zero. At this point input operands are
3843 // guaranteed to be non-zero.
3844 DCHECK(right.is(a0));
3845 __ Ret(USE_DELAY_SLOT);
3846 __ mov(v0, a0); // In the delay slot.
3847 __ bind(&is_symbol);
3850 // Check that both strings are sequential one-byte.
3852 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3855 // Compare flat one-byte strings. Returns when done.
3857 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3860 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3864 // Handle more complex cases in runtime.
3866 __ Push(left, right);
3868 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3870 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3878 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3879 DCHECK(state() == CompareICState::OBJECT);
3881 __ And(a2, a1, Operand(a0));
3882 __ JumpIfSmi(a2, &miss);
3884 __ GetObjectType(a0, a2, a2);
3885 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3886 __ GetObjectType(a1, a2, a2);
3887 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3889 DCHECK(GetCondition() == eq);
3890 __ Ret(USE_DELAY_SLOT);
3891 __ subu(v0, a0, a1);
3898 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3900 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3902 __ JumpIfSmi(a2, &miss);
3903 __ GetWeakValue(t0, cell);
3904 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3905 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3906 __ Branch(&miss, ne, a2, Operand(t0));
3907 __ Branch(&miss, ne, a3, Operand(t0));
3909 __ Ret(USE_DELAY_SLOT);
3910 __ subu(v0, a0, a1);
3917 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3919 // Call the runtime system in a fresh internal frame.
3920 FrameScope scope(masm, StackFrame::INTERNAL);
3922 __ Push(ra, a1, a0);
3923 __ li(t0, Operand(Smi::FromInt(op())));
3924 __ addiu(sp, sp, -kPointerSize);
3925 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3927 __ sw(t0, MemOperand(sp)); // In the delay slot.
3928 // Compute the entry point of the rewritten stub.
3929 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3930 // Restore registers.
3937 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3938 // Make place for arguments to fit C calling convention. Most of the callers
3939 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3940 // so they handle stack restoring and we don't have to do that here.
3941 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3942 // kCArgsSlotsSize stack space after the call.
3943 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
3944 // Place the return address on the stack, making the call
3945 // GC safe. The RegExp backend also relies on this.
3946 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
3947 __ Call(t9); // Call the C++ function.
3948 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
3950 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3951 // In case of an error the return address may point to a memory area
3952 // filled with kZapValue by the GC.
3953 // Dereference the address and check for this.
3954 __ lw(t0, MemOperand(t9));
3955 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
3956 Operand(reinterpret_cast<uint32_t>(kZapValue)));
3962 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3965 reinterpret_cast<intptr_t>(GetCode().location());
3966 __ Move(t9, target);
3967 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3972 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3976 Register properties,
3978 Register scratch0) {
3979 DCHECK(name->IsUniqueName());
3980 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3981 // not equal to the name and kProbes-th slot is not used (its name is the
3982 // undefined value), it guarantees the hash table doesn't contain the
3983 // property. It's true even if some slots represent deleted properties
3984 // (their names are the hole value).
3985 for (int i = 0; i < kInlinedProbes; i++) {
3986 // scratch0 points to properties hash.
3987 // Compute the masked index: (hash + i + i * i) & mask.
3988 Register index = scratch0;
3989 // Capacity is smi 2^n.
3990 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
3991 __ Subu(index, index, Operand(1));
3992 __ And(index, index, Operand(
3993 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3995 // Scale the index by multiplying by the entry size.
3996 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3997 __ sll(at, index, 1);
3998 __ Addu(index, index, at);
4000 Register entity_name = scratch0;
4001 // Having undefined at this place means the name is not contained.
4002 STATIC_ASSERT(kSmiTagSize == 1);
4003 Register tmp = properties;
4004 __ sll(scratch0, index, 1);
4005 __ Addu(tmp, properties, scratch0);
4006 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4008 DCHECK(!tmp.is(entity_name));
4009 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4010 __ Branch(done, eq, entity_name, Operand(tmp));
4012 // Load the hole ready for use below:
4013 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4015 // Stop if found the property.
4016 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4019 __ Branch(&good, eq, entity_name, Operand(tmp));
4021 // Check if the entry name is not a unique name.
4022 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4024 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4025 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4028 // Restore the properties.
4030 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4033 const int spill_mask =
4034 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
4035 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4037 __ MultiPush(spill_mask);
4038 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4039 __ li(a1, Operand(Handle<Name>(name)));
4040 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4043 __ MultiPop(spill_mask);
4045 __ Branch(done, eq, at, Operand(zero_reg));
4046 __ Branch(miss, ne, at, Operand(zero_reg));
4050 // Probe the name dictionary in the |elements| register. Jump to the
4051 // |done| label if a property with the given name is found. Jump to
4052 // the |miss| label otherwise.
4053 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4054 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4060 Register scratch2) {
4061 DCHECK(!elements.is(scratch1));
4062 DCHECK(!elements.is(scratch2));
4063 DCHECK(!name.is(scratch1));
4064 DCHECK(!name.is(scratch2));
4066 __ AssertName(name);
4068 // Compute the capacity mask.
4069 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
4070 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
4071 __ Subu(scratch1, scratch1, Operand(1));
4073 // Generate an unrolled loop that performs a few probes before
4074 // giving up. Measurements done on Gmail indicate that 2 probes
4075 // cover ~93% of loads from dictionaries.
4076 for (int i = 0; i < kInlinedProbes; i++) {
4077 // Compute the masked index: (hash + i + i * i) & mask.
4078 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4080 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4081 // the hash in a separate instruction. The value hash + i + i * i is right
4082 // shifted in the following and instruction.
4083 DCHECK(NameDictionary::GetProbeOffset(i) <
4084 1 << (32 - Name::kHashFieldOffset));
4085 __ Addu(scratch2, scratch2, Operand(
4086 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4088 __ srl(scratch2, scratch2, Name::kHashShift);
4089 __ And(scratch2, scratch1, scratch2);
4091 // Scale the index by multiplying by the element size.
4092 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4093 // scratch2 = scratch2 * 3.
4095 __ sll(at, scratch2, 1);
4096 __ Addu(scratch2, scratch2, at);
4098 // Check if the key is identical to the name.
4099 __ sll(at, scratch2, 2);
4100 __ Addu(scratch2, elements, at);
4101 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
4102 __ Branch(done, eq, name, Operand(at));
4105 const int spill_mask =
4106 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
4107 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4108 ~(scratch1.bit() | scratch2.bit());
4110 __ MultiPush(spill_mask);
4112 DCHECK(!elements.is(a1));
4114 __ Move(a0, elements);
4116 __ Move(a0, elements);
4119 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4121 __ mov(scratch2, a2);
4123 __ MultiPop(spill_mask);
4125 __ Branch(done, ne, at, Operand(zero_reg));
4126 __ Branch(miss, eq, at, Operand(zero_reg));
4130 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4131 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4132 // we cannot call anything that could cause a GC from this stub.
4134 // result: NameDictionary to probe
4136 // dictionary: NameDictionary to probe.
4137 // index: will hold an index of entry if lookup is successful.
4138 // might alias with result_.
4140 // result_ is zero if lookup failed, non zero otherwise.
4142 Register result = v0;
4143 Register dictionary = a0;
4145 Register index = a2;
4148 Register undefined = t1;
4149 Register entry_key = t2;
4151 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4153 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
4154 __ sra(mask, mask, kSmiTagSize);
4155 __ Subu(mask, mask, Operand(1));
4157 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4159 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4161 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4162 // Compute the masked index: (hash + i + i * i) & mask.
4163 // Capacity is smi 2^n.
4165 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4166 // the hash in a separate instruction. The value hash + i + i * i is right
4167 // shifted in the following and instruction.
4168 DCHECK(NameDictionary::GetProbeOffset(i) <
4169 1 << (32 - Name::kHashFieldOffset));
4170 __ Addu(index, hash, Operand(
4171 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4173 __ mov(index, hash);
4175 __ srl(index, index, Name::kHashShift);
4176 __ And(index, mask, index);
4178 // Scale the index by multiplying by the entry size.
4179 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4182 __ sll(index, index, 1);
4183 __ Addu(index, index, at);
4186 STATIC_ASSERT(kSmiTagSize == 1);
4187 __ sll(index, index, 2);
4188 __ Addu(index, index, dictionary);
4189 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
4191 // Having undefined at this place means the name is not contained.
4192 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4194 // Stop if found the property.
4195 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4197 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4198 // Check if the entry name is not a unique name.
4199 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4201 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4202 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4206 __ bind(&maybe_in_dictionary);
4207 // If we are doing negative lookup then probing failure should be
4208 // treated as a lookup success. For positive lookup probing failure
4209 // should be treated as lookup failure.
4210 if (mode() == POSITIVE_LOOKUP) {
4211 __ Ret(USE_DELAY_SLOT);
4212 __ mov(result, zero_reg);
4215 __ bind(&in_dictionary);
4216 __ Ret(USE_DELAY_SLOT);
4219 __ bind(¬_in_dictionary);
4220 __ Ret(USE_DELAY_SLOT);
4221 __ mov(result, zero_reg);
4225 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4227 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4229 // Hydrogen code stubs need stub2 at snapshot time.
4230 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4235 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4236 // the value has just been written into the object, now this stub makes sure
4237 // we keep the GC informed. The word in the object where the value has been
4238 // written is in the address register.
4239 void RecordWriteStub::Generate(MacroAssembler* masm) {
4240 Label skip_to_incremental_noncompacting;
4241 Label skip_to_incremental_compacting;
4243 // The first two branch+nop instructions are generated with labels so as to
4244 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4245 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4246 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4247 // incremental heap marking.
4248 // See RecordWriteStub::Patch for details.
4249 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4251 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4254 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4255 __ RememberedSetHelper(object(),
4258 save_fp_regs_mode(),
4259 MacroAssembler::kReturnAtEnd);
4263 __ bind(&skip_to_incremental_noncompacting);
4264 GenerateIncremental(masm, INCREMENTAL);
4266 __ bind(&skip_to_incremental_compacting);
4267 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4269 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4270 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4272 PatchBranchIntoNop(masm, 0);
4273 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4277 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4280 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4281 Label dont_need_remembered_set;
4283 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4284 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4286 &dont_need_remembered_set);
4288 __ CheckPageFlag(regs_.object(),
4290 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4292 &dont_need_remembered_set);
4294 // First notify the incremental marker if necessary, then update the
4296 CheckNeedsToInformIncrementalMarker(
4297 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4298 InformIncrementalMarker(masm);
4299 regs_.Restore(masm);
4300 __ RememberedSetHelper(object(),
4303 save_fp_regs_mode(),
4304 MacroAssembler::kReturnAtEnd);
4306 __ bind(&dont_need_remembered_set);
4309 CheckNeedsToInformIncrementalMarker(
4310 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4311 InformIncrementalMarker(masm);
4312 regs_.Restore(masm);
4317 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4318 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4319 int argument_count = 3;
4320 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4322 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4323 DCHECK(!address.is(regs_.object()));
4324 DCHECK(!address.is(a0));
4325 __ Move(address, regs_.address());
4326 __ Move(a0, regs_.object());
4327 __ Move(a1, address);
4328 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4330 AllowExternalCallThatCantCauseGC scope(masm);
4332 ExternalReference::incremental_marking_record_write_function(isolate()),
4334 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4338 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4339 MacroAssembler* masm,
4340 OnNoNeedToInformIncrementalMarker on_no_need,
4343 Label need_incremental;
4344 Label need_incremental_pop_scratch;
4346 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4347 __ lw(regs_.scratch1(),
4348 MemOperand(regs_.scratch0(),
4349 MemoryChunk::kWriteBarrierCounterOffset));
4350 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4351 __ sw(regs_.scratch1(),
4352 MemOperand(regs_.scratch0(),
4353 MemoryChunk::kWriteBarrierCounterOffset));
4354 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4356 // Let's look at the color of the object: If it is not black we don't have
4357 // to inform the incremental marker.
4358 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4360 regs_.Restore(masm);
4361 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4362 __ RememberedSetHelper(object(),
4365 save_fp_regs_mode(),
4366 MacroAssembler::kReturnAtEnd);
4373 // Get the value from the slot.
4374 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4376 if (mode == INCREMENTAL_COMPACTION) {
4377 Label ensure_not_white;
4379 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4380 regs_.scratch1(), // Scratch.
4381 MemoryChunk::kEvacuationCandidateMask,
4385 __ CheckPageFlag(regs_.object(),
4386 regs_.scratch1(), // Scratch.
4387 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4391 __ bind(&ensure_not_white);
4394 // We need extra registers for this, so we push the object and the address
4395 // register temporarily.
4396 __ Push(regs_.object(), regs_.address());
4397 __ EnsureNotWhite(regs_.scratch0(), // The value.
4398 regs_.scratch1(), // Scratch.
4399 regs_.object(), // Scratch.
4400 regs_.address(), // Scratch.
4401 &need_incremental_pop_scratch);
4402 __ Pop(regs_.object(), regs_.address());
4404 regs_.Restore(masm);
4405 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4406 __ RememberedSetHelper(object(),
4409 save_fp_regs_mode(),
4410 MacroAssembler::kReturnAtEnd);
4415 __ bind(&need_incremental_pop_scratch);
4416 __ Pop(regs_.object(), regs_.address());
4418 __ bind(&need_incremental);
4420 // Fall through when we need to inform the incremental marker.
4424 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4425 // ----------- S t a t e -------------
4426 // -- a0 : element value to store
4427 // -- a3 : element index as smi
4428 // -- sp[0] : array literal index in function as smi
4429 // -- sp[4] : array literal
4430 // clobbers a1, a2, t0
4431 // -----------------------------------
4434 Label double_elements;
4436 Label slow_elements;
4437 Label fast_elements;
4439 // Get array literal index, array literal and its map.
4440 __ lw(t0, MemOperand(sp, 0 * kPointerSize));
4441 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
4442 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4444 __ CheckFastElements(a2, t1, &double_elements);
4445 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4446 __ JumpIfSmi(a0, &smi_element);
4447 __ CheckFastSmiElements(a2, t1, &fast_elements);
4449 // Store into the array literal requires a elements transition. Call into
4451 __ bind(&slow_elements);
4453 __ Push(a1, a3, a0);
4454 __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4455 __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset));
4457 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4459 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4460 __ bind(&fast_elements);
4461 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4462 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4463 __ Addu(t2, t1, t2);
4464 __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4465 __ sw(a0, MemOperand(t2, 0));
4466 // Update the write barrier for the array store.
4467 __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4468 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4469 __ Ret(USE_DELAY_SLOT);
4472 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4473 // and value is Smi.
4474 __ bind(&smi_element);
4475 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4476 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4477 __ Addu(t2, t1, t2);
4478 __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize));
4479 __ Ret(USE_DELAY_SLOT);
4482 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4483 __ bind(&double_elements);
4484 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4485 __ StoreNumberToDoubleElements(a0, a3, t1, t3, t5, a2, &slow_elements);
4486 __ Ret(USE_DELAY_SLOT);
4491 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4492 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4493 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4494 int parameter_count_offset =
4495 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4496 __ lw(a1, MemOperand(fp, parameter_count_offset));
4497 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4498 __ Addu(a1, a1, Operand(1));
4500 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4501 __ sll(a1, a1, kPointerSizeLog2);
4502 __ Ret(USE_DELAY_SLOT);
4503 __ Addu(sp, sp, a1);
4507 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4508 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4509 LoadICStub stub(isolate(), state());
4510 stub.GenerateForTrampoline(masm);
4514 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4515 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4516 KeyedLoadICStub stub(isolate(), state());
4517 stub.GenerateForTrampoline(masm);
4521 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4522 EmitLoadTypeFeedbackVector(masm, a2);
4523 CallICStub stub(isolate(), state());
4524 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4528 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4529 EmitLoadTypeFeedbackVector(masm, a2);
4530 CallIC_ArrayStub stub(isolate(), state());
4531 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4535 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4538 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4539 GenerateImpl(masm, true);
4543 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4544 Register receiver_map, Register scratch1,
4545 Register scratch2, bool is_polymorphic,
4547 // feedback initially contains the feedback array
4548 Label next_loop, prepare_next;
4549 Label start_polymorphic;
4551 Register cached_map = scratch1;
4554 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4555 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4556 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4557 // found, now call handler.
4558 Register handler = feedback;
4559 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4560 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4564 Register length = scratch2;
4565 __ bind(&start_polymorphic);
4566 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4567 if (!is_polymorphic) {
4568 // If the IC could be monomorphic we have to make sure we don't go past the
4569 // end of the feedback array.
4570 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4573 Register too_far = length;
4574 Register pointer_reg = feedback;
4576 // +-----+------+------+-----+-----+ ... ----+
4577 // | map | len | wm0 | h0 | wm1 | hN |
4578 // +-----+------+------+-----+-----+ ... ----+
4582 // pointer_reg too_far
4583 // aka feedback scratch2
4584 // also need receiver_map
4585 // use cached_map (scratch1) to look in the weak map values.
4586 __ sll(at, length, kPointerSizeLog2 - kSmiTagSize);
4587 __ Addu(too_far, feedback, Operand(at));
4588 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4589 __ Addu(pointer_reg, feedback,
4590 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4592 __ bind(&next_loop);
4593 __ lw(cached_map, MemOperand(pointer_reg));
4594 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4595 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4596 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
4597 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4600 __ bind(&prepare_next);
4601 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4602 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4604 // We exhausted our array of map handler pairs.
4609 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4610 Register receiver_map, Register feedback,
4611 Register vector, Register slot,
4612 Register scratch, Label* compare_map,
4613 Label* load_smi_map, Label* try_array) {
4614 __ JumpIfSmi(receiver, load_smi_map);
4615 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4616 __ bind(compare_map);
4617 Register cached_map = scratch;
4618 // Move the weak map into the weak_cell register.
4619 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4620 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4621 Register handler = feedback;
4623 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4624 __ Addu(handler, vector, Operand(at));
4626 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4627 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4632 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4633 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4634 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4635 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4636 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4637 Register feedback = t0;
4638 Register receiver_map = t1;
4639 Register scratch1 = t4;
4641 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4642 __ Addu(feedback, vector, Operand(at));
4643 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4645 // Try to quickly handle the monomorphic case without knowing for sure
4646 // if we have a weak cell in feedback. We do know it's safe to look
4647 // at WeakCell::kValueOffset.
4648 Label try_array, load_smi_map, compare_map;
4649 Label not_array, miss;
4650 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4651 scratch1, &compare_map, &load_smi_map, &try_array);
4653 // Is it a fixed array?
4654 __ bind(&try_array);
4655 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4656 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4657 __ Branch(¬_array, ne, at, Operand(scratch1));
4658 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
4660 __ bind(¬_array);
4661 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4662 __ Branch(&miss, ne, at, Operand(feedback));
4663 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4664 Code::ComputeHandlerFlags(Code::LOAD_IC));
4665 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4666 receiver, name, feedback,
4667 receiver_map, scratch1, t5);
4670 LoadIC::GenerateMiss(masm);
4672 __ bind(&load_smi_map);
4673 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4674 __ jmp(&compare_map);
4678 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4679 GenerateImpl(masm, false);
4683 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4684 GenerateImpl(masm, true);
4688 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4689 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4690 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4691 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4692 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4693 Register feedback = t0;
4694 Register receiver_map = t1;
4695 Register scratch1 = t4;
4697 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4698 __ Addu(feedback, vector, Operand(at));
4699 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4701 // Try to quickly handle the monomorphic case without knowing for sure
4702 // if we have a weak cell in feedback. We do know it's safe to look
4703 // at WeakCell::kValueOffset.
4704 Label try_array, load_smi_map, compare_map;
4705 Label not_array, miss;
4706 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4707 scratch1, &compare_map, &load_smi_map, &try_array);
4709 __ bind(&try_array);
4710 // Is it a fixed array?
4711 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4712 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4713 __ Branch(¬_array, ne, at, Operand(scratch1));
4714 // We have a polymorphic element handler.
4715 __ JumpIfNotSmi(key, &miss);
4717 Label polymorphic, try_poly_name;
4718 __ bind(&polymorphic);
4719 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
4721 __ bind(¬_array);
4723 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4724 __ Branch(&try_poly_name, ne, at, Operand(feedback));
4725 Handle<Code> megamorphic_stub =
4726 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4727 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4729 __ bind(&try_poly_name);
4730 // We might have a name in feedback, and a fixed array in the next slot.
4731 __ Branch(&miss, ne, key, Operand(feedback));
4732 // If the name comparison succeeded, we know we have a fixed array with
4733 // at least one map/handler pair.
4734 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4735 __ Addu(feedback, vector, Operand(at));
4737 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4738 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, false, &miss);
4741 KeyedLoadIC::GenerateMiss(masm);
4743 __ bind(&load_smi_map);
4744 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4745 __ jmp(&compare_map);
4749 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4750 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4751 VectorStoreICStub stub(isolate(), state());
4752 stub.GenerateForTrampoline(masm);
4756 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4757 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4758 VectorKeyedStoreICStub stub(isolate(), state());
4759 stub.GenerateForTrampoline(masm);
4763 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4764 GenerateImpl(masm, false);
4768 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4769 GenerateImpl(masm, true);
4773 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4774 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4775 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4776 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4777 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
4778 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4779 Register feedback = t1;
4780 Register receiver_map = t2;
4781 Register scratch1 = t5;
4783 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4784 __ Addu(feedback, vector, Operand(scratch1));
4785 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4787 // Try to quickly handle the monomorphic case without knowing for sure
4788 // if we have a weak cell in feedback. We do know it's safe to look
4789 // at WeakCell::kValueOffset.
4790 Label try_array, load_smi_map, compare_map;
4791 Label not_array, miss;
4792 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4793 scratch1, &compare_map, &load_smi_map, &try_array);
4795 // Is it a fixed array?
4796 __ bind(&try_array);
4797 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4798 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4799 __ Branch(¬_array, ne, scratch1, Operand(at));
4801 Register scratch2 = t4;
4802 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4805 __ bind(¬_array);
4806 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4807 __ Branch(&miss, ne, feedback, Operand(at));
4808 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4809 Code::ComputeHandlerFlags(Code::STORE_IC));
4810 masm->isolate()->stub_cache()->GenerateProbe(
4811 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4812 scratch1, scratch2);
4815 StoreIC::GenerateMiss(masm);
4817 __ bind(&load_smi_map);
4818 __ Branch(USE_DELAY_SLOT, &compare_map);
4819 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4823 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4824 GenerateImpl(masm, false);
4828 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4829 GenerateImpl(masm, true);
4833 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4834 Register receiver_map, Register scratch1,
4835 Register scratch2, Label* miss) {
4836 // feedback initially contains the feedback array
4837 Label next_loop, prepare_next;
4838 Label start_polymorphic;
4839 Label transition_call;
4841 Register cached_map = scratch1;
4842 Register too_far = scratch2;
4843 Register pointer_reg = feedback;
4844 __ lw(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4846 // +-----+------+------+-----+-----+-----+ ... ----+
4847 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4848 // +-----+------+------+-----+-----+ ----+ ... ----+
4852 // pointer_reg too_far
4853 // aka feedback scratch2
4854 // also need receiver_map
4855 // use cached_map (scratch1) to look in the weak map values.
4856 __ sll(scratch1, too_far, kPointerSizeLog2 - kSmiTagSize);
4857 __ Addu(too_far, feedback, Operand(scratch1));
4858 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4859 __ Addu(pointer_reg, feedback,
4860 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4862 __ bind(&next_loop);
4863 __ lw(cached_map, MemOperand(pointer_reg));
4864 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4865 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4866 // Is it a transitioning store?
4867 __ lw(too_far, MemOperand(pointer_reg, kPointerSize));
4868 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4869 __ Branch(&transition_call, ne, too_far, Operand(at));
4870 __ lw(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4871 __ Addu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4874 __ bind(&transition_call);
4875 __ lw(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4876 __ JumpIfSmi(too_far, miss);
4878 __ lw(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4880 // Load the map into the correct register.
4881 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4882 __ mov(feedback, too_far);
4884 __ Addu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4887 __ bind(&prepare_next);
4888 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4889 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4891 // We exhausted our array of map handler pairs.
4896 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4897 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4898 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4899 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4900 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
4901 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4902 Register feedback = t1;
4903 Register receiver_map = t2;
4904 Register scratch1 = t5;
4906 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4907 __ Addu(feedback, vector, Operand(scratch1));
4908 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4910 // Try to quickly handle the monomorphic case without knowing for sure
4911 // if we have a weak cell in feedback. We do know it's safe to look
4912 // at WeakCell::kValueOffset.
4913 Label try_array, load_smi_map, compare_map;
4914 Label not_array, miss;
4915 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4916 scratch1, &compare_map, &load_smi_map, &try_array);
4918 __ bind(&try_array);
4919 // Is it a fixed array?
4920 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4921 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4922 __ Branch(¬_array, ne, scratch1, Operand(at));
4924 // We have a polymorphic element handler.
4925 Label polymorphic, try_poly_name;
4926 __ bind(&polymorphic);
4928 Register scratch2 = t4;
4930 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4933 __ bind(¬_array);
4935 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4936 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4937 Handle<Code> megamorphic_stub =
4938 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4939 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4941 __ bind(&try_poly_name);
4942 // We might have a name in feedback, and a fixed array in the next slot.
4943 __ Branch(&miss, ne, key, Operand(feedback));
4944 // If the name comparison succeeded, we know we have a fixed array with
4945 // at least one map/handler pair.
4946 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4947 __ Addu(feedback, vector, Operand(scratch1));
4949 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4950 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4954 KeyedStoreIC::GenerateMiss(masm);
4956 __ bind(&load_smi_map);
4957 __ Branch(USE_DELAY_SLOT, &compare_map);
4958 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4962 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4963 if (masm->isolate()->function_entry_hook() != NULL) {
4964 ProfileEntryHookStub stub(masm->isolate());
4972 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4973 // The entry hook is a "push ra" instruction, followed by a call.
4974 // Note: on MIPS "push" is 2 instruction
4975 const int32_t kReturnAddressDistanceFromFunctionStart =
4976 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4978 // This should contain all kJSCallerSaved registers.
4979 const RegList kSavedRegs =
4980 kJSCallerSaved | // Caller saved registers.
4981 s5.bit(); // Saved stack pointer.
4983 // We also save ra, so the count here is one higher than the mask indicates.
4984 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4986 // Save all caller-save registers as this may be called from anywhere.
4987 __ MultiPush(kSavedRegs | ra.bit());
4989 // Compute the function's address for the first argument.
4990 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4992 // The caller's return address is above the saved temporaries.
4993 // Grab that for the second argument to the hook.
4994 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4996 // Align the stack if necessary.
4997 int frame_alignment = masm->ActivationFrameAlignment();
4998 if (frame_alignment > kPointerSize) {
5000 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5001 __ And(sp, sp, Operand(-frame_alignment));
5003 __ Subu(sp, sp, kCArgsSlotsSize);
5004 #if defined(V8_HOST_ARCH_MIPS)
5005 int32_t entry_hook =
5006 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
5007 __ li(t9, Operand(entry_hook));
5009 // Under the simulator we need to indirect the entry hook through a
5010 // trampoline function at a known address.
5011 // It additionally takes an isolate as a third parameter.
5012 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
5014 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
5015 __ li(t9, Operand(ExternalReference(&dispatcher,
5016 ExternalReference::BUILTIN_CALL,
5019 // Call C function through t9 to conform ABI for PIC.
5022 // Restore the stack pointer if needed.
5023 if (frame_alignment > kPointerSize) {
5026 __ Addu(sp, sp, kCArgsSlotsSize);
5029 // Also pop ra to get Ret(0).
5030 __ MultiPop(kSavedRegs | ra.bit());
5036 static void CreateArrayDispatch(MacroAssembler* masm,
5037 AllocationSiteOverrideMode mode) {
5038 if (mode == DISABLE_ALLOCATION_SITES) {
5039 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5040 __ TailCallStub(&stub);
5041 } else if (mode == DONT_OVERRIDE) {
5042 int last_index = GetSequenceIndexFromFastElementsKind(
5043 TERMINAL_FAST_ELEMENTS_KIND);
5044 for (int i = 0; i <= last_index; ++i) {
5045 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5046 T stub(masm->isolate(), kind);
5047 __ TailCallStub(&stub, eq, a3, Operand(kind));
5050 // If we reached this point there is a problem.
5051 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5058 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5059 AllocationSiteOverrideMode mode) {
5060 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5061 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5062 // a0 - number of arguments
5063 // a1 - constructor?
5064 // sp[0] - last argument
5065 Label normal_sequence;
5066 if (mode == DONT_OVERRIDE) {
5067 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5068 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5069 STATIC_ASSERT(FAST_ELEMENTS == 2);
5070 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5071 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5072 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5074 // is the low bit set? If so, we are holey and that is good.
5075 __ And(at, a3, Operand(1));
5076 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5079 // look at the first argument
5080 __ lw(t1, MemOperand(sp, 0));
5081 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
5083 if (mode == DISABLE_ALLOCATION_SITES) {
5084 ElementsKind initial = GetInitialFastElementsKind();
5085 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5087 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5089 DISABLE_ALLOCATION_SITES);
5090 __ TailCallStub(&stub_holey);
5092 __ bind(&normal_sequence);
5093 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5095 DISABLE_ALLOCATION_SITES);
5096 __ TailCallStub(&stub);
5097 } else if (mode == DONT_OVERRIDE) {
5098 // We are going to create a holey array, but our kind is non-holey.
5099 // Fix kind and retry (only if we have an allocation site in the slot).
5100 __ Addu(a3, a3, Operand(1));
5102 if (FLAG_debug_code) {
5103 __ lw(t1, FieldMemOperand(a2, 0));
5104 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5105 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
5108 // Save the resulting elements kind in type info. We can't just store a3
5109 // in the AllocationSite::transition_info field because elements kind is
5110 // restricted to a portion of the field...upper bits need to be left alone.
5111 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5112 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5113 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5114 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5117 __ bind(&normal_sequence);
5118 int last_index = GetSequenceIndexFromFastElementsKind(
5119 TERMINAL_FAST_ELEMENTS_KIND);
5120 for (int i = 0; i <= last_index; ++i) {
5121 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5122 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5123 __ TailCallStub(&stub, eq, a3, Operand(kind));
5126 // If we reached this point there is a problem.
5127 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5135 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5136 int to_index = GetSequenceIndexFromFastElementsKind(
5137 TERMINAL_FAST_ELEMENTS_KIND);
5138 for (int i = 0; i <= to_index; ++i) {
5139 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5140 T stub(isolate, kind);
5142 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5143 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5150 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5151 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5153 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5155 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5160 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5162 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5163 for (int i = 0; i < 2; i++) {
5164 // For internal arrays we only need a few things.
5165 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5167 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5169 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5175 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5176 MacroAssembler* masm,
5177 AllocationSiteOverrideMode mode) {
5178 if (argument_count() == ANY) {
5179 Label not_zero_case, not_one_case;
5181 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5182 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5184 __ bind(¬_zero_case);
5185 __ Branch(¬_one_case, gt, a0, Operand(1));
5186 CreateArrayDispatchOneArgument(masm, mode);
5188 __ bind(¬_one_case);
5189 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5190 } else if (argument_count() == NONE) {
5191 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5192 } else if (argument_count() == ONE) {
5193 CreateArrayDispatchOneArgument(masm, mode);
5194 } else if (argument_count() == MORE_THAN_ONE) {
5195 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5202 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5203 // ----------- S t a t e -------------
5204 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5205 // -- a1 : constructor
5206 // -- a2 : AllocationSite or undefined
5207 // -- a3 : Original constructor
5208 // -- sp[0] : last argument
5209 // -----------------------------------
5211 if (FLAG_debug_code) {
5212 // The array construct code is only set for the global and natives
5213 // builtin Array functions which always have maps.
5215 // Initial map for the builtin Array function should be a map.
5216 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5217 // Will both indicate a NULL and a Smi.
5219 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5220 at, Operand(zero_reg));
5221 __ GetObjectType(t0, t0, t1);
5222 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5223 t1, Operand(MAP_TYPE));
5225 // We should either have undefined in a2 or a valid AllocationSite
5226 __ AssertUndefinedOrAllocationSite(a2, t0);
5230 __ Branch(&subclassing, ne, a1, Operand(a3));
5233 // Get the elements kind and case on that.
5234 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5235 __ Branch(&no_info, eq, a2, Operand(at));
5237 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5239 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5240 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5241 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5244 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5247 __ bind(&subclassing);
5252 switch (argument_count()) {
5255 __ li(at, Operand(2));
5256 __ addu(a0, a0, at);
5259 __ li(a0, Operand(2));
5262 __ li(a0, Operand(3));
5266 __ JumpToExternalReference(
5267 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5271 void InternalArrayConstructorStub::GenerateCase(
5272 MacroAssembler* masm, ElementsKind kind) {
5274 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5275 __ TailCallStub(&stub0, lo, a0, Operand(1));
5277 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5278 __ TailCallStub(&stubN, hi, a0, Operand(1));
5280 if (IsFastPackedElementsKind(kind)) {
5281 // We might need to create a holey array
5282 // look at the first argument.
5283 __ lw(at, MemOperand(sp, 0));
5285 InternalArraySingleArgumentConstructorStub
5286 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5287 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5290 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5291 __ TailCallStub(&stub1);
5295 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5296 // ----------- S t a t e -------------
5298 // -- a1 : constructor
5299 // -- sp[0] : return address
5300 // -- sp[4] : last argument
5301 // -----------------------------------
5303 if (FLAG_debug_code) {
5304 // The array construct code is only set for the global and natives
5305 // builtin Array functions which always have maps.
5307 // Initial map for the builtin Array function should be a map.
5308 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5309 // Will both indicate a NULL and a Smi.
5311 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5312 at, Operand(zero_reg));
5313 __ GetObjectType(a3, a3, t0);
5314 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5315 t0, Operand(MAP_TYPE));
5318 // Figure out the right elements kind.
5319 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5321 // Load the map's "bit field 2" into a3. We only need the first byte,
5322 // but the following bit field extraction takes care of that anyway.
5323 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5324 // Retrieve elements_kind from bit field 2.
5325 __ DecodeField<Map::ElementsKindBits>(a3);
5327 if (FLAG_debug_code) {
5329 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5331 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5332 a3, Operand(FAST_HOLEY_ELEMENTS));
5336 Label fast_elements_case;
5337 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5338 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5340 __ bind(&fast_elements_case);
5341 GenerateCase(masm, FAST_ELEMENTS);
5345 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5346 Register context_reg = cp;
5347 Register slot_reg = a2;
5348 Register result_reg = v0;
5351 // Go up context chain to the script context.
5352 for (int i = 0; i < depth(); ++i) {
5353 __ lw(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5354 context_reg = result_reg;
5357 // Load the PropertyCell value at the specified slot.
5358 __ sll(at, slot_reg, kPointerSizeLog2);
5359 __ Addu(at, at, Operand(context_reg));
5360 __ lw(result_reg, ContextOperand(at, 0));
5361 __ lw(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5363 // Check that value is not the_hole.
5364 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5365 __ Branch(&slow_case, eq, result_reg, Operand(at));
5368 // Fallback to the runtime.
5369 __ bind(&slow_case);
5370 __ SmiTag(slot_reg);
5372 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5376 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5377 Register context_reg = cp;
5378 Register slot_reg = a2;
5379 Register value_reg = a0;
5380 Register cell_reg = t0;
5381 Register cell_value_reg = t1;
5382 Register cell_details_reg = t2;
5383 Label fast_heapobject_case, fast_smi_case, slow_case;
5385 if (FLAG_debug_code) {
5386 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5387 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5390 // Go up context chain to the script context.
5391 for (int i = 0; i < depth(); ++i) {
5392 __ lw(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5393 context_reg = cell_reg;
5396 // Load the PropertyCell at the specified slot.
5397 __ sll(at, slot_reg, kPointerSizeLog2);
5398 __ Addu(at, at, Operand(context_reg));
5399 __ lw(cell_reg, ContextOperand(at, 0));
5401 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5402 __ lw(cell_details_reg,
5403 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5404 __ SmiUntag(cell_details_reg);
5405 __ And(cell_details_reg, cell_details_reg,
5406 PropertyDetails::PropertyCellTypeField::kMask |
5407 PropertyDetails::KindField::kMask |
5408 PropertyDetails::kAttributesReadOnlyMask);
5410 // Check if PropertyCell holds mutable data.
5411 Label not_mutable_data;
5412 __ Branch(¬_mutable_data, ne, cell_details_reg,
5413 Operand(PropertyDetails::PropertyCellTypeField::encode(
5414 PropertyCellType::kMutable) |
5415 PropertyDetails::KindField::encode(kData)));
5416 __ JumpIfSmi(value_reg, &fast_smi_case);
5417 __ bind(&fast_heapobject_case);
5418 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5419 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5420 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5421 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5422 // RecordWriteField clobbers the value register, so we need to reload.
5423 __ Ret(USE_DELAY_SLOT);
5424 __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5425 __ bind(¬_mutable_data);
5427 // Check if PropertyCell value matches the new value (relevant for Constant,
5428 // ConstantType and Undefined cells).
5429 Label not_same_value;
5430 __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5431 __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg));
5432 // Make sure the PropertyCell is not marked READ_ONLY.
5433 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5434 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5435 if (FLAG_debug_code) {
5437 // This can only be true for Constant, ConstantType and Undefined cells,
5438 // because we never store the_hole via this stub.
5439 __ Branch(&done, eq, cell_details_reg,
5440 Operand(PropertyDetails::PropertyCellTypeField::encode(
5441 PropertyCellType::kConstant) |
5442 PropertyDetails::KindField::encode(kData)));
5443 __ Branch(&done, eq, cell_details_reg,
5444 Operand(PropertyDetails::PropertyCellTypeField::encode(
5445 PropertyCellType::kConstantType) |
5446 PropertyDetails::KindField::encode(kData)));
5447 __ Check(eq, kUnexpectedValue, cell_details_reg,
5448 Operand(PropertyDetails::PropertyCellTypeField::encode(
5449 PropertyCellType::kUndefined) |
5450 PropertyDetails::KindField::encode(kData)));
5454 __ bind(¬_same_value);
5456 // Check if PropertyCell contains data with constant type (and is not
5458 __ Branch(&slow_case, ne, cell_details_reg,
5459 Operand(PropertyDetails::PropertyCellTypeField::encode(
5460 PropertyCellType::kConstantType) |
5461 PropertyDetails::KindField::encode(kData)));
5463 // Now either both old and new values must be SMIs or both must be heap
5464 // objects with same map.
5465 Label value_is_heap_object;
5466 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5467 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5468 // Old and new values are SMIs, no need for a write barrier here.
5469 __ bind(&fast_smi_case);
5470 __ Ret(USE_DELAY_SLOT);
5471 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5472 __ bind(&value_is_heap_object);
5473 __ JumpIfSmi(cell_value_reg, &slow_case);
5474 Register cell_value_map_reg = cell_value_reg;
5475 __ lw(cell_value_map_reg,
5476 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5477 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5478 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5480 // Fallback to the runtime.
5481 __ bind(&slow_case);
5482 __ SmiTag(slot_reg);
5483 __ Push(slot_reg, value_reg);
5484 __ TailCallRuntime(is_strict(language_mode())
5485 ? Runtime::kStoreGlobalViaContext_Strict
5486 : Runtime::kStoreGlobalViaContext_Sloppy,
5491 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5492 return ref0.address() - ref1.address();
5496 // Calls an API function. Allocates HandleScope, extracts returned value
5497 // from handle and propagates exceptions. Restores context. stack_space
5498 // - space to be unwound on exit (includes the call JS arguments space and
5499 // the additional space allocated for the fast call).
5500 static void CallApiFunctionAndReturn(
5501 MacroAssembler* masm, Register function_address,
5502 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5503 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5504 Isolate* isolate = masm->isolate();
5505 ExternalReference next_address =
5506 ExternalReference::handle_scope_next_address(isolate);
5507 const int kNextOffset = 0;
5508 const int kLimitOffset = AddressOffset(
5509 ExternalReference::handle_scope_limit_address(isolate), next_address);
5510 const int kLevelOffset = AddressOffset(
5511 ExternalReference::handle_scope_level_address(isolate), next_address);
5513 DCHECK(function_address.is(a1) || function_address.is(a2));
5515 Label profiler_disabled;
5516 Label end_profiler_check;
5517 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5518 __ lb(t9, MemOperand(t9, 0));
5519 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5521 // Additional parameter is the address of the actual callback.
5522 __ li(t9, Operand(thunk_ref));
5523 __ jmp(&end_profiler_check);
5525 __ bind(&profiler_disabled);
5526 __ mov(t9, function_address);
5527 __ bind(&end_profiler_check);
5529 // Allocate HandleScope in callee-save registers.
5530 __ li(s3, Operand(next_address));
5531 __ lw(s0, MemOperand(s3, kNextOffset));
5532 __ lw(s1, MemOperand(s3, kLimitOffset));
5533 __ lw(s2, MemOperand(s3, kLevelOffset));
5534 __ Addu(s2, s2, Operand(1));
5535 __ sw(s2, MemOperand(s3, kLevelOffset));
5537 if (FLAG_log_timer_events) {
5538 FrameScope frame(masm, StackFrame::MANUAL);
5539 __ PushSafepointRegisters();
5540 __ PrepareCallCFunction(1, a0);
5541 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5542 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5544 __ PopSafepointRegisters();
5547 // Native call returns to the DirectCEntry stub which redirects to the
5548 // return address pushed on stack (could have moved after GC).
5549 // DirectCEntry stub itself is generated early and never moves.
5550 DirectCEntryStub stub(isolate);
5551 stub.GenerateCall(masm, t9);
5553 if (FLAG_log_timer_events) {
5554 FrameScope frame(masm, StackFrame::MANUAL);
5555 __ PushSafepointRegisters();
5556 __ PrepareCallCFunction(1, a0);
5557 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5558 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5560 __ PopSafepointRegisters();
5563 Label promote_scheduled_exception;
5564 Label delete_allocated_handles;
5565 Label leave_exit_frame;
5566 Label return_value_loaded;
5568 // Load value from ReturnValue.
5569 __ lw(v0, return_value_operand);
5570 __ bind(&return_value_loaded);
5572 // No more valid handles (the result handle was the last one). Restore
5573 // previous handle scope.
5574 __ sw(s0, MemOperand(s3, kNextOffset));
5575 if (__ emit_debug_code()) {
5576 __ lw(a1, MemOperand(s3, kLevelOffset));
5577 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5579 __ Subu(s2, s2, Operand(1));
5580 __ sw(s2, MemOperand(s3, kLevelOffset));
5581 __ lw(at, MemOperand(s3, kLimitOffset));
5582 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5584 // Leave the API exit frame.
5585 __ bind(&leave_exit_frame);
5587 bool restore_context = context_restore_operand != NULL;
5588 if (restore_context) {
5589 __ lw(cp, *context_restore_operand);
5591 if (stack_space_offset != kInvalidStackOffset) {
5592 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5593 // so this must be accounted for.
5594 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5596 __ li(s0, Operand(stack_space));
5598 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5599 stack_space_offset != kInvalidStackOffset);
5601 // Check if the function scheduled an exception.
5602 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5603 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5604 __ lw(t1, MemOperand(at));
5605 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5609 // Re-throw by promoting a scheduled exception.
5610 __ bind(&promote_scheduled_exception);
5611 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5613 // HandleScope limit has changed. Delete allocated extensions.
5614 __ bind(&delete_allocated_handles);
5615 __ sw(s1, MemOperand(s3, kLimitOffset));
5618 __ PrepareCallCFunction(1, s1);
5619 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5620 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5623 __ jmp(&leave_exit_frame);
5627 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5628 const ParameterCount& argc,
5629 bool return_first_arg,
5630 bool call_data_undefined) {
5631 // ----------- S t a t e -------------
5633 // -- t0 : call_data
5635 // -- a1 : api_function_address
5636 // -- a3 : number of arguments if argc is a register
5639 // -- sp[0] : last argument
5641 // -- sp[(argc - 1)* 4] : first argument
5642 // -- sp[argc * 4] : receiver
5643 // -----------------------------------
5645 Register callee = a0;
5646 Register call_data = t0;
5647 Register holder = a2;
5648 Register api_function_address = a1;
5649 Register context = cp;
5651 typedef FunctionCallbackArguments FCA;
5653 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5654 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5655 STATIC_ASSERT(FCA::kDataIndex == 4);
5656 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5657 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5658 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5659 STATIC_ASSERT(FCA::kHolderIndex == 0);
5660 STATIC_ASSERT(FCA::kArgsLength == 7);
5662 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5664 // Save context, callee and call data.
5665 __ Push(context, callee, call_data);
5666 // Load context from callee.
5667 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5669 Register scratch = call_data;
5670 if (!call_data_undefined) {
5671 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5673 // Push return value and default return value.
5674 __ Push(scratch, scratch);
5675 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5676 // Push isolate and holder.
5677 __ Push(scratch, holder);
5679 // Prepare arguments.
5680 __ mov(scratch, sp);
5682 // Allocate the v8::Arguments structure in the arguments' space since
5683 // it's not controlled by GC.
5684 const int kApiStackSpace = 4;
5686 FrameScope frame_scope(masm, StackFrame::MANUAL);
5687 __ EnterExitFrame(false, kApiStackSpace);
5689 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5690 // a0 = FunctionCallbackInfo&
5691 // Arguments is after the return address.
5692 __ Addu(a0, sp, Operand(1 * kPointerSize));
5693 // FunctionCallbackInfo::implicit_args_
5694 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
5695 if (argc.is_immediate()) {
5696 // FunctionCallbackInfo::values_
5697 __ Addu(at, scratch,
5698 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5699 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5700 // FunctionCallbackInfo::length_ = argc
5701 __ li(at, Operand(argc.immediate()));
5702 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5703 // FunctionCallbackInfo::is_construct_call_ = 0
5704 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
5706 // FunctionCallbackInfo::values_
5707 __ sll(at, argc.reg(), kPointerSizeLog2);
5708 __ Addu(at, at, scratch);
5709 __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5710 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5711 // FunctionCallbackInfo::length_ = argc
5712 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5713 // FunctionCallbackInfo::is_construct_call_
5714 __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5715 __ sll(at, argc.reg(), kPointerSizeLog2);
5716 __ sw(at, MemOperand(a0, 3 * kPointerSize));
5719 ExternalReference thunk_ref =
5720 ExternalReference::invoke_function_callback(masm->isolate());
5722 AllowExternalCallThatCantCauseGC scope(masm);
5723 MemOperand context_restore_operand(
5724 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5725 // Stores return the first js argument.
5726 int return_value_offset = 0;
5727 if (return_first_arg) {
5728 return_value_offset = 2 + FCA::kArgsLength;
5730 return_value_offset = 2 + FCA::kReturnValueOffset;
5732 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5733 int stack_space = 0;
5734 int32_t stack_space_offset = 4 * kPointerSize;
5735 if (argc.is_immediate()) {
5736 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5737 stack_space_offset = kInvalidStackOffset;
5739 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5740 stack_space_offset, return_value_operand,
5741 &context_restore_operand);
5745 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5746 bool call_data_undefined = this->call_data_undefined();
5747 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5748 call_data_undefined);
5752 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5753 bool is_store = this->is_store();
5754 int argc = this->argc();
5755 bool call_data_undefined = this->call_data_undefined();
5756 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5757 call_data_undefined);
5761 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5762 // ----------- S t a t e -------------
5764 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5766 // -- a2 : api_function_address
5767 // -----------------------------------
5769 Register api_function_address = ApiGetterDescriptor::function_address();
5770 DCHECK(api_function_address.is(a2));
5772 __ mov(a0, sp); // a0 = Handle<Name>
5773 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5775 const int kApiStackSpace = 1;
5776 FrameScope frame_scope(masm, StackFrame::MANUAL);
5777 __ EnterExitFrame(false, kApiStackSpace);
5779 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5780 // a1 (internal::Object** args_) as the data.
5781 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
5782 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5784 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5786 ExternalReference thunk_ref =
5787 ExternalReference::invoke_accessor_getter_callback(isolate());
5788 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5789 kStackUnwindSpace, kInvalidStackOffset,
5790 MemOperand(fp, 6 * kPointerSize), NULL);
5796 } // namespace internal
5799 #endif // V8_TARGET_ARCH_MIPS