1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #if V8_TARGET_ARCH_MIPS
7 #include "src/base/bits.h"
8 #include "src/bootstrapper.h"
9 #include "src/code-stubs.h"
10 #include "src/codegen.h"
11 #include "src/ic/handler-compiler.h"
12 #include "src/ic/ic.h"
13 #include "src/ic/stub-cache.h"
14 #include "src/isolate.h"
15 #include "src/mips/code-stubs-mips.h"
16 #include "src/regexp/jsregexp.h"
17 #include "src/regexp/regexp-macro-assembler.h"
18 #include "src/runtime/runtime.h"
24 static void InitializeArrayConstructorDescriptor(
25 Isolate* isolate, CodeStubDescriptor* descriptor,
26 int constant_stack_parameter_count) {
27 Address deopt_handler = Runtime::FunctionForId(
28 Runtime::kArrayConstructor)->entry;
30 if (constant_stack_parameter_count == 0) {
31 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
32 JS_FUNCTION_STUB_MODE);
34 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
35 JS_FUNCTION_STUB_MODE);
40 static void InitializeInternalArrayConstructorDescriptor(
41 Isolate* isolate, CodeStubDescriptor* descriptor,
42 int constant_stack_parameter_count) {
43 Address deopt_handler = Runtime::FunctionForId(
44 Runtime::kInternalArrayConstructor)->entry;
46 if (constant_stack_parameter_count == 0) {
47 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
48 JS_FUNCTION_STUB_MODE);
50 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
51 JS_FUNCTION_STUB_MODE);
56 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
57 CodeStubDescriptor* descriptor) {
58 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
62 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
63 CodeStubDescriptor* descriptor) {
64 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
68 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
69 CodeStubDescriptor* descriptor) {
70 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
74 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
75 CodeStubDescriptor* descriptor) {
76 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
80 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
81 CodeStubDescriptor* descriptor) {
82 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
86 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
87 CodeStubDescriptor* descriptor) {
88 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
92 #define __ ACCESS_MASM(masm)
95 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
96 Condition cc, Strength strength);
97 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
103 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
108 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
109 ExternalReference miss) {
110 // Update the static counter each time a new code stub is generated.
111 isolate()->counters()->code_stubs()->Increment();
113 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
114 int param_count = descriptor.GetRegisterParameterCount();
116 // Call the runtime system in a fresh internal frame.
117 FrameScope scope(masm, StackFrame::INTERNAL);
118 DCHECK(param_count == 0 ||
119 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
120 // Push arguments, adjust sp.
121 __ Subu(sp, sp, Operand(param_count * kPointerSize));
122 for (int i = 0; i < param_count; ++i) {
123 // Store argument to stack.
124 __ sw(descriptor.GetRegisterParameter(i),
125 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
127 __ CallExternalReference(miss, param_count);
134 void DoubleToIStub::Generate(MacroAssembler* masm) {
135 Label out_of_range, only_low, negate, done;
136 Register input_reg = source();
137 Register result_reg = destination();
139 int double_offset = offset();
140 // Account for saved regs if input is sp.
141 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
144 GetRegisterThatIsNotOneOf(input_reg, result_reg);
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
148 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
149 DoubleRegister double_scratch = kLithiumScratchDouble;
151 __ Push(scratch, scratch2, scratch3);
153 if (!skip_fastpath()) {
154 // Load double input.
155 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
157 // Clear cumulative exception flags and save the FCSR.
158 __ cfc1(scratch2, FCSR);
159 __ ctc1(zero_reg, FCSR);
161 // Try a conversion to a signed integer.
162 __ Trunc_w_d(double_scratch, double_scratch);
163 // Move the converted value into the result register.
164 __ mfc1(scratch3, double_scratch);
166 // Retrieve and restore the FCSR.
167 __ cfc1(scratch, FCSR);
168 __ ctc1(scratch2, FCSR);
170 // Check for overflow and NaNs.
173 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
174 | kFCSRInvalidOpFlagMask);
175 // If we had no exceptions then set result_reg and we are done.
177 __ Branch(&error, ne, scratch, Operand(zero_reg));
178 __ Move(result_reg, scratch3);
183 // Load the double value and perform a manual truncation.
184 Register input_high = scratch2;
185 Register input_low = scratch3;
188 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
190 MemOperand(input_reg, double_offset + Register::kExponentOffset));
192 Label normal_exponent, restore_sign;
193 // Extract the biased exponent in result.
196 HeapNumber::kExponentShift,
197 HeapNumber::kExponentBits);
199 // Check for Infinity and NaNs, which should return 0.
200 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
201 __ Movz(result_reg, zero_reg, scratch);
202 __ Branch(&done, eq, scratch, Operand(zero_reg));
204 // Express exponent as delta to (number of mantissa bits + 31).
207 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
209 // If the delta is strictly positive, all bits would be shifted away,
210 // which means that we can return 0.
211 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
212 __ mov(result_reg, zero_reg);
215 __ bind(&normal_exponent);
216 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
218 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
221 Register sign = result_reg;
223 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
225 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
226 // to check for this specific case.
227 Label high_shift_needed, high_shift_done;
228 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
229 __ mov(input_high, zero_reg);
230 __ Branch(&high_shift_done);
231 __ bind(&high_shift_needed);
233 // Set the implicit 1 before the mantissa part in input_high.
236 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
237 // Shift the mantissa bits to the correct position.
238 // We don't need to clear non-mantissa bits as they will be shifted away.
239 // If they weren't, it would mean that the answer is in the 32bit range.
240 __ sllv(input_high, input_high, scratch);
242 __ bind(&high_shift_done);
244 // Replace the shifted bits with bits from the lower mantissa word.
245 Label pos_shift, shift_done;
247 __ subu(scratch, at, scratch);
248 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
251 __ Subu(scratch, zero_reg, scratch);
252 __ sllv(input_low, input_low, scratch);
253 __ Branch(&shift_done);
256 __ srlv(input_low, input_low, scratch);
258 __ bind(&shift_done);
259 __ Or(input_high, input_high, Operand(input_low));
260 // Restore sign if necessary.
261 __ mov(scratch, sign);
264 __ Subu(result_reg, zero_reg, input_high);
265 __ Movz(result_reg, input_high, scratch);
269 __ Pop(scratch, scratch2, scratch3);
274 // Handle the case where the lhs and rhs are the same object.
275 // Equality is almost reflexive (everything but NaN), so this is a test
276 // for "identity and not NaN".
277 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
278 Condition cc, Strength strength) {
280 Label heap_number, return_equal;
281 Register exp_mask_reg = t5;
283 __ Branch(¬_identical, ne, a0, Operand(a1));
285 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
287 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
288 // so we do the second best thing - test it ourselves.
289 // They are both equal and they are not both Smis so both of them are not
290 // Smis. If it's not a heap number, then return equal.
291 __ GetObjectType(a0, t4, t4);
292 if (cc == less || cc == greater) {
293 // Call runtime on identical JSObjects.
294 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
295 // Call runtime on identical symbols since we need to throw a TypeError.
296 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
297 // Call runtime on identical SIMD values since we must throw a TypeError.
298 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
299 if (is_strong(strength)) {
300 // Call the runtime on anything that is converted in the semantics, since
301 // we need to throw a TypeError. Smis have already been ruled out.
302 __ Branch(&return_equal, eq, t4, Operand(HEAP_NUMBER_TYPE));
303 __ And(t4, t4, Operand(kIsNotStringMask));
304 __ Branch(slow, ne, t4, Operand(zero_reg));
307 __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE));
308 // Comparing JS objects with <=, >= is complicated.
310 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
311 // Call runtime on identical symbols since we need to throw a TypeError.
312 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
313 // Call runtime on identical SIMD values since we must throw a TypeError.
314 __ Branch(slow, eq, t4, Operand(SIMD128_VALUE_TYPE));
315 if (is_strong(strength)) {
316 // Call the runtime on anything that is converted in the semantics,
317 // since we need to throw a TypeError. Smis and heap numbers have
318 // already been ruled out.
319 __ And(t4, t4, Operand(kIsNotStringMask));
320 __ Branch(slow, ne, t4, Operand(zero_reg));
322 // Normally here we fall through to return_equal, but undefined is
323 // special: (undefined == undefined) == true, but
324 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
325 if (cc == less_equal || cc == greater_equal) {
326 __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE));
327 __ LoadRoot(t2, Heap::kUndefinedValueRootIndex);
328 __ Branch(&return_equal, ne, a0, Operand(t2));
329 DCHECK(is_int16(GREATER) && is_int16(LESS));
330 __ Ret(USE_DELAY_SLOT);
332 // undefined <= undefined should fail.
333 __ li(v0, Operand(GREATER));
335 // undefined >= undefined should fail.
336 __ li(v0, Operand(LESS));
342 __ bind(&return_equal);
343 DCHECK(is_int16(GREATER) && is_int16(LESS));
344 __ Ret(USE_DELAY_SLOT);
346 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
347 } else if (cc == greater) {
348 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
350 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
353 // For less and greater we don't have to check for NaN since the result of
354 // x < x is false regardless. For the others here is some code to check
356 if (cc != lt && cc != gt) {
357 __ bind(&heap_number);
358 // It is a heap number, so return non-equal if it's NaN and equal if it's
361 // The representation of NaN values has all exponent bits (52..62) set,
362 // and not all mantissa bits (0..51) clear.
363 // Read top bits of double representation (second word of value).
364 __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset));
365 // Test that exponent bits are all set.
366 __ And(t3, t2, Operand(exp_mask_reg));
367 // If all bits not set (ne cond), then not a NaN, objects are equal.
368 __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg));
370 // Shift out flag and all exponent bits, retaining only mantissa.
371 __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord);
372 // Or with all low-bits of mantissa.
373 __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
374 __ Or(v0, t3, Operand(t2));
375 // For equal we already have the right value in v0: Return zero (equal)
376 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
377 // not (it's a NaN). For <= and >= we need to load v0 with the failing
378 // value if it's a NaN.
380 // All-zero means Infinity means equal.
381 __ Ret(eq, v0, Operand(zero_reg));
382 DCHECK(is_int16(GREATER) && is_int16(LESS));
383 __ Ret(USE_DELAY_SLOT);
385 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
387 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
391 // No fall through here.
393 __ bind(¬_identical);
397 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
400 Label* both_loaded_as_doubles,
403 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
404 (lhs.is(a1) && rhs.is(a0)));
407 __ JumpIfSmi(lhs, &lhs_is_smi);
409 // Check whether the non-smi is a heap number.
410 __ GetObjectType(lhs, t4, t4);
412 // If lhs was not a number and rhs was a Smi then strict equality cannot
413 // succeed. Return non-equal (lhs is already not zero).
414 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
417 // Smi compared non-strictly with a non-Smi non-heap-number. Call
419 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
422 // Rhs is a smi, lhs is a number.
423 // Convert smi rhs to double.
424 __ sra(at, rhs, kSmiTagSize);
426 __ cvt_d_w(f14, f14);
427 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
429 // We now have both loaded as doubles.
430 __ jmp(both_loaded_as_doubles);
432 __ bind(&lhs_is_smi);
433 // Lhs is a Smi. Check whether the non-smi is a heap number.
434 __ GetObjectType(rhs, t4, t4);
436 // If lhs was not a number and rhs was a Smi then strict equality cannot
437 // succeed. Return non-equal.
438 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
439 __ li(v0, Operand(1));
441 // Smi compared non-strictly with a non-Smi non-heap-number. Call
443 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
446 // Lhs is a smi, rhs is a number.
447 // Convert smi lhs to double.
448 __ sra(at, lhs, kSmiTagSize);
450 __ cvt_d_w(f12, f12);
451 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
452 // Fall through to both_loaded_as_doubles.
456 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
459 // If either operand is a JS object or an oddball value, then they are
460 // not equal since their pointers are different.
461 // There is no test for undetectability in strict equality.
462 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
463 Label first_non_object;
464 // Get the type of the first operand into a2 and compare it with
465 // FIRST_SPEC_OBJECT_TYPE.
466 __ GetObjectType(lhs, a2, a2);
467 __ Branch(&first_non_object, less, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
470 Label return_not_equal;
471 __ bind(&return_not_equal);
472 __ Ret(USE_DELAY_SLOT);
473 __ li(v0, Operand(1));
475 __ bind(&first_non_object);
476 // Check for oddballs: true, false, null, undefined.
477 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
479 __ GetObjectType(rhs, a3, a3);
480 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
482 // Check for oddballs: true, false, null, undefined.
483 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
485 // Now that we have the types we might as well check for
486 // internalized-internalized.
487 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
488 __ Or(a2, a2, Operand(a3));
489 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
490 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
494 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
497 Label* both_loaded_as_doubles,
498 Label* not_heap_numbers,
500 __ GetObjectType(lhs, a3, a2);
501 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
502 __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
503 // If first was a heap number & second wasn't, go to slow case.
504 __ Branch(slow, ne, a3, Operand(a2));
506 // Both are heap numbers. Load them up then jump to the code we have
508 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
509 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
511 __ jmp(both_loaded_as_doubles);
515 // Fast negative check for internalized-to-internalized equality.
516 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
519 Label* possible_strings,
520 Label* not_both_strings) {
521 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
522 (lhs.is(a1) && rhs.is(a0)));
524 // a2 is object type of rhs.
526 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
527 __ And(at, a2, Operand(kIsNotStringMask));
528 __ Branch(&object_test, ne, at, Operand(zero_reg));
529 __ And(at, a2, Operand(kIsNotInternalizedMask));
530 __ Branch(possible_strings, ne, at, Operand(zero_reg));
531 __ GetObjectType(rhs, a3, a3);
532 __ Branch(not_both_strings, ge, a3, Operand(FIRST_NONSTRING_TYPE));
533 __ And(at, a3, Operand(kIsNotInternalizedMask));
534 __ Branch(possible_strings, ne, at, Operand(zero_reg));
536 // Both are internalized strings. We already checked they weren't the same
537 // pointer so they are not equal.
538 __ Ret(USE_DELAY_SLOT);
539 __ li(v0, Operand(1)); // Non-zero indicates not equal.
541 __ bind(&object_test);
542 __ Branch(not_both_strings, lt, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
543 __ GetObjectType(rhs, a2, a3);
544 __ Branch(not_both_strings, lt, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
546 // If both objects are undetectable, they are equal. Otherwise, they
547 // are not equal, since they are different objects and an object is not
548 // equal to undefined.
549 __ lw(a3, FieldMemOperand(lhs, HeapObject::kMapOffset));
550 __ lbu(a2, FieldMemOperand(a2, Map::kBitFieldOffset));
551 __ lbu(a3, FieldMemOperand(a3, Map::kBitFieldOffset));
553 __ And(a0, a0, Operand(1 << Map::kIsUndetectable));
554 __ Ret(USE_DELAY_SLOT);
555 __ xori(v0, a0, 1 << Map::kIsUndetectable);
559 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
561 CompareICState::State expected,
564 if (expected == CompareICState::SMI) {
565 __ JumpIfNotSmi(input, fail);
566 } else if (expected == CompareICState::NUMBER) {
567 __ JumpIfSmi(input, &ok);
568 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
571 // We could be strict about internalized/string here, but as long as
572 // hydrogen doesn't care, the stub doesn't have to care either.
577 // On entry a1 and a2 are the values to be compared.
578 // On exit a0 is 0, positive or negative to indicate the result of
580 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
583 Condition cc = GetCondition();
586 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
587 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
589 Label slow; // Call builtin.
590 Label not_smis, both_loaded_as_doubles;
592 Label not_two_smis, smi_done;
594 __ JumpIfNotSmi(a2, ¬_two_smis);
597 __ Ret(USE_DELAY_SLOT);
599 __ bind(¬_two_smis);
601 // NOTICE! This code is only reached after a smi-fast-case check, so
602 // it is certain that at least one operand isn't a smi.
604 // Handle the case where the objects are identical. Either returns the answer
605 // or goes to slow. Only falls through if the objects were not identical.
606 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
608 // If either is a Smi (we know that not both are), then they can only
609 // be strictly equal if the other is a HeapNumber.
610 STATIC_ASSERT(kSmiTag == 0);
611 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
612 __ And(t2, lhs, Operand(rhs));
613 __ JumpIfNotSmi(t2, ¬_smis, t0);
614 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
615 // 1) Return the answer.
617 // 3) Fall through to both_loaded_as_doubles.
618 // 4) Jump to rhs_not_nan.
619 // In cases 3 and 4 we have found out we were dealing with a number-number
620 // comparison and the numbers have been loaded into f12 and f14 as doubles,
621 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
622 EmitSmiNonsmiComparison(masm, lhs, rhs,
623 &both_loaded_as_doubles, &slow, strict());
625 __ bind(&both_loaded_as_doubles);
626 // f12, f14 are the double representations of the left hand side
627 // and the right hand side if we have FPU. Otherwise a2, a3 represent
628 // left hand side and a0, a1 represent right hand side.
630 __ li(t0, Operand(LESS));
631 __ li(t1, Operand(GREATER));
632 __ li(t2, Operand(EQUAL));
634 // Check if either rhs or lhs is NaN.
635 __ BranchF(NULL, &nan, eq, f12, f14);
637 // Check if LESS condition is satisfied. If true, move conditionally
639 if (!IsMipsArchVariant(kMips32r6)) {
640 __ c(OLT, D, f12, f14);
642 // Use previous check to store conditionally to v0 oposite condition
643 // (GREATER). If rhs is equal to lhs, this will be corrected in next
646 // Check if EQUAL condition is satisfied. If true, move conditionally
648 __ c(EQ, D, f12, f14);
652 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
653 __ mov(v0, t0); // Return LESS as result.
655 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
656 __ mov(v0, t2); // Return EQUAL as result.
658 __ mov(v0, t1); // Return GREATER as result.
665 // NaN comparisons always fail.
666 // Load whatever we need in v0 to make the comparison fail.
667 DCHECK(is_int16(GREATER) && is_int16(LESS));
668 __ Ret(USE_DELAY_SLOT);
669 if (cc == lt || cc == le) {
670 __ li(v0, Operand(GREATER));
672 __ li(v0, Operand(LESS));
677 // At this point we know we are dealing with two different objects,
678 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
680 // This returns non-equal for some object types, or falls through if it
682 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
685 Label check_for_internalized_strings;
686 Label flat_string_check;
687 // Check for heap-number-heap-number comparison. Can jump to slow case,
688 // or load both doubles and jump to the code that handles
689 // that case. If the inputs are not doubles then jumps to
690 // check_for_internalized_strings.
691 // In this case a2 will contain the type of lhs_.
692 EmitCheckForTwoHeapNumbers(masm,
695 &both_loaded_as_doubles,
696 &check_for_internalized_strings,
699 __ bind(&check_for_internalized_strings);
700 if (cc == eq && !strict()) {
701 // Returns an answer for two internalized strings or two
702 // detectable objects.
703 // Otherwise jumps to string case or not both strings case.
704 // Assumes that a2 is the type of lhs_ on entry.
705 EmitCheckForInternalizedStringsOrObjects(
706 masm, lhs, rhs, &flat_string_check, &slow);
709 // Check for both being sequential one-byte strings,
710 // and inline if that is the case.
711 __ bind(&flat_string_check);
713 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
715 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
718 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0);
720 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0,
723 // Never falls through to here.
726 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
729 // Figure out which native to call and setup the arguments.
730 if (cc == eq && strict()) {
731 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
735 context_index = Context::EQUALS_BUILTIN_INDEX;
737 context_index = is_strong(strength())
738 ? Context::COMPARE_STRONG_BUILTIN_INDEX
739 : Context::COMPARE_BUILTIN_INDEX;
740 int ncr; // NaN compare result.
741 if (cc == lt || cc == le) {
744 DCHECK(cc == gt || cc == ge); // Remaining cases.
747 __ li(a0, Operand(Smi::FromInt(ncr)));
751 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
752 // tagged as a small integer.
753 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
761 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
764 __ PushSafepointRegisters();
769 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
772 __ PopSafepointRegisters();
777 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
778 // We don't allow a GC during a store buffer overflow so there is no need to
779 // store the registers in any particular way, but we do have to store and
781 __ MultiPush(kJSCallerSaved | ra.bit());
782 if (save_doubles()) {
783 __ MultiPushFPU(kCallerSavedFPU);
785 const int argument_count = 1;
786 const int fp_argument_count = 0;
787 const Register scratch = a1;
789 AllowExternalCallThatCantCauseGC scope(masm);
790 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
791 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
793 ExternalReference::store_buffer_overflow_function(isolate()),
795 if (save_doubles()) {
796 __ MultiPopFPU(kCallerSavedFPU);
799 __ MultiPop(kJSCallerSaved | ra.bit());
804 void MathPowStub::Generate(MacroAssembler* masm) {
805 const Register base = a1;
806 const Register exponent = MathPowTaggedDescriptor::exponent();
807 DCHECK(exponent.is(a2));
808 const Register heapnumbermap = t1;
809 const Register heapnumber = v0;
810 const DoubleRegister double_base = f2;
811 const DoubleRegister double_exponent = f4;
812 const DoubleRegister double_result = f0;
813 const DoubleRegister double_scratch = f6;
814 const FPURegister single_scratch = f8;
815 const Register scratch = t5;
816 const Register scratch2 = t3;
818 Label call_runtime, done, int_exponent;
819 if (exponent_type() == ON_STACK) {
820 Label base_is_smi, unpack_exponent;
821 // The exponent and base are supplied as arguments on the stack.
822 // This can only happen if the stub is called from non-optimized code.
823 // Load input parameters from stack to double registers.
824 __ lw(base, MemOperand(sp, 1 * kPointerSize));
825 __ lw(exponent, MemOperand(sp, 0 * kPointerSize));
827 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
829 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
830 __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset));
831 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
833 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
834 __ jmp(&unpack_exponent);
836 __ bind(&base_is_smi);
837 __ mtc1(scratch, single_scratch);
838 __ cvt_d_w(double_base, single_scratch);
839 __ bind(&unpack_exponent);
841 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
843 __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
844 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
845 __ ldc1(double_exponent,
846 FieldMemOperand(exponent, HeapNumber::kValueOffset));
847 } else if (exponent_type() == TAGGED) {
848 // Base is already in double_base.
849 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
851 __ ldc1(double_exponent,
852 FieldMemOperand(exponent, HeapNumber::kValueOffset));
855 if (exponent_type() != INTEGER) {
856 Label int_exponent_convert;
857 // Detect integer exponents stored as double.
858 __ EmitFPUTruncate(kRoundToMinusInf,
864 kCheckForInexactConversion);
865 // scratch2 == 0 means there was no conversion error.
866 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
868 if (exponent_type() == ON_STACK) {
869 // Detect square root case. Crankshaft detects constant +/-0.5 at
870 // compile time and uses DoMathPowHalf instead. We then skip this check
871 // for non-constant cases of +/-0.5 as these hardly occur.
874 __ Move(double_scratch, 0.5);
875 __ BranchF(USE_DELAY_SLOT,
881 // double_scratch can be overwritten in the delay slot.
882 // Calculates square root of base. Check for the special case of
883 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
884 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
885 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
886 __ neg_d(double_result, double_scratch);
888 // Add +0 to convert -0 to +0.
889 __ add_d(double_scratch, double_base, kDoubleRegZero);
890 __ sqrt_d(double_result, double_scratch);
893 __ bind(¬_plus_half);
894 __ Move(double_scratch, -0.5);
895 __ BranchF(USE_DELAY_SLOT,
901 // double_scratch can be overwritten in the delay slot.
902 // Calculates square root of base. Check for the special case of
903 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
904 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
905 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
906 __ Move(double_result, kDoubleRegZero);
908 // Add +0 to convert -0 to +0.
909 __ add_d(double_scratch, double_base, kDoubleRegZero);
910 __ Move(double_result, 1.);
911 __ sqrt_d(double_scratch, double_scratch);
912 __ div_d(double_result, double_result, double_scratch);
918 AllowExternalCallThatCantCauseGC scope(masm);
919 __ PrepareCallCFunction(0, 2, scratch2);
920 __ MovToFloatParameters(double_base, double_exponent);
922 ExternalReference::power_double_double_function(isolate()),
926 __ MovFromFloatResult(double_result);
929 __ bind(&int_exponent_convert);
932 // Calculate power with integer exponent.
933 __ bind(&int_exponent);
935 // Get two copies of exponent in the registers scratch and exponent.
936 if (exponent_type() == INTEGER) {
937 __ mov(scratch, exponent);
939 // Exponent has previously been stored into scratch as untagged integer.
940 __ mov(exponent, scratch);
943 __ mov_d(double_scratch, double_base); // Back up base.
944 __ Move(double_result, 1.0);
946 // Get absolute value of exponent.
947 Label positive_exponent;
948 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
949 __ Subu(scratch, zero_reg, scratch);
950 __ bind(&positive_exponent);
952 Label while_true, no_carry, loop_end;
953 __ bind(&while_true);
955 __ And(scratch2, scratch, 1);
957 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
958 __ mul_d(double_result, double_result, double_scratch);
961 __ sra(scratch, scratch, 1);
963 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
964 __ mul_d(double_scratch, double_scratch, double_scratch);
966 __ Branch(&while_true);
970 __ Branch(&done, ge, exponent, Operand(zero_reg));
971 __ Move(double_scratch, 1.0);
972 __ div_d(double_result, double_scratch, double_result);
973 // Test whether result is zero. Bail out to check for subnormal result.
974 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
975 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
977 // double_exponent may not contain the exponent value if the input was a
978 // smi. We set it with exponent value before bailing out.
979 __ mtc1(exponent, single_scratch);
980 __ cvt_d_w(double_exponent, single_scratch);
982 // Returning or bailing out.
983 Counters* counters = isolate()->counters();
984 if (exponent_type() == ON_STACK) {
985 // The arguments are still on the stack.
986 __ bind(&call_runtime);
987 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
989 // The stub is called from non-optimized code, which expects the result
990 // as heap number in exponent.
992 __ AllocateHeapNumber(
993 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
994 __ sdc1(double_result,
995 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
996 DCHECK(heapnumber.is(v0));
997 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1002 AllowExternalCallThatCantCauseGC scope(masm);
1003 __ PrepareCallCFunction(0, 2, scratch);
1004 __ MovToFloatParameters(double_base, double_exponent);
1006 ExternalReference::power_double_double_function(isolate()),
1010 __ MovFromFloatResult(double_result);
1013 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1019 bool CEntryStub::NeedsImmovableCode() {
1024 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1025 CEntryStub::GenerateAheadOfTime(isolate);
1026 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1027 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1028 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1029 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1030 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1031 BinaryOpICStub::GenerateAheadOfTime(isolate);
1032 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1033 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1034 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1035 StoreFastElementStub::GenerateAheadOfTime(isolate);
1036 TypeofStub::GenerateAheadOfTime(isolate);
1040 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1041 StoreRegistersStateStub stub(isolate);
1046 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1047 RestoreRegistersStateStub stub(isolate);
1052 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1053 // Generate if not already in cache.
1054 SaveFPRegsMode mode = kSaveFPRegs;
1055 CEntryStub(isolate, 1, mode).GetCode();
1056 StoreBufferOverflowStub(isolate, mode).GetCode();
1057 isolate->set_fp_stubs_generated(true);
1061 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1062 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1067 void CEntryStub::Generate(MacroAssembler* masm) {
1068 // Called from JavaScript; parameters are on stack as if calling JS function
1069 // a0: number of arguments including receiver
1070 // a1: pointer to builtin function
1071 // fp: frame pointer (restored after C call)
1072 // sp: stack pointer (restored as callee's sp after C call)
1073 // cp: current context (C callee-saved)
1075 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1077 // Compute the argv pointer in a callee-saved register.
1078 __ sll(s1, a0, kPointerSizeLog2);
1079 __ Addu(s1, sp, s1);
1080 __ Subu(s1, s1, kPointerSize);
1082 // Enter the exit frame that transitions from JavaScript to C++.
1083 FrameScope scope(masm, StackFrame::MANUAL);
1084 __ EnterExitFrame(save_doubles());
1086 // s0: number of arguments including receiver (C callee-saved)
1087 // s1: pointer to first argument (C callee-saved)
1088 // s2: pointer to builtin function (C callee-saved)
1090 // Prepare arguments for C routine.
1094 // a1 = argv (set in the delay slot after find_ra below).
1096 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1097 // also need to reserve the 4 argument slots on the stack.
1099 __ AssertStackIsAligned();
1101 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1103 // To let the GC traverse the return address of the exit frames, we need to
1104 // know where the return address is. The CEntryStub is unmovable, so
1105 // we can store the address on the stack to be able to find it again and
1106 // we never have to restore it, because it will not change.
1107 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1108 // This branch-and-link sequence is needed to find the current PC on mips,
1109 // saved to the ra register.
1110 // Use masm-> here instead of the double-underscore macro since extra
1111 // coverage code can interfere with the proper calculation of ra.
1113 masm->bal(&find_ra); // bal exposes branch delay slot.
1115 masm->bind(&find_ra);
1117 // Adjust the value in ra to point to the correct return location, 2nd
1118 // instruction past the real call into C code (the jalr(t9)), and push it.
1119 // This is the return address of the exit frame.
1120 const int kNumInstructionsToJump = 5;
1121 masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize);
1122 masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1123 // Stack space reservation moved to the branch delay slot below.
1124 // Stack is still aligned.
1126 // Call the C routine.
1127 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1129 // Set up sp in the delay slot.
1130 masm->addiu(sp, sp, -kCArgsSlotsSize);
1131 // Make sure the stored 'ra' points to this position.
1132 DCHECK_EQ(kNumInstructionsToJump,
1133 masm->InstructionsGeneratedSince(&find_ra));
1137 // Check result for exception sentinel.
1138 Label exception_returned;
1139 __ LoadRoot(t0, Heap::kExceptionRootIndex);
1140 __ Branch(&exception_returned, eq, t0, Operand(v0));
1142 // Check that there is no pending exception, otherwise we
1143 // should have returned the exception sentinel.
1144 if (FLAG_debug_code) {
1146 ExternalReference pending_exception_address(
1147 Isolate::kPendingExceptionAddress, isolate());
1148 __ li(a2, Operand(pending_exception_address));
1149 __ lw(a2, MemOperand(a2));
1150 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1151 // Cannot use check here as it attempts to generate call into runtime.
1152 __ Branch(&okay, eq, t0, Operand(a2));
1153 __ stop("Unexpected pending exception");
1157 // Exit C frame and return.
1159 // sp: stack pointer
1160 // fp: frame pointer
1161 // s0: still holds argc (callee-saved).
1162 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1164 // Handling of exception.
1165 __ bind(&exception_returned);
1167 ExternalReference pending_handler_context_address(
1168 Isolate::kPendingHandlerContextAddress, isolate());
1169 ExternalReference pending_handler_code_address(
1170 Isolate::kPendingHandlerCodeAddress, isolate());
1171 ExternalReference pending_handler_offset_address(
1172 Isolate::kPendingHandlerOffsetAddress, isolate());
1173 ExternalReference pending_handler_fp_address(
1174 Isolate::kPendingHandlerFPAddress, isolate());
1175 ExternalReference pending_handler_sp_address(
1176 Isolate::kPendingHandlerSPAddress, isolate());
1178 // Ask the runtime for help to determine the handler. This will set v0 to
1179 // contain the current pending exception, don't clobber it.
1180 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1183 FrameScope scope(masm, StackFrame::MANUAL);
1184 __ PrepareCallCFunction(3, 0, a0);
1185 __ mov(a0, zero_reg);
1186 __ mov(a1, zero_reg);
1187 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1188 __ CallCFunction(find_handler, 3);
1191 // Retrieve the handler context, SP and FP.
1192 __ li(cp, Operand(pending_handler_context_address));
1193 __ lw(cp, MemOperand(cp));
1194 __ li(sp, Operand(pending_handler_sp_address));
1195 __ lw(sp, MemOperand(sp));
1196 __ li(fp, Operand(pending_handler_fp_address));
1197 __ lw(fp, MemOperand(fp));
1199 // If the handler is a JS frame, restore the context to the frame. Note that
1200 // the context will be set to (cp == 0) for non-JS frames.
1202 __ Branch(&zero, eq, cp, Operand(zero_reg));
1203 __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1206 // Compute the handler entry address and jump to it.
1207 __ li(a1, Operand(pending_handler_code_address));
1208 __ lw(a1, MemOperand(a1));
1209 __ li(a2, Operand(pending_handler_offset_address));
1210 __ lw(a2, MemOperand(a2));
1211 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1212 __ Addu(t9, a1, a2);
1217 void JSEntryStub::Generate(MacroAssembler* masm) {
1218 Label invoke, handler_entry, exit;
1219 Isolate* isolate = masm->isolate();
1222 // a0: entry address
1231 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1233 // Save callee saved registers on the stack.
1234 __ MultiPush(kCalleeSaved | ra.bit());
1236 // Save callee-saved FPU registers.
1237 __ MultiPushFPU(kCalleeSavedFPU);
1238 // Set up the reserved register for 0.0.
1239 __ Move(kDoubleRegZero, 0.0);
1242 // Load argv in s0 register.
1243 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1244 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1246 __ InitializeRootRegister();
1247 __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1249 // We build an EntryFrame.
1250 __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1251 int marker = type();
1252 __ li(t2, Operand(Smi::FromInt(marker)));
1253 __ li(t1, Operand(Smi::FromInt(marker)));
1254 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1256 __ lw(t0, MemOperand(t0));
1257 __ Push(t3, t2, t1, t0);
1258 // Set up frame pointer for the frame to be pushed.
1259 __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1262 // a0: entry_address
1264 // a2: receiver_pointer
1270 // function slot | entry frame
1272 // bad fp (0xff...f) |
1273 // callee saved registers + ra
1277 // If this is the outermost JS call, set js_entry_sp value.
1278 Label non_outermost_js;
1279 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1280 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1281 __ lw(t2, MemOperand(t1));
1282 __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
1283 __ sw(fp, MemOperand(t1));
1284 __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1287 __ nop(); // Branch delay slot nop.
1288 __ bind(&non_outermost_js);
1289 __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1293 // Jump to a faked try block that does the invoke, with a faked catch
1294 // block that sets the pending exception.
1296 __ bind(&handler_entry);
1297 handler_offset_ = handler_entry.pos();
1298 // Caught exception: Store result (exception) in the pending exception
1299 // field in the JSEnv and return a failure sentinel. Coming in here the
1300 // fp will be invalid because the PushStackHandler below sets it to 0 to
1301 // signal the existence of the JSEntry frame.
1302 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1304 __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
1305 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1306 __ b(&exit); // b exposes branch delay slot.
1307 __ nop(); // Branch delay slot nop.
1309 // Invoke: Link this frame into the handler chain.
1311 __ PushStackHandler();
1312 // If an exception not caught by another handler occurs, this handler
1313 // returns control to the code after the bal(&invoke) above, which
1314 // restores all kCalleeSaved registers (including cp and fp) to their
1315 // saved values before returning a failure to C.
1317 // Clear any pending exceptions.
1318 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
1319 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1321 __ sw(t1, MemOperand(t0));
1323 // Invoke the function by calling through JS entry trampoline builtin.
1324 // Notice that we cannot store a reference to the trampoline code directly in
1325 // this stub, because runtime stubs are not traversed when doing GC.
1328 // a0: entry_address
1330 // a2: receiver_pointer
1337 // callee saved registers + ra
1341 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1342 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1344 __ li(t0, Operand(construct_entry));
1346 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1347 __ li(t0, Operand(entry));
1349 __ lw(t9, MemOperand(t0)); // Deref address.
1351 // Call JSEntryTrampoline.
1352 __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1355 // Unlink this frame from the handler chain.
1356 __ PopStackHandler();
1358 __ bind(&exit); // v0 holds result
1359 // Check if the current stack frame is marked as the outermost JS frame.
1360 Label non_outermost_js_2;
1362 __ Branch(&non_outermost_js_2,
1365 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1366 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1367 __ sw(zero_reg, MemOperand(t1));
1368 __ bind(&non_outermost_js_2);
1370 // Restore the top frame descriptors from the stack.
1372 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1374 __ sw(t1, MemOperand(t0));
1376 // Reset the stack to the callee saved registers.
1377 __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1379 // Restore callee-saved fpu registers.
1380 __ MultiPopFPU(kCalleeSavedFPU);
1382 // Restore callee saved registers from the stack.
1383 __ MultiPop(kCalleeSaved | ra.bit());
1389 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1390 // Return address is in ra.
1393 Register receiver = LoadDescriptor::ReceiverRegister();
1394 Register index = LoadDescriptor::NameRegister();
1395 Register scratch = t1;
1396 Register result = v0;
1397 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1398 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1400 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1401 &miss, // When not a string.
1402 &miss, // When not a number.
1403 &miss, // When index out of range.
1404 STRING_INDEX_IS_ARRAY_INDEX,
1405 RECEIVER_IS_STRING);
1406 char_at_generator.GenerateFast(masm);
1409 StubRuntimeCallHelper call_helper;
1410 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1413 PropertyAccessCompiler::TailCallBuiltin(
1414 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1418 void InstanceOfStub::Generate(MacroAssembler* masm) {
1419 Register const object = a1; // Object (lhs).
1420 Register const function = a0; // Function (rhs).
1421 Register const object_map = a2; // Map of {object}.
1422 Register const function_map = a3; // Map of {function}.
1423 Register const function_prototype = t0; // Prototype of {function}.
1424 Register const scratch = t1;
1426 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1427 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1429 // Check if {object} is a smi.
1430 Label object_is_smi;
1431 __ JumpIfSmi(object, &object_is_smi);
1433 // Lookup the {function} and the {object} map in the global instanceof cache.
1434 // Note: This is safe because we clear the global instanceof cache whenever
1435 // we change the prototype of any object.
1436 Label fast_case, slow_case;
1437 __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1438 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1439 __ Branch(&fast_case, ne, function, Operand(at));
1440 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1441 __ Branch(&fast_case, ne, object_map, Operand(at));
1442 __ Ret(USE_DELAY_SLOT);
1443 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1445 // If {object} is a smi we can safely return false if {function} is a JS
1446 // function, otherwise we have to miss to the runtime and throw an exception.
1447 __ bind(&object_is_smi);
1448 __ JumpIfSmi(function, &slow_case);
1449 __ GetObjectType(function, function_map, scratch);
1450 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1451 __ Ret(USE_DELAY_SLOT);
1452 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
1454 // Fast-case: The {function} must be a valid JSFunction.
1455 __ bind(&fast_case);
1456 __ JumpIfSmi(function, &slow_case);
1457 __ GetObjectType(function, function_map, scratch);
1458 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1460 // Ensure that {function} has an instance prototype.
1461 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1462 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1463 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1465 // Ensure that {function} is not bound.
1466 Register const shared_info = scratch;
1468 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1470 FieldMemOperand(shared_info, SharedFunctionInfo::kBoundByteOffset));
1471 __ And(at, scratch, Operand(1 << SharedFunctionInfo::kBoundBitWithinByte));
1472 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1474 // Get the "prototype" (or initial map) of the {function}.
1475 __ lw(function_prototype,
1476 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1477 __ AssertNotSmi(function_prototype);
1479 // Resolve the prototype if the {function} has an initial map. Afterwards the
1480 // {function_prototype} will be either the JSReceiver prototype object or the
1481 // hole value, which means that no instances of the {function} were created so
1482 // far and hence we should return false.
1483 Label function_prototype_valid;
1484 __ GetObjectType(function_prototype, scratch, scratch);
1485 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1486 __ lw(function_prototype,
1487 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1488 __ bind(&function_prototype_valid);
1489 __ AssertNotSmi(function_prototype);
1491 // Update the global instanceof cache with the current {object} map and
1492 // {function}. The cached answer will be set when it is known below.
1493 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1494 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1496 // Loop through the prototype chain looking for the {function} prototype.
1497 // Assume true, and change to false if not found.
1498 Register const object_prototype = object_map;
1499 Register const null = scratch;
1501 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1502 __ LoadRoot(null, Heap::kNullValueRootIndex);
1504 __ lw(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1505 __ Branch(&done, eq, object_prototype, Operand(function_prototype));
1506 __ Branch(USE_DELAY_SLOT, &loop, ne, object_prototype, Operand(null));
1507 __ lw(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1508 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1510 __ Ret(USE_DELAY_SLOT);
1511 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1513 // Slow-case: Call the runtime function.
1514 __ bind(&slow_case);
1515 __ Push(object, function);
1516 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1520 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1522 Register receiver = LoadDescriptor::ReceiverRegister();
1523 // Ensure that the vector and slot registers won't be clobbered before
1524 // calling the miss handler.
1525 DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(),
1526 LoadWithVectorDescriptor::SlotRegister()));
1528 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0,
1531 PropertyAccessCompiler::TailCallBuiltin(
1532 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1536 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1537 // The displacement is the offset of the last parameter (if any)
1538 // relative to the frame pointer.
1539 const int kDisplacement =
1540 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1541 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1542 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1544 // Check that the key is a smiGenerateReadElement.
1546 __ JumpIfNotSmi(a1, &slow);
1548 // Check if the calling frame is an arguments adaptor frame.
1550 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1551 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1555 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1557 // Check index (a1) against formal parameters count limit passed in
1558 // through register a0. Use unsigned comparison to get negative
1560 __ Branch(&slow, hs, a1, Operand(a0));
1562 // Read the argument from the stack and return it.
1563 __ subu(a3, a0, a1);
1564 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1565 __ Addu(a3, fp, Operand(t3));
1566 __ Ret(USE_DELAY_SLOT);
1567 __ lw(v0, MemOperand(a3, kDisplacement));
1569 // Arguments adaptor case: Check index (a1) against actual arguments
1570 // limit found in the arguments adaptor frame. Use unsigned
1571 // comparison to get negative check for free.
1573 __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1574 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1576 // Read the argument from the adaptor frame and return it.
1577 __ subu(a3, a0, a1);
1578 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1579 __ Addu(a3, a2, Operand(t3));
1580 __ Ret(USE_DELAY_SLOT);
1581 __ lw(v0, MemOperand(a3, kDisplacement));
1583 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1584 // by calling the runtime system.
1587 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1591 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1592 // sp[0] : number of parameters
1593 // sp[4] : receiver displacement
1596 // Check if the calling frame is an arguments adaptor frame.
1598 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1599 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1603 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1605 // Patch the arguments.length and the parameters pointer in the current frame.
1606 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1607 __ sw(a2, MemOperand(sp, 0 * kPointerSize));
1609 __ Addu(a3, a3, Operand(t3));
1610 __ addiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1611 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1614 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1618 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1620 // sp[0] : number of parameters (tagged)
1621 // sp[4] : address of receiver argument
1623 // Registers used over whole function:
1624 // t2 : allocated object (tagged)
1625 // t5 : mapped parameter count (tagged)
1627 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1628 // a1 = parameter count (tagged)
1630 // Check if the calling frame is an arguments adaptor frame.
1632 Label adaptor_frame, try_allocate;
1633 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1634 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1635 __ Branch(&adaptor_frame,
1638 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1640 // No adaptor, parameter count = argument count.
1642 __ b(&try_allocate);
1643 __ nop(); // Branch delay slot nop.
1645 // We have an adaptor frame. Patch the parameters pointer.
1646 __ bind(&adaptor_frame);
1647 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1649 __ Addu(a3, a3, Operand(t6));
1650 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1651 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1653 // a1 = parameter count (tagged)
1654 // a2 = argument count (tagged)
1655 // Compute the mapped parameter count = min(a1, a2) in a1.
1657 __ Branch(&skip_min, lt, a1, Operand(a2));
1661 __ bind(&try_allocate);
1663 // Compute the sizes of backing store, parameter map, and arguments object.
1664 // 1. Parameter map, has 2 extra words containing context and backing store.
1665 const int kParameterMapHeaderSize =
1666 FixedArray::kHeaderSize + 2 * kPointerSize;
1667 // If there are no mapped parameters, we do not need the parameter_map.
1668 Label param_map_size;
1669 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1670 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1671 __ mov(t5, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1673 __ addiu(t5, t5, kParameterMapHeaderSize);
1674 __ bind(¶m_map_size);
1676 // 2. Backing store.
1678 __ Addu(t5, t5, Operand(t6));
1679 __ Addu(t5, t5, Operand(FixedArray::kHeaderSize));
1681 // 3. Arguments object.
1682 __ Addu(t5, t5, Operand(Heap::kSloppyArgumentsObjectSize));
1684 // Do the allocation of all three objects in one go.
1685 __ Allocate(t5, v0, a3, t0, &runtime, TAG_OBJECT);
1687 // v0 = address of new object(s) (tagged)
1688 // a2 = argument count (smi-tagged)
1689 // Get the arguments boilerplate from the current native context into t0.
1690 const int kNormalOffset =
1691 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1692 const int kAliasedOffset =
1693 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1695 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1696 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1697 Label skip2_ne, skip2_eq;
1698 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1699 __ lw(t0, MemOperand(t0, kNormalOffset));
1702 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1703 __ lw(t0, MemOperand(t0, kAliasedOffset));
1706 // v0 = address of new object (tagged)
1707 // a1 = mapped parameter count (tagged)
1708 // a2 = argument count (smi-tagged)
1709 // t0 = address of arguments map (tagged)
1710 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1711 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1712 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1713 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1715 // Set up the callee in-object property.
1716 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1717 __ lw(a3, MemOperand(sp, 2 * kPointerSize));
1718 __ AssertNotSmi(a3);
1719 const int kCalleeOffset = JSObject::kHeaderSize +
1720 Heap::kArgumentsCalleeIndex * kPointerSize;
1721 __ sw(a3, FieldMemOperand(v0, kCalleeOffset));
1723 // Use the length (smi tagged) and set that as an in-object property too.
1725 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1726 const int kLengthOffset = JSObject::kHeaderSize +
1727 Heap::kArgumentsLengthIndex * kPointerSize;
1728 __ sw(a2, FieldMemOperand(v0, kLengthOffset));
1730 // Set up the elements pointer in the allocated arguments object.
1731 // If we allocated a parameter map, t0 will point there, otherwise
1732 // it will point to the backing store.
1733 __ Addu(t0, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1734 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1736 // v0 = address of new object (tagged)
1737 // a1 = mapped parameter count (tagged)
1738 // a2 = argument count (tagged)
1739 // t0 = address of parameter map or backing store (tagged)
1740 // Initialize parameter map. If there are no mapped arguments, we're done.
1741 Label skip_parameter_map;
1743 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1744 // Move backing store address to a3, because it is
1745 // expected there when filling in the unmapped arguments.
1749 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1751 __ LoadRoot(t2, Heap::kSloppyArgumentsElementsMapRootIndex);
1752 __ sw(t2, FieldMemOperand(t0, FixedArray::kMapOffset));
1753 __ Addu(t2, a1, Operand(Smi::FromInt(2)));
1754 __ sw(t2, FieldMemOperand(t0, FixedArray::kLengthOffset));
1755 __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize));
1757 __ Addu(t2, t0, Operand(t6));
1758 __ Addu(t2, t2, Operand(kParameterMapHeaderSize));
1759 __ sw(t2, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize));
1761 // Copy the parameter slots and the holes in the arguments.
1762 // We need to fill in mapped_parameter_count slots. They index the context,
1763 // where parameters are stored in reverse order, at
1764 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1765 // The mapped parameter thus need to get indices
1766 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1767 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1768 // We loop from right to left.
1769 Label parameters_loop, parameters_test;
1771 __ lw(t5, MemOperand(sp, 0 * kPointerSize));
1772 __ Addu(t5, t5, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1773 __ Subu(t5, t5, Operand(a1));
1774 __ LoadRoot(t3, Heap::kTheHoleValueRootIndex);
1776 __ Addu(a3, t0, Operand(t6));
1777 __ Addu(a3, a3, Operand(kParameterMapHeaderSize));
1779 // t2 = loop variable (tagged)
1780 // a1 = mapping index (tagged)
1781 // a3 = address of backing store (tagged)
1782 // t0 = address of parameter map (tagged)
1783 // t1 = temporary scratch (a.o., for address calculation)
1784 // t3 = the hole value
1785 __ jmp(¶meters_test);
1787 __ bind(¶meters_loop);
1788 __ Subu(t2, t2, Operand(Smi::FromInt(1)));
1790 __ Addu(t1, t1, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1791 __ Addu(t6, t0, t1);
1792 __ sw(t5, MemOperand(t6));
1793 __ Subu(t1, t1, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1794 __ Addu(t6, a3, t1);
1795 __ sw(t3, MemOperand(t6));
1796 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1797 __ bind(¶meters_test);
1798 __ Branch(¶meters_loop, ne, t2, Operand(Smi::FromInt(0)));
1800 __ bind(&skip_parameter_map);
1801 // a2 = argument count (tagged)
1802 // a3 = address of backing store (tagged)
1804 // Copy arguments header and remaining slots (if there are any).
1805 __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex);
1806 __ sw(t1, FieldMemOperand(a3, FixedArray::kMapOffset));
1807 __ sw(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1809 Label arguments_loop, arguments_test;
1811 __ lw(t0, MemOperand(sp, 1 * kPointerSize));
1813 __ Subu(t0, t0, Operand(t6));
1814 __ jmp(&arguments_test);
1816 __ bind(&arguments_loop);
1817 __ Subu(t0, t0, Operand(kPointerSize));
1818 __ lw(t2, MemOperand(t0, 0));
1820 __ Addu(t1, a3, Operand(t6));
1821 __ sw(t2, FieldMemOperand(t1, FixedArray::kHeaderSize));
1822 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1824 __ bind(&arguments_test);
1825 __ Branch(&arguments_loop, lt, t5, Operand(a2));
1827 // Return and remove the on-stack parameters.
1830 // Do the runtime call to allocate the arguments object.
1831 // a2 = argument count (tagged)
1833 __ sw(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1834 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1838 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1839 // Return address is in ra.
1842 Register receiver = LoadDescriptor::ReceiverRegister();
1843 Register key = LoadDescriptor::NameRegister();
1845 // Check that the key is an array index, that is Uint32.
1846 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1847 __ Branch(&slow, ne, t0, Operand(zero_reg));
1849 // Everything is fine, call runtime.
1850 __ Push(receiver, key); // Receiver, key.
1852 // Perform tail call to the entry.
1853 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1856 PropertyAccessCompiler::TailCallBuiltin(
1857 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1861 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1862 // sp[0] : number of parameters
1863 // sp[4] : receiver displacement
1865 // Check if the calling frame is an arguments adaptor frame.
1866 Label adaptor_frame, try_allocate, runtime;
1867 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1868 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1869 __ Branch(&adaptor_frame,
1872 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1874 // Get the length from the frame.
1875 __ lw(a1, MemOperand(sp, 0));
1876 __ Branch(&try_allocate);
1878 // Patch the arguments.length and the parameters pointer.
1879 __ bind(&adaptor_frame);
1880 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1881 __ sw(a1, MemOperand(sp, 0));
1882 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1883 __ Addu(a3, a2, Operand(at));
1885 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1886 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1888 // Try the new space allocation. Start out with computing the size
1889 // of the arguments object and the elements array in words.
1890 Label add_arguments_object;
1891 __ bind(&try_allocate);
1892 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1893 __ srl(a1, a1, kSmiTagSize);
1895 __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1896 __ bind(&add_arguments_object);
1897 __ Addu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1899 // Do the allocation of both objects in one go.
1900 __ Allocate(a1, v0, a2, a3, &runtime,
1901 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1903 // Get the arguments boilerplate from the current native context.
1904 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1905 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1906 __ lw(t0, MemOperand(
1907 t0, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
1909 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1910 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1911 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1912 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1914 // Get the length (smi tagged) and set that as an in-object property too.
1915 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1916 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1918 __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
1919 Heap::kArgumentsLengthIndex * kPointerSize));
1922 __ Branch(&done, eq, a1, Operand(zero_reg));
1924 // Get the parameters pointer from the stack.
1925 __ lw(a2, MemOperand(sp, 1 * kPointerSize));
1927 // Set up the elements pointer in the allocated arguments object and
1928 // initialize the header in the elements fixed array.
1929 __ Addu(t0, v0, Operand(Heap::kStrictArgumentsObjectSize));
1930 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1931 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
1932 __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset));
1933 __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset));
1934 // Untag the length for the loop.
1935 __ srl(a1, a1, kSmiTagSize);
1937 // Copy the fixed array slots.
1939 // Set up t0 to point to the first array slot.
1940 __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1942 // Pre-decrement a2 with kPointerSize on each iteration.
1943 // Pre-decrement in order to skip receiver.
1944 __ Addu(a2, a2, Operand(-kPointerSize));
1945 __ lw(a3, MemOperand(a2));
1946 // Post-increment t0 with kPointerSize on each iteration.
1947 __ sw(a3, MemOperand(t0));
1948 __ Addu(t0, t0, Operand(kPointerSize));
1949 __ Subu(a1, a1, Operand(1));
1950 __ Branch(&loop, ne, a1, Operand(zero_reg));
1952 // Return and remove the on-stack parameters.
1956 // Do the runtime call to allocate the arguments object.
1958 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1962 void RegExpExecStub::Generate(MacroAssembler* masm) {
1963 // Just jump directly to runtime if native RegExp is not selected at compile
1964 // time or if regexp entry in generated code is turned off runtime switch or
1966 #ifdef V8_INTERPRETED_REGEXP
1967 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1968 #else // V8_INTERPRETED_REGEXP
1970 // Stack frame on entry.
1971 // sp[0]: last_match_info (expected JSArray)
1972 // sp[4]: previous index
1973 // sp[8]: subject string
1974 // sp[12]: JSRegExp object
1976 const int kLastMatchInfoOffset = 0 * kPointerSize;
1977 const int kPreviousIndexOffset = 1 * kPointerSize;
1978 const int kSubjectOffset = 2 * kPointerSize;
1979 const int kJSRegExpOffset = 3 * kPointerSize;
1982 // Allocation of registers for this function. These are in callee save
1983 // registers and will be preserved by the call to the native RegExp code, as
1984 // this code is called using the normal C calling convention. When calling
1985 // directly from generated code the native RegExp code will not do a GC and
1986 // therefore the content of these registers are safe to use after the call.
1987 // MIPS - using s0..s2, since we are not using CEntry Stub.
1988 Register subject = s0;
1989 Register regexp_data = s1;
1990 Register last_match_info_elements = s2;
1992 // Ensure that a RegExp stack is allocated.
1993 ExternalReference address_of_regexp_stack_memory_address =
1994 ExternalReference::address_of_regexp_stack_memory_address(
1996 ExternalReference address_of_regexp_stack_memory_size =
1997 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1998 __ li(a0, Operand(address_of_regexp_stack_memory_size));
1999 __ lw(a0, MemOperand(a0, 0));
2000 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2002 // Check that the first argument is a JSRegExp object.
2003 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
2004 STATIC_ASSERT(kSmiTag == 0);
2005 __ JumpIfSmi(a0, &runtime);
2006 __ GetObjectType(a0, a1, a1);
2007 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2009 // Check that the RegExp has been compiled (data contains a fixed array).
2010 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2011 if (FLAG_debug_code) {
2012 __ SmiTst(regexp_data, t0);
2014 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2017 __ GetObjectType(regexp_data, a0, a0);
2019 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2021 Operand(FIXED_ARRAY_TYPE));
2024 // regexp_data: RegExp data (FixedArray)
2025 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2026 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2027 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2029 // regexp_data: RegExp data (FixedArray)
2030 // Check that the number of captures fit in the static offsets vector buffer.
2032 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2033 // Check (number_of_captures + 1) * 2 <= offsets vector size
2034 // Or number_of_captures * 2 <= offsets vector size - 2
2035 // Multiplying by 2 comes for free since a2 is smi-tagged.
2036 STATIC_ASSERT(kSmiTag == 0);
2037 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2038 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2040 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2042 // Reset offset for possibly sliced string.
2043 __ mov(t0, zero_reg);
2044 __ lw(subject, MemOperand(sp, kSubjectOffset));
2045 __ JumpIfSmi(subject, &runtime);
2046 __ mov(a3, subject); // Make a copy of the original subject string.
2047 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2048 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2049 // subject: subject string
2050 // a3: subject string
2051 // a0: subject string instance type
2052 // regexp_data: RegExp data (FixedArray)
2053 // Handle subject string according to its encoding and representation:
2054 // (1) Sequential string? If yes, go to (5).
2055 // (2) Anything but sequential or cons? If yes, go to (6).
2056 // (3) Cons string. If the string is flat, replace subject with first string.
2057 // Otherwise bailout.
2058 // (4) Is subject external? If yes, go to (7).
2059 // (5) Sequential string. Load regexp code according to encoding.
2063 // Deferred code at the end of the stub:
2064 // (6) Not a long external string? If yes, go to (8).
2065 // (7) External string. Make it, offset-wise, look like a sequential string.
2067 // (8) Short external string or not a string? If yes, bail out to runtime.
2068 // (9) Sliced string. Replace subject with parent. Go to (4).
2070 Label seq_string /* 5 */, external_string /* 7 */,
2071 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2072 not_long_external /* 8 */;
2074 // (1) Sequential string? If yes, go to (5).
2077 Operand(kIsNotStringMask |
2078 kStringRepresentationMask |
2079 kShortExternalStringMask));
2080 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2081 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2083 // (2) Anything but sequential or cons? If yes, go to (6).
2084 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2085 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2086 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2087 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2089 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2091 // (3) Cons string. Check that it's flat.
2092 // Replace subject with first string and reload instance type.
2093 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2094 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2095 __ Branch(&runtime, ne, a0, Operand(a1));
2096 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2098 // (4) Is subject external? If yes, go to (7).
2099 __ bind(&check_underlying);
2100 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2101 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2102 STATIC_ASSERT(kSeqStringTag == 0);
2103 __ And(at, a0, Operand(kStringRepresentationMask));
2104 // The underlying external string is never a short external string.
2105 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2106 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2107 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2109 // (5) Sequential string. Load regexp code according to encoding.
2110 __ bind(&seq_string);
2111 // subject: sequential subject string (or look-alike, external string)
2112 // a3: original subject string
2113 // Load previous index and check range before a3 is overwritten. We have to
2114 // use a3 instead of subject here because subject might have been only made
2115 // to look like a sequential string when it actually is an external string.
2116 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
2117 __ JumpIfNotSmi(a1, &runtime);
2118 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
2119 __ Branch(&runtime, ls, a3, Operand(a1));
2120 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
2122 STATIC_ASSERT(kStringEncodingMask == 4);
2123 STATIC_ASSERT(kOneByteStringTag == 4);
2124 STATIC_ASSERT(kTwoByteStringTag == 0);
2125 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
2126 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2127 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
2128 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2129 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2131 // (E) Carry on. String handling is done.
2132 // t9: irregexp code
2133 // Check that the irregexp code has been generated for the actual string
2134 // encoding. If it has, the field contains a code object otherwise it contains
2135 // a smi (code flushing support).
2136 __ JumpIfSmi(t9, &runtime);
2138 // a1: previous index
2139 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2141 // subject: Subject string
2142 // regexp_data: RegExp data (FixedArray)
2143 // All checks done. Now push arguments for native regexp code.
2144 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2147 // Isolates: note we add an additional parameter here (isolate pointer).
2148 const int kRegExpExecuteArguments = 9;
2149 const int kParameterRegisters = 4;
2150 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2152 // Stack pointer now points to cell where return address is to be written.
2153 // Arguments are before that on the stack or in registers, meaning we
2154 // treat the return address as argument 5. Thus every argument after that
2155 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2156 // allocating space for the c argument slots, we don't need to calculate
2157 // that into the argument positions on the stack. This is how the stack will
2158 // look (sp meaning the value of sp at this moment):
2159 // [sp + 5] - Argument 9
2160 // [sp + 4] - Argument 8
2161 // [sp + 3] - Argument 7
2162 // [sp + 2] - Argument 6
2163 // [sp + 1] - Argument 5
2164 // [sp + 0] - saved ra
2166 // Argument 9: Pass current isolate address.
2167 // CFunctionArgumentOperand handles MIPS stack argument slots.
2168 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2169 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
2171 // Argument 8: Indicate that this is a direct call from JavaScript.
2172 __ li(a0, Operand(1));
2173 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
2175 // Argument 7: Start (high end) of backtracking stack memory area.
2176 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2177 __ lw(a0, MemOperand(a0, 0));
2178 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2179 __ lw(a2, MemOperand(a2, 0));
2180 __ addu(a0, a0, a2);
2181 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
2183 // Argument 6: Set the number of capture registers to zero to force global
2184 // regexps to behave as non-global. This does not affect non-global regexps.
2185 __ mov(a0, zero_reg);
2186 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
2188 // Argument 5: static offsets vector buffer.
2190 ExternalReference::address_of_static_offsets_vector(isolate())));
2191 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
2193 // For arguments 4 and 3 get string length, calculate start of string data
2194 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2195 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2196 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2197 // Load the length from the original subject string from the previous stack
2198 // frame. Therefore we have to use fp, which points exactly to two pointer
2199 // sizes below the previous sp. (Because creating a new stack frame pushes
2200 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2201 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2202 // If slice offset is not 0, load the length from the original sliced string.
2203 // Argument 4, a3: End of string data
2204 // Argument 3, a2: Start of string data
2205 // Prepare start and end index of the input.
2206 __ sllv(t1, t0, a3);
2207 __ addu(t0, t2, t1);
2208 __ sllv(t1, a1, a3);
2209 __ addu(a2, t0, t1);
2211 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
2212 __ sra(t2, t2, kSmiTagSize);
2213 __ sllv(t1, t2, a3);
2214 __ addu(a3, t0, t1);
2215 // Argument 2 (a1): Previous index.
2218 // Argument 1 (a0): Subject string.
2219 __ mov(a0, subject);
2221 // Locate the code entry and call it.
2222 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2223 DirectCEntryStub stub(isolate());
2224 stub.GenerateCall(masm, t9);
2226 __ LeaveExitFrame(false, no_reg, true);
2229 // subject: subject string (callee saved)
2230 // regexp_data: RegExp data (callee saved)
2231 // last_match_info_elements: Last match info elements (callee saved)
2232 // Check the result.
2234 __ Branch(&success, eq, v0, Operand(1));
2235 // We expect exactly one result since we force the called regexp to behave
2238 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2239 // If not exception it can only be retry. Handle that in the runtime system.
2240 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2241 // Result must now be exception. If there is no pending exception already a
2242 // stack overflow (on the backtrack stack) was detected in RegExp code but
2243 // haven't created the exception yet. Handle that in the runtime system.
2244 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2245 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2246 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2248 __ lw(v0, MemOperand(a2, 0));
2249 __ Branch(&runtime, eq, v0, Operand(a1));
2251 // For exception, throw the exception again.
2252 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2255 // For failure and exception return null.
2256 __ li(v0, Operand(isolate()->factory()->null_value()));
2259 // Process the result from the native regexp code.
2262 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2263 // Calculate number of capture registers (number_of_captures + 1) * 2.
2264 // Multiplying by 2 comes for free since r1 is smi-tagged.
2265 STATIC_ASSERT(kSmiTag == 0);
2266 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2267 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
2269 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
2270 __ JumpIfSmi(a0, &runtime);
2271 __ GetObjectType(a0, a2, a2);
2272 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2273 // Check that the JSArray is in fast case.
2274 __ lw(last_match_info_elements,
2275 FieldMemOperand(a0, JSArray::kElementsOffset));
2276 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2277 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2278 __ Branch(&runtime, ne, a0, Operand(at));
2279 // Check that the last match info has space for the capture registers and the
2280 // additional information.
2282 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2283 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2284 __ sra(at, a0, kSmiTagSize);
2285 __ Branch(&runtime, gt, a2, Operand(at));
2287 // a1: number of capture registers
2288 // subject: subject string
2289 // Store the capture count.
2290 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
2291 __ sw(a2, FieldMemOperand(last_match_info_elements,
2292 RegExpImpl::kLastCaptureCountOffset));
2293 // Store last subject and last input.
2295 FieldMemOperand(last_match_info_elements,
2296 RegExpImpl::kLastSubjectOffset));
2297 __ mov(a2, subject);
2298 __ RecordWriteField(last_match_info_elements,
2299 RegExpImpl::kLastSubjectOffset,
2304 __ mov(subject, a2);
2306 FieldMemOperand(last_match_info_elements,
2307 RegExpImpl::kLastInputOffset));
2308 __ RecordWriteField(last_match_info_elements,
2309 RegExpImpl::kLastInputOffset,
2315 // Get the static offsets vector filled by the native regexp code.
2316 ExternalReference address_of_static_offsets_vector =
2317 ExternalReference::address_of_static_offsets_vector(isolate());
2318 __ li(a2, Operand(address_of_static_offsets_vector));
2320 // a1: number of capture registers
2321 // a2: offsets vector
2322 Label next_capture, done;
2323 // Capture register counter starts from number of capture registers and
2324 // counts down until wrapping after zero.
2326 last_match_info_elements,
2327 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2328 __ bind(&next_capture);
2329 __ Subu(a1, a1, Operand(1));
2330 __ Branch(&done, lt, a1, Operand(zero_reg));
2331 // Read the value from the static offsets vector buffer.
2332 __ lw(a3, MemOperand(a2, 0));
2333 __ addiu(a2, a2, kPointerSize);
2334 // Store the smi value in the last match info.
2335 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
2336 __ sw(a3, MemOperand(a0, 0));
2337 __ Branch(&next_capture, USE_DELAY_SLOT);
2338 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
2342 // Return last match info.
2343 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
2346 // Do the runtime call to execute the regexp.
2348 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2350 // Deferred code for string handling.
2351 // (6) Not a long external string? If yes, go to (8).
2352 __ bind(¬_seq_nor_cons);
2354 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2356 // (7) External string. Make it, offset-wise, look like a sequential string.
2357 __ bind(&external_string);
2358 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2359 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2360 if (FLAG_debug_code) {
2361 // Assert that we do not have a cons or slice (indirect strings) here.
2362 // Sequential strings have already been ruled out.
2363 __ And(at, a0, Operand(kIsIndirectStringMask));
2365 kExternalStringExpectedButNotFound,
2370 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2371 // Move the pointer so that offset-wise, it looks like a sequential string.
2372 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2375 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2376 __ jmp(&seq_string); // Go to (5).
2378 // (8) Short external string or not a string? If yes, bail out to runtime.
2379 __ bind(¬_long_external);
2380 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2381 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2382 __ Branch(&runtime, ne, at, Operand(zero_reg));
2384 // (9) Sliced string. Replace subject with parent. Go to (4).
2385 // Load offset into t0 and replace subject string with parent.
2386 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2387 __ sra(t0, t0, kSmiTagSize);
2388 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2389 __ jmp(&check_underlying); // Go to (4).
2390 #endif // V8_INTERPRETED_REGEXP
2394 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2396 // a0 : number of arguments to the construct function
2397 // a2 : feedback vector
2398 // a3 : slot in feedback vector (Smi)
2399 // a1 : the function to call
2400 // t0 : original constructor (for IsSuperConstructorCall)
2401 FrameScope scope(masm, StackFrame::INTERNAL);
2402 const RegList kSavedRegs = 1 << 4 | // a0
2406 BoolToInt(is_super) << 8; // t0
2408 // Number-of-arguments register must be smi-tagged to call out.
2410 __ MultiPush(kSavedRegs);
2414 __ MultiPop(kSavedRegs);
2419 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2420 // Cache the called function in a feedback vector slot. Cache states
2421 // are uninitialized, monomorphic (indicated by a JSFunction), and
2423 // a0 : number of arguments to the construct function
2424 // a1 : the function to call
2425 // a2 : feedback vector
2426 // a3 : slot in feedback vector (Smi)
2427 // t0 : original constructor (for IsSuperConstructorCall)
2428 Label initialize, done, miss, megamorphic, not_array_function;
2430 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2431 masm->isolate()->heap()->megamorphic_symbol());
2432 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2433 masm->isolate()->heap()->uninitialized_symbol());
2435 // Load the cache state into t2.
2436 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2437 __ Addu(t2, a2, Operand(t2));
2438 __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize));
2440 // A monomorphic cache hit or an already megamorphic state: invoke the
2441 // function without changing the state.
2442 // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at
2443 // this position in a symbol (see static asserts in type-feedback-vector.h).
2444 Label check_allocation_site;
2445 Register feedback_map = t1;
2446 Register weak_value = t4;
2447 __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset));
2448 __ Branch(&done, eq, a1, Operand(weak_value));
2449 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2450 __ Branch(&done, eq, t2, Operand(at));
2451 __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset));
2452 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2453 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2454 feedback_map, Operand(at));
2456 // If the weak cell is cleared, we have a new chance to become monomorphic.
2457 __ JumpIfSmi(weak_value, &initialize);
2458 __ jmp(&megamorphic);
2460 if (!FLAG_pretenuring_call_new) {
2461 __ bind(&check_allocation_site);
2462 // If we came here, we need to see if we are the array function.
2463 // If we didn't have a matching function, and we didn't find the megamorph
2464 // sentinel, then we have in the slot either some other function or an
2466 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2467 __ Branch(&miss, ne, feedback_map, Operand(at));
2469 // Make sure the function is the Array() function
2470 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2471 __ Branch(&megamorphic, ne, a1, Operand(t2));
2477 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2479 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2480 __ Branch(&initialize, eq, t2, Operand(at));
2481 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2482 // write-barrier is needed.
2483 __ bind(&megamorphic);
2484 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2485 __ Addu(t2, a2, Operand(t2));
2486 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2487 __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize));
2490 // An uninitialized cache is patched with the function.
2491 __ bind(&initialize);
2492 if (!FLAG_pretenuring_call_new) {
2493 // Make sure the function is the Array() function.
2494 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2495 __ Branch(¬_array_function, ne, a1, Operand(t2));
2497 // The target function is the Array constructor,
2498 // Create an AllocationSite if we don't already have it, store it in the
2500 CreateAllocationSiteStub create_stub(masm->isolate());
2501 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2504 __ bind(¬_array_function);
2507 CreateWeakCellStub create_stub(masm->isolate());
2508 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2513 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2514 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2515 __ lw(t0, FieldMemOperand(a3, SharedFunctionInfo::kCompilerHintsOffset));
2517 // Do not transform the receiver for strict mode functions.
2518 int32_t strict_mode_function_mask =
2519 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
2520 // Do not transform the receiver for native (Compilerhints already in a3).
2521 int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize);
2522 __ And(at, t0, Operand(strict_mode_function_mask | native_mask));
2523 __ Branch(cont, ne, at, Operand(zero_reg));
2527 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2528 __ li(a0, Operand(argc));
2529 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2533 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2534 // Wrap the receiver and patch it back onto the stack.
2535 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2538 ToObjectStub stub(masm->isolate());
2542 __ Branch(USE_DELAY_SLOT, cont);
2543 __ sw(v0, MemOperand(sp, argc * kPointerSize));
2547 static void CallFunctionNoFeedback(MacroAssembler* masm,
2548 int argc, bool needs_checks,
2549 bool call_as_method) {
2550 // a1 : the function to call
2551 Label slow, wrap, cont;
2554 // Check that the function is really a JavaScript function.
2555 // a1: pushed function (to be verified)
2556 __ JumpIfSmi(a1, &slow);
2558 // Goto slow case if we do not have a function.
2559 __ GetObjectType(a1, t0, t0);
2560 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2563 // Fast-case: Invoke the function now.
2564 // a1: pushed function
2565 ParameterCount actual(argc);
2567 if (call_as_method) {
2569 EmitContinueIfStrictOrNative(masm, &cont);
2572 // Compute the receiver in sloppy mode.
2573 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2576 __ JumpIfSmi(a3, &wrap);
2577 __ GetObjectType(a3, t0, t0);
2578 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2586 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2589 // Slow-case: Non-function called.
2591 EmitSlowCase(masm, argc);
2594 if (call_as_method) {
2596 // Wrap the receiver and patch it back onto the stack.
2597 EmitWrapCase(masm, argc, &cont);
2602 void CallFunctionStub::Generate(MacroAssembler* masm) {
2603 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2607 void CallConstructStub::Generate(MacroAssembler* masm) {
2608 // a0 : number of arguments
2609 // a1 : the function to call
2610 // a2 : feedback vector
2611 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2612 // t0 : original constructor (for IsSuperConstructorCall)
2613 Label slow, non_function_call;
2615 // Check that the function is not a smi.
2616 __ JumpIfSmi(a1, &non_function_call);
2617 // Check that the function is a JSFunction.
2618 __ GetObjectType(a1, t1, t1);
2619 __ Branch(&slow, ne, t1, Operand(JS_FUNCTION_TYPE));
2621 if (RecordCallTarget()) {
2622 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2624 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2625 __ Addu(t1, a2, at);
2626 if (FLAG_pretenuring_call_new) {
2627 // Put the AllocationSite from the feedback vector into a2.
2628 // By adding kPointerSize we encode that we know the AllocationSite
2629 // entry is at the feedback vector slot given by a3 + 1.
2630 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize + kPointerSize));
2632 Label feedback_register_initialized;
2633 // Put the AllocationSite from the feedback vector into a2, or undefined.
2634 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
2635 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
2636 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2637 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
2638 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2639 __ bind(&feedback_register_initialized);
2642 __ AssertUndefinedOrAllocationSite(a2, t1);
2645 // Pass function as original constructor.
2646 if (IsSuperConstructorCall()) {
2652 // Jump to the function-specific construct stub.
2653 Register jmp_reg = t0;
2654 __ lw(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2655 __ lw(jmp_reg, FieldMemOperand(jmp_reg,
2656 SharedFunctionInfo::kConstructStubOffset));
2657 __ Addu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2660 // a0: number of arguments
2661 // a1: called object
2665 __ Branch(&non_function_call, ne, t1, Operand(JS_FUNCTION_PROXY_TYPE));
2666 __ GetBuiltinFunction(
2667 a1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2670 __ bind(&non_function_call);
2671 __ GetBuiltinFunction(
2672 a1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2674 // Set expected number of arguments to zero (not changing r0).
2675 __ li(a2, Operand(0, RelocInfo::NONE32));
2676 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2677 RelocInfo::CODE_TARGET);
2681 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2682 __ lw(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2683 __ lw(vector, FieldMemOperand(vector,
2684 JSFunction::kSharedFunctionInfoOffset));
2685 __ lw(vector, FieldMemOperand(vector,
2686 SharedFunctionInfo::kFeedbackVectorOffset));
2690 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2696 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2697 __ Branch(&miss, ne, a1, Operand(at));
2699 __ li(a0, Operand(arg_count()));
2700 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2701 __ Addu(at, a2, Operand(at));
2702 __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize));
2704 // Verify that t0 contains an AllocationSite
2705 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2706 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2707 __ Branch(&miss, ne, t1, Operand(at));
2709 // Increment the call count for monomorphic function calls.
2710 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2711 __ Addu(at, a2, Operand(at));
2712 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2713 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2714 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2718 ArrayConstructorStub stub(masm->isolate(), arg_count());
2719 __ TailCallStub(&stub);
2724 // The slow case, we need this no matter what to complete a call after a miss.
2725 __ li(a0, Operand(arg_count()));
2726 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2730 void CallICStub::Generate(MacroAssembler* masm) {
2732 // a3 - slot id (Smi)
2734 const int with_types_offset =
2735 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2736 const int generic_offset =
2737 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2738 Label extra_checks_or_miss, slow_start;
2739 Label slow, wrap, cont;
2740 Label have_js_function;
2741 int argc = arg_count();
2742 ParameterCount actual(argc);
2744 // The checks. First, does r1 match the recorded monomorphic target?
2745 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2746 __ Addu(t0, a2, Operand(t0));
2747 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2749 // We don't know that we have a weak cell. We might have a private symbol
2750 // or an AllocationSite, but the memory is safe to examine.
2751 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2753 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2754 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2755 // computed, meaning that it can't appear to be a pointer. If the low bit is
2756 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2758 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2759 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2760 WeakCell::kValueOffset &&
2761 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2763 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2764 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
2766 // The compare above could have been a SMI/SMI comparison. Guard against this
2767 // convincing us that we have a monomorphic JSFunction.
2768 __ JumpIfSmi(a1, &extra_checks_or_miss);
2770 // Increment the call count for monomorphic function calls.
2771 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2772 __ Addu(at, a2, Operand(at));
2773 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2774 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2775 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2777 __ bind(&have_js_function);
2778 if (CallAsMethod()) {
2779 EmitContinueIfStrictOrNative(masm, &cont);
2780 // Compute the receiver in sloppy mode.
2781 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2783 __ JumpIfSmi(a3, &wrap);
2784 __ GetObjectType(a3, t0, t0);
2785 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2790 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2793 EmitSlowCase(masm, argc);
2795 if (CallAsMethod()) {
2797 EmitWrapCase(masm, argc, &cont);
2800 __ bind(&extra_checks_or_miss);
2801 Label uninitialized, miss;
2803 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2804 __ Branch(&slow_start, eq, t0, Operand(at));
2806 // The following cases attempt to handle MISS cases without going to the
2808 if (FLAG_trace_ic) {
2812 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2813 __ Branch(&uninitialized, eq, t0, Operand(at));
2815 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2816 // to handle it here. More complex cases are dealt with in the runtime.
2817 __ AssertNotSmi(t0);
2818 __ GetObjectType(t0, t1, t1);
2819 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
2820 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2821 __ Addu(t0, a2, Operand(t0));
2822 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2823 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2824 // We have to update statistics for runtime profiling.
2825 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2826 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
2827 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2828 __ lw(t0, FieldMemOperand(a2, generic_offset));
2829 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2830 __ Branch(USE_DELAY_SLOT, &slow_start);
2831 __ sw(t0, FieldMemOperand(a2, generic_offset)); // In delay slot.
2833 __ bind(&uninitialized);
2835 // We are going monomorphic, provided we actually have a JSFunction.
2836 __ JumpIfSmi(a1, &miss);
2838 // Goto miss case if we do not have a function.
2839 __ GetObjectType(a1, t0, t0);
2840 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2842 // Make sure the function is not the Array() function, which requires special
2843 // behavior on MISS.
2844 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2845 __ Branch(&miss, eq, a1, Operand(t0));
2848 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2849 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2850 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2852 // Initialize the call counter.
2853 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2854 __ Addu(at, a2, Operand(at));
2855 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2856 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2858 // Store the function. Use a stub since we need a frame for allocation.
2863 FrameScope scope(masm, StackFrame::INTERNAL);
2864 CreateWeakCellStub create_stub(masm->isolate());
2866 __ CallStub(&create_stub);
2870 __ Branch(&have_js_function);
2872 // We are here because tracing is on or we encountered a MISS case we can't
2878 __ bind(&slow_start);
2879 // Check that the function is really a JavaScript function.
2880 // r1: pushed function (to be verified)
2881 __ JumpIfSmi(a1, &slow);
2883 // Goto slow case if we do not have a function.
2884 __ GetObjectType(a1, t0, t0);
2885 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2886 __ Branch(&have_js_function);
2890 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2891 FrameScope scope(masm, StackFrame::INTERNAL);
2893 // Push the receiver and the function and feedback info.
2894 __ Push(a1, a2, a3);
2897 Runtime::FunctionId id = GetICState() == DEFAULT
2898 ? Runtime::kCallIC_Miss
2899 : Runtime::kCallIC_Customization_Miss;
2900 __ CallRuntime(id, 3);
2902 // Move result to a1 and exit the internal frame.
2907 // StringCharCodeAtGenerator.
2908 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2909 DCHECK(!t0.is(index_));
2910 DCHECK(!t0.is(result_));
2911 DCHECK(!t0.is(object_));
2912 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2913 // If the receiver is a smi trigger the non-string case.
2914 __ JumpIfSmi(object_, receiver_not_string_);
2916 // Fetch the instance type of the receiver into result register.
2917 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2918 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2919 // If the receiver is not a string trigger the non-string case.
2920 __ And(t0, result_, Operand(kIsNotStringMask));
2921 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
2924 // If the index is non-smi trigger the non-smi case.
2925 __ JumpIfNotSmi(index_, &index_not_smi_);
2927 __ bind(&got_smi_index_);
2929 // Check for index out of range.
2930 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
2931 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
2933 __ sra(index_, index_, kSmiTagSize);
2935 StringCharLoadGenerator::Generate(masm,
2941 __ sll(result_, result_, kSmiTagSize);
2946 void StringCharCodeAtGenerator::GenerateSlow(
2947 MacroAssembler* masm, EmbedMode embed_mode,
2948 const RuntimeCallHelper& call_helper) {
2949 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2951 // Index is not a smi.
2952 __ bind(&index_not_smi_);
2953 // If index is a heap number, try converting it to an integer.
2956 Heap::kHeapNumberMapRootIndex,
2959 call_helper.BeforeCall(masm);
2960 // Consumed by runtime conversion function:
2961 if (embed_mode == PART_OF_IC_HANDLER) {
2962 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2963 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2965 __ Push(object_, index_);
2967 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2968 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2970 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2971 // NumberToSmi discards numbers that are not exact integers.
2972 __ CallRuntime(Runtime::kNumberToSmi, 1);
2975 // Save the conversion result before the pop instructions below
2976 // have a chance to overwrite it.
2977 __ Move(index_, v0);
2978 if (embed_mode == PART_OF_IC_HANDLER) {
2979 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2980 LoadWithVectorDescriptor::SlotRegister(), object_);
2984 // Reload the instance type.
2985 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2986 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2987 call_helper.AfterCall(masm);
2988 // If index is still not a smi, it must be out of range.
2989 __ JumpIfNotSmi(index_, index_out_of_range_);
2990 // Otherwise, return to the fast path.
2991 __ Branch(&got_smi_index_);
2993 // Call runtime. We get here when the receiver is a string and the
2994 // index is a number, but the code of getting the actual character
2995 // is too complex (e.g., when the string needs to be flattened).
2996 __ bind(&call_runtime_);
2997 call_helper.BeforeCall(masm);
2998 __ sll(index_, index_, kSmiTagSize);
2999 __ Push(object_, index_);
3000 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3002 __ Move(result_, v0);
3004 call_helper.AfterCall(masm);
3007 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3011 // -------------------------------------------------------------------------
3012 // StringCharFromCodeGenerator
3014 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3015 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3017 DCHECK(!t0.is(result_));
3018 DCHECK(!t0.is(code_));
3020 STATIC_ASSERT(kSmiTag == 0);
3021 STATIC_ASSERT(kSmiShiftSize == 0);
3022 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3023 __ And(t0, code_, Operand(kSmiTagMask |
3024 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3025 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
3027 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3028 // At this point code register contains smi tagged one-byte char code.
3029 STATIC_ASSERT(kSmiTag == 0);
3030 __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize);
3031 __ Addu(result_, result_, t0);
3032 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3033 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
3034 __ Branch(&slow_case_, eq, result_, Operand(t0));
3039 void StringCharFromCodeGenerator::GenerateSlow(
3040 MacroAssembler* masm,
3041 const RuntimeCallHelper& call_helper) {
3042 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3044 __ bind(&slow_case_);
3045 call_helper.BeforeCall(masm);
3047 __ CallRuntime(Runtime::kCharFromCode, 1);
3048 __ Move(result_, v0);
3050 call_helper.AfterCall(masm);
3053 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3057 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3060 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3065 String::Encoding encoding) {
3066 if (FLAG_debug_code) {
3067 // Check that destination is word aligned.
3068 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3070 kDestinationOfCopyNotAligned,
3075 // Assumes word reads and writes are little endian.
3076 // Nothing to do for zero characters.
3079 if (encoding == String::TWO_BYTE_ENCODING) {
3080 __ Addu(count, count, count);
3083 Register limit = count; // Read until dest equals this.
3084 __ Addu(limit, dest, Operand(count));
3086 Label loop_entry, loop;
3087 // Copy bytes from src to dest until dest hits limit.
3088 __ Branch(&loop_entry);
3090 __ lbu(scratch, MemOperand(src));
3091 __ Addu(src, src, Operand(1));
3092 __ sb(scratch, MemOperand(dest));
3093 __ Addu(dest, dest, Operand(1));
3094 __ bind(&loop_entry);
3095 __ Branch(&loop, lt, dest, Operand(limit));
3101 void SubStringStub::Generate(MacroAssembler* masm) {
3103 // Stack frame on entry.
3104 // ra: return address
3109 // This stub is called from the native-call %_SubString(...), so
3110 // nothing can be assumed about the arguments. It is tested that:
3111 // "string" is a sequential string,
3112 // both "from" and "to" are smis, and
3113 // 0 <= from <= to <= string.length.
3114 // If any of these assumptions fail, we call the runtime system.
3116 const int kToOffset = 0 * kPointerSize;
3117 const int kFromOffset = 1 * kPointerSize;
3118 const int kStringOffset = 2 * kPointerSize;
3120 __ lw(a2, MemOperand(sp, kToOffset));
3121 __ lw(a3, MemOperand(sp, kFromOffset));
3122 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3123 STATIC_ASSERT(kSmiTag == 0);
3124 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3126 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3127 // safe in this case.
3128 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
3129 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
3130 // Both a2 and a3 are untagged integers.
3132 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3134 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3135 __ Subu(a2, a2, a3);
3137 // Make sure first argument is a string.
3138 __ lw(v0, MemOperand(sp, kStringOffset));
3139 __ JumpIfSmi(v0, &runtime);
3140 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3141 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3142 __ And(t0, a1, Operand(kIsNotStringMask));
3144 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3147 __ Branch(&single_char, eq, a2, Operand(1));
3149 // Short-cut for the case of trivial substring.
3151 // v0: original string
3152 // a2: result string length
3153 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
3155 // Return original string.
3156 __ Branch(&return_v0, eq, a2, Operand(t0));
3157 // Longer than original string's length or negative: unsafe arguments.
3158 __ Branch(&runtime, hi, a2, Operand(t0));
3159 // Shorter than original string's length: an actual substring.
3161 // Deal with different string types: update the index if necessary
3162 // and put the underlying string into t1.
3163 // v0: original string
3164 // a1: instance type
3166 // a3: from index (untagged)
3167 Label underlying_unpacked, sliced_string, seq_or_external_string;
3168 // If the string is not indirect, it can only be sequential or external.
3169 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3170 STATIC_ASSERT(kIsIndirectStringMask != 0);
3171 __ And(t0, a1, Operand(kIsIndirectStringMask));
3172 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
3173 // t0 is used as a scratch register and can be overwritten in either case.
3174 __ And(t0, a1, Operand(kSlicedNotConsMask));
3175 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
3176 // Cons string. Check whether it is flat, then fetch first part.
3177 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
3178 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
3179 __ Branch(&runtime, ne, t1, Operand(t0));
3180 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
3181 // Update instance type.
3182 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3183 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3184 __ jmp(&underlying_unpacked);
3186 __ bind(&sliced_string);
3187 // Sliced string. Fetch parent and correct start index by offset.
3188 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3189 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3190 __ sra(t0, t0, 1); // Add offset to index.
3191 __ Addu(a3, a3, t0);
3192 // Update instance type.
3193 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3194 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3195 __ jmp(&underlying_unpacked);
3197 __ bind(&seq_or_external_string);
3198 // Sequential or external string. Just move string to the expected register.
3201 __ bind(&underlying_unpacked);
3203 if (FLAG_string_slices) {
3205 // t1: underlying subject string
3206 // a1: instance type of underlying subject string
3208 // a3: adjusted start index (untagged)
3209 // Short slice. Copy instead of slicing.
3210 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3211 // Allocate new sliced string. At this point we do not reload the instance
3212 // type including the string encoding because we simply rely on the info
3213 // provided by the original string. It does not matter if the original
3214 // string's encoding is wrong because we always have to recheck encoding of
3215 // the newly created string's parent anyways due to externalized strings.
3216 Label two_byte_slice, set_slice_header;
3217 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3218 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3219 __ And(t0, a1, Operand(kStringEncodingMask));
3220 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
3221 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
3222 __ jmp(&set_slice_header);
3223 __ bind(&two_byte_slice);
3224 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
3225 __ bind(&set_slice_header);
3227 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3228 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3231 __ bind(©_routine);
3234 // t1: underlying subject string
3235 // a1: instance type of underlying subject string
3237 // a3: adjusted start index (untagged)
3238 Label two_byte_sequential, sequential_string, allocate_result;
3239 STATIC_ASSERT(kExternalStringTag != 0);
3240 STATIC_ASSERT(kSeqStringTag == 0);
3241 __ And(t0, a1, Operand(kExternalStringTag));
3242 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
3244 // Handle external string.
3245 // Rule out short external strings.
3246 STATIC_ASSERT(kShortExternalStringTag != 0);
3247 __ And(t0, a1, Operand(kShortExternalStringTag));
3248 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3249 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
3250 // t1 already points to the first character of underlying string.
3251 __ jmp(&allocate_result);
3253 __ bind(&sequential_string);
3254 // Locate first character of underlying subject string.
3255 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3256 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3258 __ bind(&allocate_result);
3259 // Sequential acii string. Allocate the result.
3260 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3261 __ And(t0, a1, Operand(kStringEncodingMask));
3262 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
3264 // Allocate and copy the resulting ASCII string.
3265 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
3267 // Locate first character of substring to copy.
3268 __ Addu(t1, t1, a3);
3270 // Locate first character of result.
3271 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3273 // v0: result string
3274 // a1: first character of result string
3275 // a2: result string length
3276 // t1: first character of substring to copy
3277 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3278 StringHelper::GenerateCopyCharacters(
3279 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
3282 // Allocate and copy the resulting two-byte string.
3283 __ bind(&two_byte_sequential);
3284 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
3286 // Locate first character of substring to copy.
3287 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3289 __ Addu(t1, t1, t0);
3290 // Locate first character of result.
3291 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3293 // v0: result string.
3294 // a1: first character of result.
3295 // a2: result length.
3296 // t1: first character of substring to copy.
3297 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3298 StringHelper::GenerateCopyCharacters(
3299 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
3301 __ bind(&return_v0);
3302 Counters* counters = isolate()->counters();
3303 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
3306 // Just jump to runtime to create the sub string.
3308 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3310 __ bind(&single_char);
3311 // v0: original string
3312 // a1: instance type
3314 // a3: from index (untagged)
3316 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3317 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3318 generator.GenerateFast(masm);
3320 generator.SkipSlow(masm, &runtime);
3324 void ToNumberStub::Generate(MacroAssembler* masm) {
3325 // The ToNumber stub takes one argument in a0.
3327 __ JumpIfNotSmi(a0, ¬_smi);
3328 __ Ret(USE_DELAY_SLOT);
3332 Label not_heap_number;
3333 __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3334 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3336 // a1: instance type.
3337 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3338 __ Ret(USE_DELAY_SLOT);
3340 __ bind(¬_heap_number);
3342 Label not_string, slow_string;
3343 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3344 // Check if string has a cached array index.
3345 __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3346 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3347 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3348 __ IndexFromHash(a2, a0);
3349 __ Ret(USE_DELAY_SLOT);
3351 __ bind(&slow_string);
3352 __ push(a0); // Push argument.
3353 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3354 __ bind(¬_string);
3357 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3358 __ Ret(USE_DELAY_SLOT);
3359 __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3360 __ bind(¬_oddball);
3362 __ push(a0); // Push argument.
3363 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3367 void ToStringStub::Generate(MacroAssembler* masm) {
3368 // The ToString stub takes on argument in a0.
3370 __ JumpIfSmi(a0, &is_number);
3373 __ GetObjectType(a0, a1, a1);
3375 // a1: receiver instance type
3376 __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
3377 __ Ret(USE_DELAY_SLOT);
3379 __ bind(¬_string);
3381 Label not_heap_number;
3382 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3383 __ bind(&is_number);
3384 NumberToStringStub stub(isolate());
3385 __ TailCallStub(&stub);
3386 __ bind(¬_heap_number);
3389 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3390 __ Ret(USE_DELAY_SLOT);
3391 __ lw(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
3392 __ bind(¬_oddball);
3394 __ push(a0); // Push argument.
3395 __ TailCallRuntime(Runtime::kToString, 1, 1);
3399 void StringHelper::GenerateFlatOneByteStringEquals(
3400 MacroAssembler* masm, Register left, Register right, Register scratch1,
3401 Register scratch2, Register scratch3) {
3402 Register length = scratch1;
3405 Label strings_not_equal, check_zero_length;
3406 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
3407 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3408 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3409 __ bind(&strings_not_equal);
3410 DCHECK(is_int16(NOT_EQUAL));
3411 __ Ret(USE_DELAY_SLOT);
3412 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3414 // Check if the length is zero.
3415 Label compare_chars;
3416 __ bind(&check_zero_length);
3417 STATIC_ASSERT(kSmiTag == 0);
3418 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3419 DCHECK(is_int16(EQUAL));
3420 __ Ret(USE_DELAY_SLOT);
3421 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3423 // Compare characters.
3424 __ bind(&compare_chars);
3426 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3427 v0, &strings_not_equal);
3429 // Characters are equal.
3430 __ Ret(USE_DELAY_SLOT);
3431 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3435 void StringHelper::GenerateCompareFlatOneByteStrings(
3436 MacroAssembler* masm, Register left, Register right, Register scratch1,
3437 Register scratch2, Register scratch3, Register scratch4) {
3438 Label result_not_equal, compare_lengths;
3439 // Find minimum length and length difference.
3440 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
3441 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3442 __ Subu(scratch3, scratch1, Operand(scratch2));
3443 Register length_delta = scratch3;
3444 __ slt(scratch4, scratch2, scratch1);
3445 __ Movn(scratch1, scratch2, scratch4);
3446 Register min_length = scratch1;
3447 STATIC_ASSERT(kSmiTag == 0);
3448 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3451 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3452 scratch4, v0, &result_not_equal);
3454 // Compare lengths - strings up to min-length are equal.
3455 __ bind(&compare_lengths);
3456 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3457 // Use length_delta as result if it's zero.
3458 __ mov(scratch2, length_delta);
3459 __ mov(scratch4, zero_reg);
3460 __ mov(v0, zero_reg);
3462 __ bind(&result_not_equal);
3463 // Conditionally update the result based either on length_delta or
3464 // the last comparion performed in the loop above.
3466 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3467 __ li(v0, Operand(Smi::FromInt(GREATER)));
3468 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3469 __ li(v0, Operand(Smi::FromInt(LESS)));
3475 void StringHelper::GenerateOneByteCharsCompareLoop(
3476 MacroAssembler* masm, Register left, Register right, Register length,
3477 Register scratch1, Register scratch2, Register scratch3,
3478 Label* chars_not_equal) {
3479 // Change index to run from -length to -1 by adding length to string
3480 // start. This means that loop ends when index reaches zero, which
3481 // doesn't need an additional compare.
3482 __ SmiUntag(length);
3483 __ Addu(scratch1, length,
3484 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3485 __ Addu(left, left, Operand(scratch1));
3486 __ Addu(right, right, Operand(scratch1));
3487 __ Subu(length, zero_reg, length);
3488 Register index = length; // index = -length;
3494 __ Addu(scratch3, left, index);
3495 __ lbu(scratch1, MemOperand(scratch3));
3496 __ Addu(scratch3, right, index);
3497 __ lbu(scratch2, MemOperand(scratch3));
3498 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3499 __ Addu(index, index, 1);
3500 __ Branch(&loop, ne, index, Operand(zero_reg));
3504 void StringCompareStub::Generate(MacroAssembler* masm) {
3507 Counters* counters = isolate()->counters();
3509 // Stack frame on entry.
3510 // sp[0]: right string
3511 // sp[4]: left string
3512 __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3513 __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3516 __ Branch(¬_same, ne, a0, Operand(a1));
3517 STATIC_ASSERT(EQUAL == 0);
3518 STATIC_ASSERT(kSmiTag == 0);
3519 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3520 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3525 // Check that both objects are sequential one-byte strings.
3526 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3528 // Compare flat ASCII strings natively. Remove arguments from stack first.
3529 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3530 __ Addu(sp, sp, Operand(2 * kPointerSize));
3531 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3534 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3538 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3539 // ----------- S t a t e -------------
3542 // -- ra : return address
3543 // -----------------------------------
3545 // Load a2 with the allocation site. We stick an undefined dummy value here
3546 // and replace it with the real allocation site later when we instantiate this
3547 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3548 __ li(a2, handle(isolate()->heap()->undefined_value()));
3550 // Make sure that we actually patched the allocation site.
3551 if (FLAG_debug_code) {
3552 __ And(at, a2, Operand(kSmiTagMask));
3553 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3554 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
3555 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3556 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
3559 // Tail call into the stub that handles binary operations with allocation
3561 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3562 __ TailCallStub(&stub);
3566 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3567 DCHECK(state() == CompareICState::SMI);
3570 __ JumpIfNotSmi(a2, &miss);
3572 if (GetCondition() == eq) {
3573 // For equality we do not care about the sign of the result.
3574 __ Ret(USE_DELAY_SLOT);
3575 __ Subu(v0, a0, a1);
3577 // Untag before subtracting to avoid handling overflow.
3580 __ Ret(USE_DELAY_SLOT);
3581 __ Subu(v0, a1, a0);
3589 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3590 DCHECK(state() == CompareICState::NUMBER);
3593 Label unordered, maybe_undefined1, maybe_undefined2;
3596 if (left() == CompareICState::SMI) {
3597 __ JumpIfNotSmi(a1, &miss);
3599 if (right() == CompareICState::SMI) {
3600 __ JumpIfNotSmi(a0, &miss);
3603 // Inlining the double comparison and falling back to the general compare
3604 // stub if NaN is involved.
3605 // Load left and right operand.
3606 Label done, left, left_smi, right_smi;
3607 __ JumpIfSmi(a0, &right_smi);
3608 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3610 __ Subu(a2, a0, Operand(kHeapObjectTag));
3611 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3613 __ bind(&right_smi);
3614 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3615 FPURegister single_scratch = f6;
3616 __ mtc1(a2, single_scratch);
3617 __ cvt_d_w(f2, single_scratch);
3620 __ JumpIfSmi(a1, &left_smi);
3621 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3623 __ Subu(a2, a1, Operand(kHeapObjectTag));
3624 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3627 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3628 single_scratch = f8;
3629 __ mtc1(a2, single_scratch);
3630 __ cvt_d_w(f0, single_scratch);
3634 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3635 Label fpu_eq, fpu_lt;
3636 // Test if equal, and also handle the unordered/NaN case.
3637 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3639 // Test if less (unordered case is already handled).
3640 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3642 // Otherwise it's greater, so just fall thru, and return.
3643 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3644 __ Ret(USE_DELAY_SLOT);
3645 __ li(v0, Operand(GREATER));
3648 __ Ret(USE_DELAY_SLOT);
3649 __ li(v0, Operand(EQUAL));
3652 __ Ret(USE_DELAY_SLOT);
3653 __ li(v0, Operand(LESS));
3655 __ bind(&unordered);
3656 __ bind(&generic_stub);
3657 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3658 CompareICState::GENERIC, CompareICState::GENERIC);
3659 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3661 __ bind(&maybe_undefined1);
3662 if (Token::IsOrderedRelationalCompareOp(op())) {
3663 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3664 __ Branch(&miss, ne, a0, Operand(at));
3665 __ JumpIfSmi(a1, &unordered);
3666 __ GetObjectType(a1, a2, a2);
3667 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3671 __ bind(&maybe_undefined2);
3672 if (Token::IsOrderedRelationalCompareOp(op())) {
3673 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3674 __ Branch(&unordered, eq, a1, Operand(at));
3682 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3683 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3686 // Registers containing left and right operands respectively.
3688 Register right = a0;
3692 // Check that both operands are heap objects.
3693 __ JumpIfEitherSmi(left, right, &miss);
3695 // Check that both operands are internalized strings.
3696 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3697 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3698 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3699 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3700 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3701 __ Or(tmp1, tmp1, Operand(tmp2));
3702 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3703 __ Branch(&miss, ne, at, Operand(zero_reg));
3705 // Make sure a0 is non-zero. At this point input operands are
3706 // guaranteed to be non-zero.
3707 DCHECK(right.is(a0));
3708 STATIC_ASSERT(EQUAL == 0);
3709 STATIC_ASSERT(kSmiTag == 0);
3711 // Internalized strings are compared by identity.
3712 __ Ret(ne, left, Operand(right));
3713 DCHECK(is_int16(EQUAL));
3714 __ Ret(USE_DELAY_SLOT);
3715 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3722 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3723 DCHECK(state() == CompareICState::UNIQUE_NAME);
3724 DCHECK(GetCondition() == eq);
3727 // Registers containing left and right operands respectively.
3729 Register right = a0;
3733 // Check that both operands are heap objects.
3734 __ JumpIfEitherSmi(left, right, &miss);
3736 // Check that both operands are unique names. This leaves the instance
3737 // types loaded in tmp1 and tmp2.
3738 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3739 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3740 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3741 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3743 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3744 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3749 // Unique names are compared by identity.
3751 __ Branch(&done, ne, left, Operand(right));
3752 // Make sure a0 is non-zero. At this point input operands are
3753 // guaranteed to be non-zero.
3754 DCHECK(right.is(a0));
3755 STATIC_ASSERT(EQUAL == 0);
3756 STATIC_ASSERT(kSmiTag == 0);
3757 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3766 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3767 DCHECK(state() == CompareICState::STRING);
3770 bool equality = Token::IsEqualityOp(op());
3772 // Registers containing left and right operands respectively.
3774 Register right = a0;
3781 // Check that both operands are heap objects.
3782 __ JumpIfEitherSmi(left, right, &miss);
3784 // Check that both operands are strings. This leaves the instance
3785 // types loaded in tmp1 and tmp2.
3786 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3787 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3788 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3789 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3790 STATIC_ASSERT(kNotStringTag != 0);
3791 __ Or(tmp3, tmp1, tmp2);
3792 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3793 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3795 // Fast check for identical strings.
3796 Label left_ne_right;
3797 STATIC_ASSERT(EQUAL == 0);
3798 STATIC_ASSERT(kSmiTag == 0);
3799 __ Branch(&left_ne_right, ne, left, Operand(right));
3800 __ Ret(USE_DELAY_SLOT);
3801 __ mov(v0, zero_reg); // In the delay slot.
3802 __ bind(&left_ne_right);
3804 // Handle not identical strings.
3806 // Check that both strings are internalized strings. If they are, we're done
3807 // because we already know they are not identical. We know they are both
3810 DCHECK(GetCondition() == eq);
3811 STATIC_ASSERT(kInternalizedTag == 0);
3812 __ Or(tmp3, tmp1, Operand(tmp2));
3813 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3815 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3816 // Make sure a0 is non-zero. At this point input operands are
3817 // guaranteed to be non-zero.
3818 DCHECK(right.is(a0));
3819 __ Ret(USE_DELAY_SLOT);
3820 __ mov(v0, a0); // In the delay slot.
3821 __ bind(&is_symbol);
3824 // Check that both strings are sequential one-byte.
3826 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3829 // Compare flat one-byte strings. Returns when done.
3831 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3834 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3838 // Handle more complex cases in runtime.
3840 __ Push(left, right);
3842 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3844 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3852 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3853 DCHECK(state() == CompareICState::OBJECT);
3855 __ And(a2, a1, Operand(a0));
3856 __ JumpIfSmi(a2, &miss);
3858 __ GetObjectType(a0, a2, a2);
3859 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3860 __ GetObjectType(a1, a2, a2);
3861 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3863 DCHECK(GetCondition() == eq);
3864 __ Ret(USE_DELAY_SLOT);
3865 __ subu(v0, a0, a1);
3872 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3874 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3876 __ JumpIfSmi(a2, &miss);
3877 __ GetWeakValue(t0, cell);
3878 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3879 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3880 __ Branch(&miss, ne, a2, Operand(t0));
3881 __ Branch(&miss, ne, a3, Operand(t0));
3883 __ Ret(USE_DELAY_SLOT);
3884 __ subu(v0, a0, a1);
3891 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3893 // Call the runtime system in a fresh internal frame.
3894 FrameScope scope(masm, StackFrame::INTERNAL);
3896 __ Push(ra, a1, a0);
3897 __ li(t0, Operand(Smi::FromInt(op())));
3898 __ addiu(sp, sp, -kPointerSize);
3899 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3901 __ sw(t0, MemOperand(sp)); // In the delay slot.
3902 // Compute the entry point of the rewritten stub.
3903 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3904 // Restore registers.
3911 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3912 // Make place for arguments to fit C calling convention. Most of the callers
3913 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3914 // so they handle stack restoring and we don't have to do that here.
3915 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3916 // kCArgsSlotsSize stack space after the call.
3917 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
3918 // Place the return address on the stack, making the call
3919 // GC safe. The RegExp backend also relies on this.
3920 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
3921 __ Call(t9); // Call the C++ function.
3922 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
3924 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3925 // In case of an error the return address may point to a memory area
3926 // filled with kZapValue by the GC.
3927 // Dereference the address and check for this.
3928 __ lw(t0, MemOperand(t9));
3929 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
3930 Operand(reinterpret_cast<uint32_t>(kZapValue)));
3936 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3939 reinterpret_cast<intptr_t>(GetCode().location());
3940 __ Move(t9, target);
3941 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3946 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3950 Register properties,
3952 Register scratch0) {
3953 DCHECK(name->IsUniqueName());
3954 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3955 // not equal to the name and kProbes-th slot is not used (its name is the
3956 // undefined value), it guarantees the hash table doesn't contain the
3957 // property. It's true even if some slots represent deleted properties
3958 // (their names are the hole value).
3959 for (int i = 0; i < kInlinedProbes; i++) {
3960 // scratch0 points to properties hash.
3961 // Compute the masked index: (hash + i + i * i) & mask.
3962 Register index = scratch0;
3963 // Capacity is smi 2^n.
3964 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
3965 __ Subu(index, index, Operand(1));
3966 __ And(index, index, Operand(
3967 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
3969 // Scale the index by multiplying by the entry size.
3970 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3971 __ sll(at, index, 1);
3972 __ Addu(index, index, at);
3974 Register entity_name = scratch0;
3975 // Having undefined at this place means the name is not contained.
3976 STATIC_ASSERT(kSmiTagSize == 1);
3977 Register tmp = properties;
3978 __ sll(scratch0, index, 1);
3979 __ Addu(tmp, properties, scratch0);
3980 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3982 DCHECK(!tmp.is(entity_name));
3983 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3984 __ Branch(done, eq, entity_name, Operand(tmp));
3986 // Load the hole ready for use below:
3987 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
3989 // Stop if found the property.
3990 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
3993 __ Branch(&good, eq, entity_name, Operand(tmp));
3995 // Check if the entry name is not a unique name.
3996 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
3998 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
3999 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4002 // Restore the properties.
4004 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4007 const int spill_mask =
4008 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
4009 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4011 __ MultiPush(spill_mask);
4012 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4013 __ li(a1, Operand(Handle<Name>(name)));
4014 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4017 __ MultiPop(spill_mask);
4019 __ Branch(done, eq, at, Operand(zero_reg));
4020 __ Branch(miss, ne, at, Operand(zero_reg));
4024 // Probe the name dictionary in the |elements| register. Jump to the
4025 // |done| label if a property with the given name is found. Jump to
4026 // the |miss| label otherwise.
4027 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4028 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4034 Register scratch2) {
4035 DCHECK(!elements.is(scratch1));
4036 DCHECK(!elements.is(scratch2));
4037 DCHECK(!name.is(scratch1));
4038 DCHECK(!name.is(scratch2));
4040 __ AssertName(name);
4042 // Compute the capacity mask.
4043 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
4044 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
4045 __ Subu(scratch1, scratch1, Operand(1));
4047 // Generate an unrolled loop that performs a few probes before
4048 // giving up. Measurements done on Gmail indicate that 2 probes
4049 // cover ~93% of loads from dictionaries.
4050 for (int i = 0; i < kInlinedProbes; i++) {
4051 // Compute the masked index: (hash + i + i * i) & mask.
4052 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4054 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4055 // the hash in a separate instruction. The value hash + i + i * i is right
4056 // shifted in the following and instruction.
4057 DCHECK(NameDictionary::GetProbeOffset(i) <
4058 1 << (32 - Name::kHashFieldOffset));
4059 __ Addu(scratch2, scratch2, Operand(
4060 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4062 __ srl(scratch2, scratch2, Name::kHashShift);
4063 __ And(scratch2, scratch1, scratch2);
4065 // Scale the index by multiplying by the element size.
4066 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4067 // scratch2 = scratch2 * 3.
4069 __ sll(at, scratch2, 1);
4070 __ Addu(scratch2, scratch2, at);
4072 // Check if the key is identical to the name.
4073 __ sll(at, scratch2, 2);
4074 __ Addu(scratch2, elements, at);
4075 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
4076 __ Branch(done, eq, name, Operand(at));
4079 const int spill_mask =
4080 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
4081 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4082 ~(scratch1.bit() | scratch2.bit());
4084 __ MultiPush(spill_mask);
4086 DCHECK(!elements.is(a1));
4088 __ Move(a0, elements);
4090 __ Move(a0, elements);
4093 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4095 __ mov(scratch2, a2);
4097 __ MultiPop(spill_mask);
4099 __ Branch(done, ne, at, Operand(zero_reg));
4100 __ Branch(miss, eq, at, Operand(zero_reg));
4104 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4105 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4106 // we cannot call anything that could cause a GC from this stub.
4108 // result: NameDictionary to probe
4110 // dictionary: NameDictionary to probe.
4111 // index: will hold an index of entry if lookup is successful.
4112 // might alias with result_.
4114 // result_ is zero if lookup failed, non zero otherwise.
4116 Register result = v0;
4117 Register dictionary = a0;
4119 Register index = a2;
4122 Register undefined = t1;
4123 Register entry_key = t2;
4125 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4127 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
4128 __ sra(mask, mask, kSmiTagSize);
4129 __ Subu(mask, mask, Operand(1));
4131 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4133 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4135 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4136 // Compute the masked index: (hash + i + i * i) & mask.
4137 // Capacity is smi 2^n.
4139 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4140 // the hash in a separate instruction. The value hash + i + i * i is right
4141 // shifted in the following and instruction.
4142 DCHECK(NameDictionary::GetProbeOffset(i) <
4143 1 << (32 - Name::kHashFieldOffset));
4144 __ Addu(index, hash, Operand(
4145 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4147 __ mov(index, hash);
4149 __ srl(index, index, Name::kHashShift);
4150 __ And(index, mask, index);
4152 // Scale the index by multiplying by the entry size.
4153 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4156 __ sll(index, index, 1);
4157 __ Addu(index, index, at);
4160 STATIC_ASSERT(kSmiTagSize == 1);
4161 __ sll(index, index, 2);
4162 __ Addu(index, index, dictionary);
4163 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
4165 // Having undefined at this place means the name is not contained.
4166 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4168 // Stop if found the property.
4169 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4171 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4172 // Check if the entry name is not a unique name.
4173 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4175 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4176 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4180 __ bind(&maybe_in_dictionary);
4181 // If we are doing negative lookup then probing failure should be
4182 // treated as a lookup success. For positive lookup probing failure
4183 // should be treated as lookup failure.
4184 if (mode() == POSITIVE_LOOKUP) {
4185 __ Ret(USE_DELAY_SLOT);
4186 __ mov(result, zero_reg);
4189 __ bind(&in_dictionary);
4190 __ Ret(USE_DELAY_SLOT);
4193 __ bind(¬_in_dictionary);
4194 __ Ret(USE_DELAY_SLOT);
4195 __ mov(result, zero_reg);
4199 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4201 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4203 // Hydrogen code stubs need stub2 at snapshot time.
4204 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4209 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4210 // the value has just been written into the object, now this stub makes sure
4211 // we keep the GC informed. The word in the object where the value has been
4212 // written is in the address register.
4213 void RecordWriteStub::Generate(MacroAssembler* masm) {
4214 Label skip_to_incremental_noncompacting;
4215 Label skip_to_incremental_compacting;
4217 // The first two branch+nop instructions are generated with labels so as to
4218 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4219 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4220 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4221 // incremental heap marking.
4222 // See RecordWriteStub::Patch for details.
4223 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4225 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4228 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4229 __ RememberedSetHelper(object(),
4232 save_fp_regs_mode(),
4233 MacroAssembler::kReturnAtEnd);
4237 __ bind(&skip_to_incremental_noncompacting);
4238 GenerateIncremental(masm, INCREMENTAL);
4240 __ bind(&skip_to_incremental_compacting);
4241 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4243 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4244 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4246 PatchBranchIntoNop(masm, 0);
4247 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4251 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4254 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4255 Label dont_need_remembered_set;
4257 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4258 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4260 &dont_need_remembered_set);
4262 __ CheckPageFlag(regs_.object(),
4264 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4266 &dont_need_remembered_set);
4268 // First notify the incremental marker if necessary, then update the
4270 CheckNeedsToInformIncrementalMarker(
4271 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4272 InformIncrementalMarker(masm);
4273 regs_.Restore(masm);
4274 __ RememberedSetHelper(object(),
4277 save_fp_regs_mode(),
4278 MacroAssembler::kReturnAtEnd);
4280 __ bind(&dont_need_remembered_set);
4283 CheckNeedsToInformIncrementalMarker(
4284 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4285 InformIncrementalMarker(masm);
4286 regs_.Restore(masm);
4291 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4292 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4293 int argument_count = 3;
4294 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4296 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4297 DCHECK(!address.is(regs_.object()));
4298 DCHECK(!address.is(a0));
4299 __ Move(address, regs_.address());
4300 __ Move(a0, regs_.object());
4301 __ Move(a1, address);
4302 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4304 AllowExternalCallThatCantCauseGC scope(masm);
4306 ExternalReference::incremental_marking_record_write_function(isolate()),
4308 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4312 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4313 MacroAssembler* masm,
4314 OnNoNeedToInformIncrementalMarker on_no_need,
4317 Label need_incremental;
4318 Label need_incremental_pop_scratch;
4320 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4321 __ lw(regs_.scratch1(),
4322 MemOperand(regs_.scratch0(),
4323 MemoryChunk::kWriteBarrierCounterOffset));
4324 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4325 __ sw(regs_.scratch1(),
4326 MemOperand(regs_.scratch0(),
4327 MemoryChunk::kWriteBarrierCounterOffset));
4328 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4330 // Let's look at the color of the object: If it is not black we don't have
4331 // to inform the incremental marker.
4332 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4334 regs_.Restore(masm);
4335 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4336 __ RememberedSetHelper(object(),
4339 save_fp_regs_mode(),
4340 MacroAssembler::kReturnAtEnd);
4347 // Get the value from the slot.
4348 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4350 if (mode == INCREMENTAL_COMPACTION) {
4351 Label ensure_not_white;
4353 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4354 regs_.scratch1(), // Scratch.
4355 MemoryChunk::kEvacuationCandidateMask,
4359 __ CheckPageFlag(regs_.object(),
4360 regs_.scratch1(), // Scratch.
4361 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4365 __ bind(&ensure_not_white);
4368 // We need extra registers for this, so we push the object and the address
4369 // register temporarily.
4370 __ Push(regs_.object(), regs_.address());
4371 __ EnsureNotWhite(regs_.scratch0(), // The value.
4372 regs_.scratch1(), // Scratch.
4373 regs_.object(), // Scratch.
4374 regs_.address(), // Scratch.
4375 &need_incremental_pop_scratch);
4376 __ Pop(regs_.object(), regs_.address());
4378 regs_.Restore(masm);
4379 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4380 __ RememberedSetHelper(object(),
4383 save_fp_regs_mode(),
4384 MacroAssembler::kReturnAtEnd);
4389 __ bind(&need_incremental_pop_scratch);
4390 __ Pop(regs_.object(), regs_.address());
4392 __ bind(&need_incremental);
4394 // Fall through when we need to inform the incremental marker.
4398 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4399 // ----------- S t a t e -------------
4400 // -- a0 : element value to store
4401 // -- a3 : element index as smi
4402 // -- sp[0] : array literal index in function as smi
4403 // -- sp[4] : array literal
4404 // clobbers a1, a2, t0
4405 // -----------------------------------
4408 Label double_elements;
4410 Label slow_elements;
4411 Label fast_elements;
4413 // Get array literal index, array literal and its map.
4414 __ lw(t0, MemOperand(sp, 0 * kPointerSize));
4415 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
4416 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4418 __ CheckFastElements(a2, t1, &double_elements);
4419 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4420 __ JumpIfSmi(a0, &smi_element);
4421 __ CheckFastSmiElements(a2, t1, &fast_elements);
4423 // Store into the array literal requires a elements transition. Call into
4425 __ bind(&slow_elements);
4427 __ Push(a1, a3, a0);
4428 __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4429 __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset));
4431 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4433 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4434 __ bind(&fast_elements);
4435 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4436 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4437 __ Addu(t2, t1, t2);
4438 __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4439 __ sw(a0, MemOperand(t2, 0));
4440 // Update the write barrier for the array store.
4441 __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4442 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4443 __ Ret(USE_DELAY_SLOT);
4446 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4447 // and value is Smi.
4448 __ bind(&smi_element);
4449 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4450 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4451 __ Addu(t2, t1, t2);
4452 __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize));
4453 __ Ret(USE_DELAY_SLOT);
4456 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4457 __ bind(&double_elements);
4458 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4459 __ StoreNumberToDoubleElements(a0, a3, t1, t3, t5, a2, &slow_elements);
4460 __ Ret(USE_DELAY_SLOT);
4465 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4466 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4467 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4468 int parameter_count_offset =
4469 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4470 __ lw(a1, MemOperand(fp, parameter_count_offset));
4471 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4472 __ Addu(a1, a1, Operand(1));
4474 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4475 __ sll(a1, a1, kPointerSizeLog2);
4476 __ Ret(USE_DELAY_SLOT);
4477 __ Addu(sp, sp, a1);
4481 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4482 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4483 LoadICStub stub(isolate(), state());
4484 stub.GenerateForTrampoline(masm);
4488 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4489 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4490 KeyedLoadICStub stub(isolate(), state());
4491 stub.GenerateForTrampoline(masm);
4495 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4496 EmitLoadTypeFeedbackVector(masm, a2);
4497 CallICStub stub(isolate(), state());
4498 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4502 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4503 EmitLoadTypeFeedbackVector(masm, a2);
4504 CallIC_ArrayStub stub(isolate(), state());
4505 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4509 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4512 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4513 GenerateImpl(masm, true);
4517 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4518 Register receiver_map, Register scratch1,
4519 Register scratch2, bool is_polymorphic,
4521 // feedback initially contains the feedback array
4522 Label next_loop, prepare_next;
4523 Label start_polymorphic;
4525 Register cached_map = scratch1;
4528 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4529 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4530 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4531 // found, now call handler.
4532 Register handler = feedback;
4533 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4534 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4538 Register length = scratch2;
4539 __ bind(&start_polymorphic);
4540 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4541 if (!is_polymorphic) {
4542 // If the IC could be monomorphic we have to make sure we don't go past the
4543 // end of the feedback array.
4544 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4547 Register too_far = length;
4548 Register pointer_reg = feedback;
4550 // +-----+------+------+-----+-----+ ... ----+
4551 // | map | len | wm0 | h0 | wm1 | hN |
4552 // +-----+------+------+-----+-----+ ... ----+
4556 // pointer_reg too_far
4557 // aka feedback scratch2
4558 // also need receiver_map
4559 // use cached_map (scratch1) to look in the weak map values.
4560 __ sll(at, length, kPointerSizeLog2 - kSmiTagSize);
4561 __ Addu(too_far, feedback, Operand(at));
4562 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4563 __ Addu(pointer_reg, feedback,
4564 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4566 __ bind(&next_loop);
4567 __ lw(cached_map, MemOperand(pointer_reg));
4568 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4569 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4570 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
4571 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4574 __ bind(&prepare_next);
4575 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4576 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4578 // We exhausted our array of map handler pairs.
4583 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4584 Register receiver_map, Register feedback,
4585 Register vector, Register slot,
4586 Register scratch, Label* compare_map,
4587 Label* load_smi_map, Label* try_array) {
4588 __ JumpIfSmi(receiver, load_smi_map);
4589 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4590 __ bind(compare_map);
4591 Register cached_map = scratch;
4592 // Move the weak map into the weak_cell register.
4593 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4594 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4595 Register handler = feedback;
4597 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4598 __ Addu(handler, vector, Operand(at));
4600 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4601 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4606 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4607 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4608 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4609 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4610 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4611 Register feedback = t0;
4612 Register receiver_map = t1;
4613 Register scratch1 = t4;
4615 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4616 __ Addu(feedback, vector, Operand(at));
4617 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4619 // Try to quickly handle the monomorphic case without knowing for sure
4620 // if we have a weak cell in feedback. We do know it's safe to look
4621 // at WeakCell::kValueOffset.
4622 Label try_array, load_smi_map, compare_map;
4623 Label not_array, miss;
4624 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4625 scratch1, &compare_map, &load_smi_map, &try_array);
4627 // Is it a fixed array?
4628 __ bind(&try_array);
4629 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4630 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4631 __ Branch(¬_array, ne, at, Operand(scratch1));
4632 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
4634 __ bind(¬_array);
4635 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4636 __ Branch(&miss, ne, at, Operand(feedback));
4637 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4638 Code::ComputeHandlerFlags(Code::LOAD_IC));
4639 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4640 receiver, name, feedback,
4641 receiver_map, scratch1, t5);
4644 LoadIC::GenerateMiss(masm);
4646 __ bind(&load_smi_map);
4647 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4648 __ jmp(&compare_map);
4652 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4653 GenerateImpl(masm, false);
4657 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4658 GenerateImpl(masm, true);
4662 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4663 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4664 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4665 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4666 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4667 Register feedback = t0;
4668 Register receiver_map = t1;
4669 Register scratch1 = t4;
4671 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4672 __ Addu(feedback, vector, Operand(at));
4673 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4675 // Try to quickly handle the monomorphic case without knowing for sure
4676 // if we have a weak cell in feedback. We do know it's safe to look
4677 // at WeakCell::kValueOffset.
4678 Label try_array, load_smi_map, compare_map;
4679 Label not_array, miss;
4680 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4681 scratch1, &compare_map, &load_smi_map, &try_array);
4683 __ bind(&try_array);
4684 // Is it a fixed array?
4685 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4686 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4687 __ Branch(¬_array, ne, at, Operand(scratch1));
4688 // We have a polymorphic element handler.
4689 __ JumpIfNotSmi(key, &miss);
4691 Label polymorphic, try_poly_name;
4692 __ bind(&polymorphic);
4693 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, true, &miss);
4695 __ bind(¬_array);
4697 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4698 __ Branch(&try_poly_name, ne, at, Operand(feedback));
4699 Handle<Code> megamorphic_stub =
4700 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4701 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4703 __ bind(&try_poly_name);
4704 // We might have a name in feedback, and a fixed array in the next slot.
4705 __ Branch(&miss, ne, key, Operand(feedback));
4706 // If the name comparison succeeded, we know we have a fixed array with
4707 // at least one map/handler pair.
4708 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4709 __ Addu(feedback, vector, Operand(at));
4711 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4712 HandleArrayCases(masm, feedback, receiver_map, scratch1, t5, false, &miss);
4715 KeyedLoadIC::GenerateMiss(masm);
4717 __ bind(&load_smi_map);
4718 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4719 __ jmp(&compare_map);
4723 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4724 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4725 VectorStoreICStub stub(isolate(), state());
4726 stub.GenerateForTrampoline(masm);
4730 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4731 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4732 VectorKeyedStoreICStub stub(isolate(), state());
4733 stub.GenerateForTrampoline(masm);
4737 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4738 GenerateImpl(masm, false);
4742 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4743 GenerateImpl(masm, true);
4747 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4748 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4749 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4750 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4751 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
4752 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4753 Register feedback = t1;
4754 Register receiver_map = t2;
4755 Register scratch1 = t5;
4757 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4758 __ Addu(feedback, vector, Operand(scratch1));
4759 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4761 // Try to quickly handle the monomorphic case without knowing for sure
4762 // if we have a weak cell in feedback. We do know it's safe to look
4763 // at WeakCell::kValueOffset.
4764 Label try_array, load_smi_map, compare_map;
4765 Label not_array, miss;
4766 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4767 scratch1, &compare_map, &load_smi_map, &try_array);
4769 // Is it a fixed array?
4770 __ bind(&try_array);
4771 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4772 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4773 __ Branch(¬_array, ne, scratch1, Operand(at));
4775 Register scratch2 = t4;
4776 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4779 __ bind(¬_array);
4780 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4781 __ Branch(&miss, ne, feedback, Operand(at));
4782 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4783 Code::ComputeHandlerFlags(Code::STORE_IC));
4784 masm->isolate()->stub_cache()->GenerateProbe(
4785 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4786 scratch1, scratch2);
4789 StoreIC::GenerateMiss(masm);
4791 __ bind(&load_smi_map);
4792 __ Branch(USE_DELAY_SLOT, &compare_map);
4793 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4797 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4798 GenerateImpl(masm, false);
4802 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4803 GenerateImpl(masm, true);
4807 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4808 Register receiver_map, Register scratch1,
4809 Register scratch2, Label* miss) {
4810 // feedback initially contains the feedback array
4811 Label next_loop, prepare_next;
4812 Label start_polymorphic;
4813 Label transition_call;
4815 Register cached_map = scratch1;
4816 Register too_far = scratch2;
4817 Register pointer_reg = feedback;
4818 __ lw(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4820 // +-----+------+------+-----+-----+-----+ ... ----+
4821 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4822 // +-----+------+------+-----+-----+ ----+ ... ----+
4826 // pointer_reg too_far
4827 // aka feedback scratch2
4828 // also need receiver_map
4829 // use cached_map (scratch1) to look in the weak map values.
4830 __ sll(scratch1, too_far, kPointerSizeLog2 - kSmiTagSize);
4831 __ Addu(too_far, feedback, Operand(scratch1));
4832 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4833 __ Addu(pointer_reg, feedback,
4834 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4836 __ bind(&next_loop);
4837 __ lw(cached_map, MemOperand(pointer_reg));
4838 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4839 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4840 // Is it a transitioning store?
4841 __ lw(too_far, MemOperand(pointer_reg, kPointerSize));
4842 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4843 __ Branch(&transition_call, ne, too_far, Operand(at));
4844 __ lw(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4845 __ Addu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4848 __ bind(&transition_call);
4849 __ lw(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4850 __ JumpIfSmi(too_far, miss);
4852 __ lw(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4854 // Load the map into the correct register.
4855 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4856 __ mov(feedback, too_far);
4858 __ Addu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4861 __ bind(&prepare_next);
4862 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4863 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4865 // We exhausted our array of map handler pairs.
4870 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4871 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4872 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4873 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4874 Register slot = VectorStoreICDescriptor::SlotRegister(); // t0
4875 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4876 Register feedback = t1;
4877 Register receiver_map = t2;
4878 Register scratch1 = t5;
4880 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4881 __ Addu(feedback, vector, Operand(scratch1));
4882 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4884 // Try to quickly handle the monomorphic case without knowing for sure
4885 // if we have a weak cell in feedback. We do know it's safe to look
4886 // at WeakCell::kValueOffset.
4887 Label try_array, load_smi_map, compare_map;
4888 Label not_array, miss;
4889 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4890 scratch1, &compare_map, &load_smi_map, &try_array);
4892 __ bind(&try_array);
4893 // Is it a fixed array?
4894 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4895 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4896 __ Branch(¬_array, ne, scratch1, Operand(at));
4898 // We have a polymorphic element handler.
4899 Label polymorphic, try_poly_name;
4900 __ bind(&polymorphic);
4902 Register scratch2 = t4;
4904 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4907 __ bind(¬_array);
4909 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4910 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4911 Handle<Code> megamorphic_stub =
4912 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4913 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4915 __ bind(&try_poly_name);
4916 // We might have a name in feedback, and a fixed array in the next slot.
4917 __ Branch(&miss, ne, key, Operand(feedback));
4918 // If the name comparison succeeded, we know we have a fixed array with
4919 // at least one map/handler pair.
4920 __ sll(scratch1, slot, kPointerSizeLog2 - kSmiTagSize);
4921 __ Addu(feedback, vector, Operand(scratch1));
4923 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4924 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4928 KeyedStoreIC::GenerateMiss(masm);
4930 __ bind(&load_smi_map);
4931 __ Branch(USE_DELAY_SLOT, &compare_map);
4932 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4936 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4937 if (masm->isolate()->function_entry_hook() != NULL) {
4938 ProfileEntryHookStub stub(masm->isolate());
4946 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4947 // The entry hook is a "push ra" instruction, followed by a call.
4948 // Note: on MIPS "push" is 2 instruction
4949 const int32_t kReturnAddressDistanceFromFunctionStart =
4950 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4952 // This should contain all kJSCallerSaved registers.
4953 const RegList kSavedRegs =
4954 kJSCallerSaved | // Caller saved registers.
4955 s5.bit(); // Saved stack pointer.
4957 // We also save ra, so the count here is one higher than the mask indicates.
4958 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4960 // Save all caller-save registers as this may be called from anywhere.
4961 __ MultiPush(kSavedRegs | ra.bit());
4963 // Compute the function's address for the first argument.
4964 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4966 // The caller's return address is above the saved temporaries.
4967 // Grab that for the second argument to the hook.
4968 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4970 // Align the stack if necessary.
4971 int frame_alignment = masm->ActivationFrameAlignment();
4972 if (frame_alignment > kPointerSize) {
4974 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4975 __ And(sp, sp, Operand(-frame_alignment));
4977 __ Subu(sp, sp, kCArgsSlotsSize);
4978 #if defined(V8_HOST_ARCH_MIPS)
4979 int32_t entry_hook =
4980 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4981 __ li(t9, Operand(entry_hook));
4983 // Under the simulator we need to indirect the entry hook through a
4984 // trampoline function at a known address.
4985 // It additionally takes an isolate as a third parameter.
4986 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4988 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4989 __ li(t9, Operand(ExternalReference(&dispatcher,
4990 ExternalReference::BUILTIN_CALL,
4993 // Call C function through t9 to conform ABI for PIC.
4996 // Restore the stack pointer if needed.
4997 if (frame_alignment > kPointerSize) {
5000 __ Addu(sp, sp, kCArgsSlotsSize);
5003 // Also pop ra to get Ret(0).
5004 __ MultiPop(kSavedRegs | ra.bit());
5010 static void CreateArrayDispatch(MacroAssembler* masm,
5011 AllocationSiteOverrideMode mode) {
5012 if (mode == DISABLE_ALLOCATION_SITES) {
5013 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5014 __ TailCallStub(&stub);
5015 } else if (mode == DONT_OVERRIDE) {
5016 int last_index = GetSequenceIndexFromFastElementsKind(
5017 TERMINAL_FAST_ELEMENTS_KIND);
5018 for (int i = 0; i <= last_index; ++i) {
5019 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5020 T stub(masm->isolate(), kind);
5021 __ TailCallStub(&stub, eq, a3, Operand(kind));
5024 // If we reached this point there is a problem.
5025 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5032 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5033 AllocationSiteOverrideMode mode) {
5034 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5035 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5036 // a0 - number of arguments
5037 // a1 - constructor?
5038 // sp[0] - last argument
5039 Label normal_sequence;
5040 if (mode == DONT_OVERRIDE) {
5041 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5042 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5043 STATIC_ASSERT(FAST_ELEMENTS == 2);
5044 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5045 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5046 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5048 // is the low bit set? If so, we are holey and that is good.
5049 __ And(at, a3, Operand(1));
5050 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5053 // look at the first argument
5054 __ lw(t1, MemOperand(sp, 0));
5055 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
5057 if (mode == DISABLE_ALLOCATION_SITES) {
5058 ElementsKind initial = GetInitialFastElementsKind();
5059 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5061 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5063 DISABLE_ALLOCATION_SITES);
5064 __ TailCallStub(&stub_holey);
5066 __ bind(&normal_sequence);
5067 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5069 DISABLE_ALLOCATION_SITES);
5070 __ TailCallStub(&stub);
5071 } else if (mode == DONT_OVERRIDE) {
5072 // We are going to create a holey array, but our kind is non-holey.
5073 // Fix kind and retry (only if we have an allocation site in the slot).
5074 __ Addu(a3, a3, Operand(1));
5076 if (FLAG_debug_code) {
5077 __ lw(t1, FieldMemOperand(a2, 0));
5078 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5079 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
5082 // Save the resulting elements kind in type info. We can't just store a3
5083 // in the AllocationSite::transition_info field because elements kind is
5084 // restricted to a portion of the field...upper bits need to be left alone.
5085 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5086 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5087 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5088 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5091 __ bind(&normal_sequence);
5092 int last_index = GetSequenceIndexFromFastElementsKind(
5093 TERMINAL_FAST_ELEMENTS_KIND);
5094 for (int i = 0; i <= last_index; ++i) {
5095 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5096 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5097 __ TailCallStub(&stub, eq, a3, Operand(kind));
5100 // If we reached this point there is a problem.
5101 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5109 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5110 int to_index = GetSequenceIndexFromFastElementsKind(
5111 TERMINAL_FAST_ELEMENTS_KIND);
5112 for (int i = 0; i <= to_index; ++i) {
5113 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5114 T stub(isolate, kind);
5116 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5117 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5124 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5125 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5127 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5129 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5134 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5136 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5137 for (int i = 0; i < 2; i++) {
5138 // For internal arrays we only need a few things.
5139 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5141 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5143 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5149 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5150 MacroAssembler* masm,
5151 AllocationSiteOverrideMode mode) {
5152 if (argument_count() == ANY) {
5153 Label not_zero_case, not_one_case;
5155 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5156 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5158 __ bind(¬_zero_case);
5159 __ Branch(¬_one_case, gt, a0, Operand(1));
5160 CreateArrayDispatchOneArgument(masm, mode);
5162 __ bind(¬_one_case);
5163 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5164 } else if (argument_count() == NONE) {
5165 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5166 } else if (argument_count() == ONE) {
5167 CreateArrayDispatchOneArgument(masm, mode);
5168 } else if (argument_count() == MORE_THAN_ONE) {
5169 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5176 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5177 // ----------- S t a t e -------------
5178 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5179 // -- a1 : constructor
5180 // -- a2 : AllocationSite or undefined
5181 // -- a3 : Original constructor
5182 // -- sp[0] : last argument
5183 // -----------------------------------
5185 if (FLAG_debug_code) {
5186 // The array construct code is only set for the global and natives
5187 // builtin Array functions which always have maps.
5189 // Initial map for the builtin Array function should be a map.
5190 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5191 // Will both indicate a NULL and a Smi.
5193 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5194 at, Operand(zero_reg));
5195 __ GetObjectType(t0, t0, t1);
5196 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5197 t1, Operand(MAP_TYPE));
5199 // We should either have undefined in a2 or a valid AllocationSite
5200 __ AssertUndefinedOrAllocationSite(a2, t0);
5204 __ Branch(&subclassing, ne, a1, Operand(a3));
5207 // Get the elements kind and case on that.
5208 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5209 __ Branch(&no_info, eq, a2, Operand(at));
5211 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5213 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5214 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5215 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5218 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5221 __ bind(&subclassing);
5226 switch (argument_count()) {
5229 __ li(at, Operand(2));
5230 __ addu(a0, a0, at);
5233 __ li(a0, Operand(2));
5236 __ li(a0, Operand(3));
5240 __ JumpToExternalReference(
5241 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5245 void InternalArrayConstructorStub::GenerateCase(
5246 MacroAssembler* masm, ElementsKind kind) {
5248 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5249 __ TailCallStub(&stub0, lo, a0, Operand(1));
5251 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5252 __ TailCallStub(&stubN, hi, a0, Operand(1));
5254 if (IsFastPackedElementsKind(kind)) {
5255 // We might need to create a holey array
5256 // look at the first argument.
5257 __ lw(at, MemOperand(sp, 0));
5259 InternalArraySingleArgumentConstructorStub
5260 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5261 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5264 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5265 __ TailCallStub(&stub1);
5269 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5270 // ----------- S t a t e -------------
5272 // -- a1 : constructor
5273 // -- sp[0] : return address
5274 // -- sp[4] : last argument
5275 // -----------------------------------
5277 if (FLAG_debug_code) {
5278 // The array construct code is only set for the global and natives
5279 // builtin Array functions which always have maps.
5281 // Initial map for the builtin Array function should be a map.
5282 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5283 // Will both indicate a NULL and a Smi.
5285 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5286 at, Operand(zero_reg));
5287 __ GetObjectType(a3, a3, t0);
5288 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5289 t0, Operand(MAP_TYPE));
5292 // Figure out the right elements kind.
5293 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5295 // Load the map's "bit field 2" into a3. We only need the first byte,
5296 // but the following bit field extraction takes care of that anyway.
5297 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5298 // Retrieve elements_kind from bit field 2.
5299 __ DecodeField<Map::ElementsKindBits>(a3);
5301 if (FLAG_debug_code) {
5303 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5305 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5306 a3, Operand(FAST_HOLEY_ELEMENTS));
5310 Label fast_elements_case;
5311 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5312 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5314 __ bind(&fast_elements_case);
5315 GenerateCase(masm, FAST_ELEMENTS);
5319 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5320 Register context_reg = cp;
5321 Register slot_reg = a2;
5322 Register result_reg = v0;
5325 // Go up context chain to the script context.
5326 for (int i = 0; i < depth(); ++i) {
5327 __ lw(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5328 context_reg = result_reg;
5331 // Load the PropertyCell value at the specified slot.
5332 __ sll(at, slot_reg, kPointerSizeLog2);
5333 __ Addu(at, at, Operand(context_reg));
5334 __ lw(result_reg, ContextOperand(at, 0));
5335 __ lw(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5337 // Check that value is not the_hole.
5338 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5339 __ Branch(&slow_case, eq, result_reg, Operand(at));
5342 // Fallback to the runtime.
5343 __ bind(&slow_case);
5344 __ SmiTag(slot_reg);
5346 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5350 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5351 Register context_reg = cp;
5352 Register slot_reg = a2;
5353 Register value_reg = a0;
5354 Register cell_reg = t0;
5355 Register cell_value_reg = t1;
5356 Register cell_details_reg = t2;
5357 Label fast_heapobject_case, fast_smi_case, slow_case;
5359 if (FLAG_debug_code) {
5360 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5361 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5364 // Go up context chain to the script context.
5365 for (int i = 0; i < depth(); ++i) {
5366 __ lw(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5367 context_reg = cell_reg;
5370 // Load the PropertyCell at the specified slot.
5371 __ sll(at, slot_reg, kPointerSizeLog2);
5372 __ Addu(at, at, Operand(context_reg));
5373 __ lw(cell_reg, ContextOperand(at, 0));
5375 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5376 __ lw(cell_details_reg,
5377 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5378 __ SmiUntag(cell_details_reg);
5379 __ And(cell_details_reg, cell_details_reg,
5380 PropertyDetails::PropertyCellTypeField::kMask |
5381 PropertyDetails::KindField::kMask |
5382 PropertyDetails::kAttributesReadOnlyMask);
5384 // Check if PropertyCell holds mutable data.
5385 Label not_mutable_data;
5386 __ Branch(¬_mutable_data, ne, cell_details_reg,
5387 Operand(PropertyDetails::PropertyCellTypeField::encode(
5388 PropertyCellType::kMutable) |
5389 PropertyDetails::KindField::encode(kData)));
5390 __ JumpIfSmi(value_reg, &fast_smi_case);
5391 __ bind(&fast_heapobject_case);
5392 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5393 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5394 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5395 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5396 // RecordWriteField clobbers the value register, so we need to reload.
5397 __ Ret(USE_DELAY_SLOT);
5398 __ lw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5399 __ bind(¬_mutable_data);
5401 // Check if PropertyCell value matches the new value (relevant for Constant,
5402 // ConstantType and Undefined cells).
5403 Label not_same_value;
5404 __ lw(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5405 __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg));
5406 // Make sure the PropertyCell is not marked READ_ONLY.
5407 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5408 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5409 if (FLAG_debug_code) {
5411 // This can only be true for Constant, ConstantType and Undefined cells,
5412 // because we never store the_hole via this stub.
5413 __ Branch(&done, eq, cell_details_reg,
5414 Operand(PropertyDetails::PropertyCellTypeField::encode(
5415 PropertyCellType::kConstant) |
5416 PropertyDetails::KindField::encode(kData)));
5417 __ Branch(&done, eq, cell_details_reg,
5418 Operand(PropertyDetails::PropertyCellTypeField::encode(
5419 PropertyCellType::kConstantType) |
5420 PropertyDetails::KindField::encode(kData)));
5421 __ Check(eq, kUnexpectedValue, cell_details_reg,
5422 Operand(PropertyDetails::PropertyCellTypeField::encode(
5423 PropertyCellType::kUndefined) |
5424 PropertyDetails::KindField::encode(kData)));
5428 __ bind(¬_same_value);
5430 // Check if PropertyCell contains data with constant type (and is not
5432 __ Branch(&slow_case, ne, cell_details_reg,
5433 Operand(PropertyDetails::PropertyCellTypeField::encode(
5434 PropertyCellType::kConstantType) |
5435 PropertyDetails::KindField::encode(kData)));
5437 // Now either both old and new values must be SMIs or both must be heap
5438 // objects with same map.
5439 Label value_is_heap_object;
5440 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5441 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5442 // Old and new values are SMIs, no need for a write barrier here.
5443 __ bind(&fast_smi_case);
5444 __ Ret(USE_DELAY_SLOT);
5445 __ sw(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5446 __ bind(&value_is_heap_object);
5447 __ JumpIfSmi(cell_value_reg, &slow_case);
5448 Register cell_value_map_reg = cell_value_reg;
5449 __ lw(cell_value_map_reg,
5450 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5451 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5452 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5454 // Fallback to the runtime.
5455 __ bind(&slow_case);
5456 __ SmiTag(slot_reg);
5457 __ Push(slot_reg, value_reg);
5458 __ TailCallRuntime(is_strict(language_mode())
5459 ? Runtime::kStoreGlobalViaContext_Strict
5460 : Runtime::kStoreGlobalViaContext_Sloppy,
5465 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5466 return ref0.address() - ref1.address();
5470 // Calls an API function. Allocates HandleScope, extracts returned value
5471 // from handle and propagates exceptions. Restores context. stack_space
5472 // - space to be unwound on exit (includes the call JS arguments space and
5473 // the additional space allocated for the fast call).
5474 static void CallApiFunctionAndReturn(
5475 MacroAssembler* masm, Register function_address,
5476 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5477 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5478 Isolate* isolate = masm->isolate();
5479 ExternalReference next_address =
5480 ExternalReference::handle_scope_next_address(isolate);
5481 const int kNextOffset = 0;
5482 const int kLimitOffset = AddressOffset(
5483 ExternalReference::handle_scope_limit_address(isolate), next_address);
5484 const int kLevelOffset = AddressOffset(
5485 ExternalReference::handle_scope_level_address(isolate), next_address);
5487 DCHECK(function_address.is(a1) || function_address.is(a2));
5489 Label profiler_disabled;
5490 Label end_profiler_check;
5491 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5492 __ lb(t9, MemOperand(t9, 0));
5493 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5495 // Additional parameter is the address of the actual callback.
5496 __ li(t9, Operand(thunk_ref));
5497 __ jmp(&end_profiler_check);
5499 __ bind(&profiler_disabled);
5500 __ mov(t9, function_address);
5501 __ bind(&end_profiler_check);
5503 // Allocate HandleScope in callee-save registers.
5504 __ li(s3, Operand(next_address));
5505 __ lw(s0, MemOperand(s3, kNextOffset));
5506 __ lw(s1, MemOperand(s3, kLimitOffset));
5507 __ lw(s2, MemOperand(s3, kLevelOffset));
5508 __ Addu(s2, s2, Operand(1));
5509 __ sw(s2, MemOperand(s3, kLevelOffset));
5511 if (FLAG_log_timer_events) {
5512 FrameScope frame(masm, StackFrame::MANUAL);
5513 __ PushSafepointRegisters();
5514 __ PrepareCallCFunction(1, a0);
5515 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5516 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5518 __ PopSafepointRegisters();
5521 // Native call returns to the DirectCEntry stub which redirects to the
5522 // return address pushed on stack (could have moved after GC).
5523 // DirectCEntry stub itself is generated early and never moves.
5524 DirectCEntryStub stub(isolate);
5525 stub.GenerateCall(masm, t9);
5527 if (FLAG_log_timer_events) {
5528 FrameScope frame(masm, StackFrame::MANUAL);
5529 __ PushSafepointRegisters();
5530 __ PrepareCallCFunction(1, a0);
5531 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5532 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5534 __ PopSafepointRegisters();
5537 Label promote_scheduled_exception;
5538 Label delete_allocated_handles;
5539 Label leave_exit_frame;
5540 Label return_value_loaded;
5542 // Load value from ReturnValue.
5543 __ lw(v0, return_value_operand);
5544 __ bind(&return_value_loaded);
5546 // No more valid handles (the result handle was the last one). Restore
5547 // previous handle scope.
5548 __ sw(s0, MemOperand(s3, kNextOffset));
5549 if (__ emit_debug_code()) {
5550 __ lw(a1, MemOperand(s3, kLevelOffset));
5551 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5553 __ Subu(s2, s2, Operand(1));
5554 __ sw(s2, MemOperand(s3, kLevelOffset));
5555 __ lw(at, MemOperand(s3, kLimitOffset));
5556 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5558 // Leave the API exit frame.
5559 __ bind(&leave_exit_frame);
5561 bool restore_context = context_restore_operand != NULL;
5562 if (restore_context) {
5563 __ lw(cp, *context_restore_operand);
5565 if (stack_space_offset != kInvalidStackOffset) {
5566 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5567 // so this must be accounted for.
5568 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5570 __ li(s0, Operand(stack_space));
5572 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5573 stack_space_offset != kInvalidStackOffset);
5575 // Check if the function scheduled an exception.
5576 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5577 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5578 __ lw(t1, MemOperand(at));
5579 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5583 // Re-throw by promoting a scheduled exception.
5584 __ bind(&promote_scheduled_exception);
5585 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5587 // HandleScope limit has changed. Delete allocated extensions.
5588 __ bind(&delete_allocated_handles);
5589 __ sw(s1, MemOperand(s3, kLimitOffset));
5592 __ PrepareCallCFunction(1, s1);
5593 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5594 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5597 __ jmp(&leave_exit_frame);
5601 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5602 const ParameterCount& argc,
5603 bool return_first_arg,
5604 bool call_data_undefined) {
5605 // ----------- S t a t e -------------
5607 // -- t0 : call_data
5609 // -- a1 : api_function_address
5610 // -- a3 : number of arguments if argc is a register
5613 // -- sp[0] : last argument
5615 // -- sp[(argc - 1)* 4] : first argument
5616 // -- sp[argc * 4] : receiver
5617 // -----------------------------------
5619 Register callee = a0;
5620 Register call_data = t0;
5621 Register holder = a2;
5622 Register api_function_address = a1;
5623 Register context = cp;
5625 typedef FunctionCallbackArguments FCA;
5627 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5628 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5629 STATIC_ASSERT(FCA::kDataIndex == 4);
5630 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5631 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5632 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5633 STATIC_ASSERT(FCA::kHolderIndex == 0);
5634 STATIC_ASSERT(FCA::kArgsLength == 7);
5636 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5638 // Save context, callee and call data.
5639 __ Push(context, callee, call_data);
5640 // Load context from callee.
5641 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5643 Register scratch = call_data;
5644 if (!call_data_undefined) {
5645 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5647 // Push return value and default return value.
5648 __ Push(scratch, scratch);
5649 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5650 // Push isolate and holder.
5651 __ Push(scratch, holder);
5653 // Prepare arguments.
5654 __ mov(scratch, sp);
5656 // Allocate the v8::Arguments structure in the arguments' space since
5657 // it's not controlled by GC.
5658 const int kApiStackSpace = 4;
5660 FrameScope frame_scope(masm, StackFrame::MANUAL);
5661 __ EnterExitFrame(false, kApiStackSpace);
5663 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5664 // a0 = FunctionCallbackInfo&
5665 // Arguments is after the return address.
5666 __ Addu(a0, sp, Operand(1 * kPointerSize));
5667 // FunctionCallbackInfo::implicit_args_
5668 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
5669 if (argc.is_immediate()) {
5670 // FunctionCallbackInfo::values_
5671 __ Addu(at, scratch,
5672 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5673 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5674 // FunctionCallbackInfo::length_ = argc
5675 __ li(at, Operand(argc.immediate()));
5676 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5677 // FunctionCallbackInfo::is_construct_call_ = 0
5678 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
5680 // FunctionCallbackInfo::values_
5681 __ sll(at, argc.reg(), kPointerSizeLog2);
5682 __ Addu(at, at, scratch);
5683 __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5684 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5685 // FunctionCallbackInfo::length_ = argc
5686 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5687 // FunctionCallbackInfo::is_construct_call_
5688 __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5689 __ sll(at, argc.reg(), kPointerSizeLog2);
5690 __ sw(at, MemOperand(a0, 3 * kPointerSize));
5693 ExternalReference thunk_ref =
5694 ExternalReference::invoke_function_callback(masm->isolate());
5696 AllowExternalCallThatCantCauseGC scope(masm);
5697 MemOperand context_restore_operand(
5698 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5699 // Stores return the first js argument.
5700 int return_value_offset = 0;
5701 if (return_first_arg) {
5702 return_value_offset = 2 + FCA::kArgsLength;
5704 return_value_offset = 2 + FCA::kReturnValueOffset;
5706 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5707 int stack_space = 0;
5708 int32_t stack_space_offset = 4 * kPointerSize;
5709 if (argc.is_immediate()) {
5710 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5711 stack_space_offset = kInvalidStackOffset;
5713 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5714 stack_space_offset, return_value_operand,
5715 &context_restore_operand);
5719 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5720 bool call_data_undefined = this->call_data_undefined();
5721 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5722 call_data_undefined);
5726 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5727 bool is_store = this->is_store();
5728 int argc = this->argc();
5729 bool call_data_undefined = this->call_data_undefined();
5730 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5731 call_data_undefined);
5735 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5736 // ----------- S t a t e -------------
5738 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5740 // -- a2 : api_function_address
5741 // -----------------------------------
5743 Register api_function_address = ApiGetterDescriptor::function_address();
5744 DCHECK(api_function_address.is(a2));
5746 __ mov(a0, sp); // a0 = Handle<Name>
5747 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5749 const int kApiStackSpace = 1;
5750 FrameScope frame_scope(masm, StackFrame::MANUAL);
5751 __ EnterExitFrame(false, kApiStackSpace);
5753 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5754 // a1 (internal::Object** args_) as the data.
5755 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
5756 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5758 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5760 ExternalReference thunk_ref =
5761 ExternalReference::invoke_accessor_getter_callback(isolate());
5762 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5763 kStackUnwindSpace, kInvalidStackOffset,
5764 MemOperand(fp, 6 * kPointerSize), NULL);
5770 } // namespace internal
5773 #endif // V8_TARGET_ARCH_MIPS