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.
731 __ TailCallRuntime(strict() ? Runtime::kStrictEquals : Runtime::kEquals, 2,
734 int ncr; // NaN compare result.
735 if (cc == lt || cc == le) {
738 DCHECK(cc == gt || cc == ge); // Remaining cases.
741 __ li(a0, Operand(Smi::FromInt(ncr)));
744 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
745 // tagged as a small integer.
747 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3,
756 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
759 __ PushSafepointRegisters();
764 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
767 __ PopSafepointRegisters();
772 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
773 // We don't allow a GC during a store buffer overflow so there is no need to
774 // store the registers in any particular way, but we do have to store and
776 __ MultiPush(kJSCallerSaved | ra.bit());
777 if (save_doubles()) {
778 __ MultiPushFPU(kCallerSavedFPU);
780 const int argument_count = 1;
781 const int fp_argument_count = 0;
782 const Register scratch = a1;
784 AllowExternalCallThatCantCauseGC scope(masm);
785 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
786 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
788 ExternalReference::store_buffer_overflow_function(isolate()),
790 if (save_doubles()) {
791 __ MultiPopFPU(kCallerSavedFPU);
794 __ MultiPop(kJSCallerSaved | ra.bit());
799 void MathPowStub::Generate(MacroAssembler* masm) {
800 const Register base = a1;
801 const Register exponent = MathPowTaggedDescriptor::exponent();
802 DCHECK(exponent.is(a2));
803 const Register heapnumbermap = t1;
804 const Register heapnumber = v0;
805 const DoubleRegister double_base = f2;
806 const DoubleRegister double_exponent = f4;
807 const DoubleRegister double_result = f0;
808 const DoubleRegister double_scratch = f6;
809 const FPURegister single_scratch = f8;
810 const Register scratch = t5;
811 const Register scratch2 = t3;
813 Label call_runtime, done, int_exponent;
814 if (exponent_type() == ON_STACK) {
815 Label base_is_smi, unpack_exponent;
816 // The exponent and base are supplied as arguments on the stack.
817 // This can only happen if the stub is called from non-optimized code.
818 // Load input parameters from stack to double registers.
819 __ lw(base, MemOperand(sp, 1 * kPointerSize));
820 __ lw(exponent, MemOperand(sp, 0 * kPointerSize));
822 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
824 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
825 __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset));
826 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
828 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
829 __ jmp(&unpack_exponent);
831 __ bind(&base_is_smi);
832 __ mtc1(scratch, single_scratch);
833 __ cvt_d_w(double_base, single_scratch);
834 __ bind(&unpack_exponent);
836 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
838 __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
839 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
840 __ ldc1(double_exponent,
841 FieldMemOperand(exponent, HeapNumber::kValueOffset));
842 } else if (exponent_type() == TAGGED) {
843 // Base is already in double_base.
844 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
846 __ ldc1(double_exponent,
847 FieldMemOperand(exponent, HeapNumber::kValueOffset));
850 if (exponent_type() != INTEGER) {
851 Label int_exponent_convert;
852 // Detect integer exponents stored as double.
853 __ EmitFPUTruncate(kRoundToMinusInf,
859 kCheckForInexactConversion);
860 // scratch2 == 0 means there was no conversion error.
861 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
863 if (exponent_type() == ON_STACK) {
864 // Detect square root case. Crankshaft detects constant +/-0.5 at
865 // compile time and uses DoMathPowHalf instead. We then skip this check
866 // for non-constant cases of +/-0.5 as these hardly occur.
869 __ Move(double_scratch, 0.5);
870 __ BranchF(USE_DELAY_SLOT,
876 // double_scratch can be overwritten in the delay slot.
877 // Calculates square root of base. Check for the special case of
878 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
879 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
880 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
881 __ neg_d(double_result, double_scratch);
883 // Add +0 to convert -0 to +0.
884 __ add_d(double_scratch, double_base, kDoubleRegZero);
885 __ sqrt_d(double_result, double_scratch);
888 __ bind(¬_plus_half);
889 __ Move(double_scratch, -0.5);
890 __ BranchF(USE_DELAY_SLOT,
896 // double_scratch can be overwritten in the delay slot.
897 // Calculates square root of base. Check for the special case of
898 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
899 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
900 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
901 __ Move(double_result, kDoubleRegZero);
903 // Add +0 to convert -0 to +0.
904 __ add_d(double_scratch, double_base, kDoubleRegZero);
905 __ Move(double_result, 1.);
906 __ sqrt_d(double_scratch, double_scratch);
907 __ div_d(double_result, double_result, double_scratch);
913 AllowExternalCallThatCantCauseGC scope(masm);
914 __ PrepareCallCFunction(0, 2, scratch2);
915 __ MovToFloatParameters(double_base, double_exponent);
917 ExternalReference::power_double_double_function(isolate()),
921 __ MovFromFloatResult(double_result);
924 __ bind(&int_exponent_convert);
927 // Calculate power with integer exponent.
928 __ bind(&int_exponent);
930 // Get two copies of exponent in the registers scratch and exponent.
931 if (exponent_type() == INTEGER) {
932 __ mov(scratch, exponent);
934 // Exponent has previously been stored into scratch as untagged integer.
935 __ mov(exponent, scratch);
938 __ mov_d(double_scratch, double_base); // Back up base.
939 __ Move(double_result, 1.0);
941 // Get absolute value of exponent.
942 Label positive_exponent;
943 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
944 __ Subu(scratch, zero_reg, scratch);
945 __ bind(&positive_exponent);
947 Label while_true, no_carry, loop_end;
948 __ bind(&while_true);
950 __ And(scratch2, scratch, 1);
952 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
953 __ mul_d(double_result, double_result, double_scratch);
956 __ sra(scratch, scratch, 1);
958 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
959 __ mul_d(double_scratch, double_scratch, double_scratch);
961 __ Branch(&while_true);
965 __ Branch(&done, ge, exponent, Operand(zero_reg));
966 __ Move(double_scratch, 1.0);
967 __ div_d(double_result, double_scratch, double_result);
968 // Test whether result is zero. Bail out to check for subnormal result.
969 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
970 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
972 // double_exponent may not contain the exponent value if the input was a
973 // smi. We set it with exponent value before bailing out.
974 __ mtc1(exponent, single_scratch);
975 __ cvt_d_w(double_exponent, single_scratch);
977 // Returning or bailing out.
978 Counters* counters = isolate()->counters();
979 if (exponent_type() == ON_STACK) {
980 // The arguments are still on the stack.
981 __ bind(&call_runtime);
982 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
984 // The stub is called from non-optimized code, which expects the result
985 // as heap number in exponent.
987 __ AllocateHeapNumber(
988 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
989 __ sdc1(double_result,
990 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
991 DCHECK(heapnumber.is(v0));
992 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
997 AllowExternalCallThatCantCauseGC scope(masm);
998 __ PrepareCallCFunction(0, 2, scratch);
999 __ MovToFloatParameters(double_base, double_exponent);
1001 ExternalReference::power_double_double_function(isolate()),
1005 __ MovFromFloatResult(double_result);
1008 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1014 bool CEntryStub::NeedsImmovableCode() {
1019 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1020 CEntryStub::GenerateAheadOfTime(isolate);
1021 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1022 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1023 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1024 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1025 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1026 BinaryOpICStub::GenerateAheadOfTime(isolate);
1027 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1028 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1029 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1030 StoreFastElementStub::GenerateAheadOfTime(isolate);
1031 TypeofStub::GenerateAheadOfTime(isolate);
1035 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1036 StoreRegistersStateStub stub(isolate);
1041 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1042 RestoreRegistersStateStub stub(isolate);
1047 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1048 // Generate if not already in cache.
1049 SaveFPRegsMode mode = kSaveFPRegs;
1050 CEntryStub(isolate, 1, mode).GetCode();
1051 StoreBufferOverflowStub(isolate, mode).GetCode();
1052 isolate->set_fp_stubs_generated(true);
1056 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1057 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1062 void CEntryStub::Generate(MacroAssembler* masm) {
1063 // Called from JavaScript; parameters are on stack as if calling JS function
1064 // a0: number of arguments including receiver
1065 // a1: pointer to builtin function
1066 // fp: frame pointer (restored after C call)
1067 // sp: stack pointer (restored as callee's sp after C call)
1068 // cp: current context (C callee-saved)
1070 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1072 // Compute the argv pointer in a callee-saved register.
1073 __ sll(s1, a0, kPointerSizeLog2);
1074 __ Addu(s1, sp, s1);
1075 __ Subu(s1, s1, kPointerSize);
1077 // Enter the exit frame that transitions from JavaScript to C++.
1078 FrameScope scope(masm, StackFrame::MANUAL);
1079 __ EnterExitFrame(save_doubles());
1081 // s0: number of arguments including receiver (C callee-saved)
1082 // s1: pointer to first argument (C callee-saved)
1083 // s2: pointer to builtin function (C callee-saved)
1085 // Prepare arguments for C routine.
1089 // a1 = argv (set in the delay slot after find_ra below).
1091 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1092 // also need to reserve the 4 argument slots on the stack.
1094 __ AssertStackIsAligned();
1096 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1098 // To let the GC traverse the return address of the exit frames, we need to
1099 // know where the return address is. The CEntryStub is unmovable, so
1100 // we can store the address on the stack to be able to find it again and
1101 // we never have to restore it, because it will not change.
1102 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1103 // This branch-and-link sequence is needed to find the current PC on mips,
1104 // saved to the ra register.
1105 // Use masm-> here instead of the double-underscore macro since extra
1106 // coverage code can interfere with the proper calculation of ra.
1108 masm->bal(&find_ra); // bal exposes branch delay slot.
1110 masm->bind(&find_ra);
1112 // Adjust the value in ra to point to the correct return location, 2nd
1113 // instruction past the real call into C code (the jalr(t9)), and push it.
1114 // This is the return address of the exit frame.
1115 const int kNumInstructionsToJump = 5;
1116 masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize);
1117 masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1118 // Stack space reservation moved to the branch delay slot below.
1119 // Stack is still aligned.
1121 // Call the C routine.
1122 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1124 // Set up sp in the delay slot.
1125 masm->addiu(sp, sp, -kCArgsSlotsSize);
1126 // Make sure the stored 'ra' points to this position.
1127 DCHECK_EQ(kNumInstructionsToJump,
1128 masm->InstructionsGeneratedSince(&find_ra));
1132 // Check result for exception sentinel.
1133 Label exception_returned;
1134 __ LoadRoot(t0, Heap::kExceptionRootIndex);
1135 __ Branch(&exception_returned, eq, t0, Operand(v0));
1137 // Check that there is no pending exception, otherwise we
1138 // should have returned the exception sentinel.
1139 if (FLAG_debug_code) {
1141 ExternalReference pending_exception_address(
1142 Isolate::kPendingExceptionAddress, isolate());
1143 __ li(a2, Operand(pending_exception_address));
1144 __ lw(a2, MemOperand(a2));
1145 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1146 // Cannot use check here as it attempts to generate call into runtime.
1147 __ Branch(&okay, eq, t0, Operand(a2));
1148 __ stop("Unexpected pending exception");
1152 // Exit C frame and return.
1154 // sp: stack pointer
1155 // fp: frame pointer
1156 // s0: still holds argc (callee-saved).
1157 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1159 // Handling of exception.
1160 __ bind(&exception_returned);
1162 ExternalReference pending_handler_context_address(
1163 Isolate::kPendingHandlerContextAddress, isolate());
1164 ExternalReference pending_handler_code_address(
1165 Isolate::kPendingHandlerCodeAddress, isolate());
1166 ExternalReference pending_handler_offset_address(
1167 Isolate::kPendingHandlerOffsetAddress, isolate());
1168 ExternalReference pending_handler_fp_address(
1169 Isolate::kPendingHandlerFPAddress, isolate());
1170 ExternalReference pending_handler_sp_address(
1171 Isolate::kPendingHandlerSPAddress, isolate());
1173 // Ask the runtime for help to determine the handler. This will set v0 to
1174 // contain the current pending exception, don't clobber it.
1175 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1178 FrameScope scope(masm, StackFrame::MANUAL);
1179 __ PrepareCallCFunction(3, 0, a0);
1180 __ mov(a0, zero_reg);
1181 __ mov(a1, zero_reg);
1182 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1183 __ CallCFunction(find_handler, 3);
1186 // Retrieve the handler context, SP and FP.
1187 __ li(cp, Operand(pending_handler_context_address));
1188 __ lw(cp, MemOperand(cp));
1189 __ li(sp, Operand(pending_handler_sp_address));
1190 __ lw(sp, MemOperand(sp));
1191 __ li(fp, Operand(pending_handler_fp_address));
1192 __ lw(fp, MemOperand(fp));
1194 // If the handler is a JS frame, restore the context to the frame. Note that
1195 // the context will be set to (cp == 0) for non-JS frames.
1197 __ Branch(&zero, eq, cp, Operand(zero_reg));
1198 __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1201 // Compute the handler entry address and jump to it.
1202 __ li(a1, Operand(pending_handler_code_address));
1203 __ lw(a1, MemOperand(a1));
1204 __ li(a2, Operand(pending_handler_offset_address));
1205 __ lw(a2, MemOperand(a2));
1206 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1207 __ Addu(t9, a1, a2);
1212 void JSEntryStub::Generate(MacroAssembler* masm) {
1213 Label invoke, handler_entry, exit;
1214 Isolate* isolate = masm->isolate();
1217 // a0: entry address
1226 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1228 // Save callee saved registers on the stack.
1229 __ MultiPush(kCalleeSaved | ra.bit());
1231 // Save callee-saved FPU registers.
1232 __ MultiPushFPU(kCalleeSavedFPU);
1233 // Set up the reserved register for 0.0.
1234 __ Move(kDoubleRegZero, 0.0);
1237 // Load argv in s0 register.
1238 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1239 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1241 __ InitializeRootRegister();
1242 __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1244 // We build an EntryFrame.
1245 __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1246 int marker = type();
1247 __ li(t2, Operand(Smi::FromInt(marker)));
1248 __ li(t1, Operand(Smi::FromInt(marker)));
1249 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1251 __ lw(t0, MemOperand(t0));
1252 __ Push(t3, t2, t1, t0);
1253 // Set up frame pointer for the frame to be pushed.
1254 __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1257 // a0: entry_address
1259 // a2: receiver_pointer
1265 // function slot | entry frame
1267 // bad fp (0xff...f) |
1268 // callee saved registers + ra
1272 // If this is the outermost JS call, set js_entry_sp value.
1273 Label non_outermost_js;
1274 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1275 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1276 __ lw(t2, MemOperand(t1));
1277 __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
1278 __ sw(fp, MemOperand(t1));
1279 __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1282 __ nop(); // Branch delay slot nop.
1283 __ bind(&non_outermost_js);
1284 __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1288 // Jump to a faked try block that does the invoke, with a faked catch
1289 // block that sets the pending exception.
1291 __ bind(&handler_entry);
1292 handler_offset_ = handler_entry.pos();
1293 // Caught exception: Store result (exception) in the pending exception
1294 // field in the JSEnv and return a failure sentinel. Coming in here the
1295 // fp will be invalid because the PushStackHandler below sets it to 0 to
1296 // signal the existence of the JSEntry frame.
1297 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1299 __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
1300 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1301 __ b(&exit); // b exposes branch delay slot.
1302 __ nop(); // Branch delay slot nop.
1304 // Invoke: Link this frame into the handler chain.
1306 __ PushStackHandler();
1307 // If an exception not caught by another handler occurs, this handler
1308 // returns control to the code after the bal(&invoke) above, which
1309 // restores all kCalleeSaved registers (including cp and fp) to their
1310 // saved values before returning a failure to C.
1312 // Clear any pending exceptions.
1313 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
1314 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1316 __ sw(t1, MemOperand(t0));
1318 // Invoke the function by calling through JS entry trampoline builtin.
1319 // Notice that we cannot store a reference to the trampoline code directly in
1320 // this stub, because runtime stubs are not traversed when doing GC.
1323 // a0: entry_address
1325 // a2: receiver_pointer
1332 // callee saved registers + ra
1336 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1337 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1339 __ li(t0, Operand(construct_entry));
1341 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1342 __ li(t0, Operand(entry));
1344 __ lw(t9, MemOperand(t0)); // Deref address.
1346 // Call JSEntryTrampoline.
1347 __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1350 // Unlink this frame from the handler chain.
1351 __ PopStackHandler();
1353 __ bind(&exit); // v0 holds result
1354 // Check if the current stack frame is marked as the outermost JS frame.
1355 Label non_outermost_js_2;
1357 __ Branch(&non_outermost_js_2,
1360 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1361 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1362 __ sw(zero_reg, MemOperand(t1));
1363 __ bind(&non_outermost_js_2);
1365 // Restore the top frame descriptors from the stack.
1367 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1369 __ sw(t1, MemOperand(t0));
1371 // Reset the stack to the callee saved registers.
1372 __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1374 // Restore callee-saved fpu registers.
1375 __ MultiPopFPU(kCalleeSavedFPU);
1377 // Restore callee saved registers from the stack.
1378 __ MultiPop(kCalleeSaved | ra.bit());
1384 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1385 // Return address is in ra.
1388 Register receiver = LoadDescriptor::ReceiverRegister();
1389 Register index = LoadDescriptor::NameRegister();
1390 Register scratch = t1;
1391 Register result = v0;
1392 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1393 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1395 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1396 &miss, // When not a string.
1397 &miss, // When not a number.
1398 &miss, // When index out of range.
1399 STRING_INDEX_IS_ARRAY_INDEX,
1400 RECEIVER_IS_STRING);
1401 char_at_generator.GenerateFast(masm);
1404 StubRuntimeCallHelper call_helper;
1405 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1408 PropertyAccessCompiler::TailCallBuiltin(
1409 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1413 void InstanceOfStub::Generate(MacroAssembler* masm) {
1414 Register const object = a1; // Object (lhs).
1415 Register const function = a0; // Function (rhs).
1416 Register const object_map = a2; // Map of {object}.
1417 Register const function_map = a3; // Map of {function}.
1418 Register const function_prototype = t0; // Prototype of {function}.
1419 Register const scratch = t1;
1421 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1422 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1424 // Check if {object} is a smi.
1425 Label object_is_smi;
1426 __ JumpIfSmi(object, &object_is_smi);
1428 // Lookup the {function} and the {object} map in the global instanceof cache.
1429 // Note: This is safe because we clear the global instanceof cache whenever
1430 // we change the prototype of any object.
1431 Label fast_case, slow_case;
1432 __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1433 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1434 __ Branch(&fast_case, ne, function, Operand(at));
1435 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1436 __ Branch(&fast_case, ne, object_map, Operand(at));
1437 __ Ret(USE_DELAY_SLOT);
1438 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1440 // If {object} is a smi we can safely return false if {function} is a JS
1441 // function, otherwise we have to miss to the runtime and throw an exception.
1442 __ bind(&object_is_smi);
1443 __ JumpIfSmi(function, &slow_case);
1444 __ GetObjectType(function, function_map, scratch);
1445 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1446 __ Ret(USE_DELAY_SLOT);
1447 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
1449 // Fast-case: The {function} must be a valid JSFunction.
1450 __ bind(&fast_case);
1451 __ JumpIfSmi(function, &slow_case);
1452 __ GetObjectType(function, function_map, scratch);
1453 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1455 // Ensure that {function} has an instance prototype.
1456 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1457 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1458 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1460 // Ensure that {function} is not bound.
1461 Register const shared_info = scratch;
1463 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1465 FieldMemOperand(shared_info, SharedFunctionInfo::kBoundByteOffset));
1466 __ And(at, scratch, Operand(1 << SharedFunctionInfo::kBoundBitWithinByte));
1467 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1469 // Get the "prototype" (or initial map) of the {function}.
1470 __ lw(function_prototype,
1471 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1472 __ AssertNotSmi(function_prototype);
1474 // Resolve the prototype if the {function} has an initial map. Afterwards the
1475 // {function_prototype} will be either the JSReceiver prototype object or the
1476 // hole value, which means that no instances of the {function} were created so
1477 // far and hence we should return false.
1478 Label function_prototype_valid;
1479 __ GetObjectType(function_prototype, scratch, scratch);
1480 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1481 __ lw(function_prototype,
1482 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1483 __ bind(&function_prototype_valid);
1484 __ AssertNotSmi(function_prototype);
1486 // Update the global instanceof cache with the current {object} map and
1487 // {function}. The cached answer will be set when it is known below.
1488 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1489 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1491 // Loop through the prototype chain looking for the {function} prototype.
1492 // Assume true, and change to false if not found.
1493 Register const object_prototype = object_map;
1494 Register const null = scratch;
1496 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1497 __ LoadRoot(null, Heap::kNullValueRootIndex);
1499 __ lw(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1500 __ Branch(&done, eq, object_prototype, Operand(function_prototype));
1501 __ Branch(USE_DELAY_SLOT, &loop, ne, object_prototype, Operand(null));
1502 __ lw(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1503 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1505 __ Ret(USE_DELAY_SLOT);
1506 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1508 // Slow-case: Call the runtime function.
1509 __ bind(&slow_case);
1510 __ Push(object, function);
1511 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1515 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1517 Register receiver = LoadDescriptor::ReceiverRegister();
1518 // Ensure that the vector and slot registers won't be clobbered before
1519 // calling the miss handler.
1520 DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(),
1521 LoadWithVectorDescriptor::SlotRegister()));
1523 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0,
1526 PropertyAccessCompiler::TailCallBuiltin(
1527 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1531 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1532 // The displacement is the offset of the last parameter (if any)
1533 // relative to the frame pointer.
1534 const int kDisplacement =
1535 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1536 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1537 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1539 // Check that the key is a smiGenerateReadElement.
1541 __ JumpIfNotSmi(a1, &slow);
1543 // Check if the calling frame is an arguments adaptor frame.
1545 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1546 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1550 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1552 // Check index (a1) against formal parameters count limit passed in
1553 // through register a0. Use unsigned comparison to get negative
1555 __ Branch(&slow, hs, a1, Operand(a0));
1557 // Read the argument from the stack and return it.
1558 __ subu(a3, a0, a1);
1559 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1560 __ Addu(a3, fp, Operand(t3));
1561 __ Ret(USE_DELAY_SLOT);
1562 __ lw(v0, MemOperand(a3, kDisplacement));
1564 // Arguments adaptor case: Check index (a1) against actual arguments
1565 // limit found in the arguments adaptor frame. Use unsigned
1566 // comparison to get negative check for free.
1568 __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1569 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1571 // Read the argument from the adaptor frame and return it.
1572 __ subu(a3, a0, a1);
1573 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1574 __ Addu(a3, a2, Operand(t3));
1575 __ Ret(USE_DELAY_SLOT);
1576 __ lw(v0, MemOperand(a3, kDisplacement));
1578 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1579 // by calling the runtime system.
1582 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1586 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1587 // sp[0] : number of parameters
1588 // sp[4] : receiver displacement
1591 // Check if the calling frame is an arguments adaptor frame.
1593 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1594 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1598 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1600 // Patch the arguments.length and the parameters pointer in the current frame.
1601 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1602 __ sw(a2, MemOperand(sp, 0 * kPointerSize));
1604 __ Addu(a3, a3, Operand(t3));
1605 __ addiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1606 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1609 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1613 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1615 // sp[0] : number of parameters (tagged)
1616 // sp[4] : address of receiver argument
1618 // Registers used over whole function:
1619 // t2 : allocated object (tagged)
1620 // t5 : mapped parameter count (tagged)
1622 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1623 // a1 = parameter count (tagged)
1625 // Check if the calling frame is an arguments adaptor frame.
1627 Label adaptor_frame, try_allocate;
1628 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1629 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1630 __ Branch(&adaptor_frame,
1633 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1635 // No adaptor, parameter count = argument count.
1637 __ b(&try_allocate);
1638 __ nop(); // Branch delay slot nop.
1640 // We have an adaptor frame. Patch the parameters pointer.
1641 __ bind(&adaptor_frame);
1642 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1644 __ Addu(a3, a3, Operand(t6));
1645 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1646 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1648 // a1 = parameter count (tagged)
1649 // a2 = argument count (tagged)
1650 // Compute the mapped parameter count = min(a1, a2) in a1.
1652 __ Branch(&skip_min, lt, a1, Operand(a2));
1656 __ bind(&try_allocate);
1658 // Compute the sizes of backing store, parameter map, and arguments object.
1659 // 1. Parameter map, has 2 extra words containing context and backing store.
1660 const int kParameterMapHeaderSize =
1661 FixedArray::kHeaderSize + 2 * kPointerSize;
1662 // If there are no mapped parameters, we do not need the parameter_map.
1663 Label param_map_size;
1664 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1665 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1666 __ mov(t5, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1668 __ addiu(t5, t5, kParameterMapHeaderSize);
1669 __ bind(¶m_map_size);
1671 // 2. Backing store.
1673 __ Addu(t5, t5, Operand(t6));
1674 __ Addu(t5, t5, Operand(FixedArray::kHeaderSize));
1676 // 3. Arguments object.
1677 __ Addu(t5, t5, Operand(Heap::kSloppyArgumentsObjectSize));
1679 // Do the allocation of all three objects in one go.
1680 __ Allocate(t5, v0, a3, t0, &runtime, TAG_OBJECT);
1682 // v0 = address of new object(s) (tagged)
1683 // a2 = argument count (smi-tagged)
1684 // Get the arguments boilerplate from the current native context into t0.
1685 const int kNormalOffset =
1686 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1687 const int kAliasedOffset =
1688 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1690 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1691 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1692 Label skip2_ne, skip2_eq;
1693 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1694 __ lw(t0, MemOperand(t0, kNormalOffset));
1697 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1698 __ lw(t0, MemOperand(t0, kAliasedOffset));
1701 // v0 = address of new object (tagged)
1702 // a1 = mapped parameter count (tagged)
1703 // a2 = argument count (smi-tagged)
1704 // t0 = address of arguments map (tagged)
1705 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1706 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1707 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1708 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1710 // Set up the callee in-object property.
1711 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1712 __ lw(a3, MemOperand(sp, 2 * kPointerSize));
1713 __ AssertNotSmi(a3);
1714 const int kCalleeOffset = JSObject::kHeaderSize +
1715 Heap::kArgumentsCalleeIndex * kPointerSize;
1716 __ sw(a3, FieldMemOperand(v0, kCalleeOffset));
1718 // Use the length (smi tagged) and set that as an in-object property too.
1720 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1721 const int kLengthOffset = JSObject::kHeaderSize +
1722 Heap::kArgumentsLengthIndex * kPointerSize;
1723 __ sw(a2, FieldMemOperand(v0, kLengthOffset));
1725 // Set up the elements pointer in the allocated arguments object.
1726 // If we allocated a parameter map, t0 will point there, otherwise
1727 // it will point to the backing store.
1728 __ Addu(t0, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1729 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1731 // v0 = address of new object (tagged)
1732 // a1 = mapped parameter count (tagged)
1733 // a2 = argument count (tagged)
1734 // t0 = address of parameter map or backing store (tagged)
1735 // Initialize parameter map. If there are no mapped arguments, we're done.
1736 Label skip_parameter_map;
1738 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1739 // Move backing store address to a3, because it is
1740 // expected there when filling in the unmapped arguments.
1744 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1746 __ LoadRoot(t2, Heap::kSloppyArgumentsElementsMapRootIndex);
1747 __ sw(t2, FieldMemOperand(t0, FixedArray::kMapOffset));
1748 __ Addu(t2, a1, Operand(Smi::FromInt(2)));
1749 __ sw(t2, FieldMemOperand(t0, FixedArray::kLengthOffset));
1750 __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize));
1752 __ Addu(t2, t0, Operand(t6));
1753 __ Addu(t2, t2, Operand(kParameterMapHeaderSize));
1754 __ sw(t2, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize));
1756 // Copy the parameter slots and the holes in the arguments.
1757 // We need to fill in mapped_parameter_count slots. They index the context,
1758 // where parameters are stored in reverse order, at
1759 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1760 // The mapped parameter thus need to get indices
1761 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1762 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1763 // We loop from right to left.
1764 Label parameters_loop, parameters_test;
1766 __ lw(t5, MemOperand(sp, 0 * kPointerSize));
1767 __ Addu(t5, t5, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1768 __ Subu(t5, t5, Operand(a1));
1769 __ LoadRoot(t3, Heap::kTheHoleValueRootIndex);
1771 __ Addu(a3, t0, Operand(t6));
1772 __ Addu(a3, a3, Operand(kParameterMapHeaderSize));
1774 // t2 = loop variable (tagged)
1775 // a1 = mapping index (tagged)
1776 // a3 = address of backing store (tagged)
1777 // t0 = address of parameter map (tagged)
1778 // t1 = temporary scratch (a.o., for address calculation)
1779 // t3 = the hole value
1780 __ jmp(¶meters_test);
1782 __ bind(¶meters_loop);
1783 __ Subu(t2, t2, Operand(Smi::FromInt(1)));
1785 __ Addu(t1, t1, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1786 __ Addu(t6, t0, t1);
1787 __ sw(t5, MemOperand(t6));
1788 __ Subu(t1, t1, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1789 __ Addu(t6, a3, t1);
1790 __ sw(t3, MemOperand(t6));
1791 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1792 __ bind(¶meters_test);
1793 __ Branch(¶meters_loop, ne, t2, Operand(Smi::FromInt(0)));
1795 __ bind(&skip_parameter_map);
1796 // a2 = argument count (tagged)
1797 // a3 = address of backing store (tagged)
1799 // Copy arguments header and remaining slots (if there are any).
1800 __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex);
1801 __ sw(t1, FieldMemOperand(a3, FixedArray::kMapOffset));
1802 __ sw(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1804 Label arguments_loop, arguments_test;
1806 __ lw(t0, MemOperand(sp, 1 * kPointerSize));
1808 __ Subu(t0, t0, Operand(t6));
1809 __ jmp(&arguments_test);
1811 __ bind(&arguments_loop);
1812 __ Subu(t0, t0, Operand(kPointerSize));
1813 __ lw(t2, MemOperand(t0, 0));
1815 __ Addu(t1, a3, Operand(t6));
1816 __ sw(t2, FieldMemOperand(t1, FixedArray::kHeaderSize));
1817 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1819 __ bind(&arguments_test);
1820 __ Branch(&arguments_loop, lt, t5, Operand(a2));
1822 // Return and remove the on-stack parameters.
1825 // Do the runtime call to allocate the arguments object.
1826 // a2 = argument count (tagged)
1828 __ sw(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1829 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1833 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1834 // Return address is in ra.
1837 Register receiver = LoadDescriptor::ReceiverRegister();
1838 Register key = LoadDescriptor::NameRegister();
1840 // Check that the key is an array index, that is Uint32.
1841 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1842 __ Branch(&slow, ne, t0, Operand(zero_reg));
1844 // Everything is fine, call runtime.
1845 __ Push(receiver, key); // Receiver, key.
1847 // Perform tail call to the entry.
1848 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1851 PropertyAccessCompiler::TailCallBuiltin(
1852 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1856 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1857 // sp[0] : number of parameters
1858 // sp[4] : receiver displacement
1860 // Check if the calling frame is an arguments adaptor frame.
1861 Label adaptor_frame, try_allocate, runtime;
1862 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1863 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1864 __ Branch(&adaptor_frame,
1867 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1869 // Get the length from the frame.
1870 __ lw(a1, MemOperand(sp, 0));
1871 __ Branch(&try_allocate);
1873 // Patch the arguments.length and the parameters pointer.
1874 __ bind(&adaptor_frame);
1875 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1876 __ sw(a1, MemOperand(sp, 0));
1877 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1878 __ Addu(a3, a2, Operand(at));
1880 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1881 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1883 // Try the new space allocation. Start out with computing the size
1884 // of the arguments object and the elements array in words.
1885 Label add_arguments_object;
1886 __ bind(&try_allocate);
1887 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1888 __ srl(a1, a1, kSmiTagSize);
1890 __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1891 __ bind(&add_arguments_object);
1892 __ Addu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1894 // Do the allocation of both objects in one go.
1895 __ Allocate(a1, v0, a2, a3, &runtime,
1896 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1898 // Get the arguments boilerplate from the current native context.
1899 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1900 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1901 __ lw(t0, MemOperand(
1902 t0, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1904 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1905 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1906 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1907 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1909 // Get the length (smi tagged) and set that as an in-object property too.
1910 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1911 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1913 __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
1914 Heap::kArgumentsLengthIndex * kPointerSize));
1917 __ Branch(&done, eq, a1, Operand(zero_reg));
1919 // Get the parameters pointer from the stack.
1920 __ lw(a2, MemOperand(sp, 1 * kPointerSize));
1922 // Set up the elements pointer in the allocated arguments object and
1923 // initialize the header in the elements fixed array.
1924 __ Addu(t0, v0, Operand(Heap::kStrictArgumentsObjectSize));
1925 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1926 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
1927 __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset));
1928 __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset));
1929 // Untag the length for the loop.
1930 __ srl(a1, a1, kSmiTagSize);
1932 // Copy the fixed array slots.
1934 // Set up t0 to point to the first array slot.
1935 __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1937 // Pre-decrement a2 with kPointerSize on each iteration.
1938 // Pre-decrement in order to skip receiver.
1939 __ Addu(a2, a2, Operand(-kPointerSize));
1940 __ lw(a3, MemOperand(a2));
1941 // Post-increment t0 with kPointerSize on each iteration.
1942 __ sw(a3, MemOperand(t0));
1943 __ Addu(t0, t0, Operand(kPointerSize));
1944 __ Subu(a1, a1, Operand(1));
1945 __ Branch(&loop, ne, a1, Operand(zero_reg));
1947 // Return and remove the on-stack parameters.
1951 // Do the runtime call to allocate the arguments object.
1953 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1957 void RegExpExecStub::Generate(MacroAssembler* masm) {
1958 // Just jump directly to runtime if native RegExp is not selected at compile
1959 // time or if regexp entry in generated code is turned off runtime switch or
1961 #ifdef V8_INTERPRETED_REGEXP
1962 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1963 #else // V8_INTERPRETED_REGEXP
1965 // Stack frame on entry.
1966 // sp[0]: last_match_info (expected JSArray)
1967 // sp[4]: previous index
1968 // sp[8]: subject string
1969 // sp[12]: JSRegExp object
1971 const int kLastMatchInfoOffset = 0 * kPointerSize;
1972 const int kPreviousIndexOffset = 1 * kPointerSize;
1973 const int kSubjectOffset = 2 * kPointerSize;
1974 const int kJSRegExpOffset = 3 * kPointerSize;
1977 // Allocation of registers for this function. These are in callee save
1978 // registers and will be preserved by the call to the native RegExp code, as
1979 // this code is called using the normal C calling convention. When calling
1980 // directly from generated code the native RegExp code will not do a GC and
1981 // therefore the content of these registers are safe to use after the call.
1982 // MIPS - using s0..s2, since we are not using CEntry Stub.
1983 Register subject = s0;
1984 Register regexp_data = s1;
1985 Register last_match_info_elements = s2;
1987 // Ensure that a RegExp stack is allocated.
1988 ExternalReference address_of_regexp_stack_memory_address =
1989 ExternalReference::address_of_regexp_stack_memory_address(
1991 ExternalReference address_of_regexp_stack_memory_size =
1992 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1993 __ li(a0, Operand(address_of_regexp_stack_memory_size));
1994 __ lw(a0, MemOperand(a0, 0));
1995 __ Branch(&runtime, eq, a0, Operand(zero_reg));
1997 // Check that the first argument is a JSRegExp object.
1998 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
1999 STATIC_ASSERT(kSmiTag == 0);
2000 __ JumpIfSmi(a0, &runtime);
2001 __ GetObjectType(a0, a1, a1);
2002 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2004 // Check that the RegExp has been compiled (data contains a fixed array).
2005 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2006 if (FLAG_debug_code) {
2007 __ SmiTst(regexp_data, t0);
2009 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2012 __ GetObjectType(regexp_data, a0, a0);
2014 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2016 Operand(FIXED_ARRAY_TYPE));
2019 // regexp_data: RegExp data (FixedArray)
2020 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2021 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2022 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2024 // regexp_data: RegExp data (FixedArray)
2025 // Check that the number of captures fit in the static offsets vector buffer.
2027 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2028 // Check (number_of_captures + 1) * 2 <= offsets vector size
2029 // Or number_of_captures * 2 <= offsets vector size - 2
2030 // Multiplying by 2 comes for free since a2 is smi-tagged.
2031 STATIC_ASSERT(kSmiTag == 0);
2032 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2033 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2035 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2037 // Reset offset for possibly sliced string.
2038 __ mov(t0, zero_reg);
2039 __ lw(subject, MemOperand(sp, kSubjectOffset));
2040 __ JumpIfSmi(subject, &runtime);
2041 __ mov(a3, subject); // Make a copy of the original subject string.
2042 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2043 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2044 // subject: subject string
2045 // a3: subject string
2046 // a0: subject string instance type
2047 // regexp_data: RegExp data (FixedArray)
2048 // Handle subject string according to its encoding and representation:
2049 // (1) Sequential string? If yes, go to (5).
2050 // (2) Anything but sequential or cons? If yes, go to (6).
2051 // (3) Cons string. If the string is flat, replace subject with first string.
2052 // Otherwise bailout.
2053 // (4) Is subject external? If yes, go to (7).
2054 // (5) Sequential string. Load regexp code according to encoding.
2058 // Deferred code at the end of the stub:
2059 // (6) Not a long external string? If yes, go to (8).
2060 // (7) External string. Make it, offset-wise, look like a sequential string.
2062 // (8) Short external string or not a string? If yes, bail out to runtime.
2063 // (9) Sliced string. Replace subject with parent. Go to (4).
2065 Label seq_string /* 5 */, external_string /* 7 */,
2066 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2067 not_long_external /* 8 */;
2069 // (1) Sequential string? If yes, go to (5).
2072 Operand(kIsNotStringMask |
2073 kStringRepresentationMask |
2074 kShortExternalStringMask));
2075 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2076 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2078 // (2) Anything but sequential or cons? If yes, go to (6).
2079 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2080 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2081 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2082 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2084 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2086 // (3) Cons string. Check that it's flat.
2087 // Replace subject with first string and reload instance type.
2088 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2089 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2090 __ Branch(&runtime, ne, a0, Operand(a1));
2091 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2093 // (4) Is subject external? If yes, go to (7).
2094 __ bind(&check_underlying);
2095 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2096 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2097 STATIC_ASSERT(kSeqStringTag == 0);
2098 __ And(at, a0, Operand(kStringRepresentationMask));
2099 // The underlying external string is never a short external string.
2100 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2101 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2102 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2104 // (5) Sequential string. Load regexp code according to encoding.
2105 __ bind(&seq_string);
2106 // subject: sequential subject string (or look-alike, external string)
2107 // a3: original subject string
2108 // Load previous index and check range before a3 is overwritten. We have to
2109 // use a3 instead of subject here because subject might have been only made
2110 // to look like a sequential string when it actually is an external string.
2111 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
2112 __ JumpIfNotSmi(a1, &runtime);
2113 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
2114 __ Branch(&runtime, ls, a3, Operand(a1));
2115 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
2117 STATIC_ASSERT(kStringEncodingMask == 4);
2118 STATIC_ASSERT(kOneByteStringTag == 4);
2119 STATIC_ASSERT(kTwoByteStringTag == 0);
2120 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
2121 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2122 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
2123 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2124 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2126 // (E) Carry on. String handling is done.
2127 // t9: irregexp code
2128 // Check that the irregexp code has been generated for the actual string
2129 // encoding. If it has, the field contains a code object otherwise it contains
2130 // a smi (code flushing support).
2131 __ JumpIfSmi(t9, &runtime);
2133 // a1: previous index
2134 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2136 // subject: Subject string
2137 // regexp_data: RegExp data (FixedArray)
2138 // All checks done. Now push arguments for native regexp code.
2139 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2142 // Isolates: note we add an additional parameter here (isolate pointer).
2143 const int kRegExpExecuteArguments = 9;
2144 const int kParameterRegisters = 4;
2145 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2147 // Stack pointer now points to cell where return address is to be written.
2148 // Arguments are before that on the stack or in registers, meaning we
2149 // treat the return address as argument 5. Thus every argument after that
2150 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2151 // allocating space for the c argument slots, we don't need to calculate
2152 // that into the argument positions on the stack. This is how the stack will
2153 // look (sp meaning the value of sp at this moment):
2154 // [sp + 5] - Argument 9
2155 // [sp + 4] - Argument 8
2156 // [sp + 3] - Argument 7
2157 // [sp + 2] - Argument 6
2158 // [sp + 1] - Argument 5
2159 // [sp + 0] - saved ra
2161 // Argument 9: Pass current isolate address.
2162 // CFunctionArgumentOperand handles MIPS stack argument slots.
2163 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2164 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
2166 // Argument 8: Indicate that this is a direct call from JavaScript.
2167 __ li(a0, Operand(1));
2168 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
2170 // Argument 7: Start (high end) of backtracking stack memory area.
2171 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2172 __ lw(a0, MemOperand(a0, 0));
2173 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2174 __ lw(a2, MemOperand(a2, 0));
2175 __ addu(a0, a0, a2);
2176 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
2178 // Argument 6: Set the number of capture registers to zero to force global
2179 // regexps to behave as non-global. This does not affect non-global regexps.
2180 __ mov(a0, zero_reg);
2181 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
2183 // Argument 5: static offsets vector buffer.
2185 ExternalReference::address_of_static_offsets_vector(isolate())));
2186 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
2188 // For arguments 4 and 3 get string length, calculate start of string data
2189 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2190 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2191 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2192 // Load the length from the original subject string from the previous stack
2193 // frame. Therefore we have to use fp, which points exactly to two pointer
2194 // sizes below the previous sp. (Because creating a new stack frame pushes
2195 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2196 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2197 // If slice offset is not 0, load the length from the original sliced string.
2198 // Argument 4, a3: End of string data
2199 // Argument 3, a2: Start of string data
2200 // Prepare start and end index of the input.
2201 __ sllv(t1, t0, a3);
2202 __ addu(t0, t2, t1);
2203 __ sllv(t1, a1, a3);
2204 __ addu(a2, t0, t1);
2206 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
2207 __ sra(t2, t2, kSmiTagSize);
2208 __ sllv(t1, t2, a3);
2209 __ addu(a3, t0, t1);
2210 // Argument 2 (a1): Previous index.
2213 // Argument 1 (a0): Subject string.
2214 __ mov(a0, subject);
2216 // Locate the code entry and call it.
2217 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2218 DirectCEntryStub stub(isolate());
2219 stub.GenerateCall(masm, t9);
2221 __ LeaveExitFrame(false, no_reg, true);
2224 // subject: subject string (callee saved)
2225 // regexp_data: RegExp data (callee saved)
2226 // last_match_info_elements: Last match info elements (callee saved)
2227 // Check the result.
2229 __ Branch(&success, eq, v0, Operand(1));
2230 // We expect exactly one result since we force the called regexp to behave
2233 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2234 // If not exception it can only be retry. Handle that in the runtime system.
2235 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2236 // Result must now be exception. If there is no pending exception already a
2237 // stack overflow (on the backtrack stack) was detected in RegExp code but
2238 // haven't created the exception yet. Handle that in the runtime system.
2239 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2240 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2241 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2243 __ lw(v0, MemOperand(a2, 0));
2244 __ Branch(&runtime, eq, v0, Operand(a1));
2246 // For exception, throw the exception again.
2247 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2250 // For failure and exception return null.
2251 __ li(v0, Operand(isolate()->factory()->null_value()));
2254 // Process the result from the native regexp code.
2257 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2258 // Calculate number of capture registers (number_of_captures + 1) * 2.
2259 // Multiplying by 2 comes for free since r1 is smi-tagged.
2260 STATIC_ASSERT(kSmiTag == 0);
2261 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2262 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
2264 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
2265 __ JumpIfSmi(a0, &runtime);
2266 __ GetObjectType(a0, a2, a2);
2267 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2268 // Check that the JSArray is in fast case.
2269 __ lw(last_match_info_elements,
2270 FieldMemOperand(a0, JSArray::kElementsOffset));
2271 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2272 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2273 __ Branch(&runtime, ne, a0, Operand(at));
2274 // Check that the last match info has space for the capture registers and the
2275 // additional information.
2277 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2278 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2279 __ sra(at, a0, kSmiTagSize);
2280 __ Branch(&runtime, gt, a2, Operand(at));
2282 // a1: number of capture registers
2283 // subject: subject string
2284 // Store the capture count.
2285 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
2286 __ sw(a2, FieldMemOperand(last_match_info_elements,
2287 RegExpImpl::kLastCaptureCountOffset));
2288 // Store last subject and last input.
2290 FieldMemOperand(last_match_info_elements,
2291 RegExpImpl::kLastSubjectOffset));
2292 __ mov(a2, subject);
2293 __ RecordWriteField(last_match_info_elements,
2294 RegExpImpl::kLastSubjectOffset,
2299 __ mov(subject, a2);
2301 FieldMemOperand(last_match_info_elements,
2302 RegExpImpl::kLastInputOffset));
2303 __ RecordWriteField(last_match_info_elements,
2304 RegExpImpl::kLastInputOffset,
2310 // Get the static offsets vector filled by the native regexp code.
2311 ExternalReference address_of_static_offsets_vector =
2312 ExternalReference::address_of_static_offsets_vector(isolate());
2313 __ li(a2, Operand(address_of_static_offsets_vector));
2315 // a1: number of capture registers
2316 // a2: offsets vector
2317 Label next_capture, done;
2318 // Capture register counter starts from number of capture registers and
2319 // counts down until wrapping after zero.
2321 last_match_info_elements,
2322 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2323 __ bind(&next_capture);
2324 __ Subu(a1, a1, Operand(1));
2325 __ Branch(&done, lt, a1, Operand(zero_reg));
2326 // Read the value from the static offsets vector buffer.
2327 __ lw(a3, MemOperand(a2, 0));
2328 __ addiu(a2, a2, kPointerSize);
2329 // Store the smi value in the last match info.
2330 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
2331 __ sw(a3, MemOperand(a0, 0));
2332 __ Branch(&next_capture, USE_DELAY_SLOT);
2333 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
2337 // Return last match info.
2338 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
2341 // Do the runtime call to execute the regexp.
2343 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2345 // Deferred code for string handling.
2346 // (6) Not a long external string? If yes, go to (8).
2347 __ bind(¬_seq_nor_cons);
2349 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2351 // (7) External string. Make it, offset-wise, look like a sequential string.
2352 __ bind(&external_string);
2353 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2354 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2355 if (FLAG_debug_code) {
2356 // Assert that we do not have a cons or slice (indirect strings) here.
2357 // Sequential strings have already been ruled out.
2358 __ And(at, a0, Operand(kIsIndirectStringMask));
2360 kExternalStringExpectedButNotFound,
2365 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2366 // Move the pointer so that offset-wise, it looks like a sequential string.
2367 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2370 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2371 __ jmp(&seq_string); // Go to (5).
2373 // (8) Short external string or not a string? If yes, bail out to runtime.
2374 __ bind(¬_long_external);
2375 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2376 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2377 __ Branch(&runtime, ne, at, Operand(zero_reg));
2379 // (9) Sliced string. Replace subject with parent. Go to (4).
2380 // Load offset into t0 and replace subject string with parent.
2381 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2382 __ sra(t0, t0, kSmiTagSize);
2383 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2384 __ jmp(&check_underlying); // Go to (4).
2385 #endif // V8_INTERPRETED_REGEXP
2389 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2391 // a0 : number of arguments to the construct function
2392 // a2 : feedback vector
2393 // a3 : slot in feedback vector (Smi)
2394 // a1 : the function to call
2395 // t0 : original constructor (for IsSuperConstructorCall)
2396 FrameScope scope(masm, StackFrame::INTERNAL);
2397 const RegList kSavedRegs = 1 << 4 | // a0
2401 BoolToInt(is_super) << 8; // t0
2403 // Number-of-arguments register must be smi-tagged to call out.
2405 __ MultiPush(kSavedRegs);
2409 __ MultiPop(kSavedRegs);
2414 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2415 // Cache the called function in a feedback vector slot. Cache states
2416 // are uninitialized, monomorphic (indicated by a JSFunction), and
2418 // a0 : number of arguments to the construct function
2419 // a1 : the function to call
2420 // a2 : feedback vector
2421 // a3 : slot in feedback vector (Smi)
2422 // t0 : original constructor (for IsSuperConstructorCall)
2423 Label initialize, done, miss, megamorphic, not_array_function;
2425 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2426 masm->isolate()->heap()->megamorphic_symbol());
2427 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2428 masm->isolate()->heap()->uninitialized_symbol());
2430 // Load the cache state into t2.
2431 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2432 __ Addu(t2, a2, Operand(t2));
2433 __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize));
2435 // A monomorphic cache hit or an already megamorphic state: invoke the
2436 // function without changing the state.
2437 // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at
2438 // this position in a symbol (see static asserts in type-feedback-vector.h).
2439 Label check_allocation_site;
2440 Register feedback_map = t1;
2441 Register weak_value = t4;
2442 __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset));
2443 __ Branch(&done, eq, a1, Operand(weak_value));
2444 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2445 __ Branch(&done, eq, t2, Operand(at));
2446 __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset));
2447 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2448 __ Branch(&check_allocation_site, ne, feedback_map, Operand(at));
2450 // If the weak cell is cleared, we have a new chance to become monomorphic.
2451 __ JumpIfSmi(weak_value, &initialize);
2452 __ jmp(&megamorphic);
2454 __ bind(&check_allocation_site);
2455 // If we came here, we need to see if we are the array function.
2456 // If we didn't have a matching function, and we didn't find the megamorph
2457 // sentinel, then we have in the slot either some other function or an
2459 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2460 __ Branch(&miss, ne, feedback_map, Operand(at));
2462 // Make sure the function is the Array() function
2463 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2464 __ Branch(&megamorphic, ne, a1, Operand(t2));
2469 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2471 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2472 __ Branch(&initialize, eq, t2, Operand(at));
2473 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2474 // write-barrier is needed.
2475 __ bind(&megamorphic);
2476 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2477 __ Addu(t2, a2, Operand(t2));
2478 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2479 __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize));
2482 // An uninitialized cache is patched with the function.
2483 __ bind(&initialize);
2484 // Make sure the function is the Array() function.
2485 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2486 __ Branch(¬_array_function, ne, a1, Operand(t2));
2488 // The target function is the Array constructor,
2489 // Create an AllocationSite if we don't already have it, store it in the
2491 CreateAllocationSiteStub create_stub(masm->isolate());
2492 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2495 __ bind(¬_array_function);
2496 CreateWeakCellStub weak_cell_stub(masm->isolate());
2497 CallStubInRecordCallTarget(masm, &weak_cell_stub, is_super);
2502 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2503 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2504 __ lw(t0, FieldMemOperand(a3, SharedFunctionInfo::kCompilerHintsOffset));
2506 // Do not transform the receiver for strict mode functions.
2507 int32_t strict_mode_function_mask =
2508 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
2509 // Do not transform the receiver for native (Compilerhints already in a3).
2510 int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize);
2511 __ And(at, t0, Operand(strict_mode_function_mask | native_mask));
2512 __ Branch(cont, ne, at, Operand(zero_reg));
2516 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2517 __ li(a0, Operand(argc));
2518 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2522 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2523 // Wrap the receiver and patch it back onto the stack.
2524 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2527 ToObjectStub stub(masm->isolate());
2531 __ Branch(USE_DELAY_SLOT, cont);
2532 __ sw(v0, MemOperand(sp, argc * kPointerSize));
2536 static void CallFunctionNoFeedback(MacroAssembler* masm,
2537 int argc, bool needs_checks,
2538 bool call_as_method) {
2539 // a1 : the function to call
2540 Label slow, wrap, cont;
2543 // Check that the function is really a JavaScript function.
2544 // a1: pushed function (to be verified)
2545 __ JumpIfSmi(a1, &slow);
2547 // Goto slow case if we do not have a function.
2548 __ GetObjectType(a1, t0, t0);
2549 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2552 // Fast-case: Invoke the function now.
2553 // a1: pushed function
2554 ParameterCount actual(argc);
2556 if (call_as_method) {
2558 EmitContinueIfStrictOrNative(masm, &cont);
2561 // Compute the receiver in sloppy mode.
2562 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2565 __ JumpIfSmi(a3, &wrap);
2566 __ GetObjectType(a3, t0, t0);
2567 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2575 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2578 // Slow-case: Non-function called.
2580 EmitSlowCase(masm, argc);
2583 if (call_as_method) {
2585 // Wrap the receiver and patch it back onto the stack.
2586 EmitWrapCase(masm, argc, &cont);
2591 void CallFunctionStub::Generate(MacroAssembler* masm) {
2592 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2596 void CallConstructStub::Generate(MacroAssembler* masm) {
2597 // a0 : number of arguments
2598 // a1 : the function to call
2599 // a2 : feedback vector
2600 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2601 // t0 : original constructor (for IsSuperConstructorCall)
2602 Label slow, non_function_call;
2604 // Check that the function is not a smi.
2605 __ JumpIfSmi(a1, &non_function_call);
2606 // Check that the function is a JSFunction.
2607 __ GetObjectType(a1, t1, t1);
2608 __ Branch(&slow, ne, t1, Operand(JS_FUNCTION_TYPE));
2610 if (RecordCallTarget()) {
2611 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2613 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2614 __ Addu(t1, a2, at);
2615 Label feedback_register_initialized;
2616 // Put the AllocationSite from the feedback vector into a2, or undefined.
2617 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
2618 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
2619 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2620 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
2621 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2622 __ bind(&feedback_register_initialized);
2624 __ AssertUndefinedOrAllocationSite(a2, t1);
2627 // Pass function as original constructor.
2628 if (IsSuperConstructorCall()) {
2634 // Jump to the function-specific construct stub.
2635 Register jmp_reg = t0;
2636 __ lw(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2637 __ lw(jmp_reg, FieldMemOperand(jmp_reg,
2638 SharedFunctionInfo::kConstructStubOffset));
2639 __ Addu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2642 // a0: number of arguments
2643 // a1: called object
2647 __ Branch(&non_function_call, ne, t1, Operand(JS_FUNCTION_PROXY_TYPE));
2648 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies.
2649 __ lw(a1, FieldMemOperand(a1, JSFunctionProxy::kConstructTrapOffset));
2650 __ Jump(isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2652 __ bind(&non_function_call);
2654 // Determine the delegate for the target (if any).
2655 FrameScope scope(masm, StackFrame::INTERNAL);
2658 __ CallRuntime(Runtime::kGetConstructorDelegate, 1);
2663 // The delegate is always a regular function.
2664 __ AssertFunction(a1);
2665 __ Jump(masm->isolate()->builtins()->CallFunction(),
2666 RelocInfo::CODE_TARGET);
2671 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2672 __ lw(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2673 __ lw(vector, FieldMemOperand(vector,
2674 JSFunction::kSharedFunctionInfoOffset));
2675 __ lw(vector, FieldMemOperand(vector,
2676 SharedFunctionInfo::kFeedbackVectorOffset));
2680 void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
2684 // t0 - loaded from vector[slot]
2685 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2686 __ Branch(miss, ne, a1, Operand(at));
2688 __ li(a0, Operand(arg_count()));
2690 // Increment the call count for monomorphic function calls.
2691 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2692 __ Addu(at, a2, Operand(at));
2693 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2694 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2695 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2699 ArrayConstructorStub stub(masm->isolate(), arg_count());
2700 __ TailCallStub(&stub);
2704 void CallICStub::Generate(MacroAssembler* masm) {
2706 // a3 - slot id (Smi)
2708 const int with_types_offset =
2709 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2710 const int generic_offset =
2711 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2712 Label extra_checks_or_miss, slow_start;
2713 Label slow, wrap, cont;
2714 Label have_js_function;
2715 int argc = arg_count();
2716 ParameterCount actual(argc);
2718 // The checks. First, does r1 match the recorded monomorphic target?
2719 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2720 __ Addu(t0, a2, Operand(t0));
2721 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2723 // We don't know that we have a weak cell. We might have a private symbol
2724 // or an AllocationSite, but the memory is safe to examine.
2725 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2727 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2728 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2729 // computed, meaning that it can't appear to be a pointer. If the low bit is
2730 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2732 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2733 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2734 WeakCell::kValueOffset &&
2735 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2737 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2738 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
2740 // The compare above could have been a SMI/SMI comparison. Guard against this
2741 // convincing us that we have a monomorphic JSFunction.
2742 __ JumpIfSmi(a1, &extra_checks_or_miss);
2744 // Increment the call count for monomorphic function calls.
2745 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2746 __ Addu(at, a2, Operand(at));
2747 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2748 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2749 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2751 __ bind(&have_js_function);
2752 if (CallAsMethod()) {
2753 EmitContinueIfStrictOrNative(masm, &cont);
2754 // Compute the receiver in sloppy mode.
2755 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2757 __ JumpIfSmi(a3, &wrap);
2758 __ GetObjectType(a3, t0, t0);
2759 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2764 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2767 EmitSlowCase(masm, argc);
2769 if (CallAsMethod()) {
2771 EmitWrapCase(masm, argc, &cont);
2774 __ bind(&extra_checks_or_miss);
2775 Label uninitialized, miss, not_allocation_site;
2777 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2778 __ Branch(&slow_start, eq, t0, Operand(at));
2780 // Verify that t0 contains an AllocationSite
2781 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2782 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2783 __ Branch(¬_allocation_site, ne, t1, Operand(at));
2785 HandleArrayCase(masm, &miss);
2787 __ bind(¬_allocation_site);
2789 // The following cases attempt to handle MISS cases without going to the
2791 if (FLAG_trace_ic) {
2795 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2796 __ Branch(&uninitialized, eq, t0, Operand(at));
2798 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2799 // to handle it here. More complex cases are dealt with in the runtime.
2800 __ AssertNotSmi(t0);
2801 __ GetObjectType(t0, t1, t1);
2802 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
2803 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2804 __ Addu(t0, a2, Operand(t0));
2805 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2806 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2807 // We have to update statistics for runtime profiling.
2808 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2809 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
2810 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2811 __ lw(t0, FieldMemOperand(a2, generic_offset));
2812 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2813 __ Branch(USE_DELAY_SLOT, &slow_start);
2814 __ sw(t0, FieldMemOperand(a2, generic_offset)); // In delay slot.
2816 __ bind(&uninitialized);
2818 // We are going monomorphic, provided we actually have a JSFunction.
2819 __ JumpIfSmi(a1, &miss);
2821 // Goto miss case if we do not have a function.
2822 __ GetObjectType(a1, t0, t0);
2823 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2825 // Make sure the function is not the Array() function, which requires special
2826 // behavior on MISS.
2827 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2828 __ Branch(&miss, eq, a1, Operand(t0));
2831 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2832 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2833 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2835 // Initialize the call counter.
2836 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2837 __ Addu(at, a2, Operand(at));
2838 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2839 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2841 // Store the function. Use a stub since we need a frame for allocation.
2846 FrameScope scope(masm, StackFrame::INTERNAL);
2847 CreateWeakCellStub create_stub(masm->isolate());
2849 __ CallStub(&create_stub);
2853 __ Branch(&have_js_function);
2855 // We are here because tracing is on or we encountered a MISS case we can't
2861 __ bind(&slow_start);
2862 // Check that the function is really a JavaScript function.
2863 // r1: pushed function (to be verified)
2864 __ JumpIfSmi(a1, &slow);
2866 // Goto slow case if we do not have a function.
2867 __ GetObjectType(a1, t0, t0);
2868 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2869 __ Branch(&have_js_function);
2873 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2874 FrameScope scope(masm, StackFrame::INTERNAL);
2876 // Push the receiver and the function and feedback info.
2877 __ Push(a1, a2, a3);
2880 __ CallRuntime(Runtime::kCallIC_Miss, 3);
2882 // Move result to a1 and exit the internal frame.
2887 // StringCharCodeAtGenerator.
2888 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2889 DCHECK(!t0.is(index_));
2890 DCHECK(!t0.is(result_));
2891 DCHECK(!t0.is(object_));
2892 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2893 // If the receiver is a smi trigger the non-string case.
2894 __ JumpIfSmi(object_, receiver_not_string_);
2896 // Fetch the instance type of the receiver into result register.
2897 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2898 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2899 // If the receiver is not a string trigger the non-string case.
2900 __ And(t0, result_, Operand(kIsNotStringMask));
2901 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
2904 // If the index is non-smi trigger the non-smi case.
2905 __ JumpIfNotSmi(index_, &index_not_smi_);
2907 __ bind(&got_smi_index_);
2909 // Check for index out of range.
2910 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
2911 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
2913 __ sra(index_, index_, kSmiTagSize);
2915 StringCharLoadGenerator::Generate(masm,
2921 __ sll(result_, result_, kSmiTagSize);
2926 void StringCharCodeAtGenerator::GenerateSlow(
2927 MacroAssembler* masm, EmbedMode embed_mode,
2928 const RuntimeCallHelper& call_helper) {
2929 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2931 // Index is not a smi.
2932 __ bind(&index_not_smi_);
2933 // If index is a heap number, try converting it to an integer.
2936 Heap::kHeapNumberMapRootIndex,
2939 call_helper.BeforeCall(masm);
2940 // Consumed by runtime conversion function:
2941 if (embed_mode == PART_OF_IC_HANDLER) {
2942 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2943 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2945 __ Push(object_, index_);
2947 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2948 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2950 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2951 // NumberToSmi discards numbers that are not exact integers.
2952 __ CallRuntime(Runtime::kNumberToSmi, 1);
2955 // Save the conversion result before the pop instructions below
2956 // have a chance to overwrite it.
2957 __ Move(index_, v0);
2958 if (embed_mode == PART_OF_IC_HANDLER) {
2959 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2960 LoadWithVectorDescriptor::SlotRegister(), object_);
2964 // Reload the instance type.
2965 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2966 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2967 call_helper.AfterCall(masm);
2968 // If index is still not a smi, it must be out of range.
2969 __ JumpIfNotSmi(index_, index_out_of_range_);
2970 // Otherwise, return to the fast path.
2971 __ Branch(&got_smi_index_);
2973 // Call runtime. We get here when the receiver is a string and the
2974 // index is a number, but the code of getting the actual character
2975 // is too complex (e.g., when the string needs to be flattened).
2976 __ bind(&call_runtime_);
2977 call_helper.BeforeCall(masm);
2978 __ sll(index_, index_, kSmiTagSize);
2979 __ Push(object_, index_);
2980 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2982 __ Move(result_, v0);
2984 call_helper.AfterCall(masm);
2987 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2991 // -------------------------------------------------------------------------
2992 // StringCharFromCodeGenerator
2994 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2995 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2997 DCHECK(!t0.is(result_));
2998 DCHECK(!t0.is(code_));
3000 STATIC_ASSERT(kSmiTag == 0);
3001 STATIC_ASSERT(kSmiShiftSize == 0);
3002 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3003 __ And(t0, code_, Operand(kSmiTagMask |
3004 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3005 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
3007 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3008 // At this point code register contains smi tagged one-byte char code.
3009 STATIC_ASSERT(kSmiTag == 0);
3010 __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize);
3011 __ Addu(result_, result_, t0);
3012 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3013 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
3014 __ Branch(&slow_case_, eq, result_, Operand(t0));
3019 void StringCharFromCodeGenerator::GenerateSlow(
3020 MacroAssembler* masm,
3021 const RuntimeCallHelper& call_helper) {
3022 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3024 __ bind(&slow_case_);
3025 call_helper.BeforeCall(masm);
3027 __ CallRuntime(Runtime::kCharFromCode, 1);
3028 __ Move(result_, v0);
3030 call_helper.AfterCall(masm);
3033 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3037 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3040 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3045 String::Encoding encoding) {
3046 if (FLAG_debug_code) {
3047 // Check that destination is word aligned.
3048 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3050 kDestinationOfCopyNotAligned,
3055 // Assumes word reads and writes are little endian.
3056 // Nothing to do for zero characters.
3059 if (encoding == String::TWO_BYTE_ENCODING) {
3060 __ Addu(count, count, count);
3063 Register limit = count; // Read until dest equals this.
3064 __ Addu(limit, dest, Operand(count));
3066 Label loop_entry, loop;
3067 // Copy bytes from src to dest until dest hits limit.
3068 __ Branch(&loop_entry);
3070 __ lbu(scratch, MemOperand(src));
3071 __ Addu(src, src, Operand(1));
3072 __ sb(scratch, MemOperand(dest));
3073 __ Addu(dest, dest, Operand(1));
3074 __ bind(&loop_entry);
3075 __ Branch(&loop, lt, dest, Operand(limit));
3081 void SubStringStub::Generate(MacroAssembler* masm) {
3083 // Stack frame on entry.
3084 // ra: return address
3089 // This stub is called from the native-call %_SubString(...), so
3090 // nothing can be assumed about the arguments. It is tested that:
3091 // "string" is a sequential string,
3092 // both "from" and "to" are smis, and
3093 // 0 <= from <= to <= string.length.
3094 // If any of these assumptions fail, we call the runtime system.
3096 const int kToOffset = 0 * kPointerSize;
3097 const int kFromOffset = 1 * kPointerSize;
3098 const int kStringOffset = 2 * kPointerSize;
3100 __ lw(a2, MemOperand(sp, kToOffset));
3101 __ lw(a3, MemOperand(sp, kFromOffset));
3102 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3103 STATIC_ASSERT(kSmiTag == 0);
3104 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3106 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3107 // safe in this case.
3108 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
3109 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
3110 // Both a2 and a3 are untagged integers.
3112 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3114 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3115 __ Subu(a2, a2, a3);
3117 // Make sure first argument is a string.
3118 __ lw(v0, MemOperand(sp, kStringOffset));
3119 __ JumpIfSmi(v0, &runtime);
3120 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3121 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3122 __ And(t0, a1, Operand(kIsNotStringMask));
3124 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3127 __ Branch(&single_char, eq, a2, Operand(1));
3129 // Short-cut for the case of trivial substring.
3131 // v0: original string
3132 // a2: result string length
3133 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
3135 // Return original string.
3136 __ Branch(&return_v0, eq, a2, Operand(t0));
3137 // Longer than original string's length or negative: unsafe arguments.
3138 __ Branch(&runtime, hi, a2, Operand(t0));
3139 // Shorter than original string's length: an actual substring.
3141 // Deal with different string types: update the index if necessary
3142 // and put the underlying string into t1.
3143 // v0: original string
3144 // a1: instance type
3146 // a3: from index (untagged)
3147 Label underlying_unpacked, sliced_string, seq_or_external_string;
3148 // If the string is not indirect, it can only be sequential or external.
3149 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3150 STATIC_ASSERT(kIsIndirectStringMask != 0);
3151 __ And(t0, a1, Operand(kIsIndirectStringMask));
3152 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
3153 // t0 is used as a scratch register and can be overwritten in either case.
3154 __ And(t0, a1, Operand(kSlicedNotConsMask));
3155 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
3156 // Cons string. Check whether it is flat, then fetch first part.
3157 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
3158 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
3159 __ Branch(&runtime, ne, t1, Operand(t0));
3160 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
3161 // Update instance type.
3162 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3163 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3164 __ jmp(&underlying_unpacked);
3166 __ bind(&sliced_string);
3167 // Sliced string. Fetch parent and correct start index by offset.
3168 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3169 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3170 __ sra(t0, t0, 1); // Add offset to index.
3171 __ Addu(a3, a3, t0);
3172 // Update instance type.
3173 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3174 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3175 __ jmp(&underlying_unpacked);
3177 __ bind(&seq_or_external_string);
3178 // Sequential or external string. Just move string to the expected register.
3181 __ bind(&underlying_unpacked);
3183 if (FLAG_string_slices) {
3185 // t1: underlying subject string
3186 // a1: instance type of underlying subject string
3188 // a3: adjusted start index (untagged)
3189 // Short slice. Copy instead of slicing.
3190 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3191 // Allocate new sliced string. At this point we do not reload the instance
3192 // type including the string encoding because we simply rely on the info
3193 // provided by the original string. It does not matter if the original
3194 // string's encoding is wrong because we always have to recheck encoding of
3195 // the newly created string's parent anyways due to externalized strings.
3196 Label two_byte_slice, set_slice_header;
3197 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3198 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3199 __ And(t0, a1, Operand(kStringEncodingMask));
3200 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
3201 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
3202 __ jmp(&set_slice_header);
3203 __ bind(&two_byte_slice);
3204 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
3205 __ bind(&set_slice_header);
3207 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3208 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3211 __ bind(©_routine);
3214 // t1: underlying subject string
3215 // a1: instance type of underlying subject string
3217 // a3: adjusted start index (untagged)
3218 Label two_byte_sequential, sequential_string, allocate_result;
3219 STATIC_ASSERT(kExternalStringTag != 0);
3220 STATIC_ASSERT(kSeqStringTag == 0);
3221 __ And(t0, a1, Operand(kExternalStringTag));
3222 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
3224 // Handle external string.
3225 // Rule out short external strings.
3226 STATIC_ASSERT(kShortExternalStringTag != 0);
3227 __ And(t0, a1, Operand(kShortExternalStringTag));
3228 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3229 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
3230 // t1 already points to the first character of underlying string.
3231 __ jmp(&allocate_result);
3233 __ bind(&sequential_string);
3234 // Locate first character of underlying subject string.
3235 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3236 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3238 __ bind(&allocate_result);
3239 // Sequential acii string. Allocate the result.
3240 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3241 __ And(t0, a1, Operand(kStringEncodingMask));
3242 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
3244 // Allocate and copy the resulting ASCII string.
3245 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
3247 // Locate first character of substring to copy.
3248 __ Addu(t1, t1, a3);
3250 // Locate first character of result.
3251 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3253 // v0: result string
3254 // a1: first character of result string
3255 // a2: result string length
3256 // t1: first character of substring to copy
3257 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3258 StringHelper::GenerateCopyCharacters(
3259 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
3262 // Allocate and copy the resulting two-byte string.
3263 __ bind(&two_byte_sequential);
3264 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
3266 // Locate first character of substring to copy.
3267 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3269 __ Addu(t1, t1, t0);
3270 // Locate first character of result.
3271 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3273 // v0: result string.
3274 // a1: first character of result.
3275 // a2: result length.
3276 // t1: first character of substring to copy.
3277 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3278 StringHelper::GenerateCopyCharacters(
3279 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
3281 __ bind(&return_v0);
3282 Counters* counters = isolate()->counters();
3283 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
3286 // Just jump to runtime to create the sub string.
3288 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3290 __ bind(&single_char);
3291 // v0: original string
3292 // a1: instance type
3294 // a3: from index (untagged)
3296 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3297 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3298 generator.GenerateFast(masm);
3300 generator.SkipSlow(masm, &runtime);
3304 void ToNumberStub::Generate(MacroAssembler* masm) {
3305 // The ToNumber stub takes one argument in a0.
3307 __ JumpIfNotSmi(a0, ¬_smi);
3308 __ Ret(USE_DELAY_SLOT);
3312 Label not_heap_number;
3313 __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3314 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3316 // a1: instance type.
3317 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3318 __ Ret(USE_DELAY_SLOT);
3320 __ bind(¬_heap_number);
3322 Label not_string, slow_string;
3323 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3324 // Check if string has a cached array index.
3325 __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3326 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3327 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3328 __ IndexFromHash(a2, a0);
3329 __ Ret(USE_DELAY_SLOT);
3331 __ bind(&slow_string);
3332 __ push(a0); // Push argument.
3333 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3334 __ bind(¬_string);
3337 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3338 __ Ret(USE_DELAY_SLOT);
3339 __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3340 __ bind(¬_oddball);
3342 __ push(a0); // Push argument.
3343 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3347 void ToStringStub::Generate(MacroAssembler* masm) {
3348 // The ToString stub takes on argument in a0.
3350 __ JumpIfSmi(a0, &is_number);
3353 __ GetObjectType(a0, a1, a1);
3355 // a1: receiver instance type
3356 __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
3357 __ Ret(USE_DELAY_SLOT);
3359 __ bind(¬_string);
3361 Label not_heap_number;
3362 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3363 __ bind(&is_number);
3364 NumberToStringStub stub(isolate());
3365 __ TailCallStub(&stub);
3366 __ bind(¬_heap_number);
3369 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3370 __ Ret(USE_DELAY_SLOT);
3371 __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
3372 __ bind(¬_oddball);
3374 __ push(a0); // Push argument.
3375 __ TailCallRuntime(Runtime::kToString, 1, 1);
3379 void StringHelper::GenerateFlatOneByteStringEquals(
3380 MacroAssembler* masm, Register left, Register right, Register scratch1,
3381 Register scratch2, Register scratch3) {
3382 Register length = scratch1;
3385 Label strings_not_equal, check_zero_length;
3386 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
3387 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3388 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3389 __ bind(&strings_not_equal);
3390 DCHECK(is_int16(NOT_EQUAL));
3391 __ Ret(USE_DELAY_SLOT);
3392 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3394 // Check if the length is zero.
3395 Label compare_chars;
3396 __ bind(&check_zero_length);
3397 STATIC_ASSERT(kSmiTag == 0);
3398 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3399 DCHECK(is_int16(EQUAL));
3400 __ Ret(USE_DELAY_SLOT);
3401 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3403 // Compare characters.
3404 __ bind(&compare_chars);
3406 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3407 v0, &strings_not_equal);
3409 // Characters are equal.
3410 __ Ret(USE_DELAY_SLOT);
3411 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3415 void StringHelper::GenerateCompareFlatOneByteStrings(
3416 MacroAssembler* masm, Register left, Register right, Register scratch1,
3417 Register scratch2, Register scratch3, Register scratch4) {
3418 Label result_not_equal, compare_lengths;
3419 // Find minimum length and length difference.
3420 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
3421 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3422 __ Subu(scratch3, scratch1, Operand(scratch2));
3423 Register length_delta = scratch3;
3424 __ slt(scratch4, scratch2, scratch1);
3425 __ Movn(scratch1, scratch2, scratch4);
3426 Register min_length = scratch1;
3427 STATIC_ASSERT(kSmiTag == 0);
3428 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3431 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3432 scratch4, v0, &result_not_equal);
3434 // Compare lengths - strings up to min-length are equal.
3435 __ bind(&compare_lengths);
3436 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3437 // Use length_delta as result if it's zero.
3438 __ mov(scratch2, length_delta);
3439 __ mov(scratch4, zero_reg);
3440 __ mov(v0, zero_reg);
3442 __ bind(&result_not_equal);
3443 // Conditionally update the result based either on length_delta or
3444 // the last comparion performed in the loop above.
3446 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3447 __ li(v0, Operand(Smi::FromInt(GREATER)));
3448 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3449 __ li(v0, Operand(Smi::FromInt(LESS)));
3455 void StringHelper::GenerateOneByteCharsCompareLoop(
3456 MacroAssembler* masm, Register left, Register right, Register length,
3457 Register scratch1, Register scratch2, Register scratch3,
3458 Label* chars_not_equal) {
3459 // Change index to run from -length to -1 by adding length to string
3460 // start. This means that loop ends when index reaches zero, which
3461 // doesn't need an additional compare.
3462 __ SmiUntag(length);
3463 __ Addu(scratch1, length,
3464 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3465 __ Addu(left, left, Operand(scratch1));
3466 __ Addu(right, right, Operand(scratch1));
3467 __ Subu(length, zero_reg, length);
3468 Register index = length; // index = -length;
3474 __ Addu(scratch3, left, index);
3475 __ lbu(scratch1, MemOperand(scratch3));
3476 __ Addu(scratch3, right, index);
3477 __ lbu(scratch2, MemOperand(scratch3));
3478 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3479 __ Addu(index, index, 1);
3480 __ Branch(&loop, ne, index, Operand(zero_reg));
3484 void StringCompareStub::Generate(MacroAssembler* masm) {
3485 // ----------- S t a t e -------------
3488 // -- ra : return address
3489 // -----------------------------------
3490 __ AssertString(a1);
3491 __ AssertString(a0);
3494 __ Branch(¬_same, ne, a0, Operand(a1));
3495 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3496 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a1,
3502 // Check that both objects are sequential one-byte strings.
3504 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3506 // Compare flat ASCII strings natively.
3507 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
3509 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3513 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3517 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3518 // ----------- S t a t e -------------
3521 // -- ra : return address
3522 // -----------------------------------
3524 // Load a2 with the allocation site. We stick an undefined dummy value here
3525 // and replace it with the real allocation site later when we instantiate this
3526 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3527 __ li(a2, handle(isolate()->heap()->undefined_value()));
3529 // Make sure that we actually patched the allocation site.
3530 if (FLAG_debug_code) {
3531 __ And(at, a2, Operand(kSmiTagMask));
3532 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3533 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
3534 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3535 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
3538 // Tail call into the stub that handles binary operations with allocation
3540 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3541 __ TailCallStub(&stub);
3545 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3546 DCHECK(state() == CompareICState::SMI);
3549 __ JumpIfNotSmi(a2, &miss);
3551 if (GetCondition() == eq) {
3552 // For equality we do not care about the sign of the result.
3553 __ Ret(USE_DELAY_SLOT);
3554 __ Subu(v0, a0, a1);
3556 // Untag before subtracting to avoid handling overflow.
3559 __ Ret(USE_DELAY_SLOT);
3560 __ Subu(v0, a1, a0);
3568 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3569 DCHECK(state() == CompareICState::NUMBER);
3572 Label unordered, maybe_undefined1, maybe_undefined2;
3575 if (left() == CompareICState::SMI) {
3576 __ JumpIfNotSmi(a1, &miss);
3578 if (right() == CompareICState::SMI) {
3579 __ JumpIfNotSmi(a0, &miss);
3582 // Inlining the double comparison and falling back to the general compare
3583 // stub if NaN is involved.
3584 // Load left and right operand.
3585 Label done, left, left_smi, right_smi;
3586 __ JumpIfSmi(a0, &right_smi);
3587 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3589 __ Subu(a2, a0, Operand(kHeapObjectTag));
3590 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3592 __ bind(&right_smi);
3593 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3594 FPURegister single_scratch = f6;
3595 __ mtc1(a2, single_scratch);
3596 __ cvt_d_w(f2, single_scratch);
3599 __ JumpIfSmi(a1, &left_smi);
3600 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3602 __ Subu(a2, a1, Operand(kHeapObjectTag));
3603 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3606 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3607 single_scratch = f8;
3608 __ mtc1(a2, single_scratch);
3609 __ cvt_d_w(f0, single_scratch);
3613 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3614 Label fpu_eq, fpu_lt;
3615 // Test if equal, and also handle the unordered/NaN case.
3616 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3618 // Test if less (unordered case is already handled).
3619 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3621 // Otherwise it's greater, so just fall thru, and return.
3622 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3623 __ Ret(USE_DELAY_SLOT);
3624 __ li(v0, Operand(GREATER));
3627 __ Ret(USE_DELAY_SLOT);
3628 __ li(v0, Operand(EQUAL));
3631 __ Ret(USE_DELAY_SLOT);
3632 __ li(v0, Operand(LESS));
3634 __ bind(&unordered);
3635 __ bind(&generic_stub);
3636 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3637 CompareICState::GENERIC, CompareICState::GENERIC);
3638 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3640 __ bind(&maybe_undefined1);
3641 if (Token::IsOrderedRelationalCompareOp(op())) {
3642 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3643 __ Branch(&miss, ne, a0, Operand(at));
3644 __ JumpIfSmi(a1, &unordered);
3645 __ GetObjectType(a1, a2, a2);
3646 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3650 __ bind(&maybe_undefined2);
3651 if (Token::IsOrderedRelationalCompareOp(op())) {
3652 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3653 __ Branch(&unordered, eq, a1, Operand(at));
3661 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3662 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3665 // Registers containing left and right operands respectively.
3667 Register right = a0;
3671 // Check that both operands are heap objects.
3672 __ JumpIfEitherSmi(left, right, &miss);
3674 // Check that both operands are internalized strings.
3675 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3676 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3677 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3678 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3679 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3680 __ Or(tmp1, tmp1, Operand(tmp2));
3681 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3682 __ Branch(&miss, ne, at, Operand(zero_reg));
3684 // Make sure a0 is non-zero. At this point input operands are
3685 // guaranteed to be non-zero.
3686 DCHECK(right.is(a0));
3687 STATIC_ASSERT(EQUAL == 0);
3688 STATIC_ASSERT(kSmiTag == 0);
3690 // Internalized strings are compared by identity.
3691 __ Ret(ne, left, Operand(right));
3692 DCHECK(is_int16(EQUAL));
3693 __ Ret(USE_DELAY_SLOT);
3694 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3701 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3702 DCHECK(state() == CompareICState::UNIQUE_NAME);
3703 DCHECK(GetCondition() == eq);
3706 // Registers containing left and right operands respectively.
3708 Register right = a0;
3712 // Check that both operands are heap objects.
3713 __ JumpIfEitherSmi(left, right, &miss);
3715 // Check that both operands are unique names. This leaves the instance
3716 // types loaded in tmp1 and tmp2.
3717 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3718 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3719 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3720 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3722 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3723 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3728 // Unique names are compared by identity.
3730 __ Branch(&done, ne, left, Operand(right));
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);
3736 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3745 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3746 DCHECK(state() == CompareICState::STRING);
3749 bool equality = Token::IsEqualityOp(op());
3751 // Registers containing left and right operands respectively.
3753 Register right = a0;
3760 // Check that both operands are heap objects.
3761 __ JumpIfEitherSmi(left, right, &miss);
3763 // Check that both operands are strings. This leaves the instance
3764 // types loaded in tmp1 and tmp2.
3765 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3766 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3767 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3768 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3769 STATIC_ASSERT(kNotStringTag != 0);
3770 __ Or(tmp3, tmp1, tmp2);
3771 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3772 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3774 // Fast check for identical strings.
3775 Label left_ne_right;
3776 STATIC_ASSERT(EQUAL == 0);
3777 STATIC_ASSERT(kSmiTag == 0);
3778 __ Branch(&left_ne_right, ne, left, Operand(right));
3779 __ Ret(USE_DELAY_SLOT);
3780 __ mov(v0, zero_reg); // In the delay slot.
3781 __ bind(&left_ne_right);
3783 // Handle not identical strings.
3785 // Check that both strings are internalized strings. If they are, we're done
3786 // because we already know they are not identical. We know they are both
3789 DCHECK(GetCondition() == eq);
3790 STATIC_ASSERT(kInternalizedTag == 0);
3791 __ Or(tmp3, tmp1, Operand(tmp2));
3792 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3794 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3795 // Make sure a0 is non-zero. At this point input operands are
3796 // guaranteed to be non-zero.
3797 DCHECK(right.is(a0));
3798 __ Ret(USE_DELAY_SLOT);
3799 __ mov(v0, a0); // In the delay slot.
3800 __ bind(&is_symbol);
3803 // Check that both strings are sequential one-byte.
3805 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3808 // Compare flat one-byte strings. Returns when done.
3810 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3813 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3817 // Handle more complex cases in runtime.
3819 __ Push(left, right);
3821 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3823 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3831 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3832 DCHECK(state() == CompareICState::OBJECT);
3834 __ And(a2, a1, Operand(a0));
3835 __ JumpIfSmi(a2, &miss);
3837 __ GetObjectType(a0, a2, a2);
3838 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3839 __ GetObjectType(a1, a2, a2);
3840 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3842 DCHECK(GetCondition() == eq);
3843 __ Ret(USE_DELAY_SLOT);
3844 __ subu(v0, a0, a1);
3851 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3853 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3855 __ JumpIfSmi(a2, &miss);
3856 __ GetWeakValue(t0, cell);
3857 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3858 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3859 __ Branch(&miss, ne, a2, Operand(t0));
3860 __ Branch(&miss, ne, a3, Operand(t0));
3862 __ Ret(USE_DELAY_SLOT);
3863 __ subu(v0, a0, a1);
3870 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3872 // Call the runtime system in a fresh internal frame.
3873 FrameScope scope(masm, StackFrame::INTERNAL);
3875 __ Push(ra, a1, a0);
3876 __ li(t0, Operand(Smi::FromInt(op())));
3877 __ addiu(sp, sp, -kPointerSize);
3878 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3880 __ sw(t0, MemOperand(sp)); // In the delay slot.
3881 // Compute the entry point of the rewritten stub.
3882 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3883 // Restore registers.
3890 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3891 // Make place for arguments to fit C calling convention. Most of the callers
3892 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3893 // so they handle stack restoring and we don't have to do that here.
3894 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3895 // kCArgsSlotsSize stack space after the call.
3896 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
3897 // Place the return address on the stack, making the call
3898 // GC safe. The RegExp backend also relies on this.
3899 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
3900 __ Call(t9); // Call the C++ function.
3901 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
3903 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3904 // In case of an error the return address may point to a memory area
3905 // filled with kZapValue by the GC.
3906 // Dereference the address and check for this.
3907 __ lw(t0, MemOperand(t9));
3908 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
3909 Operand(reinterpret_cast<uint32_t>(kZapValue)));
3915 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3918 reinterpret_cast<intptr_t>(GetCode().location());
3919 __ Move(t9, target);
3920 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3925 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3929 Register properties,
3931 Register scratch0) {
3932 DCHECK(name->IsUniqueName());
3933 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3934 // not equal to the name and kProbes-th slot is not used (its name is the
3935 // undefined value), it guarantees the hash table doesn't contain the
3936 // property. It's true even if some slots represent deleted properties
3937 // (their names are the hole value).
3938 for (int i = 0; i < kInlinedProbes; i++) {
3939 // scratch0 points to properties hash.
3940 // Compute the masked index: (hash + i + i * i) & mask.
3941 Register index = scratch0;
3942 // Capacity is smi 2^n.
3943 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
3944 __ Subu(index, index, Operand(1));
3945 __ And(index, index, Operand(
3946 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3948 // Scale the index by multiplying by the entry size.
3949 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3950 __ sll(at, index, 1);
3951 __ Addu(index, index, at);
3953 Register entity_name = scratch0;
3954 // Having undefined at this place means the name is not contained.
3955 STATIC_ASSERT(kSmiTagSize == 1);
3956 Register tmp = properties;
3957 __ sll(scratch0, index, 1);
3958 __ Addu(tmp, properties, scratch0);
3959 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3961 DCHECK(!tmp.is(entity_name));
3962 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3963 __ Branch(done, eq, entity_name, Operand(tmp));
3965 // Load the hole ready for use below:
3966 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3968 // Stop if found the property.
3969 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
3972 __ Branch(&good, eq, entity_name, Operand(tmp));
3974 // Check if the entry name is not a unique name.
3975 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3977 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3978 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
3981 // Restore the properties.
3983 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3986 const int spill_mask =
3987 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
3988 a2.bit() | a1.bit() | a0.bit() | v0.bit());
3990 __ MultiPush(spill_mask);
3991 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
3992 __ li(a1, Operand(Handle<Name>(name)));
3993 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
3996 __ MultiPop(spill_mask);
3998 __ Branch(done, eq, at, Operand(zero_reg));
3999 __ Branch(miss, ne, at, Operand(zero_reg));
4003 // Probe the name dictionary in the |elements| register. Jump to the
4004 // |done| label if a property with the given name is found. Jump to
4005 // the |miss| label otherwise.
4006 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4007 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4013 Register scratch2) {
4014 DCHECK(!elements.is(scratch1));
4015 DCHECK(!elements.is(scratch2));
4016 DCHECK(!name.is(scratch1));
4017 DCHECK(!name.is(scratch2));
4019 __ AssertName(name);
4021 // Compute the capacity mask.
4022 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
4023 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
4024 __ Subu(scratch1, scratch1, Operand(1));
4026 // Generate an unrolled loop that performs a few probes before
4027 // giving up. Measurements done on Gmail indicate that 2 probes
4028 // cover ~93% of loads from dictionaries.
4029 for (int i = 0; i < kInlinedProbes; i++) {
4030 // Compute the masked index: (hash + i + i * i) & mask.
4031 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4033 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4034 // the hash in a separate instruction. The value hash + i + i * i is right
4035 // shifted in the following and instruction.
4036 DCHECK(NameDictionary::GetProbeOffset(i) <
4037 1 << (32 - Name::kHashFieldOffset));
4038 __ Addu(scratch2, scratch2, Operand(
4039 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4041 __ srl(scratch2, scratch2, Name::kHashShift);
4042 __ And(scratch2, scratch1, scratch2);
4044 // Scale the index by multiplying by the element size.
4045 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4046 // scratch2 = scratch2 * 3.
4048 __ sll(at, scratch2, 1);
4049 __ Addu(scratch2, scratch2, at);
4051 // Check if the key is identical to the name.
4052 __ sll(at, scratch2, 2);
4053 __ Addu(scratch2, elements, at);
4054 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
4055 __ Branch(done, eq, name, Operand(at));
4058 const int spill_mask =
4059 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
4060 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4061 ~(scratch1.bit() | scratch2.bit());
4063 __ MultiPush(spill_mask);
4065 DCHECK(!elements.is(a1));
4067 __ Move(a0, elements);
4069 __ Move(a0, elements);
4072 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4074 __ mov(scratch2, a2);
4076 __ MultiPop(spill_mask);
4078 __ Branch(done, ne, at, Operand(zero_reg));
4079 __ Branch(miss, eq, at, Operand(zero_reg));
4083 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4084 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4085 // we cannot call anything that could cause a GC from this stub.
4087 // result: NameDictionary to probe
4089 // dictionary: NameDictionary to probe.
4090 // index: will hold an index of entry if lookup is successful.
4091 // might alias with result_.
4093 // result_ is zero if lookup failed, non zero otherwise.
4095 Register result = v0;
4096 Register dictionary = a0;
4098 Register index = a2;
4101 Register undefined = t1;
4102 Register entry_key = t2;
4104 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4106 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
4107 __ sra(mask, mask, kSmiTagSize);
4108 __ Subu(mask, mask, Operand(1));
4110 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4112 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4114 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4115 // Compute the masked index: (hash + i + i * i) & mask.
4116 // Capacity is smi 2^n.
4118 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4119 // the hash in a separate instruction. The value hash + i + i * i is right
4120 // shifted in the following and instruction.
4121 DCHECK(NameDictionary::GetProbeOffset(i) <
4122 1 << (32 - Name::kHashFieldOffset));
4123 __ Addu(index, hash, Operand(
4124 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4126 __ mov(index, hash);
4128 __ srl(index, index, Name::kHashShift);
4129 __ And(index, mask, index);
4131 // Scale the index by multiplying by the entry size.
4132 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4135 __ sll(index, index, 1);
4136 __ Addu(index, index, at);
4139 STATIC_ASSERT(kSmiTagSize == 1);
4140 __ sll(index, index, 2);
4141 __ Addu(index, index, dictionary);
4142 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
4144 // Having undefined at this place means the name is not contained.
4145 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4147 // Stop if found the property.
4148 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4150 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4151 // Check if the entry name is not a unique name.
4152 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4154 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4155 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4159 __ bind(&maybe_in_dictionary);
4160 // If we are doing negative lookup then probing failure should be
4161 // treated as a lookup success. For positive lookup probing failure
4162 // should be treated as lookup failure.
4163 if (mode() == POSITIVE_LOOKUP) {
4164 __ Ret(USE_DELAY_SLOT);
4165 __ mov(result, zero_reg);
4168 __ bind(&in_dictionary);
4169 __ Ret(USE_DELAY_SLOT);
4172 __ bind(¬_in_dictionary);
4173 __ Ret(USE_DELAY_SLOT);
4174 __ mov(result, zero_reg);
4178 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4180 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4182 // Hydrogen code stubs need stub2 at snapshot time.
4183 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4188 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4189 // the value has just been written into the object, now this stub makes sure
4190 // we keep the GC informed. The word in the object where the value has been
4191 // written is in the address register.
4192 void RecordWriteStub::Generate(MacroAssembler* masm) {
4193 Label skip_to_incremental_noncompacting;
4194 Label skip_to_incremental_compacting;
4196 // The first two branch+nop instructions are generated with labels so as to
4197 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4198 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4199 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4200 // incremental heap marking.
4201 // See RecordWriteStub::Patch for details.
4202 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4204 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4207 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4208 __ RememberedSetHelper(object(),
4211 save_fp_regs_mode(),
4212 MacroAssembler::kReturnAtEnd);
4216 __ bind(&skip_to_incremental_noncompacting);
4217 GenerateIncremental(masm, INCREMENTAL);
4219 __ bind(&skip_to_incremental_compacting);
4220 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4222 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4223 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4225 PatchBranchIntoNop(masm, 0);
4226 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4230 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4233 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4234 Label dont_need_remembered_set;
4236 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4237 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4239 &dont_need_remembered_set);
4241 __ CheckPageFlag(regs_.object(),
4243 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4245 &dont_need_remembered_set);
4247 // First notify the incremental marker if necessary, then update the
4249 CheckNeedsToInformIncrementalMarker(
4250 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4251 InformIncrementalMarker(masm);
4252 regs_.Restore(masm);
4253 __ RememberedSetHelper(object(),
4256 save_fp_regs_mode(),
4257 MacroAssembler::kReturnAtEnd);
4259 __ bind(&dont_need_remembered_set);
4262 CheckNeedsToInformIncrementalMarker(
4263 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4264 InformIncrementalMarker(masm);
4265 regs_.Restore(masm);
4270 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4271 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4272 int argument_count = 3;
4273 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4275 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4276 DCHECK(!address.is(regs_.object()));
4277 DCHECK(!address.is(a0));
4278 __ Move(address, regs_.address());
4279 __ Move(a0, regs_.object());
4280 __ Move(a1, address);
4281 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4283 AllowExternalCallThatCantCauseGC scope(masm);
4285 ExternalReference::incremental_marking_record_write_function(isolate()),
4287 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4291 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4292 MacroAssembler* masm,
4293 OnNoNeedToInformIncrementalMarker on_no_need,
4296 Label need_incremental;
4297 Label need_incremental_pop_scratch;
4299 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4300 __ lw(regs_.scratch1(),
4301 MemOperand(regs_.scratch0(),
4302 MemoryChunk::kWriteBarrierCounterOffset));
4303 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4304 __ sw(regs_.scratch1(),
4305 MemOperand(regs_.scratch0(),
4306 MemoryChunk::kWriteBarrierCounterOffset));
4307 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4309 // Let's look at the color of the object: If it is not black we don't have
4310 // to inform the incremental marker.
4311 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4313 regs_.Restore(masm);
4314 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4315 __ RememberedSetHelper(object(),
4318 save_fp_regs_mode(),
4319 MacroAssembler::kReturnAtEnd);
4326 // Get the value from the slot.
4327 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4329 if (mode == INCREMENTAL_COMPACTION) {
4330 Label ensure_not_white;
4332 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4333 regs_.scratch1(), // Scratch.
4334 MemoryChunk::kEvacuationCandidateMask,
4338 __ CheckPageFlag(regs_.object(),
4339 regs_.scratch1(), // Scratch.
4340 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4344 __ bind(&ensure_not_white);
4347 // We need extra registers for this, so we push the object and the address
4348 // register temporarily.
4349 __ Push(regs_.object(), regs_.address());
4350 __ EnsureNotWhite(regs_.scratch0(), // The value.
4351 regs_.scratch1(), // Scratch.
4352 regs_.object(), // Scratch.
4353 regs_.address(), // Scratch.
4354 &need_incremental_pop_scratch);
4355 __ Pop(regs_.object(), regs_.address());
4357 regs_.Restore(masm);
4358 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4359 __ RememberedSetHelper(object(),
4362 save_fp_regs_mode(),
4363 MacroAssembler::kReturnAtEnd);
4368 __ bind(&need_incremental_pop_scratch);
4369 __ Pop(regs_.object(), regs_.address());
4371 __ bind(&need_incremental);
4373 // Fall through when we need to inform the incremental marker.
4377 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4378 // ----------- S t a t e -------------
4379 // -- a0 : element value to store
4380 // -- a3 : element index as smi
4381 // -- sp[0] : array literal index in function as smi
4382 // -- sp[4] : array literal
4383 // clobbers a1, a2, t0
4384 // -----------------------------------
4387 Label double_elements;
4389 Label slow_elements;
4390 Label fast_elements;
4392 // Get array literal index, array literal and its map.
4393 __ lw(t0, MemOperand(sp, 0 * kPointerSize));
4394 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
4395 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4397 __ CheckFastElements(a2, t1, &double_elements);
4398 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4399 __ JumpIfSmi(a0, &smi_element);
4400 __ CheckFastSmiElements(a2, t1, &fast_elements);
4402 // Store into the array literal requires a elements transition. Call into
4404 __ bind(&slow_elements);
4406 __ Push(a1, a3, a0);
4407 __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4408 __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset));
4410 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4412 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4413 __ bind(&fast_elements);
4414 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4415 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4416 __ Addu(t2, t1, t2);
4417 __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4418 __ sw(a0, MemOperand(t2, 0));
4419 // Update the write barrier for the array store.
4420 __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4421 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4422 __ Ret(USE_DELAY_SLOT);
4425 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4426 // and value is Smi.
4427 __ bind(&smi_element);
4428 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4429 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4430 __ Addu(t2, t1, t2);
4431 __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize));
4432 __ Ret(USE_DELAY_SLOT);
4435 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4436 __ bind(&double_elements);
4437 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4438 __ StoreNumberToDoubleElements(a0, a3, t1, t3, t5, a2, &slow_elements);
4439 __ Ret(USE_DELAY_SLOT);
4444 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4445 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4446 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4447 int parameter_count_offset =
4448 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4449 __ lw(a1, MemOperand(fp, parameter_count_offset));
4450 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4451 __ Addu(a1, a1, Operand(1));
4453 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4454 __ sll(a1, a1, kPointerSizeLog2);
4455 __ Ret(USE_DELAY_SLOT);
4456 __ Addu(sp, sp, a1);
4460 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4461 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4462 LoadICStub stub(isolate(), state());
4463 stub.GenerateForTrampoline(masm);
4467 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4468 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4469 KeyedLoadICStub stub(isolate(), state());
4470 stub.GenerateForTrampoline(masm);
4474 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4475 EmitLoadTypeFeedbackVector(masm, a2);
4476 CallICStub stub(isolate(), state());
4477 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4481 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4484 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4485 GenerateImpl(masm, true);
4489 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4490 Register receiver_map, Register scratch1,
4491 Register scratch2, bool is_polymorphic,
4493 // feedback initially contains the feedback array
4494 Label next_loop, prepare_next;
4495 Label start_polymorphic;
4497 Register cached_map = scratch1;
4500 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4501 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4502 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4503 // found, now call handler.
4504 Register handler = feedback;
4505 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4506 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4510 Register length = scratch2;
4511 __ bind(&start_polymorphic);
4512 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4513 if (!is_polymorphic) {
4514 // If the IC could be monomorphic we have to make sure we don't go past the
4515 // end of the feedback array.
4516 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4519 Register too_far = length;
4520 Register pointer_reg = feedback;
4522 // +-----+------+------+-----+-----+ ... ----+
4523 // | map | len | wm0 | h0 | wm1 | hN |
4524 // +-----+------+------+-----+-----+ ... ----+
4528 // pointer_reg too_far
4529 // aka feedback scratch2
4530 // also need receiver_map
4531 // use cached_map (scratch1) to look in the weak map values.
4532 __ sll(at, length, kPointerSizeLog2 - kSmiTagSize);
4533 __ Addu(too_far, feedback, Operand(at));
4534 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4535 __ Addu(pointer_reg, feedback,
4536 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4538 __ bind(&next_loop);
4539 __ lw(cached_map, MemOperand(pointer_reg));
4540 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4541 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4542 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
4543 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4546 __ bind(&prepare_next);
4547 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4548 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4550 // We exhausted our array of map handler pairs.
4555 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4556 Register receiver_map, Register feedback,
4557 Register vector, Register slot,
4558 Register scratch, Label* compare_map,
4559 Label* load_smi_map, Label* try_array) {
4560 __ JumpIfSmi(receiver, load_smi_map);
4561 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4562 __ bind(compare_map);
4563 Register cached_map = scratch;
4564 // Move the weak map into the weak_cell register.
4565 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4566 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4567 Register handler = feedback;
4569 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4570 __ Addu(handler, vector, Operand(at));
4572 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4573 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4578 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4579 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4580 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4581 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4582 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4583 Register feedback = t0;
4584 Register receiver_map = t1;
4585 Register scratch1 = t4;
4587 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4588 __ Addu(feedback, vector, Operand(at));
4589 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4591 // Try to quickly handle the monomorphic case without knowing for sure
4592 // if we have a weak cell in feedback. We do know it's safe to look
4593 // at WeakCell::kValueOffset.
4594 Label try_array, load_smi_map, compare_map;
4595 Label not_array, miss;
4596 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4597 scratch1, &compare_map, &load_smi_map, &try_array);
4599 // Is it a fixed array?
4600 __ bind(&try_array);
4601 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4602 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4603 __ Branch(¬_array, ne, at, Operand(scratch1));
4604 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
4606 __ bind(¬_array);
4607 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4608 __ Branch(&miss, ne, at, Operand(feedback));
4609 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4610 Code::ComputeHandlerFlags(Code::LOAD_IC));
4611 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4612 receiver, name, feedback,
4613 receiver_map, scratch1, t5);
4616 LoadIC::GenerateMiss(masm);
4618 __ bind(&load_smi_map);
4619 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4620 __ jmp(&compare_map);
4624 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4625 GenerateImpl(masm, false);
4629 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4630 GenerateImpl(masm, true);
4634 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4635 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4636 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4637 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4638 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4639 Register feedback = t0;
4640 Register receiver_map = t1;
4641 Register scratch1 = t4;
4643 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4644 __ Addu(feedback, vector, Operand(at));
4645 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4647 // Try to quickly handle the monomorphic case without knowing for sure
4648 // if we have a weak cell in feedback. We do know it's safe to look
4649 // at WeakCell::kValueOffset.
4650 Label try_array, load_smi_map, compare_map;
4651 Label not_array, miss;
4652 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4653 scratch1, &compare_map, &load_smi_map, &try_array);
4655 __ bind(&try_array);
4656 // Is it a fixed array?
4657 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4658 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4659 __ Branch(¬_array, ne, at, Operand(scratch1));
4660 // We have a polymorphic element handler.
4661 __ JumpIfNotSmi(key, &miss);
4663 Label polymorphic, try_poly_name;
4664 __ bind(&polymorphic);
4665 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
4667 __ bind(¬_array);
4669 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4670 __ Branch(&try_poly_name, ne, at, Operand(feedback));
4671 Handle<Code> megamorphic_stub =
4672 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4673 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4675 __ bind(&try_poly_name);
4676 // We might have a name in feedback, and a fixed array in the next slot.
4677 __ Branch(&miss, ne, key, Operand(feedback));
4678 // If the name comparison succeeded, we know we have a fixed array with
4679 // at least one map/handler pair.
4680 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4681 __ Addu(feedback, vector, Operand(at));
4683 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4684 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, false, &miss);
4687 KeyedLoadIC::GenerateMiss(masm);
4689 __ bind(&load_smi_map);
4690 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4691 __ jmp(&compare_map);
4695 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4696 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4697 VectorStoreICStub stub(isolate(), state());
4698 stub.GenerateForTrampoline(masm);
4702 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4703 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4704 VectorKeyedStoreICStub stub(isolate(), state());
4705 stub.GenerateForTrampoline(masm);
4709 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4710 GenerateImpl(masm, false);
4714 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4715 GenerateImpl(masm, true);
4719 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4720 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4721 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4722 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4723 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
4724 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4725 Register feedback = t1;
4726 Register receiver_map = t2;
4727 Register scratch1 = t5;
4729 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4730 __ Addu(feedback, vector, Operand(scratch1));
4731 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4733 // Try to quickly handle the monomorphic case without knowing for sure
4734 // if we have a weak cell in feedback. We do know it's safe to look
4735 // at WeakCell::kValueOffset.
4736 Label try_array, load_smi_map, compare_map;
4737 Label not_array, miss;
4738 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4739 scratch1, &compare_map, &load_smi_map, &try_array);
4741 // Is it a fixed array?
4742 __ bind(&try_array);
4743 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4744 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4745 __ Branch(¬_array, ne, scratch1, Operand(at));
4747 Register scratch2 = t4;
4748 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4751 __ bind(¬_array);
4752 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4753 __ Branch(&miss, ne, feedback, Operand(at));
4754 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4755 Code::ComputeHandlerFlags(Code::STORE_IC));
4756 masm->isolate()->stub_cache()->GenerateProbe(
4757 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4758 scratch1, scratch2);
4761 StoreIC::GenerateMiss(masm);
4763 __ bind(&load_smi_map);
4764 __ Branch(USE_DELAY_SLOT, &compare_map);
4765 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4769 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4770 GenerateImpl(masm, false);
4774 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4775 GenerateImpl(masm, true);
4779 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4780 Register receiver_map, Register scratch1,
4781 Register scratch2, Label* miss) {
4782 // feedback initially contains the feedback array
4783 Label next_loop, prepare_next;
4784 Label start_polymorphic;
4785 Label transition_call;
4787 Register cached_map = scratch1;
4788 Register too_far = scratch2;
4789 Register pointer_reg = feedback;
4790 __ lw(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4792 // +-----+------+------+-----+-----+-----+ ... ----+
4793 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4794 // +-----+------+------+-----+-----+ ----+ ... ----+
4798 // pointer_reg too_far
4799 // aka feedback scratch2
4800 // also need receiver_map
4801 // use cached_map (scratch1) to look in the weak map values.
4802 __ sll(scratch1, too_far, kPointerSizeLog2 - kSmiTagSize);
4803 __ Addu(too_far, feedback, Operand(scratch1));
4804 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4805 __ Addu(pointer_reg, feedback,
4806 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4808 __ bind(&next_loop);
4809 __ lw(cached_map, MemOperand(pointer_reg));
4810 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4811 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4812 // Is it a transitioning store?
4813 __ lw(too_far, MemOperand(pointer_reg, kPointerSize));
4814 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4815 __ Branch(&transition_call, ne, too_far, Operand(at));
4816 __ lw(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4817 __ Addu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4820 __ bind(&transition_call);
4821 __ lw(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4822 __ JumpIfSmi(too_far, miss);
4824 __ lw(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4826 // Load the map into the correct register.
4827 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4828 __ mov(feedback, too_far);
4830 __ Addu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4833 __ bind(&prepare_next);
4834 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4835 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4837 // We exhausted our array of map handler pairs.
4842 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4843 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4844 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4845 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4846 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
4847 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4848 Register feedback = t1;
4849 Register receiver_map = t2;
4850 Register scratch1 = t5;
4852 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4853 __ Addu(feedback, vector, Operand(scratch1));
4854 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4856 // Try to quickly handle the monomorphic case without knowing for sure
4857 // if we have a weak cell in feedback. We do know it's safe to look
4858 // at WeakCell::kValueOffset.
4859 Label try_array, load_smi_map, compare_map;
4860 Label not_array, miss;
4861 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4862 scratch1, &compare_map, &load_smi_map, &try_array);
4864 __ bind(&try_array);
4865 // Is it a fixed array?
4866 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4867 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4868 __ Branch(¬_array, ne, scratch1, Operand(at));
4870 // We have a polymorphic element handler.
4871 Label polymorphic, try_poly_name;
4872 __ bind(&polymorphic);
4874 Register scratch2 = t4;
4876 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4879 __ bind(¬_array);
4881 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4882 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4883 Handle<Code> megamorphic_stub =
4884 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4885 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4887 __ bind(&try_poly_name);
4888 // We might have a name in feedback, and a fixed array in the next slot.
4889 __ Branch(&miss, ne, key, Operand(feedback));
4890 // If the name comparison succeeded, we know we have a fixed array with
4891 // at least one map/handler pair.
4892 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4893 __ Addu(feedback, vector, Operand(scratch1));
4895 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4896 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4900 KeyedStoreIC::GenerateMiss(masm);
4902 __ bind(&load_smi_map);
4903 __ Branch(USE_DELAY_SLOT, &compare_map);
4904 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4908 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4909 if (masm->isolate()->function_entry_hook() != NULL) {
4910 ProfileEntryHookStub stub(masm->isolate());
4918 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4919 // The entry hook is a "push ra" instruction, followed by a call.
4920 // Note: on MIPS "push" is 2 instruction
4921 const int32_t kReturnAddressDistanceFromFunctionStart =
4922 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4924 // This should contain all kJSCallerSaved registers.
4925 const RegList kSavedRegs =
4926 kJSCallerSaved | // Caller saved registers.
4927 s5.bit(); // Saved stack pointer.
4929 // We also save ra, so the count here is one higher than the mask indicates.
4930 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4932 // Save all caller-save registers as this may be called from anywhere.
4933 __ MultiPush(kSavedRegs | ra.bit());
4935 // Compute the function's address for the first argument.
4936 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4938 // The caller's return address is above the saved temporaries.
4939 // Grab that for the second argument to the hook.
4940 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4942 // Align the stack if necessary.
4943 int frame_alignment = masm->ActivationFrameAlignment();
4944 if (frame_alignment > kPointerSize) {
4946 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4947 __ And(sp, sp, Operand(-frame_alignment));
4949 __ Subu(sp, sp, kCArgsSlotsSize);
4950 #if defined(V8_HOST_ARCH_MIPS)
4951 int32_t entry_hook =
4952 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4953 __ li(t9, Operand(entry_hook));
4955 // Under the simulator we need to indirect the entry hook through a
4956 // trampoline function at a known address.
4957 // It additionally takes an isolate as a third parameter.
4958 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4960 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4961 __ li(t9, Operand(ExternalReference(&dispatcher,
4962 ExternalReference::BUILTIN_CALL,
4965 // Call C function through t9 to conform ABI for PIC.
4968 // Restore the stack pointer if needed.
4969 if (frame_alignment > kPointerSize) {
4972 __ Addu(sp, sp, kCArgsSlotsSize);
4975 // Also pop ra to get Ret(0).
4976 __ MultiPop(kSavedRegs | ra.bit());
4982 static void CreateArrayDispatch(MacroAssembler* masm,
4983 AllocationSiteOverrideMode mode) {
4984 if (mode == DISABLE_ALLOCATION_SITES) {
4985 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4986 __ TailCallStub(&stub);
4987 } else if (mode == DONT_OVERRIDE) {
4988 int last_index = GetSequenceIndexFromFastElementsKind(
4989 TERMINAL_FAST_ELEMENTS_KIND);
4990 for (int i = 0; i <= last_index; ++i) {
4991 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4992 T stub(masm->isolate(), kind);
4993 __ TailCallStub(&stub, eq, a3, Operand(kind));
4996 // If we reached this point there is a problem.
4997 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5004 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5005 AllocationSiteOverrideMode mode) {
5006 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5007 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5008 // a0 - number of arguments
5009 // a1 - constructor?
5010 // sp[0] - last argument
5011 Label normal_sequence;
5012 if (mode == DONT_OVERRIDE) {
5013 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5014 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5015 STATIC_ASSERT(FAST_ELEMENTS == 2);
5016 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5017 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5018 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5020 // is the low bit set? If so, we are holey and that is good.
5021 __ And(at, a3, Operand(1));
5022 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5025 // look at the first argument
5026 __ lw(t1, MemOperand(sp, 0));
5027 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
5029 if (mode == DISABLE_ALLOCATION_SITES) {
5030 ElementsKind initial = GetInitialFastElementsKind();
5031 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5033 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5035 DISABLE_ALLOCATION_SITES);
5036 __ TailCallStub(&stub_holey);
5038 __ bind(&normal_sequence);
5039 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5041 DISABLE_ALLOCATION_SITES);
5042 __ TailCallStub(&stub);
5043 } else if (mode == DONT_OVERRIDE) {
5044 // We are going to create a holey array, but our kind is non-holey.
5045 // Fix kind and retry (only if we have an allocation site in the slot).
5046 __ Addu(a3, a3, Operand(1));
5048 if (FLAG_debug_code) {
5049 __ lw(t1, FieldMemOperand(a2, 0));
5050 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5051 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
5054 // Save the resulting elements kind in type info. We can't just store a3
5055 // in the AllocationSite::transition_info field because elements kind is
5056 // restricted to a portion of the field...upper bits need to be left alone.
5057 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5058 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5059 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5060 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5063 __ bind(&normal_sequence);
5064 int last_index = GetSequenceIndexFromFastElementsKind(
5065 TERMINAL_FAST_ELEMENTS_KIND);
5066 for (int i = 0; i <= last_index; ++i) {
5067 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5068 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5069 __ TailCallStub(&stub, eq, a3, Operand(kind));
5072 // If we reached this point there is a problem.
5073 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5081 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5082 int to_index = GetSequenceIndexFromFastElementsKind(
5083 TERMINAL_FAST_ELEMENTS_KIND);
5084 for (int i = 0; i <= to_index; ++i) {
5085 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5086 T stub(isolate, kind);
5088 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5089 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5096 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5097 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5099 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5101 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5106 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5108 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5109 for (int i = 0; i < 2; i++) {
5110 // For internal arrays we only need a few things.
5111 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5113 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5115 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5121 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5122 MacroAssembler* masm,
5123 AllocationSiteOverrideMode mode) {
5124 if (argument_count() == ANY) {
5125 Label not_zero_case, not_one_case;
5127 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5128 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5130 __ bind(¬_zero_case);
5131 __ Branch(¬_one_case, gt, a0, Operand(1));
5132 CreateArrayDispatchOneArgument(masm, mode);
5134 __ bind(¬_one_case);
5135 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5136 } else if (argument_count() == NONE) {
5137 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5138 } else if (argument_count() == ONE) {
5139 CreateArrayDispatchOneArgument(masm, mode);
5140 } else if (argument_count() == MORE_THAN_ONE) {
5141 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5148 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5149 // ----------- S t a t e -------------
5150 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5151 // -- a1 : constructor
5152 // -- a2 : AllocationSite or undefined
5153 // -- a3 : Original constructor
5154 // -- sp[0] : last argument
5155 // -----------------------------------
5157 if (FLAG_debug_code) {
5158 // The array construct code is only set for the global and natives
5159 // builtin Array functions which always have maps.
5161 // Initial map for the builtin Array function should be a map.
5162 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5163 // Will both indicate a NULL and a Smi.
5165 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5166 at, Operand(zero_reg));
5167 __ GetObjectType(t0, t0, t1);
5168 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5169 t1, Operand(MAP_TYPE));
5171 // We should either have undefined in a2 or a valid AllocationSite
5172 __ AssertUndefinedOrAllocationSite(a2, t0);
5176 __ Branch(&subclassing, ne, a1, Operand(a3));
5179 // Get the elements kind and case on that.
5180 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5181 __ Branch(&no_info, eq, a2, Operand(at));
5183 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5185 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5186 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5187 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5190 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5193 __ bind(&subclassing);
5198 switch (argument_count()) {
5201 __ li(at, Operand(2));
5202 __ addu(a0, a0, at);
5205 __ li(a0, Operand(2));
5208 __ li(a0, Operand(3));
5212 __ JumpToExternalReference(
5213 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5217 void InternalArrayConstructorStub::GenerateCase(
5218 MacroAssembler* masm, ElementsKind kind) {
5220 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5221 __ TailCallStub(&stub0, lo, a0, Operand(1));
5223 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5224 __ TailCallStub(&stubN, hi, a0, Operand(1));
5226 if (IsFastPackedElementsKind(kind)) {
5227 // We might need to create a holey array
5228 // look at the first argument.
5229 __ lw(at, MemOperand(sp, 0));
5231 InternalArraySingleArgumentConstructorStub
5232 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5233 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5236 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5237 __ TailCallStub(&stub1);
5241 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5242 // ----------- S t a t e -------------
5244 // -- a1 : constructor
5245 // -- sp[0] : return address
5246 // -- sp[4] : last argument
5247 // -----------------------------------
5249 if (FLAG_debug_code) {
5250 // The array construct code is only set for the global and natives
5251 // builtin Array functions which always have maps.
5253 // Initial map for the builtin Array function should be a map.
5254 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5255 // Will both indicate a NULL and a Smi.
5257 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5258 at, Operand(zero_reg));
5259 __ GetObjectType(a3, a3, t0);
5260 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5261 t0, Operand(MAP_TYPE));
5264 // Figure out the right elements kind.
5265 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5267 // Load the map's "bit field 2" into a3. We only need the first byte,
5268 // but the following bit field extraction takes care of that anyway.
5269 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5270 // Retrieve elements_kind from bit field 2.
5271 __ DecodeField<Map::ElementsKindBits>(a3);
5273 if (FLAG_debug_code) {
5275 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5277 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5278 a3, Operand(FAST_HOLEY_ELEMENTS));
5282 Label fast_elements_case;
5283 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5284 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5286 __ bind(&fast_elements_case);
5287 GenerateCase(masm, FAST_ELEMENTS);
5291 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5292 Register context_reg = cp;
5293 Register slot_reg = a2;
5294 Register result_reg = v0;
5297 // Go up context chain to the script context.
5298 for (int i = 0; i < depth(); ++i) {
5299 __ lw(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5300 context_reg = result_reg;
5303 // Load the PropertyCell value at the specified slot.
5304 __ sll(at, slot_reg, kPointerSizeLog2);
5305 __ Addu(at, at, Operand(context_reg));
5306 __ lw(result_reg, ContextOperand(at, 0));
5307 __ lw(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5309 // Check that value is not the_hole.
5310 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5311 __ Branch(&slow_case, eq, result_reg, Operand(at));
5314 // Fallback to the runtime.
5315 __ bind(&slow_case);
5316 __ SmiTag(slot_reg);
5318 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5322 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5323 Register context_reg = cp;
5324 Register slot_reg = a2;
5325 Register value_reg = a0;
5326 Register cell_reg = t0;
5327 Register cell_value_reg = t1;
5328 Register cell_details_reg = t2;
5329 Label fast_heapobject_case, fast_smi_case, slow_case;
5331 if (FLAG_debug_code) {
5332 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5333 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5336 // Go up context chain to the script context.
5337 for (int i = 0; i < depth(); ++i) {
5338 __ lw(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5339 context_reg = cell_reg;
5342 // Load the PropertyCell at the specified slot.
5343 __ sll(at, slot_reg, kPointerSizeLog2);
5344 __ Addu(at, at, Operand(context_reg));
5345 __ lw(cell_reg, ContextOperand(at, 0));
5347 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5348 __ lw(cell_details_reg,
5349 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5350 __ SmiUntag(cell_details_reg);
5351 __ And(cell_details_reg, cell_details_reg,
5352 PropertyDetails::PropertyCellTypeField::kMask |
5353 PropertyDetails::KindField::kMask |
5354 PropertyDetails::kAttributesReadOnlyMask);
5356 // Check if PropertyCell holds mutable data.
5357 Label not_mutable_data;
5358 __ Branch(¬_mutable_data, ne, cell_details_reg,
5359 Operand(PropertyDetails::PropertyCellTypeField::encode(
5360 PropertyCellType::kMutable) |
5361 PropertyDetails::KindField::encode(kData)));
5362 __ JumpIfSmi(value_reg, &fast_smi_case);
5363 __ bind(&fast_heapobject_case);
5364 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5365 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5366 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5367 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5368 // RecordWriteField clobbers the value register, so we need to reload.
5369 __ Ret(USE_DELAY_SLOT);
5370 __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5371 __ bind(¬_mutable_data);
5373 // Check if PropertyCell value matches the new value (relevant for Constant,
5374 // ConstantType and Undefined cells).
5375 Label not_same_value;
5376 __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5377 __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg));
5378 // Make sure the PropertyCell is not marked READ_ONLY.
5379 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5380 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5381 if (FLAG_debug_code) {
5383 // This can only be true for Constant, ConstantType and Undefined cells,
5384 // because we never store the_hole via this stub.
5385 __ Branch(&done, eq, cell_details_reg,
5386 Operand(PropertyDetails::PropertyCellTypeField::encode(
5387 PropertyCellType::kConstant) |
5388 PropertyDetails::KindField::encode(kData)));
5389 __ Branch(&done, eq, cell_details_reg,
5390 Operand(PropertyDetails::PropertyCellTypeField::encode(
5391 PropertyCellType::kConstantType) |
5392 PropertyDetails::KindField::encode(kData)));
5393 __ Check(eq, kUnexpectedValue, cell_details_reg,
5394 Operand(PropertyDetails::PropertyCellTypeField::encode(
5395 PropertyCellType::kUndefined) |
5396 PropertyDetails::KindField::encode(kData)));
5400 __ bind(¬_same_value);
5402 // Check if PropertyCell contains data with constant type (and is not
5404 __ Branch(&slow_case, ne, cell_details_reg,
5405 Operand(PropertyDetails::PropertyCellTypeField::encode(
5406 PropertyCellType::kConstantType) |
5407 PropertyDetails::KindField::encode(kData)));
5409 // Now either both old and new values must be SMIs or both must be heap
5410 // objects with same map.
5411 Label value_is_heap_object;
5412 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5413 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5414 // Old and new values are SMIs, no need for a write barrier here.
5415 __ bind(&fast_smi_case);
5416 __ Ret(USE_DELAY_SLOT);
5417 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5418 __ bind(&value_is_heap_object);
5419 __ JumpIfSmi(cell_value_reg, &slow_case);
5420 Register cell_value_map_reg = cell_value_reg;
5421 __ lw(cell_value_map_reg,
5422 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5423 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5424 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5426 // Fallback to the runtime.
5427 __ bind(&slow_case);
5428 __ SmiTag(slot_reg);
5429 __ Push(slot_reg, value_reg);
5430 __ TailCallRuntime(is_strict(language_mode())
5431 ? Runtime::kStoreGlobalViaContext_Strict
5432 : Runtime::kStoreGlobalViaContext_Sloppy,
5437 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5438 return ref0.address() - ref1.address();
5442 // Calls an API function. Allocates HandleScope, extracts returned value
5443 // from handle and propagates exceptions. Restores context. stack_space
5444 // - space to be unwound on exit (includes the call JS arguments space and
5445 // the additional space allocated for the fast call).
5446 static void CallApiFunctionAndReturn(
5447 MacroAssembler* masm, Register function_address,
5448 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5449 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5450 Isolate* isolate = masm->isolate();
5451 ExternalReference next_address =
5452 ExternalReference::handle_scope_next_address(isolate);
5453 const int kNextOffset = 0;
5454 const int kLimitOffset = AddressOffset(
5455 ExternalReference::handle_scope_limit_address(isolate), next_address);
5456 const int kLevelOffset = AddressOffset(
5457 ExternalReference::handle_scope_level_address(isolate), next_address);
5459 DCHECK(function_address.is(a1) || function_address.is(a2));
5461 Label profiler_disabled;
5462 Label end_profiler_check;
5463 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5464 __ lb(t9, MemOperand(t9, 0));
5465 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5467 // Additional parameter is the address of the actual callback.
5468 __ li(t9, Operand(thunk_ref));
5469 __ jmp(&end_profiler_check);
5471 __ bind(&profiler_disabled);
5472 __ mov(t9, function_address);
5473 __ bind(&end_profiler_check);
5475 // Allocate HandleScope in callee-save registers.
5476 __ li(s3, Operand(next_address));
5477 __ lw(s0, MemOperand(s3, kNextOffset));
5478 __ lw(s1, MemOperand(s3, kLimitOffset));
5479 __ lw(s2, MemOperand(s3, kLevelOffset));
5480 __ Addu(s2, s2, Operand(1));
5481 __ sw(s2, MemOperand(s3, kLevelOffset));
5483 if (FLAG_log_timer_events) {
5484 FrameScope frame(masm, StackFrame::MANUAL);
5485 __ PushSafepointRegisters();
5486 __ PrepareCallCFunction(1, a0);
5487 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5488 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5490 __ PopSafepointRegisters();
5493 // Native call returns to the DirectCEntry stub which redirects to the
5494 // return address pushed on stack (could have moved after GC).
5495 // DirectCEntry stub itself is generated early and never moves.
5496 DirectCEntryStub stub(isolate);
5497 stub.GenerateCall(masm, t9);
5499 if (FLAG_log_timer_events) {
5500 FrameScope frame(masm, StackFrame::MANUAL);
5501 __ PushSafepointRegisters();
5502 __ PrepareCallCFunction(1, a0);
5503 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5504 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5506 __ PopSafepointRegisters();
5509 Label promote_scheduled_exception;
5510 Label delete_allocated_handles;
5511 Label leave_exit_frame;
5512 Label return_value_loaded;
5514 // Load value from ReturnValue.
5515 __ lw(v0, return_value_operand);
5516 __ bind(&return_value_loaded);
5518 // No more valid handles (the result handle was the last one). Restore
5519 // previous handle scope.
5520 __ sw(s0, MemOperand(s3, kNextOffset));
5521 if (__ emit_debug_code()) {
5522 __ lw(a1, MemOperand(s3, kLevelOffset));
5523 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5525 __ Subu(s2, s2, Operand(1));
5526 __ sw(s2, MemOperand(s3, kLevelOffset));
5527 __ lw(at, MemOperand(s3, kLimitOffset));
5528 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5530 // Leave the API exit frame.
5531 __ bind(&leave_exit_frame);
5533 bool restore_context = context_restore_operand != NULL;
5534 if (restore_context) {
5535 __ lw(cp, *context_restore_operand);
5537 if (stack_space_offset != kInvalidStackOffset) {
5538 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5539 // so this must be accounted for.
5540 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5542 __ li(s0, Operand(stack_space));
5544 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5545 stack_space_offset != kInvalidStackOffset);
5547 // Check if the function scheduled an exception.
5548 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5549 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5550 __ lw(t1, MemOperand(at));
5551 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5555 // Re-throw by promoting a scheduled exception.
5556 __ bind(&promote_scheduled_exception);
5557 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5559 // HandleScope limit has changed. Delete allocated extensions.
5560 __ bind(&delete_allocated_handles);
5561 __ sw(s1, MemOperand(s3, kLimitOffset));
5564 __ PrepareCallCFunction(1, s1);
5565 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5566 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5569 __ jmp(&leave_exit_frame);
5573 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5574 const ParameterCount& argc,
5575 bool return_first_arg,
5576 bool call_data_undefined) {
5577 // ----------- S t a t e -------------
5579 // -- t0 : call_data
5581 // -- a1 : api_function_address
5582 // -- a3 : number of arguments if argc is a register
5585 // -- sp[0] : last argument
5587 // -- sp[(argc - 1)* 4] : first argument
5588 // -- sp[argc * 4] : receiver
5589 // -----------------------------------
5591 Register callee = a0;
5592 Register call_data = t0;
5593 Register holder = a2;
5594 Register api_function_address = a1;
5595 Register context = cp;
5597 typedef FunctionCallbackArguments FCA;
5599 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5600 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5601 STATIC_ASSERT(FCA::kDataIndex == 4);
5602 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5603 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5604 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5605 STATIC_ASSERT(FCA::kHolderIndex == 0);
5606 STATIC_ASSERT(FCA::kArgsLength == 7);
5608 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5610 // Save context, callee and call data.
5611 __ Push(context, callee, call_data);
5612 // Load context from callee.
5613 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5615 Register scratch = call_data;
5616 if (!call_data_undefined) {
5617 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5619 // Push return value and default return value.
5620 __ Push(scratch, scratch);
5621 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5622 // Push isolate and holder.
5623 __ Push(scratch, holder);
5625 // Prepare arguments.
5626 __ mov(scratch, sp);
5628 // Allocate the v8::Arguments structure in the arguments' space since
5629 // it's not controlled by GC.
5630 const int kApiStackSpace = 4;
5632 FrameScope frame_scope(masm, StackFrame::MANUAL);
5633 __ EnterExitFrame(false, kApiStackSpace);
5635 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5636 // a0 = FunctionCallbackInfo&
5637 // Arguments is after the return address.
5638 __ Addu(a0, sp, Operand(1 * kPointerSize));
5639 // FunctionCallbackInfo::implicit_args_
5640 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
5641 if (argc.is_immediate()) {
5642 // FunctionCallbackInfo::values_
5643 __ Addu(at, scratch,
5644 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5645 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5646 // FunctionCallbackInfo::length_ = argc
5647 __ li(at, Operand(argc.immediate()));
5648 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5649 // FunctionCallbackInfo::is_construct_call_ = 0
5650 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
5652 // FunctionCallbackInfo::values_
5653 __ sll(at, argc.reg(), kPointerSizeLog2);
5654 __ Addu(at, at, scratch);
5655 __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5656 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5657 // FunctionCallbackInfo::length_ = argc
5658 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5659 // FunctionCallbackInfo::is_construct_call_
5660 __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5661 __ sll(at, argc.reg(), kPointerSizeLog2);
5662 __ sw(at, MemOperand(a0, 3 * kPointerSize));
5665 ExternalReference thunk_ref =
5666 ExternalReference::invoke_function_callback(masm->isolate());
5668 AllowExternalCallThatCantCauseGC scope(masm);
5669 MemOperand context_restore_operand(
5670 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5671 // Stores return the first js argument.
5672 int return_value_offset = 0;
5673 if (return_first_arg) {
5674 return_value_offset = 2 + FCA::kArgsLength;
5676 return_value_offset = 2 + FCA::kReturnValueOffset;
5678 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5679 int stack_space = 0;
5680 int32_t stack_space_offset = 4 * kPointerSize;
5681 if (argc.is_immediate()) {
5682 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5683 stack_space_offset = kInvalidStackOffset;
5685 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5686 stack_space_offset, return_value_operand,
5687 &context_restore_operand);
5691 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5692 bool call_data_undefined = this->call_data_undefined();
5693 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5694 call_data_undefined);
5698 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5699 bool is_store = this->is_store();
5700 int argc = this->argc();
5701 bool call_data_undefined = this->call_data_undefined();
5702 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5703 call_data_undefined);
5707 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5708 // ----------- S t a t e -------------
5710 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5712 // -- a2 : api_function_address
5713 // -----------------------------------
5715 Register api_function_address = ApiGetterDescriptor::function_address();
5716 DCHECK(api_function_address.is(a2));
5718 __ mov(a0, sp); // a0 = Handle<Name>
5719 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5721 const int kApiStackSpace = 1;
5722 FrameScope frame_scope(masm, StackFrame::MANUAL);
5723 __ EnterExitFrame(false, kApiStackSpace);
5725 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5726 // a1 (internal::Object** args_) as the data.
5727 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
5728 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5730 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5732 ExternalReference thunk_ref =
5733 ExternalReference::invoke_accessor_getter_callback(isolate());
5734 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5735 kStackUnwindSpace, kInvalidStackOffset,
5736 MemOperand(fp, 6 * kPointerSize), NULL);
5742 } // namespace internal
5745 #endif // V8_TARGET_ARCH_MIPS