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.
7 #if V8_TARGET_ARCH_MIPS
9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h"
11 #include "src/code-stubs.h"
12 #include "src/codegen.h"
13 #include "src/ic/handler-compiler.h"
14 #include "src/ic/ic.h"
15 #include "src/ic/stub-cache.h"
16 #include "src/isolate.h"
17 #include "src/jsregexp.h"
18 #include "src/regexp-macro-assembler.h"
19 #include "src/runtime/runtime.h"
25 static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
28 Address deopt_handler = Runtime::FunctionForId(
29 Runtime::kArrayConstructor)->entry;
31 if (constant_stack_parameter_count == 0) {
32 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
33 JS_FUNCTION_STUB_MODE);
35 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
36 JS_FUNCTION_STUB_MODE);
41 static void InitializeInternalArrayConstructorDescriptor(
42 Isolate* isolate, CodeStubDescriptor* descriptor,
43 int constant_stack_parameter_count) {
44 Address deopt_handler = Runtime::FunctionForId(
45 Runtime::kInternalArrayConstructor)->entry;
47 if (constant_stack_parameter_count == 0) {
48 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
49 JS_FUNCTION_STUB_MODE);
51 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
52 JS_FUNCTION_STUB_MODE);
57 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
58 CodeStubDescriptor* descriptor) {
59 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
63 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
64 CodeStubDescriptor* descriptor) {
65 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
69 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
70 CodeStubDescriptor* descriptor) {
71 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
75 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
76 CodeStubDescriptor* descriptor) {
77 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
81 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
82 CodeStubDescriptor* descriptor) {
83 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
87 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
88 CodeStubDescriptor* descriptor) {
89 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
93 #define __ ACCESS_MASM(masm)
96 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
97 Condition cc, Strength strength);
98 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
104 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
109 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
110 ExternalReference miss) {
111 // Update the static counter each time a new code stub is generated.
112 isolate()->counters()->code_stubs()->Increment();
114 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
115 int param_count = descriptor.GetRegisterParameterCount();
117 // Call the runtime system in a fresh internal frame.
118 FrameScope scope(masm, StackFrame::INTERNAL);
119 DCHECK(param_count == 0 ||
120 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
121 // Push arguments, adjust sp.
122 __ Subu(sp, sp, Operand(param_count * kPointerSize));
123 for (int i = 0; i < param_count; ++i) {
124 // Store argument to stack.
125 __ sw(descriptor.GetRegisterParameter(i),
126 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
128 __ CallExternalReference(miss, param_count);
135 void DoubleToIStub::Generate(MacroAssembler* masm) {
136 Label out_of_range, only_low, negate, done;
137 Register input_reg = source();
138 Register result_reg = destination();
140 int double_offset = offset();
141 // Account for saved regs if input is sp.
142 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
145 GetRegisterThatIsNotOneOf(input_reg, result_reg);
147 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
149 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
150 DoubleRegister double_scratch = kLithiumScratchDouble;
152 __ Push(scratch, scratch2, scratch3);
154 if (!skip_fastpath()) {
155 // Load double input.
156 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
158 // Clear cumulative exception flags and save the FCSR.
159 __ cfc1(scratch2, FCSR);
160 __ ctc1(zero_reg, FCSR);
162 // Try a conversion to a signed integer.
163 __ Trunc_w_d(double_scratch, double_scratch);
164 // Move the converted value into the result register.
165 __ mfc1(scratch3, double_scratch);
167 // Retrieve and restore the FCSR.
168 __ cfc1(scratch, FCSR);
169 __ ctc1(scratch2, FCSR);
171 // Check for overflow and NaNs.
174 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
175 | kFCSRInvalidOpFlagMask);
176 // If we had no exceptions then set result_reg and we are done.
178 __ Branch(&error, ne, scratch, Operand(zero_reg));
179 __ Move(result_reg, scratch3);
184 // Load the double value and perform a manual truncation.
185 Register input_high = scratch2;
186 Register input_low = scratch3;
189 MemOperand(input_reg, double_offset + Register::kMantissaOffset));
191 MemOperand(input_reg, double_offset + Register::kExponentOffset));
193 Label normal_exponent, restore_sign;
194 // Extract the biased exponent in result.
197 HeapNumber::kExponentShift,
198 HeapNumber::kExponentBits);
200 // Check for Infinity and NaNs, which should return 0.
201 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
202 __ Movz(result_reg, zero_reg, scratch);
203 __ Branch(&done, eq, scratch, Operand(zero_reg));
205 // Express exponent as delta to (number of mantissa bits + 31).
208 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
210 // If the delta is strictly positive, all bits would be shifted away,
211 // which means that we can return 0.
212 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
213 __ mov(result_reg, zero_reg);
216 __ bind(&normal_exponent);
217 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
219 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
222 Register sign = result_reg;
224 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
226 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
227 // to check for this specific case.
228 Label high_shift_needed, high_shift_done;
229 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
230 __ mov(input_high, zero_reg);
231 __ Branch(&high_shift_done);
232 __ bind(&high_shift_needed);
234 // Set the implicit 1 before the mantissa part in input_high.
237 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
238 // Shift the mantissa bits to the correct position.
239 // We don't need to clear non-mantissa bits as they will be shifted away.
240 // If they weren't, it would mean that the answer is in the 32bit range.
241 __ sllv(input_high, input_high, scratch);
243 __ bind(&high_shift_done);
245 // Replace the shifted bits with bits from the lower mantissa word.
246 Label pos_shift, shift_done;
248 __ subu(scratch, at, scratch);
249 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
252 __ Subu(scratch, zero_reg, scratch);
253 __ sllv(input_low, input_low, scratch);
254 __ Branch(&shift_done);
257 __ srlv(input_low, input_low, scratch);
259 __ bind(&shift_done);
260 __ Or(input_high, input_high, Operand(input_low));
261 // Restore sign if necessary.
262 __ mov(scratch, sign);
265 __ Subu(result_reg, zero_reg, input_high);
266 __ Movz(result_reg, input_high, scratch);
270 __ Pop(scratch, scratch2, scratch3);
275 // Handle the case where the lhs and rhs are the same object.
276 // Equality is almost reflexive (everything but NaN), so this is a test
277 // for "identity and not NaN".
278 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
279 Condition cc, Strength strength) {
281 Label heap_number, return_equal;
282 Register exp_mask_reg = t5;
284 __ Branch(¬_identical, ne, a0, Operand(a1));
286 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
288 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
289 // so we do the second best thing - test it ourselves.
290 // They are both equal and they are not both Smis so both of them are not
291 // Smis. If it's not a heap number, then return equal.
292 __ GetObjectType(a0, t4, t4);
293 if (cc == less || cc == greater) {
294 // Call runtime on identical JSObjects.
295 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
296 // Call runtime on identical symbols since we need to throw a TypeError.
297 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
298 // Call runtime on identical SIMD values since we must throw a TypeError.
299 __ Branch(slow, eq, t4, Operand(FLOAT32X4_TYPE));
300 if (is_strong(strength)) {
301 // Call the runtime on anything that is converted in the semantics, since
302 // we need to throw a TypeError. Smis have already been ruled out.
303 __ Branch(&return_equal, eq, t4, Operand(HEAP_NUMBER_TYPE));
304 __ And(t4, t4, Operand(kIsNotStringMask));
305 __ Branch(slow, ne, t4, Operand(zero_reg));
308 __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE));
309 // Comparing JS objects with <=, >= is complicated.
311 __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
312 // Call runtime on identical symbols since we need to throw a TypeError.
313 __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
314 // Call runtime on identical SIMD values since we must throw a TypeError.
315 __ Branch(slow, eq, t4, Operand(FLOAT32X4_TYPE));
316 if (is_strong(strength)) {
317 // Call the runtime on anything that is converted in the semantics,
318 // since we need to throw a TypeError. Smis and heap numbers have
319 // already been ruled out.
320 __ And(t4, t4, Operand(kIsNotStringMask));
321 __ Branch(slow, ne, t4, Operand(zero_reg));
323 // Normally here we fall through to return_equal, but undefined is
324 // special: (undefined == undefined) == true, but
325 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
326 if (cc == less_equal || cc == greater_equal) {
327 __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE));
328 __ LoadRoot(t2, Heap::kUndefinedValueRootIndex);
329 __ Branch(&return_equal, ne, a0, Operand(t2));
330 DCHECK(is_int16(GREATER) && is_int16(LESS));
331 __ Ret(USE_DELAY_SLOT);
333 // undefined <= undefined should fail.
334 __ li(v0, Operand(GREATER));
336 // undefined >= undefined should fail.
337 __ li(v0, Operand(LESS));
343 __ bind(&return_equal);
344 DCHECK(is_int16(GREATER) && is_int16(LESS));
345 __ Ret(USE_DELAY_SLOT);
347 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
348 } else if (cc == greater) {
349 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
351 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
354 // For less and greater we don't have to check for NaN since the result of
355 // x < x is false regardless. For the others here is some code to check
357 if (cc != lt && cc != gt) {
358 __ bind(&heap_number);
359 // It is a heap number, so return non-equal if it's NaN and equal if it's
362 // The representation of NaN values has all exponent bits (52..62) set,
363 // and not all mantissa bits (0..51) clear.
364 // Read top bits of double representation (second word of value).
365 __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset));
366 // Test that exponent bits are all set.
367 __ And(t3, t2, Operand(exp_mask_reg));
368 // If all bits not set (ne cond), then not a NaN, objects are equal.
369 __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg));
371 // Shift out flag and all exponent bits, retaining only mantissa.
372 __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord);
373 // Or with all low-bits of mantissa.
374 __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
375 __ Or(v0, t3, Operand(t2));
376 // For equal we already have the right value in v0: Return zero (equal)
377 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
378 // not (it's a NaN). For <= and >= we need to load v0 with the failing
379 // value if it's a NaN.
381 // All-zero means Infinity means equal.
382 __ Ret(eq, v0, Operand(zero_reg));
383 DCHECK(is_int16(GREATER) && is_int16(LESS));
384 __ Ret(USE_DELAY_SLOT);
386 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
388 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
392 // No fall through here.
394 __ bind(¬_identical);
398 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
401 Label* both_loaded_as_doubles,
404 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
405 (lhs.is(a1) && rhs.is(a0)));
408 __ JumpIfSmi(lhs, &lhs_is_smi);
410 // Check whether the non-smi is a heap number.
411 __ GetObjectType(lhs, t4, t4);
413 // If lhs was not a number and rhs was a Smi then strict equality cannot
414 // succeed. Return non-equal (lhs is already not zero).
415 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
418 // Smi compared non-strictly with a non-Smi non-heap-number. Call
420 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
423 // Rhs is a smi, lhs is a number.
424 // Convert smi rhs to double.
425 __ sra(at, rhs, kSmiTagSize);
427 __ cvt_d_w(f14, f14);
428 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
430 // We now have both loaded as doubles.
431 __ jmp(both_loaded_as_doubles);
433 __ bind(&lhs_is_smi);
434 // Lhs is a Smi. Check whether the non-smi is a heap number.
435 __ GetObjectType(rhs, t4, t4);
437 // If lhs was not a number and rhs was a Smi then strict equality cannot
438 // succeed. Return non-equal.
439 __ Ret(USE_DELAY_SLOT, ne, t4, Operand(HEAP_NUMBER_TYPE));
440 __ li(v0, Operand(1));
442 // Smi compared non-strictly with a non-Smi non-heap-number. Call
444 __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE));
447 // Lhs is a smi, rhs is a number.
448 // Convert smi lhs to double.
449 __ sra(at, lhs, kSmiTagSize);
451 __ cvt_d_w(f12, f12);
452 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
453 // Fall through to both_loaded_as_doubles.
457 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
460 // If either operand is a JS object or an oddball value, then they are
461 // not equal since their pointers are different.
462 // There is no test for undetectability in strict equality.
463 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
464 Label first_non_object;
465 // Get the type of the first operand into a2 and compare it with
466 // FIRST_SPEC_OBJECT_TYPE.
467 __ GetObjectType(lhs, a2, a2);
468 __ Branch(&first_non_object, less, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
471 Label return_not_equal;
472 __ bind(&return_not_equal);
473 __ Ret(USE_DELAY_SLOT);
474 __ li(v0, Operand(1));
476 __ bind(&first_non_object);
477 // Check for oddballs: true, false, null, undefined.
478 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
480 __ GetObjectType(rhs, a3, a3);
481 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
483 // Check for oddballs: true, false, null, undefined.
484 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
486 // Now that we have the types we might as well check for
487 // internalized-internalized.
488 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
489 __ Or(a2, a2, Operand(a3));
490 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
491 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
495 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
498 Label* both_loaded_as_doubles,
499 Label* not_heap_numbers,
501 __ GetObjectType(lhs, a3, a2);
502 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
503 __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
504 // If first was a heap number & second wasn't, go to slow case.
505 __ Branch(slow, ne, a3, Operand(a2));
507 // Both are heap numbers. Load them up then jump to the code we have
509 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
510 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
512 __ jmp(both_loaded_as_doubles);
516 // Fast negative check for internalized-to-internalized equality.
517 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
520 Label* possible_strings,
521 Label* not_both_strings) {
522 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
523 (lhs.is(a1) && rhs.is(a0)));
525 // a2 is object type of rhs.
527 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
528 __ And(at, a2, Operand(kIsNotStringMask));
529 __ Branch(&object_test, ne, at, Operand(zero_reg));
530 __ And(at, a2, Operand(kIsNotInternalizedMask));
531 __ Branch(possible_strings, ne, at, Operand(zero_reg));
532 __ GetObjectType(rhs, a3, a3);
533 __ Branch(not_both_strings, ge, a3, Operand(FIRST_NONSTRING_TYPE));
534 __ And(at, a3, Operand(kIsNotInternalizedMask));
535 __ Branch(possible_strings, ne, at, Operand(zero_reg));
537 // Both are internalized strings. We already checked they weren't the same
538 // pointer so they are not equal.
539 __ Ret(USE_DELAY_SLOT);
540 __ li(v0, Operand(1)); // Non-zero indicates not equal.
542 __ bind(&object_test);
543 __ Branch(not_both_strings, lt, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
544 __ GetObjectType(rhs, a2, a3);
545 __ Branch(not_both_strings, lt, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
547 // If both objects are undetectable, they are equal. Otherwise, they
548 // are not equal, since they are different objects and an object is not
549 // equal to undefined.
550 __ lw(a3, FieldMemOperand(lhs, HeapObject::kMapOffset));
551 __ lbu(a2, FieldMemOperand(a2, Map::kBitFieldOffset));
552 __ lbu(a3, FieldMemOperand(a3, Map::kBitFieldOffset));
554 __ And(a0, a0, Operand(1 << Map::kIsUndetectable));
555 __ Ret(USE_DELAY_SLOT);
556 __ xori(v0, a0, 1 << Map::kIsUndetectable);
560 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
562 CompareICState::State expected,
565 if (expected == CompareICState::SMI) {
566 __ JumpIfNotSmi(input, fail);
567 } else if (expected == CompareICState::NUMBER) {
568 __ JumpIfSmi(input, &ok);
569 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
572 // We could be strict about internalized/string here, but as long as
573 // hydrogen doesn't care, the stub doesn't have to care either.
578 // On entry a1 and a2 are the values to be compared.
579 // On exit a0 is 0, positive or negative to indicate the result of
581 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
584 Condition cc = GetCondition();
587 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
588 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
590 Label slow; // Call builtin.
591 Label not_smis, both_loaded_as_doubles;
593 Label not_two_smis, smi_done;
595 __ JumpIfNotSmi(a2, ¬_two_smis);
598 __ Ret(USE_DELAY_SLOT);
600 __ bind(¬_two_smis);
602 // NOTICE! This code is only reached after a smi-fast-case check, so
603 // it is certain that at least one operand isn't a smi.
605 // Handle the case where the objects are identical. Either returns the answer
606 // or goes to slow. Only falls through if the objects were not identical.
607 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
609 // If either is a Smi (we know that not both are), then they can only
610 // be strictly equal if the other is a HeapNumber.
611 STATIC_ASSERT(kSmiTag == 0);
612 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
613 __ And(t2, lhs, Operand(rhs));
614 __ JumpIfNotSmi(t2, ¬_smis, t0);
615 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
616 // 1) Return the answer.
618 // 3) Fall through to both_loaded_as_doubles.
619 // 4) Jump to rhs_not_nan.
620 // In cases 3 and 4 we have found out we were dealing with a number-number
621 // comparison and the numbers have been loaded into f12 and f14 as doubles,
622 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
623 EmitSmiNonsmiComparison(masm, lhs, rhs,
624 &both_loaded_as_doubles, &slow, strict());
626 __ bind(&both_loaded_as_doubles);
627 // f12, f14 are the double representations of the left hand side
628 // and the right hand side if we have FPU. Otherwise a2, a3 represent
629 // left hand side and a0, a1 represent right hand side.
631 __ li(t0, Operand(LESS));
632 __ li(t1, Operand(GREATER));
633 __ li(t2, Operand(EQUAL));
635 // Check if either rhs or lhs is NaN.
636 __ BranchF(NULL, &nan, eq, f12, f14);
638 // Check if LESS condition is satisfied. If true, move conditionally
640 if (!IsMipsArchVariant(kMips32r6)) {
641 __ c(OLT, D, f12, f14);
643 // Use previous check to store conditionally to v0 oposite condition
644 // (GREATER). If rhs is equal to lhs, this will be corrected in next
647 // Check if EQUAL condition is satisfied. If true, move conditionally
649 __ c(EQ, D, f12, f14);
653 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
654 __ mov(v0, t0); // Return LESS as result.
656 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
657 __ mov(v0, t2); // Return EQUAL as result.
659 __ mov(v0, t1); // Return GREATER as result.
666 // NaN comparisons always fail.
667 // Load whatever we need in v0 to make the comparison fail.
668 DCHECK(is_int16(GREATER) && is_int16(LESS));
669 __ Ret(USE_DELAY_SLOT);
670 if (cc == lt || cc == le) {
671 __ li(v0, Operand(GREATER));
673 __ li(v0, Operand(LESS));
678 // At this point we know we are dealing with two different objects,
679 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
681 // This returns non-equal for some object types, or falls through if it
683 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
686 Label check_for_internalized_strings;
687 Label flat_string_check;
688 // Check for heap-number-heap-number comparison. Can jump to slow case,
689 // or load both doubles and jump to the code that handles
690 // that case. If the inputs are not doubles then jumps to
691 // check_for_internalized_strings.
692 // In this case a2 will contain the type of lhs_.
693 EmitCheckForTwoHeapNumbers(masm,
696 &both_loaded_as_doubles,
697 &check_for_internalized_strings,
700 __ bind(&check_for_internalized_strings);
701 if (cc == eq && !strict()) {
702 // Returns an answer for two internalized strings or two
703 // detectable objects.
704 // Otherwise jumps to string case or not both strings case.
705 // Assumes that a2 is the type of lhs_ on entry.
706 EmitCheckForInternalizedStringsOrObjects(
707 masm, lhs, rhs, &flat_string_check, &slow);
710 // Check for both being sequential one-byte strings,
711 // and inline if that is the case.
712 __ bind(&flat_string_check);
714 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
716 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
719 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, t0);
721 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, t0,
724 // Never falls through to here.
727 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
730 // Figure out which native to call and setup the arguments.
731 Builtins::JavaScript native;
733 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
736 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
737 int ncr; // NaN compare result.
738 if (cc == lt || cc == le) {
741 DCHECK(cc == gt || cc == ge); // Remaining cases.
744 __ li(a0, Operand(Smi::FromInt(ncr)));
748 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
749 // tagged as a small integer.
750 __ InvokeBuiltin(native, JUMP_FUNCTION);
757 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
760 __ PushSafepointRegisters();
765 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
768 __ PopSafepointRegisters();
773 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
774 // We don't allow a GC during a store buffer overflow so there is no need to
775 // store the registers in any particular way, but we do have to store and
777 __ MultiPush(kJSCallerSaved | ra.bit());
778 if (save_doubles()) {
779 __ MultiPushFPU(kCallerSavedFPU);
781 const int argument_count = 1;
782 const int fp_argument_count = 0;
783 const Register scratch = a1;
785 AllowExternalCallThatCantCauseGC scope(masm);
786 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
787 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
789 ExternalReference::store_buffer_overflow_function(isolate()),
791 if (save_doubles()) {
792 __ MultiPopFPU(kCallerSavedFPU);
795 __ MultiPop(kJSCallerSaved | ra.bit());
800 void MathPowStub::Generate(MacroAssembler* masm) {
801 const Register base = a1;
802 const Register exponent = MathPowTaggedDescriptor::exponent();
803 DCHECK(exponent.is(a2));
804 const Register heapnumbermap = t1;
805 const Register heapnumber = v0;
806 const DoubleRegister double_base = f2;
807 const DoubleRegister double_exponent = f4;
808 const DoubleRegister double_result = f0;
809 const DoubleRegister double_scratch = f6;
810 const FPURegister single_scratch = f8;
811 const Register scratch = t5;
812 const Register scratch2 = t3;
814 Label call_runtime, done, int_exponent;
815 if (exponent_type() == ON_STACK) {
816 Label base_is_smi, unpack_exponent;
817 // The exponent and base are supplied as arguments on the stack.
818 // This can only happen if the stub is called from non-optimized code.
819 // Load input parameters from stack to double registers.
820 __ lw(base, MemOperand(sp, 1 * kPointerSize));
821 __ lw(exponent, MemOperand(sp, 0 * kPointerSize));
823 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
825 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
826 __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset));
827 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
829 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
830 __ jmp(&unpack_exponent);
832 __ bind(&base_is_smi);
833 __ mtc1(scratch, single_scratch);
834 __ cvt_d_w(double_base, single_scratch);
835 __ bind(&unpack_exponent);
837 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
839 __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
840 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
841 __ ldc1(double_exponent,
842 FieldMemOperand(exponent, HeapNumber::kValueOffset));
843 } else if (exponent_type() == TAGGED) {
844 // Base is already in double_base.
845 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
847 __ ldc1(double_exponent,
848 FieldMemOperand(exponent, HeapNumber::kValueOffset));
851 if (exponent_type() != INTEGER) {
852 Label int_exponent_convert;
853 // Detect integer exponents stored as double.
854 __ EmitFPUTruncate(kRoundToMinusInf,
860 kCheckForInexactConversion);
861 // scratch2 == 0 means there was no conversion error.
862 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
864 if (exponent_type() == ON_STACK) {
865 // Detect square root case. Crankshaft detects constant +/-0.5 at
866 // compile time and uses DoMathPowHalf instead. We then skip this check
867 // for non-constant cases of +/-0.5 as these hardly occur.
870 __ Move(double_scratch, 0.5);
871 __ BranchF(USE_DELAY_SLOT,
877 // double_scratch can be overwritten in the delay slot.
878 // Calculates square root of base. Check for the special case of
879 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
880 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
881 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
882 __ neg_d(double_result, double_scratch);
884 // Add +0 to convert -0 to +0.
885 __ add_d(double_scratch, double_base, kDoubleRegZero);
886 __ sqrt_d(double_result, double_scratch);
889 __ bind(¬_plus_half);
890 __ Move(double_scratch, -0.5);
891 __ BranchF(USE_DELAY_SLOT,
897 // double_scratch can be overwritten in the delay slot.
898 // Calculates square root of base. Check for the special case of
899 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
900 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
901 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
902 __ Move(double_result, kDoubleRegZero);
904 // Add +0 to convert -0 to +0.
905 __ add_d(double_scratch, double_base, kDoubleRegZero);
906 __ Move(double_result, 1.);
907 __ sqrt_d(double_scratch, double_scratch);
908 __ div_d(double_result, double_result, double_scratch);
914 AllowExternalCallThatCantCauseGC scope(masm);
915 __ PrepareCallCFunction(0, 2, scratch2);
916 __ MovToFloatParameters(double_base, double_exponent);
918 ExternalReference::power_double_double_function(isolate()),
922 __ MovFromFloatResult(double_result);
925 __ bind(&int_exponent_convert);
928 // Calculate power with integer exponent.
929 __ bind(&int_exponent);
931 // Get two copies of exponent in the registers scratch and exponent.
932 if (exponent_type() == INTEGER) {
933 __ mov(scratch, exponent);
935 // Exponent has previously been stored into scratch as untagged integer.
936 __ mov(exponent, scratch);
939 __ mov_d(double_scratch, double_base); // Back up base.
940 __ Move(double_result, 1.0);
942 // Get absolute value of exponent.
943 Label positive_exponent;
944 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
945 __ Subu(scratch, zero_reg, scratch);
946 __ bind(&positive_exponent);
948 Label while_true, no_carry, loop_end;
949 __ bind(&while_true);
951 __ And(scratch2, scratch, 1);
953 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
954 __ mul_d(double_result, double_result, double_scratch);
957 __ sra(scratch, scratch, 1);
959 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
960 __ mul_d(double_scratch, double_scratch, double_scratch);
962 __ Branch(&while_true);
966 __ Branch(&done, ge, exponent, Operand(zero_reg));
967 __ Move(double_scratch, 1.0);
968 __ div_d(double_result, double_scratch, double_result);
969 // Test whether result is zero. Bail out to check for subnormal result.
970 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
971 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
973 // double_exponent may not contain the exponent value if the input was a
974 // smi. We set it with exponent value before bailing out.
975 __ mtc1(exponent, single_scratch);
976 __ cvt_d_w(double_exponent, single_scratch);
978 // Returning or bailing out.
979 Counters* counters = isolate()->counters();
980 if (exponent_type() == ON_STACK) {
981 // The arguments are still on the stack.
982 __ bind(&call_runtime);
983 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
985 // The stub is called from non-optimized code, which expects the result
986 // as heap number in exponent.
988 __ AllocateHeapNumber(
989 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
990 __ sdc1(double_result,
991 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
992 DCHECK(heapnumber.is(v0));
993 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
998 AllowExternalCallThatCantCauseGC scope(masm);
999 __ PrepareCallCFunction(0, 2, scratch);
1000 __ MovToFloatParameters(double_base, double_exponent);
1002 ExternalReference::power_double_double_function(isolate()),
1006 __ MovFromFloatResult(double_result);
1009 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1015 bool CEntryStub::NeedsImmovableCode() {
1020 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1021 CEntryStub::GenerateAheadOfTime(isolate);
1022 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1023 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1024 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1025 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1026 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1027 BinaryOpICStub::GenerateAheadOfTime(isolate);
1028 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1029 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1030 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1031 StoreFastElementStub::GenerateAheadOfTime(isolate);
1032 TypeofStub::GenerateAheadOfTime(isolate);
1036 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1037 StoreRegistersStateStub stub(isolate);
1042 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1043 RestoreRegistersStateStub stub(isolate);
1048 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1049 // Generate if not already in cache.
1050 SaveFPRegsMode mode = kSaveFPRegs;
1051 CEntryStub(isolate, 1, mode).GetCode();
1052 StoreBufferOverflowStub(isolate, mode).GetCode();
1053 isolate->set_fp_stubs_generated(true);
1057 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1058 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1063 void CEntryStub::Generate(MacroAssembler* masm) {
1064 // Called from JavaScript; parameters are on stack as if calling JS function
1065 // a0: number of arguments including receiver
1066 // a1: pointer to builtin function
1067 // fp: frame pointer (restored after C call)
1068 // sp: stack pointer (restored as callee's sp after C call)
1069 // cp: current context (C callee-saved)
1071 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1073 // Compute the argv pointer in a callee-saved register.
1074 __ sll(s1, a0, kPointerSizeLog2);
1075 __ Addu(s1, sp, s1);
1076 __ Subu(s1, s1, kPointerSize);
1078 // Enter the exit frame that transitions from JavaScript to C++.
1079 FrameScope scope(masm, StackFrame::MANUAL);
1080 __ EnterExitFrame(save_doubles());
1082 // s0: number of arguments including receiver (C callee-saved)
1083 // s1: pointer to first argument (C callee-saved)
1084 // s2: pointer to builtin function (C callee-saved)
1086 // Prepare arguments for C routine.
1090 // a1 = argv (set in the delay slot after find_ra below).
1092 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1093 // also need to reserve the 4 argument slots on the stack.
1095 __ AssertStackIsAligned();
1097 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1099 // To let the GC traverse the return address of the exit frames, we need to
1100 // know where the return address is. The CEntryStub is unmovable, so
1101 // we can store the address on the stack to be able to find it again and
1102 // we never have to restore it, because it will not change.
1103 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1104 // This branch-and-link sequence is needed to find the current PC on mips,
1105 // saved to the ra register.
1106 // Use masm-> here instead of the double-underscore macro since extra
1107 // coverage code can interfere with the proper calculation of ra.
1109 masm->bal(&find_ra); // bal exposes branch delay slot.
1111 masm->bind(&find_ra);
1113 // Adjust the value in ra to point to the correct return location, 2nd
1114 // instruction past the real call into C code (the jalr(t9)), and push it.
1115 // This is the return address of the exit frame.
1116 const int kNumInstructionsToJump = 5;
1117 masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize);
1118 masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1119 // Stack space reservation moved to the branch delay slot below.
1120 // Stack is still aligned.
1122 // Call the C routine.
1123 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1125 // Set up sp in the delay slot.
1126 masm->addiu(sp, sp, -kCArgsSlotsSize);
1127 // Make sure the stored 'ra' points to this position.
1128 DCHECK_EQ(kNumInstructionsToJump,
1129 masm->InstructionsGeneratedSince(&find_ra));
1133 // Check result for exception sentinel.
1134 Label exception_returned;
1135 __ LoadRoot(t0, Heap::kExceptionRootIndex);
1136 __ Branch(&exception_returned, eq, t0, Operand(v0));
1138 // Check that there is no pending exception, otherwise we
1139 // should have returned the exception sentinel.
1140 if (FLAG_debug_code) {
1142 ExternalReference pending_exception_address(
1143 Isolate::kPendingExceptionAddress, isolate());
1144 __ li(a2, Operand(pending_exception_address));
1145 __ lw(a2, MemOperand(a2));
1146 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1147 // Cannot use check here as it attempts to generate call into runtime.
1148 __ Branch(&okay, eq, t0, Operand(a2));
1149 __ stop("Unexpected pending exception");
1153 // Exit C frame and return.
1155 // sp: stack pointer
1156 // fp: frame pointer
1157 // s0: still holds argc (callee-saved).
1158 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1160 // Handling of exception.
1161 __ bind(&exception_returned);
1163 ExternalReference pending_handler_context_address(
1164 Isolate::kPendingHandlerContextAddress, isolate());
1165 ExternalReference pending_handler_code_address(
1166 Isolate::kPendingHandlerCodeAddress, isolate());
1167 ExternalReference pending_handler_offset_address(
1168 Isolate::kPendingHandlerOffsetAddress, isolate());
1169 ExternalReference pending_handler_fp_address(
1170 Isolate::kPendingHandlerFPAddress, isolate());
1171 ExternalReference pending_handler_sp_address(
1172 Isolate::kPendingHandlerSPAddress, isolate());
1174 // Ask the runtime for help to determine the handler. This will set v0 to
1175 // contain the current pending exception, don't clobber it.
1176 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1179 FrameScope scope(masm, StackFrame::MANUAL);
1180 __ PrepareCallCFunction(3, 0, a0);
1181 __ mov(a0, zero_reg);
1182 __ mov(a1, zero_reg);
1183 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1184 __ CallCFunction(find_handler, 3);
1187 // Retrieve the handler context, SP and FP.
1188 __ li(cp, Operand(pending_handler_context_address));
1189 __ lw(cp, MemOperand(cp));
1190 __ li(sp, Operand(pending_handler_sp_address));
1191 __ lw(sp, MemOperand(sp));
1192 __ li(fp, Operand(pending_handler_fp_address));
1193 __ lw(fp, MemOperand(fp));
1195 // If the handler is a JS frame, restore the context to the frame. Note that
1196 // the context will be set to (cp == 0) for non-JS frames.
1198 __ Branch(&zero, eq, cp, Operand(zero_reg));
1199 __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1202 // Compute the handler entry address and jump to it.
1203 __ li(a1, Operand(pending_handler_code_address));
1204 __ lw(a1, MemOperand(a1));
1205 __ li(a2, Operand(pending_handler_offset_address));
1206 __ lw(a2, MemOperand(a2));
1207 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1208 __ Addu(t9, a1, a2);
1213 void JSEntryStub::Generate(MacroAssembler* masm) {
1214 Label invoke, handler_entry, exit;
1215 Isolate* isolate = masm->isolate();
1218 // a0: entry address
1227 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1229 // Save callee saved registers on the stack.
1230 __ MultiPush(kCalleeSaved | ra.bit());
1232 // Save callee-saved FPU registers.
1233 __ MultiPushFPU(kCalleeSavedFPU);
1234 // Set up the reserved register for 0.0.
1235 __ Move(kDoubleRegZero, 0.0);
1238 // Load argv in s0 register.
1239 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1240 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1242 __ InitializeRootRegister();
1243 __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1245 // We build an EntryFrame.
1246 __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1247 int marker = type();
1248 __ li(t2, Operand(Smi::FromInt(marker)));
1249 __ li(t1, Operand(Smi::FromInt(marker)));
1250 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1252 __ lw(t0, MemOperand(t0));
1253 __ Push(t3, t2, t1, t0);
1254 // Set up frame pointer for the frame to be pushed.
1255 __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1258 // a0: entry_address
1260 // a2: receiver_pointer
1266 // function slot | entry frame
1268 // bad fp (0xff...f) |
1269 // callee saved registers + ra
1273 // If this is the outermost JS call, set js_entry_sp value.
1274 Label non_outermost_js;
1275 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1276 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1277 __ lw(t2, MemOperand(t1));
1278 __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
1279 __ sw(fp, MemOperand(t1));
1280 __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1283 __ nop(); // Branch delay slot nop.
1284 __ bind(&non_outermost_js);
1285 __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1289 // Jump to a faked try block that does the invoke, with a faked catch
1290 // block that sets the pending exception.
1292 __ bind(&handler_entry);
1293 handler_offset_ = handler_entry.pos();
1294 // Caught exception: Store result (exception) in the pending exception
1295 // field in the JSEnv and return a failure sentinel. Coming in here the
1296 // fp will be invalid because the PushStackHandler below sets it to 0 to
1297 // signal the existence of the JSEntry frame.
1298 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1300 __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
1301 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1302 __ b(&exit); // b exposes branch delay slot.
1303 __ nop(); // Branch delay slot nop.
1305 // Invoke: Link this frame into the handler chain.
1307 __ PushStackHandler();
1308 // If an exception not caught by another handler occurs, this handler
1309 // returns control to the code after the bal(&invoke) above, which
1310 // restores all kCalleeSaved registers (including cp and fp) to their
1311 // saved values before returning a failure to C.
1313 // Clear any pending exceptions.
1314 __ LoadRoot(t1, Heap::kTheHoleValueRootIndex);
1315 __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1317 __ sw(t1, MemOperand(t0));
1319 // Invoke the function by calling through JS entry trampoline builtin.
1320 // Notice that we cannot store a reference to the trampoline code directly in
1321 // this stub, because runtime stubs are not traversed when doing GC.
1324 // a0: entry_address
1326 // a2: receiver_pointer
1333 // callee saved registers + ra
1337 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1338 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1340 __ li(t0, Operand(construct_entry));
1342 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1343 __ li(t0, Operand(entry));
1345 __ lw(t9, MemOperand(t0)); // Deref address.
1347 // Call JSEntryTrampoline.
1348 __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1351 // Unlink this frame from the handler chain.
1352 __ PopStackHandler();
1354 __ bind(&exit); // v0 holds result
1355 // Check if the current stack frame is marked as the outermost JS frame.
1356 Label non_outermost_js_2;
1358 __ Branch(&non_outermost_js_2,
1361 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1362 __ li(t1, Operand(ExternalReference(js_entry_sp)));
1363 __ sw(zero_reg, MemOperand(t1));
1364 __ bind(&non_outermost_js_2);
1366 // Restore the top frame descriptors from the stack.
1368 __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1370 __ sw(t1, MemOperand(t0));
1372 // Reset the stack to the callee saved registers.
1373 __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1375 // Restore callee-saved fpu registers.
1376 __ MultiPopFPU(kCalleeSavedFPU);
1378 // Restore callee saved registers from the stack.
1379 __ MultiPop(kCalleeSaved | ra.bit());
1385 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1386 // Return address is in ra.
1389 Register receiver = LoadDescriptor::ReceiverRegister();
1390 Register index = LoadDescriptor::NameRegister();
1391 Register scratch = t1;
1392 Register result = v0;
1393 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1394 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1396 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1397 &miss, // When not a string.
1398 &miss, // When not a number.
1399 &miss, // When index out of range.
1400 STRING_INDEX_IS_ARRAY_INDEX,
1401 RECEIVER_IS_STRING);
1402 char_at_generator.GenerateFast(masm);
1405 StubRuntimeCallHelper call_helper;
1406 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1409 PropertyAccessCompiler::TailCallBuiltin(
1410 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1414 // Uses registers a0 to t0.
1415 // Expected input (depending on whether args are in registers or on the stack):
1416 // * object: a0 or at sp + 1 * kPointerSize.
1417 // * function: a1 or at sp.
1419 // An inlined call site may have been generated before calling this stub.
1420 // In this case the offset to the inline site to patch is passed on the stack,
1421 // in the safepoint slot for register t0.
1422 void InstanceofStub::Generate(MacroAssembler* masm) {
1423 // Call site inlining and patching implies arguments in registers.
1424 DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
1426 // Fixed register usage throughout the stub:
1427 const Register object = a0; // Object (lhs).
1428 Register map = a3; // Map of the object.
1429 const Register function = a1; // Function (rhs).
1430 const Register prototype = t0; // Prototype of the function.
1431 const Register inline_site = t5;
1432 const Register scratch = a2;
1434 const int32_t kDeltaToLoadBoolResult = 5 * kPointerSize;
1436 Label slow, loop, is_instance, is_not_instance, not_js_object;
1438 if (!HasArgsInRegisters()) {
1439 __ lw(object, MemOperand(sp, 1 * kPointerSize));
1440 __ lw(function, MemOperand(sp, 0));
1443 // Check that the left hand is a JS object and load map.
1444 __ JumpIfSmi(object, ¬_js_object);
1445 __ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
1447 // If there is a call site cache don't look in the global cache, but do the
1448 // real lookup and update the call site cache.
1449 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1451 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1452 __ Branch(&miss, ne, function, Operand(at));
1453 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1454 __ Branch(&miss, ne, map, Operand(at));
1455 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex);
1456 __ DropAndRet(HasArgsInRegisters() ? 0 : 2);
1461 // Get the prototype of the function.
1462 __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
1464 // Check that the function prototype is a JS object.
1465 __ JumpIfSmi(prototype, &slow);
1466 __ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
1468 // Update the global instanceof or call site inlined cache with the current
1469 // map and function. The cached answer will be set when it is known below.
1470 if (!HasCallSiteInlineCheck()) {
1471 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1472 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1474 DCHECK(HasArgsInRegisters());
1475 // Patch the (relocated) inlined map check.
1477 // The offset was stored in t0 safepoint slot.
1478 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1479 __ LoadFromSafepointRegisterSlot(scratch, t0);
1480 __ Subu(inline_site, ra, scratch);
1481 // Get the map location in scratch and patch it.
1482 __ GetRelocatedValue(inline_site, scratch, v1); // v1 used as scratch.
1483 __ sw(map, FieldMemOperand(scratch, Cell::kValueOffset));
1486 // |scratch| points at the beginning of the cell. Calculate the field
1487 // containing the map.
1488 __ Addu(function, scratch, Operand(Cell::kValueOffset - 1));
1489 __ RecordWriteField(scratch, Cell::kValueOffset, t4, function,
1490 kRAHasNotBeenSaved, kDontSaveFPRegs,
1491 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1494 // Register mapping: a3 is object map and t0 is function prototype.
1495 // Get prototype of object into a2.
1496 __ lw(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
1498 // We don't need map any more. Use it as a scratch register.
1499 Register scratch2 = map;
1502 // Loop through the prototype chain looking for the function prototype.
1503 __ LoadRoot(scratch2, Heap::kNullValueRootIndex);
1505 __ Branch(&is_instance, eq, scratch, Operand(prototype));
1506 __ Branch(&is_not_instance, eq, scratch, Operand(scratch2));
1507 __ lw(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
1508 __ lw(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
1511 __ bind(&is_instance);
1512 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1513 if (!HasCallSiteInlineCheck()) {
1514 __ mov(v0, zero_reg);
1515 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex);
1516 if (ReturnTrueFalseObject()) {
1517 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1520 // Patch the call site to return true.
1521 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1522 __ Addu(inline_site, inline_site, Operand(kDeltaToLoadBoolResult));
1523 // Get the boolean result location in scratch and patch it.
1524 __ PatchRelocatedValue(inline_site, scratch, v0);
1526 if (!ReturnTrueFalseObject()) {
1527 __ mov(v0, zero_reg);
1530 __ DropAndRet(HasArgsInRegisters() ? 0 : 2);
1532 __ bind(&is_not_instance);
1533 if (!HasCallSiteInlineCheck()) {
1534 __ li(v0, Operand(Smi::FromInt(1)));
1535 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex);
1536 if (ReturnTrueFalseObject()) {
1537 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1540 // Patch the call site to return false.
1541 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1542 __ Addu(inline_site, inline_site, Operand(kDeltaToLoadBoolResult));
1543 // Get the boolean result location in scratch and patch it.
1544 __ PatchRelocatedValue(inline_site, scratch, v0);
1546 if (!ReturnTrueFalseObject()) {
1547 __ li(v0, Operand(Smi::FromInt(1)));
1551 __ DropAndRet(HasArgsInRegisters() ? 0 : 2);
1553 Label object_not_null, object_not_null_or_smi;
1554 __ bind(¬_js_object);
1555 // Before null, smi and string value checks, check that the rhs is a function
1556 // as for a non-function rhs an exception needs to be thrown.
1557 __ JumpIfSmi(function, &slow);
1558 __ GetObjectType(function, scratch2, scratch);
1559 __ Branch(&slow, ne, scratch, Operand(JS_FUNCTION_TYPE));
1561 // Null is not instance of anything.
1562 __ Branch(&object_not_null, ne, object,
1563 Operand(isolate()->factory()->null_value()));
1564 if (ReturnTrueFalseObject()) {
1565 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1567 __ li(v0, Operand(Smi::FromInt(1)));
1569 __ DropAndRet(HasArgsInRegisters() ? 0 : 2);
1571 __ bind(&object_not_null);
1572 // Smi values are not instances of anything.
1573 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1574 if (ReturnTrueFalseObject()) {
1575 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1577 __ li(v0, Operand(Smi::FromInt(1)));
1579 __ DropAndRet(HasArgsInRegisters() ? 0 : 2);
1581 __ bind(&object_not_null_or_smi);
1582 // String values are not instances of anything.
1583 __ IsObjectJSStringType(object, scratch, &slow);
1584 if (ReturnTrueFalseObject()) {
1585 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1587 __ li(v0, Operand(Smi::FromInt(1)));
1589 __ DropAndRet(HasArgsInRegisters() ? 0 : 2);
1591 // Slow-case. Tail call builtin.
1593 if (!ReturnTrueFalseObject()) {
1594 if (HasArgsInRegisters()) {
1597 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
1600 FrameScope scope(masm, StackFrame::INTERNAL);
1602 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1605 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1606 __ DropAndRet(HasArgsInRegisters() ? 0 : 2, eq, a0, Operand(zero_reg));
1607 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1608 __ DropAndRet(HasArgsInRegisters() ? 0 : 2);
1613 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1615 Register receiver = LoadDescriptor::ReceiverRegister();
1616 // Ensure that the vector and slot registers won't be clobbered before
1617 // calling the miss handler.
1618 DCHECK(!AreAliased(t0, t1, LoadWithVectorDescriptor::VectorRegister(),
1619 LoadWithVectorDescriptor::SlotRegister()));
1621 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, t0,
1624 PropertyAccessCompiler::TailCallBuiltin(
1625 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1629 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1630 // The displacement is the offset of the last parameter (if any)
1631 // relative to the frame pointer.
1632 const int kDisplacement =
1633 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1634 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1635 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1637 // Check that the key is a smiGenerateReadElement.
1639 __ JumpIfNotSmi(a1, &slow);
1641 // Check if the calling frame is an arguments adaptor frame.
1643 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1644 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1648 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1650 // Check index (a1) against formal parameters count limit passed in
1651 // through register a0. Use unsigned comparison to get negative
1653 __ Branch(&slow, hs, a1, Operand(a0));
1655 // Read the argument from the stack and return it.
1656 __ subu(a3, a0, a1);
1657 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1658 __ Addu(a3, fp, Operand(t3));
1659 __ Ret(USE_DELAY_SLOT);
1660 __ lw(v0, MemOperand(a3, kDisplacement));
1662 // Arguments adaptor case: Check index (a1) against actual arguments
1663 // limit found in the arguments adaptor frame. Use unsigned
1664 // comparison to get negative check for free.
1666 __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1667 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1669 // Read the argument from the adaptor frame and return it.
1670 __ subu(a3, a0, a1);
1671 __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize);
1672 __ Addu(a3, a2, Operand(t3));
1673 __ Ret(USE_DELAY_SLOT);
1674 __ lw(v0, MemOperand(a3, kDisplacement));
1676 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1677 // by calling the runtime system.
1680 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1684 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1685 // sp[0] : number of parameters
1686 // sp[4] : receiver displacement
1689 // Check if the calling frame is an arguments adaptor frame.
1691 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1692 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1696 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1698 // Patch the arguments.length and the parameters pointer in the current frame.
1699 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1700 __ sw(a2, MemOperand(sp, 0 * kPointerSize));
1702 __ Addu(a3, a3, Operand(t3));
1703 __ addiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1704 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1707 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1711 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1713 // sp[0] : number of parameters (tagged)
1714 // sp[4] : address of receiver argument
1716 // Registers used over whole function:
1717 // t2 : allocated object (tagged)
1718 // t5 : mapped parameter count (tagged)
1720 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
1721 // a1 = parameter count (tagged)
1723 // Check if the calling frame is an arguments adaptor frame.
1725 Label adaptor_frame, try_allocate;
1726 __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1727 __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1728 __ Branch(&adaptor_frame,
1731 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1733 // No adaptor, parameter count = argument count.
1735 __ b(&try_allocate);
1736 __ nop(); // Branch delay slot nop.
1738 // We have an adaptor frame. Patch the parameters pointer.
1739 __ bind(&adaptor_frame);
1740 __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1742 __ Addu(a3, a3, Operand(t6));
1743 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1744 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1746 // a1 = parameter count (tagged)
1747 // a2 = argument count (tagged)
1748 // Compute the mapped parameter count = min(a1, a2) in a1.
1750 __ Branch(&skip_min, lt, a1, Operand(a2));
1754 __ bind(&try_allocate);
1756 // Compute the sizes of backing store, parameter map, and arguments object.
1757 // 1. Parameter map, has 2 extra words containing context and backing store.
1758 const int kParameterMapHeaderSize =
1759 FixedArray::kHeaderSize + 2 * kPointerSize;
1760 // If there are no mapped parameters, we do not need the parameter_map.
1761 Label param_map_size;
1762 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1763 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1764 __ mov(t5, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1766 __ addiu(t5, t5, kParameterMapHeaderSize);
1767 __ bind(¶m_map_size);
1769 // 2. Backing store.
1771 __ Addu(t5, t5, Operand(t6));
1772 __ Addu(t5, t5, Operand(FixedArray::kHeaderSize));
1774 // 3. Arguments object.
1775 __ Addu(t5, t5, Operand(Heap::kSloppyArgumentsObjectSize));
1777 // Do the allocation of all three objects in one go.
1778 __ Allocate(t5, v0, a3, t0, &runtime, TAG_OBJECT);
1780 // v0 = address of new object(s) (tagged)
1781 // a2 = argument count (smi-tagged)
1782 // Get the arguments boilerplate from the current native context into t0.
1783 const int kNormalOffset =
1784 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1785 const int kAliasedOffset =
1786 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1788 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1789 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1790 Label skip2_ne, skip2_eq;
1791 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1792 __ lw(t0, MemOperand(t0, kNormalOffset));
1795 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1796 __ lw(t0, MemOperand(t0, kAliasedOffset));
1799 // v0 = address of new object (tagged)
1800 // a1 = mapped parameter count (tagged)
1801 // a2 = argument count (smi-tagged)
1802 // t0 = address of arguments map (tagged)
1803 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
1804 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1805 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1806 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1808 // Set up the callee in-object property.
1809 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1810 __ lw(a3, MemOperand(sp, 2 * kPointerSize));
1811 __ AssertNotSmi(a3);
1812 const int kCalleeOffset = JSObject::kHeaderSize +
1813 Heap::kArgumentsCalleeIndex * kPointerSize;
1814 __ sw(a3, FieldMemOperand(v0, kCalleeOffset));
1816 // Use the length (smi tagged) and set that as an in-object property too.
1818 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1819 const int kLengthOffset = JSObject::kHeaderSize +
1820 Heap::kArgumentsLengthIndex * kPointerSize;
1821 __ sw(a2, FieldMemOperand(v0, kLengthOffset));
1823 // Set up the elements pointer in the allocated arguments object.
1824 // If we allocated a parameter map, t0 will point there, otherwise
1825 // it will point to the backing store.
1826 __ Addu(t0, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1827 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
1829 // v0 = address of new object (tagged)
1830 // a1 = mapped parameter count (tagged)
1831 // a2 = argument count (tagged)
1832 // t0 = address of parameter map or backing store (tagged)
1833 // Initialize parameter map. If there are no mapped arguments, we're done.
1834 Label skip_parameter_map;
1836 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1837 // Move backing store address to a3, because it is
1838 // expected there when filling in the unmapped arguments.
1842 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1844 __ LoadRoot(t2, Heap::kSloppyArgumentsElementsMapRootIndex);
1845 __ sw(t2, FieldMemOperand(t0, FixedArray::kMapOffset));
1846 __ Addu(t2, a1, Operand(Smi::FromInt(2)));
1847 __ sw(t2, FieldMemOperand(t0, FixedArray::kLengthOffset));
1848 __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize));
1850 __ Addu(t2, t0, Operand(t6));
1851 __ Addu(t2, t2, Operand(kParameterMapHeaderSize));
1852 __ sw(t2, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize));
1854 // Copy the parameter slots and the holes in the arguments.
1855 // We need to fill in mapped_parameter_count slots. They index the context,
1856 // where parameters are stored in reverse order, at
1857 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1858 // The mapped parameter thus need to get indices
1859 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1860 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1861 // We loop from right to left.
1862 Label parameters_loop, parameters_test;
1864 __ lw(t5, MemOperand(sp, 0 * kPointerSize));
1865 __ Addu(t5, t5, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1866 __ Subu(t5, t5, Operand(a1));
1867 __ LoadRoot(t3, Heap::kTheHoleValueRootIndex);
1869 __ Addu(a3, t0, Operand(t6));
1870 __ Addu(a3, a3, Operand(kParameterMapHeaderSize));
1872 // t2 = loop variable (tagged)
1873 // a1 = mapping index (tagged)
1874 // a3 = address of backing store (tagged)
1875 // t0 = address of parameter map (tagged)
1876 // t1 = temporary scratch (a.o., for address calculation)
1877 // t3 = the hole value
1878 __ jmp(¶meters_test);
1880 __ bind(¶meters_loop);
1881 __ Subu(t2, t2, Operand(Smi::FromInt(1)));
1883 __ Addu(t1, t1, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1884 __ Addu(t6, t0, t1);
1885 __ sw(t5, MemOperand(t6));
1886 __ Subu(t1, t1, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1887 __ Addu(t6, a3, t1);
1888 __ sw(t3, MemOperand(t6));
1889 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1890 __ bind(¶meters_test);
1891 __ Branch(¶meters_loop, ne, t2, Operand(Smi::FromInt(0)));
1893 __ bind(&skip_parameter_map);
1894 // a2 = argument count (tagged)
1895 // a3 = address of backing store (tagged)
1897 // Copy arguments header and remaining slots (if there are any).
1898 __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex);
1899 __ sw(t1, FieldMemOperand(a3, FixedArray::kMapOffset));
1900 __ sw(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1902 Label arguments_loop, arguments_test;
1904 __ lw(t0, MemOperand(sp, 1 * kPointerSize));
1906 __ Subu(t0, t0, Operand(t6));
1907 __ jmp(&arguments_test);
1909 __ bind(&arguments_loop);
1910 __ Subu(t0, t0, Operand(kPointerSize));
1911 __ lw(t2, MemOperand(t0, 0));
1913 __ Addu(t1, a3, Operand(t6));
1914 __ sw(t2, FieldMemOperand(t1, FixedArray::kHeaderSize));
1915 __ Addu(t5, t5, Operand(Smi::FromInt(1)));
1917 __ bind(&arguments_test);
1918 __ Branch(&arguments_loop, lt, t5, Operand(a2));
1920 // Return and remove the on-stack parameters.
1923 // Do the runtime call to allocate the arguments object.
1924 // a2 = argument count (tagged)
1926 __ sw(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1927 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1931 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1932 // Return address is in ra.
1935 Register receiver = LoadDescriptor::ReceiverRegister();
1936 Register key = LoadDescriptor::NameRegister();
1938 // Check that the key is an array index, that is Uint32.
1939 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1940 __ Branch(&slow, ne, t0, Operand(zero_reg));
1942 // Everything is fine, call runtime.
1943 __ Push(receiver, key); // Receiver, key.
1945 // Perform tail call to the entry.
1946 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1949 PropertyAccessCompiler::TailCallBuiltin(
1950 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1954 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1955 // sp[0] : number of parameters
1956 // sp[4] : receiver displacement
1958 // Check if the calling frame is an arguments adaptor frame.
1959 Label adaptor_frame, try_allocate, runtime;
1960 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1961 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1962 __ Branch(&adaptor_frame,
1965 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1967 // Get the length from the frame.
1968 __ lw(a1, MemOperand(sp, 0));
1969 __ Branch(&try_allocate);
1971 // Patch the arguments.length and the parameters pointer.
1972 __ bind(&adaptor_frame);
1973 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1974 __ sw(a1, MemOperand(sp, 0));
1975 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1976 __ Addu(a3, a2, Operand(at));
1978 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1979 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1981 // Try the new space allocation. Start out with computing the size
1982 // of the arguments object and the elements array in words.
1983 Label add_arguments_object;
1984 __ bind(&try_allocate);
1985 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1986 __ srl(a1, a1, kSmiTagSize);
1988 __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1989 __ bind(&add_arguments_object);
1990 __ Addu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1992 // Do the allocation of both objects in one go.
1993 __ Allocate(a1, v0, a2, a3, &runtime,
1994 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1996 // Get the arguments boilerplate from the current native context.
1997 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1998 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
1999 __ lw(t0, MemOperand(
2000 t0, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
2002 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
2003 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
2004 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
2005 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
2007 // Get the length (smi tagged) and set that as an in-object property too.
2008 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2009 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
2011 __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
2012 Heap::kArgumentsLengthIndex * kPointerSize));
2015 __ Branch(&done, eq, a1, Operand(zero_reg));
2017 // Get the parameters pointer from the stack.
2018 __ lw(a2, MemOperand(sp, 1 * kPointerSize));
2020 // Set up the elements pointer in the allocated arguments object and
2021 // initialize the header in the elements fixed array.
2022 __ Addu(t0, v0, Operand(Heap::kStrictArgumentsObjectSize));
2023 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
2024 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
2025 __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset));
2026 __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset));
2027 // Untag the length for the loop.
2028 __ srl(a1, a1, kSmiTagSize);
2030 // Copy the fixed array slots.
2032 // Set up t0 to point to the first array slot.
2033 __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2035 // Pre-decrement a2 with kPointerSize on each iteration.
2036 // Pre-decrement in order to skip receiver.
2037 __ Addu(a2, a2, Operand(-kPointerSize));
2038 __ lw(a3, MemOperand(a2));
2039 // Post-increment t0 with kPointerSize on each iteration.
2040 __ sw(a3, MemOperand(t0));
2041 __ Addu(t0, t0, Operand(kPointerSize));
2042 __ Subu(a1, a1, Operand(1));
2043 __ Branch(&loop, ne, a1, Operand(zero_reg));
2045 // Return and remove the on-stack parameters.
2049 // Do the runtime call to allocate the arguments object.
2051 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2055 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2056 // sp[0] : language mode
2057 // sp[4] : index of rest parameter
2058 // sp[8] : number of parameters
2059 // sp[12] : receiver displacement
2060 // Check if the calling frame is an arguments adaptor frame.
2063 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2064 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
2065 __ Branch(&runtime, ne, a3,
2066 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2068 // Patch the arguments.length and the parameters pointer.
2069 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
2070 __ sw(a1, MemOperand(sp, 2 * kPointerSize));
2071 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
2072 __ Addu(a3, a2, Operand(at));
2074 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
2075 __ sw(a3, MemOperand(sp, 3 * kPointerSize));
2077 // Do the runtime call to allocate the arguments object.
2079 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2083 void RegExpExecStub::Generate(MacroAssembler* masm) {
2084 // Just jump directly to runtime if native RegExp is not selected at compile
2085 // time or if regexp entry in generated code is turned off runtime switch or
2087 #ifdef V8_INTERPRETED_REGEXP
2088 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2089 #else // V8_INTERPRETED_REGEXP
2091 // Stack frame on entry.
2092 // sp[0]: last_match_info (expected JSArray)
2093 // sp[4]: previous index
2094 // sp[8]: subject string
2095 // sp[12]: JSRegExp object
2097 const int kLastMatchInfoOffset = 0 * kPointerSize;
2098 const int kPreviousIndexOffset = 1 * kPointerSize;
2099 const int kSubjectOffset = 2 * kPointerSize;
2100 const int kJSRegExpOffset = 3 * kPointerSize;
2103 // Allocation of registers for this function. These are in callee save
2104 // registers and will be preserved by the call to the native RegExp code, as
2105 // this code is called using the normal C calling convention. When calling
2106 // directly from generated code the native RegExp code will not do a GC and
2107 // therefore the content of these registers are safe to use after the call.
2108 // MIPS - using s0..s2, since we are not using CEntry Stub.
2109 Register subject = s0;
2110 Register regexp_data = s1;
2111 Register last_match_info_elements = s2;
2113 // Ensure that a RegExp stack is allocated.
2114 ExternalReference address_of_regexp_stack_memory_address =
2115 ExternalReference::address_of_regexp_stack_memory_address(
2117 ExternalReference address_of_regexp_stack_memory_size =
2118 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2119 __ li(a0, Operand(address_of_regexp_stack_memory_size));
2120 __ lw(a0, MemOperand(a0, 0));
2121 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2123 // Check that the first argument is a JSRegExp object.
2124 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
2125 STATIC_ASSERT(kSmiTag == 0);
2126 __ JumpIfSmi(a0, &runtime);
2127 __ GetObjectType(a0, a1, a1);
2128 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2130 // Check that the RegExp has been compiled (data contains a fixed array).
2131 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2132 if (FLAG_debug_code) {
2133 __ SmiTst(regexp_data, t0);
2135 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2138 __ GetObjectType(regexp_data, a0, a0);
2140 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2142 Operand(FIXED_ARRAY_TYPE));
2145 // regexp_data: RegExp data (FixedArray)
2146 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2147 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2148 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2150 // regexp_data: RegExp data (FixedArray)
2151 // Check that the number of captures fit in the static offsets vector buffer.
2153 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2154 // Check (number_of_captures + 1) * 2 <= offsets vector size
2155 // Or number_of_captures * 2 <= offsets vector size - 2
2156 // Multiplying by 2 comes for free since a2 is smi-tagged.
2157 STATIC_ASSERT(kSmiTag == 0);
2158 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2159 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2161 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2163 // Reset offset for possibly sliced string.
2164 __ mov(t0, zero_reg);
2165 __ lw(subject, MemOperand(sp, kSubjectOffset));
2166 __ JumpIfSmi(subject, &runtime);
2167 __ mov(a3, subject); // Make a copy of the original subject string.
2168 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2169 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2170 // subject: subject string
2171 // a3: subject string
2172 // a0: subject string instance type
2173 // regexp_data: RegExp data (FixedArray)
2174 // Handle subject string according to its encoding and representation:
2175 // (1) Sequential string? If yes, go to (5).
2176 // (2) Anything but sequential or cons? If yes, go to (6).
2177 // (3) Cons string. If the string is flat, replace subject with first string.
2178 // Otherwise bailout.
2179 // (4) Is subject external? If yes, go to (7).
2180 // (5) Sequential string. Load regexp code according to encoding.
2184 // Deferred code at the end of the stub:
2185 // (6) Not a long external string? If yes, go to (8).
2186 // (7) External string. Make it, offset-wise, look like a sequential string.
2188 // (8) Short external string or not a string? If yes, bail out to runtime.
2189 // (9) Sliced string. Replace subject with parent. Go to (4).
2191 Label seq_string /* 5 */, external_string /* 7 */,
2192 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2193 not_long_external /* 8 */;
2195 // (1) Sequential string? If yes, go to (5).
2198 Operand(kIsNotStringMask |
2199 kStringRepresentationMask |
2200 kShortExternalStringMask));
2201 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2202 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2204 // (2) Anything but sequential or cons? If yes, go to (6).
2205 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2206 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2207 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2208 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2210 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2212 // (3) Cons string. Check that it's flat.
2213 // Replace subject with first string and reload instance type.
2214 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2215 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2216 __ Branch(&runtime, ne, a0, Operand(a1));
2217 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2219 // (4) Is subject external? If yes, go to (7).
2220 __ bind(&check_underlying);
2221 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2222 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2223 STATIC_ASSERT(kSeqStringTag == 0);
2224 __ And(at, a0, Operand(kStringRepresentationMask));
2225 // The underlying external string is never a short external string.
2226 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2227 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2228 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2230 // (5) Sequential string. Load regexp code according to encoding.
2231 __ bind(&seq_string);
2232 // subject: sequential subject string (or look-alike, external string)
2233 // a3: original subject string
2234 // Load previous index and check range before a3 is overwritten. We have to
2235 // use a3 instead of subject here because subject might have been only made
2236 // to look like a sequential string when it actually is an external string.
2237 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
2238 __ JumpIfNotSmi(a1, &runtime);
2239 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
2240 __ Branch(&runtime, ls, a3, Operand(a1));
2241 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
2243 STATIC_ASSERT(kStringEncodingMask == 4);
2244 STATIC_ASSERT(kOneByteStringTag == 4);
2245 STATIC_ASSERT(kTwoByteStringTag == 0);
2246 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
2247 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2248 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
2249 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2250 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2252 // (E) Carry on. String handling is done.
2253 // t9: irregexp code
2254 // Check that the irregexp code has been generated for the actual string
2255 // encoding. If it has, the field contains a code object otherwise it contains
2256 // a smi (code flushing support).
2257 __ JumpIfSmi(t9, &runtime);
2259 // a1: previous index
2260 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2262 // subject: Subject string
2263 // regexp_data: RegExp data (FixedArray)
2264 // All checks done. Now push arguments for native regexp code.
2265 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2268 // Isolates: note we add an additional parameter here (isolate pointer).
2269 const int kRegExpExecuteArguments = 9;
2270 const int kParameterRegisters = 4;
2271 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2273 // Stack pointer now points to cell where return address is to be written.
2274 // Arguments are before that on the stack or in registers, meaning we
2275 // treat the return address as argument 5. Thus every argument after that
2276 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2277 // allocating space for the c argument slots, we don't need to calculate
2278 // that into the argument positions on the stack. This is how the stack will
2279 // look (sp meaning the value of sp at this moment):
2280 // [sp + 5] - Argument 9
2281 // [sp + 4] - Argument 8
2282 // [sp + 3] - Argument 7
2283 // [sp + 2] - Argument 6
2284 // [sp + 1] - Argument 5
2285 // [sp + 0] - saved ra
2287 // Argument 9: Pass current isolate address.
2288 // CFunctionArgumentOperand handles MIPS stack argument slots.
2289 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2290 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
2292 // Argument 8: Indicate that this is a direct call from JavaScript.
2293 __ li(a0, Operand(1));
2294 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
2296 // Argument 7: Start (high end) of backtracking stack memory area.
2297 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2298 __ lw(a0, MemOperand(a0, 0));
2299 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2300 __ lw(a2, MemOperand(a2, 0));
2301 __ addu(a0, a0, a2);
2302 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
2304 // Argument 6: Set the number of capture registers to zero to force global
2305 // regexps to behave as non-global. This does not affect non-global regexps.
2306 __ mov(a0, zero_reg);
2307 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
2309 // Argument 5: static offsets vector buffer.
2311 ExternalReference::address_of_static_offsets_vector(isolate())));
2312 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
2314 // For arguments 4 and 3 get string length, calculate start of string data
2315 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2316 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2317 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2318 // Load the length from the original subject string from the previous stack
2319 // frame. Therefore we have to use fp, which points exactly to two pointer
2320 // sizes below the previous sp. (Because creating a new stack frame pushes
2321 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2322 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2323 // If slice offset is not 0, load the length from the original sliced string.
2324 // Argument 4, a3: End of string data
2325 // Argument 3, a2: Start of string data
2326 // Prepare start and end index of the input.
2327 __ sllv(t1, t0, a3);
2328 __ addu(t0, t2, t1);
2329 __ sllv(t1, a1, a3);
2330 __ addu(a2, t0, t1);
2332 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
2333 __ sra(t2, t2, kSmiTagSize);
2334 __ sllv(t1, t2, a3);
2335 __ addu(a3, t0, t1);
2336 // Argument 2 (a1): Previous index.
2339 // Argument 1 (a0): Subject string.
2340 __ mov(a0, subject);
2342 // Locate the code entry and call it.
2343 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2344 DirectCEntryStub stub(isolate());
2345 stub.GenerateCall(masm, t9);
2347 __ LeaveExitFrame(false, no_reg, true);
2350 // subject: subject string (callee saved)
2351 // regexp_data: RegExp data (callee saved)
2352 // last_match_info_elements: Last match info elements (callee saved)
2353 // Check the result.
2355 __ Branch(&success, eq, v0, Operand(1));
2356 // We expect exactly one result since we force the called regexp to behave
2359 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2360 // If not exception it can only be retry. Handle that in the runtime system.
2361 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2362 // Result must now be exception. If there is no pending exception already a
2363 // stack overflow (on the backtrack stack) was detected in RegExp code but
2364 // haven't created the exception yet. Handle that in the runtime system.
2365 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2366 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2367 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2369 __ lw(v0, MemOperand(a2, 0));
2370 __ Branch(&runtime, eq, v0, Operand(a1));
2372 // For exception, throw the exception again.
2373 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2376 // For failure and exception return null.
2377 __ li(v0, Operand(isolate()->factory()->null_value()));
2380 // Process the result from the native regexp code.
2383 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2384 // Calculate number of capture registers (number_of_captures + 1) * 2.
2385 // Multiplying by 2 comes for free since r1 is smi-tagged.
2386 STATIC_ASSERT(kSmiTag == 0);
2387 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2388 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
2390 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
2391 __ JumpIfSmi(a0, &runtime);
2392 __ GetObjectType(a0, a2, a2);
2393 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2394 // Check that the JSArray is in fast case.
2395 __ lw(last_match_info_elements,
2396 FieldMemOperand(a0, JSArray::kElementsOffset));
2397 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2398 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2399 __ Branch(&runtime, ne, a0, Operand(at));
2400 // Check that the last match info has space for the capture registers and the
2401 // additional information.
2403 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2404 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2405 __ sra(at, a0, kSmiTagSize);
2406 __ Branch(&runtime, gt, a2, Operand(at));
2408 // a1: number of capture registers
2409 // subject: subject string
2410 // Store the capture count.
2411 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
2412 __ sw(a2, FieldMemOperand(last_match_info_elements,
2413 RegExpImpl::kLastCaptureCountOffset));
2414 // Store last subject and last input.
2416 FieldMemOperand(last_match_info_elements,
2417 RegExpImpl::kLastSubjectOffset));
2418 __ mov(a2, subject);
2419 __ RecordWriteField(last_match_info_elements,
2420 RegExpImpl::kLastSubjectOffset,
2425 __ mov(subject, a2);
2427 FieldMemOperand(last_match_info_elements,
2428 RegExpImpl::kLastInputOffset));
2429 __ RecordWriteField(last_match_info_elements,
2430 RegExpImpl::kLastInputOffset,
2436 // Get the static offsets vector filled by the native regexp code.
2437 ExternalReference address_of_static_offsets_vector =
2438 ExternalReference::address_of_static_offsets_vector(isolate());
2439 __ li(a2, Operand(address_of_static_offsets_vector));
2441 // a1: number of capture registers
2442 // a2: offsets vector
2443 Label next_capture, done;
2444 // Capture register counter starts from number of capture registers and
2445 // counts down until wrapping after zero.
2447 last_match_info_elements,
2448 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2449 __ bind(&next_capture);
2450 __ Subu(a1, a1, Operand(1));
2451 __ Branch(&done, lt, a1, Operand(zero_reg));
2452 // Read the value from the static offsets vector buffer.
2453 __ lw(a3, MemOperand(a2, 0));
2454 __ addiu(a2, a2, kPointerSize);
2455 // Store the smi value in the last match info.
2456 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
2457 __ sw(a3, MemOperand(a0, 0));
2458 __ Branch(&next_capture, USE_DELAY_SLOT);
2459 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
2463 // Return last match info.
2464 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
2467 // Do the runtime call to execute the regexp.
2469 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2471 // Deferred code for string handling.
2472 // (6) Not a long external string? If yes, go to (8).
2473 __ bind(¬_seq_nor_cons);
2475 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2477 // (7) External string. Make it, offset-wise, look like a sequential string.
2478 __ bind(&external_string);
2479 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2480 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2481 if (FLAG_debug_code) {
2482 // Assert that we do not have a cons or slice (indirect strings) here.
2483 // Sequential strings have already been ruled out.
2484 __ And(at, a0, Operand(kIsIndirectStringMask));
2486 kExternalStringExpectedButNotFound,
2491 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2492 // Move the pointer so that offset-wise, it looks like a sequential string.
2493 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2496 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2497 __ jmp(&seq_string); // Go to (5).
2499 // (8) Short external string or not a string? If yes, bail out to runtime.
2500 __ bind(¬_long_external);
2501 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2502 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2503 __ Branch(&runtime, ne, at, Operand(zero_reg));
2505 // (9) Sliced string. Replace subject with parent. Go to (4).
2506 // Load offset into t0 and replace subject string with parent.
2507 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2508 __ sra(t0, t0, kSmiTagSize);
2509 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2510 __ jmp(&check_underlying); // Go to (4).
2511 #endif // V8_INTERPRETED_REGEXP
2515 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2517 // a0 : number of arguments to the construct function
2518 // a2 : feedback vector
2519 // a3 : slot in feedback vector (Smi)
2520 // a1 : the function to call
2521 // t0 : original constructor (for IsSuperConstructorCall)
2522 FrameScope scope(masm, StackFrame::INTERNAL);
2523 const RegList kSavedRegs = 1 << 4 | // a0
2527 BoolToInt(is_super) << 8; // t0
2529 // Number-of-arguments register must be smi-tagged to call out.
2531 __ MultiPush(kSavedRegs);
2535 __ MultiPop(kSavedRegs);
2540 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2541 // Cache the called function in a feedback vector slot. Cache states
2542 // are uninitialized, monomorphic (indicated by a JSFunction), and
2544 // a0 : number of arguments to the construct function
2545 // a1 : the function to call
2546 // a2 : feedback vector
2547 // a3 : slot in feedback vector (Smi)
2548 // t0 : original constructor (for IsSuperConstructorCall)
2549 Label initialize, done, miss, megamorphic, not_array_function;
2551 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2552 masm->isolate()->heap()->megamorphic_symbol());
2553 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2554 masm->isolate()->heap()->uninitialized_symbol());
2556 // Load the cache state into t2.
2557 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2558 __ Addu(t2, a2, Operand(t2));
2559 __ lw(t2, FieldMemOperand(t2, FixedArray::kHeaderSize));
2561 // A monomorphic cache hit or an already megamorphic state: invoke the
2562 // function without changing the state.
2563 // We don't know if t2 is a WeakCell or a Symbol, but it's harmless to read at
2564 // this position in a symbol (see static asserts in type-feedback-vector.h).
2565 Label check_allocation_site;
2566 Register feedback_map = t1;
2567 Register weak_value = t4;
2568 __ lw(weak_value, FieldMemOperand(t2, WeakCell::kValueOffset));
2569 __ Branch(&done, eq, a1, Operand(weak_value));
2570 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2571 __ Branch(&done, eq, t2, Operand(at));
2572 __ lw(feedback_map, FieldMemOperand(t2, HeapObject::kMapOffset));
2573 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2574 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2575 feedback_map, Operand(at));
2577 // If the weak cell is cleared, we have a new chance to become monomorphic.
2578 __ JumpIfSmi(weak_value, &initialize);
2579 __ jmp(&megamorphic);
2581 if (!FLAG_pretenuring_call_new) {
2582 __ bind(&check_allocation_site);
2583 // If we came here, we need to see if we are the array function.
2584 // If we didn't have a matching function, and we didn't find the megamorph
2585 // sentinel, then we have in the slot either some other function or an
2587 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2588 __ Branch(&miss, ne, feedback_map, Operand(at));
2590 // Make sure the function is the Array() function
2591 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2592 __ Branch(&megamorphic, ne, a1, Operand(t2));
2598 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2600 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2601 __ Branch(&initialize, eq, t2, Operand(at));
2602 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2603 // write-barrier is needed.
2604 __ bind(&megamorphic);
2605 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
2606 __ Addu(t2, a2, Operand(t2));
2607 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2608 __ sw(at, FieldMemOperand(t2, FixedArray::kHeaderSize));
2611 // An uninitialized cache is patched with the function.
2612 __ bind(&initialize);
2613 if (!FLAG_pretenuring_call_new) {
2614 // Make sure the function is the Array() function.
2615 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t2);
2616 __ Branch(¬_array_function, ne, a1, Operand(t2));
2618 // The target function is the Array constructor,
2619 // Create an AllocationSite if we don't already have it, store it in the
2621 CreateAllocationSiteStub create_stub(masm->isolate());
2622 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2625 __ bind(¬_array_function);
2628 CreateWeakCellStub create_stub(masm->isolate());
2629 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2634 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2635 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2636 __ lw(t0, FieldMemOperand(a3, SharedFunctionInfo::kCompilerHintsOffset));
2638 // Do not transform the receiver for strict mode functions.
2639 int32_t strict_mode_function_mask =
2640 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
2641 // Do not transform the receiver for native (Compilerhints already in a3).
2642 int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize);
2643 __ And(at, t0, Operand(strict_mode_function_mask | native_mask));
2644 __ Branch(cont, ne, at, Operand(zero_reg));
2648 static void EmitSlowCase(MacroAssembler* masm,
2650 Label* non_function) {
2651 // Check for function proxy.
2652 __ Branch(non_function, ne, t0, Operand(JS_FUNCTION_PROXY_TYPE));
2653 __ push(a1); // put proxy as additional argument
2654 __ li(a0, Operand(argc + 1, RelocInfo::NONE32));
2655 __ mov(a2, zero_reg);
2656 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY);
2658 Handle<Code> adaptor =
2659 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2660 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2663 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2664 // of the original receiver from the call site).
2665 __ bind(non_function);
2666 __ sw(a1, MemOperand(sp, argc * kPointerSize));
2667 __ li(a0, Operand(argc)); // Set up the number of arguments.
2668 __ mov(a2, zero_reg);
2669 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION);
2670 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2671 RelocInfo::CODE_TARGET);
2675 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2676 // Wrap the receiver and patch it back onto the stack.
2677 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2679 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2682 __ Branch(USE_DELAY_SLOT, cont);
2683 __ sw(v0, MemOperand(sp, argc * kPointerSize));
2687 static void CallFunctionNoFeedback(MacroAssembler* masm,
2688 int argc, bool needs_checks,
2689 bool call_as_method) {
2690 // a1 : the function to call
2691 Label slow, non_function, wrap, cont;
2694 // Check that the function is really a JavaScript function.
2695 // a1: pushed function (to be verified)
2696 __ JumpIfSmi(a1, &non_function);
2698 // Goto slow case if we do not have a function.
2699 __ GetObjectType(a1, t0, t0);
2700 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2703 // Fast-case: Invoke the function now.
2704 // a1: pushed function
2705 ParameterCount actual(argc);
2707 if (call_as_method) {
2709 EmitContinueIfStrictOrNative(masm, &cont);
2712 // Compute the receiver in sloppy mode.
2713 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2716 __ JumpIfSmi(a3, &wrap);
2717 __ GetObjectType(a3, t0, t0);
2718 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2726 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2729 // Slow-case: Non-function called.
2731 EmitSlowCase(masm, argc, &non_function);
2734 if (call_as_method) {
2736 // Wrap the receiver and patch it back onto the stack.
2737 EmitWrapCase(masm, argc, &cont);
2742 void CallFunctionStub::Generate(MacroAssembler* masm) {
2743 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2747 void CallConstructStub::Generate(MacroAssembler* masm) {
2748 // a0 : number of arguments
2749 // a1 : the function to call
2750 // a2 : feedback vector
2751 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2752 // t0 : original constructor (for IsSuperConstructorCall)
2753 Label slow, non_function_call;
2755 // Check that the function is not a smi.
2756 __ JumpIfSmi(a1, &non_function_call);
2757 // Check that the function is a JSFunction.
2758 __ GetObjectType(a1, t1, t1);
2759 __ Branch(&slow, ne, t1, Operand(JS_FUNCTION_TYPE));
2761 if (RecordCallTarget()) {
2762 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2764 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2765 __ Addu(t1, a2, at);
2766 if (FLAG_pretenuring_call_new) {
2767 // Put the AllocationSite from the feedback vector into a2.
2768 // By adding kPointerSize we encode that we know the AllocationSite
2769 // entry is at the feedback vector slot given by a3 + 1.
2770 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize + kPointerSize));
2772 Label feedback_register_initialized;
2773 // Put the AllocationSite from the feedback vector into a2, or undefined.
2774 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
2775 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
2776 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2777 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
2778 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2779 __ bind(&feedback_register_initialized);
2782 __ AssertUndefinedOrAllocationSite(a2, t1);
2785 // Pass function as original constructor.
2786 if (IsSuperConstructorCall()) {
2792 // Jump to the function-specific construct stub.
2793 Register jmp_reg = t0;
2794 __ lw(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2795 __ lw(jmp_reg, FieldMemOperand(jmp_reg,
2796 SharedFunctionInfo::kConstructStubOffset));
2797 __ Addu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2800 // a0: number of arguments
2801 // a1: called object
2805 __ Branch(&non_function_call, ne, t1, Operand(JS_FUNCTION_PROXY_TYPE));
2806 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2809 __ bind(&non_function_call);
2810 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2812 // Set expected number of arguments to zero (not changing r0).
2813 __ li(a2, Operand(0, RelocInfo::NONE32));
2814 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2815 RelocInfo::CODE_TARGET);
2819 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2820 __ lw(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2821 __ lw(vector, FieldMemOperand(vector,
2822 JSFunction::kSharedFunctionInfoOffset));
2823 __ lw(vector, FieldMemOperand(vector,
2824 SharedFunctionInfo::kFeedbackVectorOffset));
2828 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2834 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2835 __ Branch(&miss, ne, a1, Operand(at));
2837 __ li(a0, Operand(arg_count()));
2838 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2839 __ Addu(at, a2, Operand(at));
2840 __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize));
2842 // Verify that t0 contains an AllocationSite
2843 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2844 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2845 __ Branch(&miss, ne, t1, Operand(at));
2847 // Increment the call count for monomorphic function calls.
2848 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2849 __ Addu(at, a2, Operand(at));
2850 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2851 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2852 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2856 ArrayConstructorStub stub(masm->isolate(), arg_count());
2857 __ TailCallStub(&stub);
2862 // The slow case, we need this no matter what to complete a call after a miss.
2863 CallFunctionNoFeedback(masm,
2869 __ stop("Unexpected code address");
2873 void CallICStub::Generate(MacroAssembler* masm) {
2875 // a3 - slot id (Smi)
2877 const int with_types_offset =
2878 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2879 const int generic_offset =
2880 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2881 Label extra_checks_or_miss, slow_start;
2882 Label slow, non_function, wrap, cont;
2883 Label have_js_function;
2884 int argc = arg_count();
2885 ParameterCount actual(argc);
2887 // The checks. First, does r1 match the recorded monomorphic target?
2888 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2889 __ Addu(t0, a2, Operand(t0));
2890 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2892 // We don't know that we have a weak cell. We might have a private symbol
2893 // or an AllocationSite, but the memory is safe to examine.
2894 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2896 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2897 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2898 // computed, meaning that it can't appear to be a pointer. If the low bit is
2899 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2901 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2902 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2903 WeakCell::kValueOffset &&
2904 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2906 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2907 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
2909 // The compare above could have been a SMI/SMI comparison. Guard against this
2910 // convincing us that we have a monomorphic JSFunction.
2911 __ JumpIfSmi(a1, &extra_checks_or_miss);
2913 // Increment the call count for monomorphic function calls.
2914 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2915 __ Addu(at, a2, Operand(at));
2916 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2917 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2918 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2920 __ bind(&have_js_function);
2921 if (CallAsMethod()) {
2922 EmitContinueIfStrictOrNative(masm, &cont);
2923 // Compute the receiver in sloppy mode.
2924 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2926 __ JumpIfSmi(a3, &wrap);
2927 __ GetObjectType(a3, t0, t0);
2928 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2933 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2936 EmitSlowCase(masm, argc, &non_function);
2938 if (CallAsMethod()) {
2940 EmitWrapCase(masm, argc, &cont);
2943 __ bind(&extra_checks_or_miss);
2944 Label uninitialized, miss;
2946 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2947 __ Branch(&slow_start, eq, t0, Operand(at));
2949 // The following cases attempt to handle MISS cases without going to the
2951 if (FLAG_trace_ic) {
2955 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2956 __ Branch(&uninitialized, eq, t0, Operand(at));
2958 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2959 // to handle it here. More complex cases are dealt with in the runtime.
2960 __ AssertNotSmi(t0);
2961 __ GetObjectType(t0, t1, t1);
2962 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
2963 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2964 __ Addu(t0, a2, Operand(t0));
2965 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2966 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2967 // We have to update statistics for runtime profiling.
2968 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2969 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
2970 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2971 __ lw(t0, FieldMemOperand(a2, generic_offset));
2972 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2973 __ Branch(USE_DELAY_SLOT, &slow_start);
2974 __ sw(t0, FieldMemOperand(a2, generic_offset)); // In delay slot.
2976 __ bind(&uninitialized);
2978 // We are going monomorphic, provided we actually have a JSFunction.
2979 __ JumpIfSmi(a1, &miss);
2981 // Goto miss case if we do not have a function.
2982 __ GetObjectType(a1, t0, t0);
2983 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2985 // Make sure the function is not the Array() function, which requires special
2986 // behavior on MISS.
2987 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2988 __ Branch(&miss, eq, a1, Operand(t0));
2991 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2992 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2993 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2995 // Initialize the call counter.
2996 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2997 __ Addu(at, a2, Operand(at));
2998 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2999 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
3001 // Store the function. Use a stub since we need a frame for allocation.
3006 FrameScope scope(masm, StackFrame::INTERNAL);
3007 CreateWeakCellStub create_stub(masm->isolate());
3009 __ CallStub(&create_stub);
3013 __ Branch(&have_js_function);
3015 // We are here because tracing is on or we encountered a MISS case we can't
3021 __ bind(&slow_start);
3022 // Check that the function is really a JavaScript function.
3023 // r1: pushed function (to be verified)
3024 __ JumpIfSmi(a1, &non_function);
3026 // Goto slow case if we do not have a function.
3027 __ GetObjectType(a1, t0, t0);
3028 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
3029 __ Branch(&have_js_function);
3033 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3034 FrameScope scope(masm, StackFrame::INTERNAL);
3036 // Push the receiver and the function and feedback info.
3037 __ Push(a1, a2, a3);
3040 Runtime::FunctionId id = GetICState() == DEFAULT
3041 ? Runtime::kCallIC_Miss
3042 : Runtime::kCallIC_Customization_Miss;
3043 __ CallRuntime(id, 3);
3045 // Move result to a1 and exit the internal frame.
3050 // StringCharCodeAtGenerator.
3051 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3052 DCHECK(!t0.is(index_));
3053 DCHECK(!t0.is(result_));
3054 DCHECK(!t0.is(object_));
3055 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3056 // If the receiver is a smi trigger the non-string case.
3057 __ JumpIfSmi(object_, receiver_not_string_);
3059 // Fetch the instance type of the receiver into result register.
3060 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3061 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3062 // If the receiver is not a string trigger the non-string case.
3063 __ And(t0, result_, Operand(kIsNotStringMask));
3064 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
3067 // If the index is non-smi trigger the non-smi case.
3068 __ JumpIfNotSmi(index_, &index_not_smi_);
3070 __ bind(&got_smi_index_);
3072 // Check for index out of range.
3073 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
3074 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
3076 __ sra(index_, index_, kSmiTagSize);
3078 StringCharLoadGenerator::Generate(masm,
3084 __ sll(result_, result_, kSmiTagSize);
3089 void StringCharCodeAtGenerator::GenerateSlow(
3090 MacroAssembler* masm, EmbedMode embed_mode,
3091 const RuntimeCallHelper& call_helper) {
3092 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3094 // Index is not a smi.
3095 __ bind(&index_not_smi_);
3096 // If index is a heap number, try converting it to an integer.
3099 Heap::kHeapNumberMapRootIndex,
3102 call_helper.BeforeCall(masm);
3103 // Consumed by runtime conversion function:
3104 if (embed_mode == PART_OF_IC_HANDLER) {
3105 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3106 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3108 __ Push(object_, index_);
3110 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3111 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3113 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3114 // NumberToSmi discards numbers that are not exact integers.
3115 __ CallRuntime(Runtime::kNumberToSmi, 1);
3118 // Save the conversion result before the pop instructions below
3119 // have a chance to overwrite it.
3120 __ Move(index_, v0);
3121 if (embed_mode == PART_OF_IC_HANDLER) {
3122 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3123 LoadWithVectorDescriptor::SlotRegister(), object_);
3127 // Reload the instance type.
3128 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3129 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3130 call_helper.AfterCall(masm);
3131 // If index is still not a smi, it must be out of range.
3132 __ JumpIfNotSmi(index_, index_out_of_range_);
3133 // Otherwise, return to the fast path.
3134 __ Branch(&got_smi_index_);
3136 // Call runtime. We get here when the receiver is a string and the
3137 // index is a number, but the code of getting the actual character
3138 // is too complex (e.g., when the string needs to be flattened).
3139 __ bind(&call_runtime_);
3140 call_helper.BeforeCall(masm);
3141 __ sll(index_, index_, kSmiTagSize);
3142 __ Push(object_, index_);
3143 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3145 __ Move(result_, v0);
3147 call_helper.AfterCall(masm);
3150 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3154 // -------------------------------------------------------------------------
3155 // StringCharFromCodeGenerator
3157 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3158 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3160 DCHECK(!t0.is(result_));
3161 DCHECK(!t0.is(code_));
3163 STATIC_ASSERT(kSmiTag == 0);
3164 STATIC_ASSERT(kSmiShiftSize == 0);
3165 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3166 __ And(t0, code_, Operand(kSmiTagMask |
3167 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3168 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
3170 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3171 // At this point code register contains smi tagged one-byte char code.
3172 STATIC_ASSERT(kSmiTag == 0);
3173 __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize);
3174 __ Addu(result_, result_, t0);
3175 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3176 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
3177 __ Branch(&slow_case_, eq, result_, Operand(t0));
3182 void StringCharFromCodeGenerator::GenerateSlow(
3183 MacroAssembler* masm,
3184 const RuntimeCallHelper& call_helper) {
3185 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3187 __ bind(&slow_case_);
3188 call_helper.BeforeCall(masm);
3190 __ CallRuntime(Runtime::kCharFromCode, 1);
3191 __ Move(result_, v0);
3193 call_helper.AfterCall(masm);
3196 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3200 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3203 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3208 String::Encoding encoding) {
3209 if (FLAG_debug_code) {
3210 // Check that destination is word aligned.
3211 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3213 kDestinationOfCopyNotAligned,
3218 // Assumes word reads and writes are little endian.
3219 // Nothing to do for zero characters.
3222 if (encoding == String::TWO_BYTE_ENCODING) {
3223 __ Addu(count, count, count);
3226 Register limit = count; // Read until dest equals this.
3227 __ Addu(limit, dest, Operand(count));
3229 Label loop_entry, loop;
3230 // Copy bytes from src to dest until dest hits limit.
3231 __ Branch(&loop_entry);
3233 __ lbu(scratch, MemOperand(src));
3234 __ Addu(src, src, Operand(1));
3235 __ sb(scratch, MemOperand(dest));
3236 __ Addu(dest, dest, Operand(1));
3237 __ bind(&loop_entry);
3238 __ Branch(&loop, lt, dest, Operand(limit));
3244 void SubStringStub::Generate(MacroAssembler* masm) {
3246 // Stack frame on entry.
3247 // ra: return address
3252 // This stub is called from the native-call %_SubString(...), so
3253 // nothing can be assumed about the arguments. It is tested that:
3254 // "string" is a sequential string,
3255 // both "from" and "to" are smis, and
3256 // 0 <= from <= to <= string.length.
3257 // If any of these assumptions fail, we call the runtime system.
3259 const int kToOffset = 0 * kPointerSize;
3260 const int kFromOffset = 1 * kPointerSize;
3261 const int kStringOffset = 2 * kPointerSize;
3263 __ lw(a2, MemOperand(sp, kToOffset));
3264 __ lw(a3, MemOperand(sp, kFromOffset));
3265 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3266 STATIC_ASSERT(kSmiTag == 0);
3267 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3269 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3270 // safe in this case.
3271 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
3272 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
3273 // Both a2 and a3 are untagged integers.
3275 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3277 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3278 __ Subu(a2, a2, a3);
3280 // Make sure first argument is a string.
3281 __ lw(v0, MemOperand(sp, kStringOffset));
3282 __ JumpIfSmi(v0, &runtime);
3283 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3284 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3285 __ And(t0, a1, Operand(kIsNotStringMask));
3287 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3290 __ Branch(&single_char, eq, a2, Operand(1));
3292 // Short-cut for the case of trivial substring.
3294 // v0: original string
3295 // a2: result string length
3296 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
3298 // Return original string.
3299 __ Branch(&return_v0, eq, a2, Operand(t0));
3300 // Longer than original string's length or negative: unsafe arguments.
3301 __ Branch(&runtime, hi, a2, Operand(t0));
3302 // Shorter than original string's length: an actual substring.
3304 // Deal with different string types: update the index if necessary
3305 // and put the underlying string into t1.
3306 // v0: original string
3307 // a1: instance type
3309 // a3: from index (untagged)
3310 Label underlying_unpacked, sliced_string, seq_or_external_string;
3311 // If the string is not indirect, it can only be sequential or external.
3312 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3313 STATIC_ASSERT(kIsIndirectStringMask != 0);
3314 __ And(t0, a1, Operand(kIsIndirectStringMask));
3315 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
3316 // t0 is used as a scratch register and can be overwritten in either case.
3317 __ And(t0, a1, Operand(kSlicedNotConsMask));
3318 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
3319 // Cons string. Check whether it is flat, then fetch first part.
3320 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
3321 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
3322 __ Branch(&runtime, ne, t1, Operand(t0));
3323 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
3324 // Update instance type.
3325 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3326 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3327 __ jmp(&underlying_unpacked);
3329 __ bind(&sliced_string);
3330 // Sliced string. Fetch parent and correct start index by offset.
3331 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3332 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3333 __ sra(t0, t0, 1); // Add offset to index.
3334 __ Addu(a3, a3, t0);
3335 // Update instance type.
3336 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3337 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3338 __ jmp(&underlying_unpacked);
3340 __ bind(&seq_or_external_string);
3341 // Sequential or external string. Just move string to the expected register.
3344 __ bind(&underlying_unpacked);
3346 if (FLAG_string_slices) {
3348 // t1: underlying subject string
3349 // a1: instance type of underlying subject string
3351 // a3: adjusted start index (untagged)
3352 // Short slice. Copy instead of slicing.
3353 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3354 // Allocate new sliced string. At this point we do not reload the instance
3355 // type including the string encoding because we simply rely on the info
3356 // provided by the original string. It does not matter if the original
3357 // string's encoding is wrong because we always have to recheck encoding of
3358 // the newly created string's parent anyways due to externalized strings.
3359 Label two_byte_slice, set_slice_header;
3360 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3361 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3362 __ And(t0, a1, Operand(kStringEncodingMask));
3363 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
3364 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
3365 __ jmp(&set_slice_header);
3366 __ bind(&two_byte_slice);
3367 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
3368 __ bind(&set_slice_header);
3370 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3371 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3374 __ bind(©_routine);
3377 // t1: underlying subject string
3378 // a1: instance type of underlying subject string
3380 // a3: adjusted start index (untagged)
3381 Label two_byte_sequential, sequential_string, allocate_result;
3382 STATIC_ASSERT(kExternalStringTag != 0);
3383 STATIC_ASSERT(kSeqStringTag == 0);
3384 __ And(t0, a1, Operand(kExternalStringTag));
3385 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
3387 // Handle external string.
3388 // Rule out short external strings.
3389 STATIC_ASSERT(kShortExternalStringTag != 0);
3390 __ And(t0, a1, Operand(kShortExternalStringTag));
3391 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3392 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
3393 // t1 already points to the first character of underlying string.
3394 __ jmp(&allocate_result);
3396 __ bind(&sequential_string);
3397 // Locate first character of underlying subject string.
3398 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3399 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3401 __ bind(&allocate_result);
3402 // Sequential acii string. Allocate the result.
3403 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3404 __ And(t0, a1, Operand(kStringEncodingMask));
3405 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
3407 // Allocate and copy the resulting ASCII string.
3408 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
3410 // Locate first character of substring to copy.
3411 __ Addu(t1, t1, a3);
3413 // Locate first character of result.
3414 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3416 // v0: result string
3417 // a1: first character of result string
3418 // a2: result string length
3419 // t1: first character of substring to copy
3420 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3421 StringHelper::GenerateCopyCharacters(
3422 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
3425 // Allocate and copy the resulting two-byte string.
3426 __ bind(&two_byte_sequential);
3427 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
3429 // Locate first character of substring to copy.
3430 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3432 __ Addu(t1, t1, t0);
3433 // Locate first character of result.
3434 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3436 // v0: result string.
3437 // a1: first character of result.
3438 // a2: result length.
3439 // t1: first character of substring to copy.
3440 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3441 StringHelper::GenerateCopyCharacters(
3442 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
3444 __ bind(&return_v0);
3445 Counters* counters = isolate()->counters();
3446 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
3449 // Just jump to runtime to create the sub string.
3451 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3453 __ bind(&single_char);
3454 // v0: original string
3455 // a1: instance type
3457 // a3: from index (untagged)
3459 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3460 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3461 generator.GenerateFast(masm);
3463 generator.SkipSlow(masm, &runtime);
3467 void ToNumberStub::Generate(MacroAssembler* masm) {
3468 // The ToNumber stub takes one argument in a0.
3470 __ JumpIfNotSmi(a0, ¬_smi);
3471 __ Ret(USE_DELAY_SLOT);
3475 Label not_heap_number;
3476 __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3477 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3479 // a1: instance type.
3480 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3481 __ Ret(USE_DELAY_SLOT);
3483 __ bind(¬_heap_number);
3485 Label not_string, slow_string;
3486 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3487 // Check if string has a cached array index.
3488 __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3489 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3490 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3491 __ IndexFromHash(a2, a0);
3492 __ Ret(USE_DELAY_SLOT);
3494 __ bind(&slow_string);
3495 __ push(a0); // Push argument.
3496 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3497 __ bind(¬_string);
3500 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3501 __ Ret(USE_DELAY_SLOT);
3502 __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3503 __ bind(¬_oddball);
3505 __ push(a0); // Push argument.
3506 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3510 void StringHelper::GenerateFlatOneByteStringEquals(
3511 MacroAssembler* masm, Register left, Register right, Register scratch1,
3512 Register scratch2, Register scratch3) {
3513 Register length = scratch1;
3516 Label strings_not_equal, check_zero_length;
3517 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
3518 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3519 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3520 __ bind(&strings_not_equal);
3521 DCHECK(is_int16(NOT_EQUAL));
3522 __ Ret(USE_DELAY_SLOT);
3523 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3525 // Check if the length is zero.
3526 Label compare_chars;
3527 __ bind(&check_zero_length);
3528 STATIC_ASSERT(kSmiTag == 0);
3529 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3530 DCHECK(is_int16(EQUAL));
3531 __ Ret(USE_DELAY_SLOT);
3532 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3534 // Compare characters.
3535 __ bind(&compare_chars);
3537 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3538 v0, &strings_not_equal);
3540 // Characters are equal.
3541 __ Ret(USE_DELAY_SLOT);
3542 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3546 void StringHelper::GenerateCompareFlatOneByteStrings(
3547 MacroAssembler* masm, Register left, Register right, Register scratch1,
3548 Register scratch2, Register scratch3, Register scratch4) {
3549 Label result_not_equal, compare_lengths;
3550 // Find minimum length and length difference.
3551 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
3552 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3553 __ Subu(scratch3, scratch1, Operand(scratch2));
3554 Register length_delta = scratch3;
3555 __ slt(scratch4, scratch2, scratch1);
3556 __ Movn(scratch1, scratch2, scratch4);
3557 Register min_length = scratch1;
3558 STATIC_ASSERT(kSmiTag == 0);
3559 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3562 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3563 scratch4, v0, &result_not_equal);
3565 // Compare lengths - strings up to min-length are equal.
3566 __ bind(&compare_lengths);
3567 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3568 // Use length_delta as result if it's zero.
3569 __ mov(scratch2, length_delta);
3570 __ mov(scratch4, zero_reg);
3571 __ mov(v0, zero_reg);
3573 __ bind(&result_not_equal);
3574 // Conditionally update the result based either on length_delta or
3575 // the last comparion performed in the loop above.
3577 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3578 __ li(v0, Operand(Smi::FromInt(GREATER)));
3579 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3580 __ li(v0, Operand(Smi::FromInt(LESS)));
3586 void StringHelper::GenerateOneByteCharsCompareLoop(
3587 MacroAssembler* masm, Register left, Register right, Register length,
3588 Register scratch1, Register scratch2, Register scratch3,
3589 Label* chars_not_equal) {
3590 // Change index to run from -length to -1 by adding length to string
3591 // start. This means that loop ends when index reaches zero, which
3592 // doesn't need an additional compare.
3593 __ SmiUntag(length);
3594 __ Addu(scratch1, length,
3595 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3596 __ Addu(left, left, Operand(scratch1));
3597 __ Addu(right, right, Operand(scratch1));
3598 __ Subu(length, zero_reg, length);
3599 Register index = length; // index = -length;
3605 __ Addu(scratch3, left, index);
3606 __ lbu(scratch1, MemOperand(scratch3));
3607 __ Addu(scratch3, right, index);
3608 __ lbu(scratch2, MemOperand(scratch3));
3609 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3610 __ Addu(index, index, 1);
3611 __ Branch(&loop, ne, index, Operand(zero_reg));
3615 void StringCompareStub::Generate(MacroAssembler* masm) {
3618 Counters* counters = isolate()->counters();
3620 // Stack frame on entry.
3621 // sp[0]: right string
3622 // sp[4]: left string
3623 __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3624 __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3627 __ Branch(¬_same, ne, a0, Operand(a1));
3628 STATIC_ASSERT(EQUAL == 0);
3629 STATIC_ASSERT(kSmiTag == 0);
3630 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3631 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3636 // Check that both objects are sequential one-byte strings.
3637 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3639 // Compare flat ASCII strings natively. Remove arguments from stack first.
3640 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3641 __ Addu(sp, sp, Operand(2 * kPointerSize));
3642 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3645 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3649 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3650 // ----------- S t a t e -------------
3653 // -- ra : return address
3654 // -----------------------------------
3656 // Load a2 with the allocation site. We stick an undefined dummy value here
3657 // and replace it with the real allocation site later when we instantiate this
3658 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3659 __ li(a2, handle(isolate()->heap()->undefined_value()));
3661 // Make sure that we actually patched the allocation site.
3662 if (FLAG_debug_code) {
3663 __ And(at, a2, Operand(kSmiTagMask));
3664 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3665 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
3666 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3667 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
3670 // Tail call into the stub that handles binary operations with allocation
3672 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3673 __ TailCallStub(&stub);
3677 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3678 DCHECK(state() == CompareICState::SMI);
3681 __ JumpIfNotSmi(a2, &miss);
3683 if (GetCondition() == eq) {
3684 // For equality we do not care about the sign of the result.
3685 __ Ret(USE_DELAY_SLOT);
3686 __ Subu(v0, a0, a1);
3688 // Untag before subtracting to avoid handling overflow.
3691 __ Ret(USE_DELAY_SLOT);
3692 __ Subu(v0, a1, a0);
3700 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3701 DCHECK(state() == CompareICState::NUMBER);
3704 Label unordered, maybe_undefined1, maybe_undefined2;
3707 if (left() == CompareICState::SMI) {
3708 __ JumpIfNotSmi(a1, &miss);
3710 if (right() == CompareICState::SMI) {
3711 __ JumpIfNotSmi(a0, &miss);
3714 // Inlining the double comparison and falling back to the general compare
3715 // stub if NaN is involved.
3716 // Load left and right operand.
3717 Label done, left, left_smi, right_smi;
3718 __ JumpIfSmi(a0, &right_smi);
3719 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3721 __ Subu(a2, a0, Operand(kHeapObjectTag));
3722 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3724 __ bind(&right_smi);
3725 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3726 FPURegister single_scratch = f6;
3727 __ mtc1(a2, single_scratch);
3728 __ cvt_d_w(f2, single_scratch);
3731 __ JumpIfSmi(a1, &left_smi);
3732 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3734 __ Subu(a2, a1, Operand(kHeapObjectTag));
3735 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3738 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3739 single_scratch = f8;
3740 __ mtc1(a2, single_scratch);
3741 __ cvt_d_w(f0, single_scratch);
3745 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3746 Label fpu_eq, fpu_lt;
3747 // Test if equal, and also handle the unordered/NaN case.
3748 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3750 // Test if less (unordered case is already handled).
3751 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3753 // Otherwise it's greater, so just fall thru, and return.
3754 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3755 __ Ret(USE_DELAY_SLOT);
3756 __ li(v0, Operand(GREATER));
3759 __ Ret(USE_DELAY_SLOT);
3760 __ li(v0, Operand(EQUAL));
3763 __ Ret(USE_DELAY_SLOT);
3764 __ li(v0, Operand(LESS));
3766 __ bind(&unordered);
3767 __ bind(&generic_stub);
3768 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3769 CompareICState::GENERIC, CompareICState::GENERIC);
3770 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3772 __ bind(&maybe_undefined1);
3773 if (Token::IsOrderedRelationalCompareOp(op())) {
3774 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3775 __ Branch(&miss, ne, a0, Operand(at));
3776 __ JumpIfSmi(a1, &unordered);
3777 __ GetObjectType(a1, a2, a2);
3778 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3782 __ bind(&maybe_undefined2);
3783 if (Token::IsOrderedRelationalCompareOp(op())) {
3784 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3785 __ Branch(&unordered, eq, a1, Operand(at));
3793 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3794 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3797 // Registers containing left and right operands respectively.
3799 Register right = a0;
3803 // Check that both operands are heap objects.
3804 __ JumpIfEitherSmi(left, right, &miss);
3806 // Check that both operands are internalized strings.
3807 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3808 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3809 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3810 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3811 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3812 __ Or(tmp1, tmp1, Operand(tmp2));
3813 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3814 __ Branch(&miss, ne, at, 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 STATIC_ASSERT(EQUAL == 0);
3820 STATIC_ASSERT(kSmiTag == 0);
3822 // Internalized strings are compared by identity.
3823 __ Ret(ne, left, Operand(right));
3824 DCHECK(is_int16(EQUAL));
3825 __ Ret(USE_DELAY_SLOT);
3826 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3833 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3834 DCHECK(state() == CompareICState::UNIQUE_NAME);
3835 DCHECK(GetCondition() == eq);
3838 // Registers containing left and right operands respectively.
3840 Register right = a0;
3844 // Check that both operands are heap objects.
3845 __ JumpIfEitherSmi(left, right, &miss);
3847 // Check that both operands are unique names. This leaves the instance
3848 // types loaded in tmp1 and tmp2.
3849 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3850 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3851 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3852 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3854 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3855 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3860 // Unique names are compared by identity.
3862 __ Branch(&done, ne, left, Operand(right));
3863 // Make sure a0 is non-zero. At this point input operands are
3864 // guaranteed to be non-zero.
3865 DCHECK(right.is(a0));
3866 STATIC_ASSERT(EQUAL == 0);
3867 STATIC_ASSERT(kSmiTag == 0);
3868 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3877 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3878 DCHECK(state() == CompareICState::STRING);
3881 bool equality = Token::IsEqualityOp(op());
3883 // Registers containing left and right operands respectively.
3885 Register right = a0;
3892 // Check that both operands are heap objects.
3893 __ JumpIfEitherSmi(left, right, &miss);
3895 // Check that both operands are strings. This leaves the instance
3896 // types loaded in tmp1 and tmp2.
3897 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3898 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3899 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3900 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3901 STATIC_ASSERT(kNotStringTag != 0);
3902 __ Or(tmp3, tmp1, tmp2);
3903 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3904 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3906 // Fast check for identical strings.
3907 Label left_ne_right;
3908 STATIC_ASSERT(EQUAL == 0);
3909 STATIC_ASSERT(kSmiTag == 0);
3910 __ Branch(&left_ne_right, ne, left, Operand(right));
3911 __ Ret(USE_DELAY_SLOT);
3912 __ mov(v0, zero_reg); // In the delay slot.
3913 __ bind(&left_ne_right);
3915 // Handle not identical strings.
3917 // Check that both strings are internalized strings. If they are, we're done
3918 // because we already know they are not identical. We know they are both
3921 DCHECK(GetCondition() == eq);
3922 STATIC_ASSERT(kInternalizedTag == 0);
3923 __ Or(tmp3, tmp1, Operand(tmp2));
3924 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3926 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3927 // Make sure a0 is non-zero. At this point input operands are
3928 // guaranteed to be non-zero.
3929 DCHECK(right.is(a0));
3930 __ Ret(USE_DELAY_SLOT);
3931 __ mov(v0, a0); // In the delay slot.
3932 __ bind(&is_symbol);
3935 // Check that both strings are sequential one-byte.
3937 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3940 // Compare flat one-byte strings. Returns when done.
3942 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3945 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3949 // Handle more complex cases in runtime.
3951 __ Push(left, right);
3953 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3955 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3963 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3964 DCHECK(state() == CompareICState::OBJECT);
3966 __ And(a2, a1, Operand(a0));
3967 __ JumpIfSmi(a2, &miss);
3969 __ GetObjectType(a0, a2, a2);
3970 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3971 __ GetObjectType(a1, a2, a2);
3972 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3974 DCHECK(GetCondition() == eq);
3975 __ Ret(USE_DELAY_SLOT);
3976 __ subu(v0, a0, a1);
3983 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3985 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3987 __ JumpIfSmi(a2, &miss);
3988 __ GetWeakValue(t0, cell);
3989 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3990 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3991 __ Branch(&miss, ne, a2, Operand(t0));
3992 __ Branch(&miss, ne, a3, Operand(t0));
3994 __ Ret(USE_DELAY_SLOT);
3995 __ subu(v0, a0, a1);
4002 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
4004 // Call the runtime system in a fresh internal frame.
4005 FrameScope scope(masm, StackFrame::INTERNAL);
4007 __ Push(ra, a1, a0);
4008 __ li(t0, Operand(Smi::FromInt(op())));
4009 __ addiu(sp, sp, -kPointerSize);
4010 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
4012 __ sw(t0, MemOperand(sp)); // In the delay slot.
4013 // Compute the entry point of the rewritten stub.
4014 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
4015 // Restore registers.
4022 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4023 // Make place for arguments to fit C calling convention. Most of the callers
4024 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
4025 // so they handle stack restoring and we don't have to do that here.
4026 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
4027 // kCArgsSlotsSize stack space after the call.
4028 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
4029 // Place the return address on the stack, making the call
4030 // GC safe. The RegExp backend also relies on this.
4031 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
4032 __ Call(t9); // Call the C++ function.
4033 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
4035 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
4036 // In case of an error the return address may point to a memory area
4037 // filled with kZapValue by the GC.
4038 // Dereference the address and check for this.
4039 __ lw(t0, MemOperand(t9));
4040 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
4041 Operand(reinterpret_cast<uint32_t>(kZapValue)));
4047 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4050 reinterpret_cast<intptr_t>(GetCode().location());
4051 __ Move(t9, target);
4052 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
4057 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4061 Register properties,
4063 Register scratch0) {
4064 DCHECK(name->IsUniqueName());
4065 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4066 // not equal to the name and kProbes-th slot is not used (its name is the
4067 // undefined value), it guarantees the hash table doesn't contain the
4068 // property. It's true even if some slots represent deleted properties
4069 // (their names are the hole value).
4070 for (int i = 0; i < kInlinedProbes; i++) {
4071 // scratch0 points to properties hash.
4072 // Compute the masked index: (hash + i + i * i) & mask.
4073 Register index = scratch0;
4074 // Capacity is smi 2^n.
4075 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
4076 __ Subu(index, index, Operand(1));
4077 __ And(index, index, Operand(
4078 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
4080 // Scale the index by multiplying by the entry size.
4081 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4082 __ sll(at, index, 1);
4083 __ Addu(index, index, at);
4085 Register entity_name = scratch0;
4086 // Having undefined at this place means the name is not contained.
4087 STATIC_ASSERT(kSmiTagSize == 1);
4088 Register tmp = properties;
4089 __ sll(scratch0, index, 1);
4090 __ Addu(tmp, properties, scratch0);
4091 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4093 DCHECK(!tmp.is(entity_name));
4094 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4095 __ Branch(done, eq, entity_name, Operand(tmp));
4097 // Load the hole ready for use below:
4098 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4100 // Stop if found the property.
4101 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4104 __ Branch(&good, eq, entity_name, Operand(tmp));
4106 // Check if the entry name is not a unique name.
4107 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4109 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4110 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4113 // Restore the properties.
4115 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4118 const int spill_mask =
4119 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
4120 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4122 __ MultiPush(spill_mask);
4123 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4124 __ li(a1, Operand(Handle<Name>(name)));
4125 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4128 __ MultiPop(spill_mask);
4130 __ Branch(done, eq, at, Operand(zero_reg));
4131 __ Branch(miss, ne, at, Operand(zero_reg));
4135 // Probe the name dictionary in the |elements| register. Jump to the
4136 // |done| label if a property with the given name is found. Jump to
4137 // the |miss| label otherwise.
4138 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4139 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4145 Register scratch2) {
4146 DCHECK(!elements.is(scratch1));
4147 DCHECK(!elements.is(scratch2));
4148 DCHECK(!name.is(scratch1));
4149 DCHECK(!name.is(scratch2));
4151 __ AssertName(name);
4153 // Compute the capacity mask.
4154 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
4155 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
4156 __ Subu(scratch1, scratch1, Operand(1));
4158 // Generate an unrolled loop that performs a few probes before
4159 // giving up. Measurements done on Gmail indicate that 2 probes
4160 // cover ~93% of loads from dictionaries.
4161 for (int i = 0; i < kInlinedProbes; i++) {
4162 // Compute the masked index: (hash + i + i * i) & mask.
4163 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4165 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4166 // the hash in a separate instruction. The value hash + i + i * i is right
4167 // shifted in the following and instruction.
4168 DCHECK(NameDictionary::GetProbeOffset(i) <
4169 1 << (32 - Name::kHashFieldOffset));
4170 __ Addu(scratch2, scratch2, Operand(
4171 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4173 __ srl(scratch2, scratch2, Name::kHashShift);
4174 __ And(scratch2, scratch1, scratch2);
4176 // Scale the index by multiplying by the element size.
4177 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4178 // scratch2 = scratch2 * 3.
4180 __ sll(at, scratch2, 1);
4181 __ Addu(scratch2, scratch2, at);
4183 // Check if the key is identical to the name.
4184 __ sll(at, scratch2, 2);
4185 __ Addu(scratch2, elements, at);
4186 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
4187 __ Branch(done, eq, name, Operand(at));
4190 const int spill_mask =
4191 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
4192 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4193 ~(scratch1.bit() | scratch2.bit());
4195 __ MultiPush(spill_mask);
4197 DCHECK(!elements.is(a1));
4199 __ Move(a0, elements);
4201 __ Move(a0, elements);
4204 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4206 __ mov(scratch2, a2);
4208 __ MultiPop(spill_mask);
4210 __ Branch(done, ne, at, Operand(zero_reg));
4211 __ Branch(miss, eq, at, Operand(zero_reg));
4215 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4216 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4217 // we cannot call anything that could cause a GC from this stub.
4219 // result: NameDictionary to probe
4221 // dictionary: NameDictionary to probe.
4222 // index: will hold an index of entry if lookup is successful.
4223 // might alias with result_.
4225 // result_ is zero if lookup failed, non zero otherwise.
4227 Register result = v0;
4228 Register dictionary = a0;
4230 Register index = a2;
4233 Register undefined = t1;
4234 Register entry_key = t2;
4236 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4238 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
4239 __ sra(mask, mask, kSmiTagSize);
4240 __ Subu(mask, mask, Operand(1));
4242 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4244 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4246 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4247 // Compute the masked index: (hash + i + i * i) & mask.
4248 // Capacity is smi 2^n.
4250 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4251 // the hash in a separate instruction. The value hash + i + i * i is right
4252 // shifted in the following and instruction.
4253 DCHECK(NameDictionary::GetProbeOffset(i) <
4254 1 << (32 - Name::kHashFieldOffset));
4255 __ Addu(index, hash, Operand(
4256 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4258 __ mov(index, hash);
4260 __ srl(index, index, Name::kHashShift);
4261 __ And(index, mask, index);
4263 // Scale the index by multiplying by the entry size.
4264 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4267 __ sll(index, index, 1);
4268 __ Addu(index, index, at);
4271 STATIC_ASSERT(kSmiTagSize == 1);
4272 __ sll(index, index, 2);
4273 __ Addu(index, index, dictionary);
4274 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
4276 // Having undefined at this place means the name is not contained.
4277 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4279 // Stop if found the property.
4280 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4282 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4283 // Check if the entry name is not a unique name.
4284 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4286 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4287 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4291 __ bind(&maybe_in_dictionary);
4292 // If we are doing negative lookup then probing failure should be
4293 // treated as a lookup success. For positive lookup probing failure
4294 // should be treated as lookup failure.
4295 if (mode() == POSITIVE_LOOKUP) {
4296 __ Ret(USE_DELAY_SLOT);
4297 __ mov(result, zero_reg);
4300 __ bind(&in_dictionary);
4301 __ Ret(USE_DELAY_SLOT);
4304 __ bind(¬_in_dictionary);
4305 __ Ret(USE_DELAY_SLOT);
4306 __ mov(result, zero_reg);
4310 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4312 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4314 // Hydrogen code stubs need stub2 at snapshot time.
4315 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4320 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4321 // the value has just been written into the object, now this stub makes sure
4322 // we keep the GC informed. The word in the object where the value has been
4323 // written is in the address register.
4324 void RecordWriteStub::Generate(MacroAssembler* masm) {
4325 Label skip_to_incremental_noncompacting;
4326 Label skip_to_incremental_compacting;
4328 // The first two branch+nop instructions are generated with labels so as to
4329 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4330 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4331 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4332 // incremental heap marking.
4333 // See RecordWriteStub::Patch for details.
4334 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4336 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4339 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4340 __ RememberedSetHelper(object(),
4343 save_fp_regs_mode(),
4344 MacroAssembler::kReturnAtEnd);
4348 __ bind(&skip_to_incremental_noncompacting);
4349 GenerateIncremental(masm, INCREMENTAL);
4351 __ bind(&skip_to_incremental_compacting);
4352 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4354 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4355 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4357 PatchBranchIntoNop(masm, 0);
4358 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4362 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4365 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4366 Label dont_need_remembered_set;
4368 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4369 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4371 &dont_need_remembered_set);
4373 __ CheckPageFlag(regs_.object(),
4375 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4377 &dont_need_remembered_set);
4379 // First notify the incremental marker if necessary, then update the
4381 CheckNeedsToInformIncrementalMarker(
4382 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4383 InformIncrementalMarker(masm);
4384 regs_.Restore(masm);
4385 __ RememberedSetHelper(object(),
4388 save_fp_regs_mode(),
4389 MacroAssembler::kReturnAtEnd);
4391 __ bind(&dont_need_remembered_set);
4394 CheckNeedsToInformIncrementalMarker(
4395 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4396 InformIncrementalMarker(masm);
4397 regs_.Restore(masm);
4402 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4403 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4404 int argument_count = 3;
4405 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4407 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4408 DCHECK(!address.is(regs_.object()));
4409 DCHECK(!address.is(a0));
4410 __ Move(address, regs_.address());
4411 __ Move(a0, regs_.object());
4412 __ Move(a1, address);
4413 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4415 AllowExternalCallThatCantCauseGC scope(masm);
4417 ExternalReference::incremental_marking_record_write_function(isolate()),
4419 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4423 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4424 MacroAssembler* masm,
4425 OnNoNeedToInformIncrementalMarker on_no_need,
4428 Label need_incremental;
4429 Label need_incremental_pop_scratch;
4431 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4432 __ lw(regs_.scratch1(),
4433 MemOperand(regs_.scratch0(),
4434 MemoryChunk::kWriteBarrierCounterOffset));
4435 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4436 __ sw(regs_.scratch1(),
4437 MemOperand(regs_.scratch0(),
4438 MemoryChunk::kWriteBarrierCounterOffset));
4439 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4441 // Let's look at the color of the object: If it is not black we don't have
4442 // to inform the incremental marker.
4443 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4445 regs_.Restore(masm);
4446 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4447 __ RememberedSetHelper(object(),
4450 save_fp_regs_mode(),
4451 MacroAssembler::kReturnAtEnd);
4458 // Get the value from the slot.
4459 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4461 if (mode == INCREMENTAL_COMPACTION) {
4462 Label ensure_not_white;
4464 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4465 regs_.scratch1(), // Scratch.
4466 MemoryChunk::kEvacuationCandidateMask,
4470 __ CheckPageFlag(regs_.object(),
4471 regs_.scratch1(), // Scratch.
4472 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4476 __ bind(&ensure_not_white);
4479 // We need extra registers for this, so we push the object and the address
4480 // register temporarily.
4481 __ Push(regs_.object(), regs_.address());
4482 __ EnsureNotWhite(regs_.scratch0(), // The value.
4483 regs_.scratch1(), // Scratch.
4484 regs_.object(), // Scratch.
4485 regs_.address(), // Scratch.
4486 &need_incremental_pop_scratch);
4487 __ Pop(regs_.object(), regs_.address());
4489 regs_.Restore(masm);
4490 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4491 __ RememberedSetHelper(object(),
4494 save_fp_regs_mode(),
4495 MacroAssembler::kReturnAtEnd);
4500 __ bind(&need_incremental_pop_scratch);
4501 __ Pop(regs_.object(), regs_.address());
4503 __ bind(&need_incremental);
4505 // Fall through when we need to inform the incremental marker.
4509 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4510 // ----------- S t a t e -------------
4511 // -- a0 : element value to store
4512 // -- a3 : element index as smi
4513 // -- sp[0] : array literal index in function as smi
4514 // -- sp[4] : array literal
4515 // clobbers a1, a2, t0
4516 // -----------------------------------
4519 Label double_elements;
4521 Label slow_elements;
4522 Label fast_elements;
4524 // Get array literal index, array literal and its map.
4525 __ lw(t0, MemOperand(sp, 0 * kPointerSize));
4526 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
4527 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4529 __ CheckFastElements(a2, t1, &double_elements);
4530 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4531 __ JumpIfSmi(a0, &smi_element);
4532 __ CheckFastSmiElements(a2, t1, &fast_elements);
4534 // Store into the array literal requires a elements transition. Call into
4536 __ bind(&slow_elements);
4538 __ Push(a1, a3, a0);
4539 __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4540 __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset));
4542 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4544 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4545 __ bind(&fast_elements);
4546 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4547 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4548 __ Addu(t2, t1, t2);
4549 __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4550 __ sw(a0, MemOperand(t2, 0));
4551 // Update the write barrier for the array store.
4552 __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4553 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4554 __ Ret(USE_DELAY_SLOT);
4557 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4558 // and value is Smi.
4559 __ bind(&smi_element);
4560 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4561 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4562 __ Addu(t2, t1, t2);
4563 __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize));
4564 __ Ret(USE_DELAY_SLOT);
4567 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4568 __ bind(&double_elements);
4569 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4570 __ StoreNumberToDoubleElements(a0, a3, t1, t3, t5, a2, &slow_elements);
4571 __ Ret(USE_DELAY_SLOT);
4576 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4577 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4578 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4579 int parameter_count_offset =
4580 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4581 __ lw(a1, MemOperand(fp, parameter_count_offset));
4582 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4583 __ Addu(a1, a1, Operand(1));
4585 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4586 __ sll(a1, a1, kPointerSizeLog2);
4587 __ Ret(USE_DELAY_SLOT);
4588 __ Addu(sp, sp, a1);
4592 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4593 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4594 LoadICStub stub(isolate(), state());
4595 stub.GenerateForTrampoline(masm);
4599 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4600 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4601 KeyedLoadICStub stub(isolate(), state());
4602 stub.GenerateForTrampoline(masm);
4606 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4607 EmitLoadTypeFeedbackVector(masm, a2);
4608 CallICStub stub(isolate(), state());
4609 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4613 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4614 EmitLoadTypeFeedbackVector(masm, a2);
4615 CallIC_ArrayStub stub(isolate(), state());
4616 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4620 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4623 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4624 GenerateImpl(masm, true);
4628 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4629 Register key, Register vector, Register slot,
4630 Register feedback, Register receiver_map,
4631 Register scratch1, Register scratch2,
4632 bool is_polymorphic, Label* miss) {
4633 // feedback initially contains the feedback array
4634 Label next_loop, prepare_next;
4635 Label start_polymorphic;
4637 Register cached_map = scratch1;
4640 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4641 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4642 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4643 // found, now call handler.
4644 Register handler = feedback;
4645 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4646 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4650 Register length = scratch2;
4651 __ bind(&start_polymorphic);
4652 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4653 if (!is_polymorphic) {
4654 // If the IC could be monomorphic we have to make sure we don't go past the
4655 // end of the feedback array.
4656 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4659 Register too_far = length;
4660 Register pointer_reg = feedback;
4662 // +-----+------+------+-----+-----+ ... ----+
4663 // | map | len | wm0 | h0 | wm1 | hN |
4664 // +-----+------+------+-----+-----+ ... ----+
4668 // pointer_reg too_far
4669 // aka feedback scratch2
4670 // also need receiver_map
4671 // use cached_map (scratch1) to look in the weak map values.
4672 __ sll(at, length, kPointerSizeLog2 - kSmiTagSize);
4673 __ Addu(too_far, feedback, Operand(at));
4674 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4675 __ Addu(pointer_reg, feedback,
4676 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4678 __ bind(&next_loop);
4679 __ lw(cached_map, MemOperand(pointer_reg));
4680 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4681 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4682 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
4683 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4686 __ bind(&prepare_next);
4687 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4688 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4690 // We exhausted our array of map handler pairs.
4695 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4696 Register receiver_map, Register feedback,
4697 Register vector, Register slot,
4698 Register scratch, Label* compare_map,
4699 Label* load_smi_map, Label* try_array) {
4700 __ JumpIfSmi(receiver, load_smi_map);
4701 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4702 __ bind(compare_map);
4703 Register cached_map = scratch;
4704 // Move the weak map into the weak_cell register.
4705 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4706 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4707 Register handler = feedback;
4709 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4710 __ Addu(handler, vector, Operand(at));
4712 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4713 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4718 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4719 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4720 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4721 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4722 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4723 Register feedback = t0;
4724 Register receiver_map = t1;
4725 Register scratch1 = t4;
4727 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4728 __ Addu(feedback, vector, Operand(at));
4729 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4731 // Try to quickly handle the monomorphic case without knowing for sure
4732 // if we have a weak cell in feedback. We do know it's safe to look
4733 // at WeakCell::kValueOffset.
4734 Label try_array, load_smi_map, compare_map;
4735 Label not_array, miss;
4736 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4737 scratch1, &compare_map, &load_smi_map, &try_array);
4739 // Is it a fixed array?
4740 __ bind(&try_array);
4741 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4742 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4743 __ Branch(¬_array, ne, at, Operand(scratch1));
4744 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4745 scratch1, t5, true, &miss);
4747 __ bind(¬_array);
4748 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4749 __ Branch(&miss, ne, at, Operand(feedback));
4750 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4751 Code::ComputeHandlerFlags(Code::LOAD_IC));
4752 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4753 false, receiver, name, feedback,
4754 receiver_map, scratch1, t5);
4757 LoadIC::GenerateMiss(masm);
4759 __ bind(&load_smi_map);
4760 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4761 __ jmp(&compare_map);
4765 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4766 GenerateImpl(masm, false);
4770 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4771 GenerateImpl(masm, true);
4775 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4776 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4777 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4778 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4779 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4780 Register feedback = t0;
4781 Register receiver_map = t1;
4782 Register scratch1 = t4;
4784 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4785 __ Addu(feedback, vector, Operand(at));
4786 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4788 // Try to quickly handle the monomorphic case without knowing for sure
4789 // if we have a weak cell in feedback. We do know it's safe to look
4790 // at WeakCell::kValueOffset.
4791 Label try_array, load_smi_map, compare_map;
4792 Label not_array, miss;
4793 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4794 scratch1, &compare_map, &load_smi_map, &try_array);
4796 __ bind(&try_array);
4797 // Is it a fixed array?
4798 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4799 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4800 __ Branch(¬_array, ne, at, Operand(scratch1));
4801 // We have a polymorphic element handler.
4802 __ JumpIfNotSmi(key, &miss);
4804 Label polymorphic, try_poly_name;
4805 __ bind(&polymorphic);
4806 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4807 scratch1, t5, true, &miss);
4809 __ bind(¬_array);
4811 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4812 __ Branch(&try_poly_name, ne, at, Operand(feedback));
4813 Handle<Code> megamorphic_stub =
4814 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4815 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4817 __ bind(&try_poly_name);
4818 // We might have a name in feedback, and a fixed array in the next slot.
4819 __ Branch(&miss, ne, key, Operand(feedback));
4820 // If the name comparison succeeded, we know we have a fixed array with
4821 // at least one map/handler pair.
4822 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4823 __ Addu(feedback, vector, Operand(at));
4825 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4826 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4827 scratch1, t5, false, &miss);
4830 KeyedLoadIC::GenerateMiss(masm);
4832 __ bind(&load_smi_map);
4833 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4834 __ jmp(&compare_map);
4838 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4839 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4840 VectorStoreICStub stub(isolate(), state());
4841 stub.GenerateForTrampoline(masm);
4845 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4846 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4847 VectorKeyedStoreICStub stub(isolate(), state());
4848 stub.GenerateForTrampoline(masm);
4852 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4853 GenerateImpl(masm, false);
4857 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4858 GenerateImpl(masm, true);
4862 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4865 // TODO(mvstanton): Implement.
4867 StoreIC::GenerateMiss(masm);
4871 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4872 GenerateImpl(masm, false);
4876 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4877 GenerateImpl(masm, true);
4881 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4884 // TODO(mvstanton): Implement.
4886 KeyedStoreIC::GenerateMiss(masm);
4890 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4891 if (masm->isolate()->function_entry_hook() != NULL) {
4892 ProfileEntryHookStub stub(masm->isolate());
4900 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4901 // The entry hook is a "push ra" instruction, followed by a call.
4902 // Note: on MIPS "push" is 2 instruction
4903 const int32_t kReturnAddressDistanceFromFunctionStart =
4904 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4906 // This should contain all kJSCallerSaved registers.
4907 const RegList kSavedRegs =
4908 kJSCallerSaved | // Caller saved registers.
4909 s5.bit(); // Saved stack pointer.
4911 // We also save ra, so the count here is one higher than the mask indicates.
4912 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4914 // Save all caller-save registers as this may be called from anywhere.
4915 __ MultiPush(kSavedRegs | ra.bit());
4917 // Compute the function's address for the first argument.
4918 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4920 // The caller's return address is above the saved temporaries.
4921 // Grab that for the second argument to the hook.
4922 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4924 // Align the stack if necessary.
4925 int frame_alignment = masm->ActivationFrameAlignment();
4926 if (frame_alignment > kPointerSize) {
4928 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4929 __ And(sp, sp, Operand(-frame_alignment));
4931 __ Subu(sp, sp, kCArgsSlotsSize);
4932 #if defined(V8_HOST_ARCH_MIPS)
4933 int32_t entry_hook =
4934 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4935 __ li(t9, Operand(entry_hook));
4937 // Under the simulator we need to indirect the entry hook through a
4938 // trampoline function at a known address.
4939 // It additionally takes an isolate as a third parameter.
4940 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4942 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4943 __ li(t9, Operand(ExternalReference(&dispatcher,
4944 ExternalReference::BUILTIN_CALL,
4947 // Call C function through t9 to conform ABI for PIC.
4950 // Restore the stack pointer if needed.
4951 if (frame_alignment > kPointerSize) {
4954 __ Addu(sp, sp, kCArgsSlotsSize);
4957 // Also pop ra to get Ret(0).
4958 __ MultiPop(kSavedRegs | ra.bit());
4964 static void CreateArrayDispatch(MacroAssembler* masm,
4965 AllocationSiteOverrideMode mode) {
4966 if (mode == DISABLE_ALLOCATION_SITES) {
4967 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4968 __ TailCallStub(&stub);
4969 } else if (mode == DONT_OVERRIDE) {
4970 int last_index = GetSequenceIndexFromFastElementsKind(
4971 TERMINAL_FAST_ELEMENTS_KIND);
4972 for (int i = 0; i <= last_index; ++i) {
4973 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4974 T stub(masm->isolate(), kind);
4975 __ TailCallStub(&stub, eq, a3, Operand(kind));
4978 // If we reached this point there is a problem.
4979 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4986 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4987 AllocationSiteOverrideMode mode) {
4988 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4989 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4990 // a0 - number of arguments
4991 // a1 - constructor?
4992 // sp[0] - last argument
4993 Label normal_sequence;
4994 if (mode == DONT_OVERRIDE) {
4995 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4996 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4997 STATIC_ASSERT(FAST_ELEMENTS == 2);
4998 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4999 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5000 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5002 // is the low bit set? If so, we are holey and that is good.
5003 __ And(at, a3, Operand(1));
5004 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5007 // look at the first argument
5008 __ lw(t1, MemOperand(sp, 0));
5009 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
5011 if (mode == DISABLE_ALLOCATION_SITES) {
5012 ElementsKind initial = GetInitialFastElementsKind();
5013 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5015 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5017 DISABLE_ALLOCATION_SITES);
5018 __ TailCallStub(&stub_holey);
5020 __ bind(&normal_sequence);
5021 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5023 DISABLE_ALLOCATION_SITES);
5024 __ TailCallStub(&stub);
5025 } else if (mode == DONT_OVERRIDE) {
5026 // We are going to create a holey array, but our kind is non-holey.
5027 // Fix kind and retry (only if we have an allocation site in the slot).
5028 __ Addu(a3, a3, Operand(1));
5030 if (FLAG_debug_code) {
5031 __ lw(t1, FieldMemOperand(a2, 0));
5032 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5033 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
5036 // Save the resulting elements kind in type info. We can't just store a3
5037 // in the AllocationSite::transition_info field because elements kind is
5038 // restricted to a portion of the field...upper bits need to be left alone.
5039 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5040 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5041 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5042 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5045 __ bind(&normal_sequence);
5046 int last_index = GetSequenceIndexFromFastElementsKind(
5047 TERMINAL_FAST_ELEMENTS_KIND);
5048 for (int i = 0; i <= last_index; ++i) {
5049 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5050 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5051 __ TailCallStub(&stub, eq, a3, Operand(kind));
5054 // If we reached this point there is a problem.
5055 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5063 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5064 int to_index = GetSequenceIndexFromFastElementsKind(
5065 TERMINAL_FAST_ELEMENTS_KIND);
5066 for (int i = 0; i <= to_index; ++i) {
5067 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5068 T stub(isolate, kind);
5070 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5071 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5078 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5079 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5081 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5083 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5088 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5090 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5091 for (int i = 0; i < 2; i++) {
5092 // For internal arrays we only need a few things.
5093 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5095 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5097 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5103 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5104 MacroAssembler* masm,
5105 AllocationSiteOverrideMode mode) {
5106 if (argument_count() == ANY) {
5107 Label not_zero_case, not_one_case;
5109 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5110 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5112 __ bind(¬_zero_case);
5113 __ Branch(¬_one_case, gt, a0, Operand(1));
5114 CreateArrayDispatchOneArgument(masm, mode);
5116 __ bind(¬_one_case);
5117 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5118 } else if (argument_count() == NONE) {
5119 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5120 } else if (argument_count() == ONE) {
5121 CreateArrayDispatchOneArgument(masm, mode);
5122 } else if (argument_count() == MORE_THAN_ONE) {
5123 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5130 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5131 // ----------- S t a t e -------------
5132 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5133 // -- a1 : constructor
5134 // -- a2 : AllocationSite or undefined
5135 // -- a3 : Original constructor
5136 // -- sp[0] : last argument
5137 // -----------------------------------
5139 if (FLAG_debug_code) {
5140 // The array construct code is only set for the global and natives
5141 // builtin Array functions which always have maps.
5143 // Initial map for the builtin Array function should be a map.
5144 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5145 // Will both indicate a NULL and a Smi.
5147 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5148 at, Operand(zero_reg));
5149 __ GetObjectType(t0, t0, t1);
5150 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5151 t1, Operand(MAP_TYPE));
5153 // We should either have undefined in a2 or a valid AllocationSite
5154 __ AssertUndefinedOrAllocationSite(a2, t0);
5158 __ Branch(&subclassing, ne, a1, Operand(a3));
5161 // Get the elements kind and case on that.
5162 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5163 __ Branch(&no_info, eq, a2, Operand(at));
5165 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5167 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5168 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5169 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5172 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5175 __ bind(&subclassing);
5180 switch (argument_count()) {
5183 __ li(at, Operand(2));
5184 __ addu(a0, a0, at);
5187 __ li(a0, Operand(2));
5190 __ li(a0, Operand(3));
5194 __ JumpToExternalReference(
5195 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5199 void InternalArrayConstructorStub::GenerateCase(
5200 MacroAssembler* masm, ElementsKind kind) {
5202 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5203 __ TailCallStub(&stub0, lo, a0, Operand(1));
5205 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5206 __ TailCallStub(&stubN, hi, a0, Operand(1));
5208 if (IsFastPackedElementsKind(kind)) {
5209 // We might need to create a holey array
5210 // look at the first argument.
5211 __ lw(at, MemOperand(sp, 0));
5213 InternalArraySingleArgumentConstructorStub
5214 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5215 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5218 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5219 __ TailCallStub(&stub1);
5223 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5224 // ----------- S t a t e -------------
5226 // -- a1 : constructor
5227 // -- sp[0] : return address
5228 // -- sp[4] : last argument
5229 // -----------------------------------
5231 if (FLAG_debug_code) {
5232 // The array construct code is only set for the global and natives
5233 // builtin Array functions which always have maps.
5235 // Initial map for the builtin Array function should be a map.
5236 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5237 // Will both indicate a NULL and a Smi.
5239 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5240 at, Operand(zero_reg));
5241 __ GetObjectType(a3, a3, t0);
5242 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5243 t0, Operand(MAP_TYPE));
5246 // Figure out the right elements kind.
5247 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5249 // Load the map's "bit field 2" into a3. We only need the first byte,
5250 // but the following bit field extraction takes care of that anyway.
5251 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5252 // Retrieve elements_kind from bit field 2.
5253 __ DecodeField<Map::ElementsKindBits>(a3);
5255 if (FLAG_debug_code) {
5257 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5259 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5260 a3, Operand(FAST_HOLEY_ELEMENTS));
5264 Label fast_elements_case;
5265 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5266 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5268 __ bind(&fast_elements_case);
5269 GenerateCase(masm, FAST_ELEMENTS);
5273 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5274 return ref0.address() - ref1.address();
5278 // Calls an API function. Allocates HandleScope, extracts returned value
5279 // from handle and propagates exceptions. Restores context. stack_space
5280 // - space to be unwound on exit (includes the call JS arguments space and
5281 // the additional space allocated for the fast call).
5282 static void CallApiFunctionAndReturn(
5283 MacroAssembler* masm, Register function_address,
5284 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5285 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5286 Isolate* isolate = masm->isolate();
5287 ExternalReference next_address =
5288 ExternalReference::handle_scope_next_address(isolate);
5289 const int kNextOffset = 0;
5290 const int kLimitOffset = AddressOffset(
5291 ExternalReference::handle_scope_limit_address(isolate), next_address);
5292 const int kLevelOffset = AddressOffset(
5293 ExternalReference::handle_scope_level_address(isolate), next_address);
5295 DCHECK(function_address.is(a1) || function_address.is(a2));
5297 Label profiler_disabled;
5298 Label end_profiler_check;
5299 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5300 __ lb(t9, MemOperand(t9, 0));
5301 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5303 // Additional parameter is the address of the actual callback.
5304 __ li(t9, Operand(thunk_ref));
5305 __ jmp(&end_profiler_check);
5307 __ bind(&profiler_disabled);
5308 __ mov(t9, function_address);
5309 __ bind(&end_profiler_check);
5311 // Allocate HandleScope in callee-save registers.
5312 __ li(s3, Operand(next_address));
5313 __ lw(s0, MemOperand(s3, kNextOffset));
5314 __ lw(s1, MemOperand(s3, kLimitOffset));
5315 __ lw(s2, MemOperand(s3, kLevelOffset));
5316 __ Addu(s2, s2, Operand(1));
5317 __ sw(s2, MemOperand(s3, kLevelOffset));
5319 if (FLAG_log_timer_events) {
5320 FrameScope frame(masm, StackFrame::MANUAL);
5321 __ PushSafepointRegisters();
5322 __ PrepareCallCFunction(1, a0);
5323 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5324 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5326 __ PopSafepointRegisters();
5329 // Native call returns to the DirectCEntry stub which redirects to the
5330 // return address pushed on stack (could have moved after GC).
5331 // DirectCEntry stub itself is generated early and never moves.
5332 DirectCEntryStub stub(isolate);
5333 stub.GenerateCall(masm, t9);
5335 if (FLAG_log_timer_events) {
5336 FrameScope frame(masm, StackFrame::MANUAL);
5337 __ PushSafepointRegisters();
5338 __ PrepareCallCFunction(1, a0);
5339 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5340 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5342 __ PopSafepointRegisters();
5345 Label promote_scheduled_exception;
5346 Label delete_allocated_handles;
5347 Label leave_exit_frame;
5348 Label return_value_loaded;
5350 // Load value from ReturnValue.
5351 __ lw(v0, return_value_operand);
5352 __ bind(&return_value_loaded);
5354 // No more valid handles (the result handle was the last one). Restore
5355 // previous handle scope.
5356 __ sw(s0, MemOperand(s3, kNextOffset));
5357 if (__ emit_debug_code()) {
5358 __ lw(a1, MemOperand(s3, kLevelOffset));
5359 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5361 __ Subu(s2, s2, Operand(1));
5362 __ sw(s2, MemOperand(s3, kLevelOffset));
5363 __ lw(at, MemOperand(s3, kLimitOffset));
5364 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5366 // Leave the API exit frame.
5367 __ bind(&leave_exit_frame);
5369 bool restore_context = context_restore_operand != NULL;
5370 if (restore_context) {
5371 __ lw(cp, *context_restore_operand);
5373 if (stack_space_offset != kInvalidStackOffset) {
5374 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5375 // so this must be accounted for.
5376 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5378 __ li(s0, Operand(stack_space));
5380 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5381 stack_space_offset != kInvalidStackOffset);
5383 // Check if the function scheduled an exception.
5384 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5385 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5386 __ lw(t1, MemOperand(at));
5387 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5391 // Re-throw by promoting a scheduled exception.
5392 __ bind(&promote_scheduled_exception);
5393 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5395 // HandleScope limit has changed. Delete allocated extensions.
5396 __ bind(&delete_allocated_handles);
5397 __ sw(s1, MemOperand(s3, kLimitOffset));
5400 __ PrepareCallCFunction(1, s1);
5401 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5402 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5405 __ jmp(&leave_exit_frame);
5409 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5410 const ParameterCount& argc,
5411 bool return_first_arg,
5412 bool call_data_undefined) {
5413 // ----------- S t a t e -------------
5415 // -- t0 : call_data
5417 // -- a1 : api_function_address
5418 // -- a3 : number of arguments if argc is a register
5421 // -- sp[0] : last argument
5423 // -- sp[(argc - 1)* 4] : first argument
5424 // -- sp[argc * 4] : receiver
5425 // -----------------------------------
5427 Register callee = a0;
5428 Register call_data = t0;
5429 Register holder = a2;
5430 Register api_function_address = a1;
5431 Register context = cp;
5433 typedef FunctionCallbackArguments FCA;
5435 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5436 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5437 STATIC_ASSERT(FCA::kDataIndex == 4);
5438 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5439 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5440 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5441 STATIC_ASSERT(FCA::kHolderIndex == 0);
5442 STATIC_ASSERT(FCA::kArgsLength == 7);
5444 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5446 // Save context, callee and call data.
5447 __ Push(context, callee, call_data);
5448 // Load context from callee.
5449 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5451 Register scratch = call_data;
5452 if (!call_data_undefined) {
5453 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5455 // Push return value and default return value.
5456 __ Push(scratch, scratch);
5457 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5458 // Push isolate and holder.
5459 __ Push(scratch, holder);
5461 // Prepare arguments.
5462 __ mov(scratch, sp);
5464 // Allocate the v8::Arguments structure in the arguments' space since
5465 // it's not controlled by GC.
5466 const int kApiStackSpace = 4;
5468 FrameScope frame_scope(masm, StackFrame::MANUAL);
5469 __ EnterExitFrame(false, kApiStackSpace);
5471 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5472 // a0 = FunctionCallbackInfo&
5473 // Arguments is after the return address.
5474 __ Addu(a0, sp, Operand(1 * kPointerSize));
5475 // FunctionCallbackInfo::implicit_args_
5476 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
5477 if (argc.is_immediate()) {
5478 // FunctionCallbackInfo::values_
5479 __ Addu(at, scratch,
5480 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5481 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5482 // FunctionCallbackInfo::length_ = argc
5483 __ li(at, Operand(argc.immediate()));
5484 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5485 // FunctionCallbackInfo::is_construct_call_ = 0
5486 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
5488 // FunctionCallbackInfo::values_
5489 __ sll(at, argc.reg(), kPointerSizeLog2);
5490 __ Addu(at, at, scratch);
5491 __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5492 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5493 // FunctionCallbackInfo::length_ = argc
5494 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5495 // FunctionCallbackInfo::is_construct_call_
5496 __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5497 __ sll(at, argc.reg(), kPointerSizeLog2);
5498 __ sw(at, MemOperand(a0, 3 * kPointerSize));
5501 ExternalReference thunk_ref =
5502 ExternalReference::invoke_function_callback(masm->isolate());
5504 AllowExternalCallThatCantCauseGC scope(masm);
5505 MemOperand context_restore_operand(
5506 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5507 // Stores return the first js argument.
5508 int return_value_offset = 0;
5509 if (return_first_arg) {
5510 return_value_offset = 2 + FCA::kArgsLength;
5512 return_value_offset = 2 + FCA::kReturnValueOffset;
5514 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5515 int stack_space = 0;
5516 int32_t stack_space_offset = 4 * kPointerSize;
5517 if (argc.is_immediate()) {
5518 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5519 stack_space_offset = kInvalidStackOffset;
5521 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5522 stack_space_offset, return_value_operand,
5523 &context_restore_operand);
5527 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5528 bool call_data_undefined = this->call_data_undefined();
5529 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5530 call_data_undefined);
5534 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5535 bool is_store = this->is_store();
5536 int argc = this->argc();
5537 bool call_data_undefined = this->call_data_undefined();
5538 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5539 call_data_undefined);
5543 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5544 // ----------- S t a t e -------------
5546 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5548 // -- a2 : api_function_address
5549 // -----------------------------------
5551 Register api_function_address = ApiGetterDescriptor::function_address();
5552 DCHECK(api_function_address.is(a2));
5554 __ mov(a0, sp); // a0 = Handle<Name>
5555 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5557 const int kApiStackSpace = 1;
5558 FrameScope frame_scope(masm, StackFrame::MANUAL);
5559 __ EnterExitFrame(false, kApiStackSpace);
5561 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5562 // a1 (internal::Object** args_) as the data.
5563 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
5564 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5566 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5568 ExternalReference thunk_ref =
5569 ExternalReference::invoke_accessor_getter_callback(isolate());
5570 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5571 kStackUnwindSpace, kInvalidStackOffset,
5572 MemOperand(fp, 6 * kPointerSize), NULL);
5578 } // namespace internal
5581 #endif // V8_TARGET_ARCH_MIPS