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, PASS_ARGUMENTS);
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, PASS_ARGUMENTS);
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 __ TailCallExternalReference(
1947 ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
1952 PropertyAccessCompiler::TailCallBuiltin(
1953 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1957 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1958 // sp[0] : number of parameters
1959 // sp[4] : receiver displacement
1961 // Check if the calling frame is an arguments adaptor frame.
1962 Label adaptor_frame, try_allocate, runtime;
1963 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1964 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1965 __ Branch(&adaptor_frame,
1968 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1970 // Get the length from the frame.
1971 __ lw(a1, MemOperand(sp, 0));
1972 __ Branch(&try_allocate);
1974 // Patch the arguments.length and the parameters pointer.
1975 __ bind(&adaptor_frame);
1976 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1977 __ sw(a1, MemOperand(sp, 0));
1978 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
1979 __ Addu(a3, a2, Operand(at));
1981 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1982 __ sw(a3, MemOperand(sp, 1 * kPointerSize));
1984 // Try the new space allocation. Start out with computing the size
1985 // of the arguments object and the elements array in words.
1986 Label add_arguments_object;
1987 __ bind(&try_allocate);
1988 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1989 __ srl(a1, a1, kSmiTagSize);
1991 __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1992 __ bind(&add_arguments_object);
1993 __ Addu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1995 // Do the allocation of both objects in one go.
1996 __ Allocate(a1, v0, a2, a3, &runtime,
1997 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1999 // Get the arguments boilerplate from the current native context.
2000 __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2001 __ lw(t0, FieldMemOperand(t0, GlobalObject::kNativeContextOffset));
2002 __ lw(t0, MemOperand(
2003 t0, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
2005 __ sw(t0, FieldMemOperand(v0, JSObject::kMapOffset));
2006 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
2007 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
2008 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
2010 // Get the length (smi tagged) and set that as an in-object property too.
2011 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2012 __ lw(a1, MemOperand(sp, 0 * kPointerSize));
2014 __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
2015 Heap::kArgumentsLengthIndex * kPointerSize));
2018 __ Branch(&done, eq, a1, Operand(zero_reg));
2020 // Get the parameters pointer from the stack.
2021 __ lw(a2, MemOperand(sp, 1 * kPointerSize));
2023 // Set up the elements pointer in the allocated arguments object and
2024 // initialize the header in the elements fixed array.
2025 __ Addu(t0, v0, Operand(Heap::kStrictArgumentsObjectSize));
2026 __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset));
2027 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
2028 __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset));
2029 __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset));
2030 // Untag the length for the loop.
2031 __ srl(a1, a1, kSmiTagSize);
2033 // Copy the fixed array slots.
2035 // Set up t0 to point to the first array slot.
2036 __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2038 // Pre-decrement a2 with kPointerSize on each iteration.
2039 // Pre-decrement in order to skip receiver.
2040 __ Addu(a2, a2, Operand(-kPointerSize));
2041 __ lw(a3, MemOperand(a2));
2042 // Post-increment t0 with kPointerSize on each iteration.
2043 __ sw(a3, MemOperand(t0));
2044 __ Addu(t0, t0, Operand(kPointerSize));
2045 __ Subu(a1, a1, Operand(1));
2046 __ Branch(&loop, ne, a1, Operand(zero_reg));
2048 // Return and remove the on-stack parameters.
2052 // Do the runtime call to allocate the arguments object.
2054 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2058 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2059 // sp[0] : language mode
2060 // sp[4] : index of rest parameter
2061 // sp[8] : number of parameters
2062 // sp[12] : receiver displacement
2063 // Check if the calling frame is an arguments adaptor frame.
2066 __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2067 __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
2068 __ Branch(&runtime, ne, a3,
2069 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2071 // Patch the arguments.length and the parameters pointer.
2072 __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
2073 __ sw(a1, MemOperand(sp, 2 * kPointerSize));
2074 __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize);
2075 __ Addu(a3, a2, Operand(at));
2077 __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
2078 __ sw(a3, MemOperand(sp, 3 * kPointerSize));
2080 // Do the runtime call to allocate the arguments object.
2082 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2086 void RegExpExecStub::Generate(MacroAssembler* masm) {
2087 // Just jump directly to runtime if native RegExp is not selected at compile
2088 // time or if regexp entry in generated code is turned off runtime switch or
2090 #ifdef V8_INTERPRETED_REGEXP
2091 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2092 #else // V8_INTERPRETED_REGEXP
2094 // Stack frame on entry.
2095 // sp[0]: last_match_info (expected JSArray)
2096 // sp[4]: previous index
2097 // sp[8]: subject string
2098 // sp[12]: JSRegExp object
2100 const int kLastMatchInfoOffset = 0 * kPointerSize;
2101 const int kPreviousIndexOffset = 1 * kPointerSize;
2102 const int kSubjectOffset = 2 * kPointerSize;
2103 const int kJSRegExpOffset = 3 * kPointerSize;
2106 // Allocation of registers for this function. These are in callee save
2107 // registers and will be preserved by the call to the native RegExp code, as
2108 // this code is called using the normal C calling convention. When calling
2109 // directly from generated code the native RegExp code will not do a GC and
2110 // therefore the content of these registers are safe to use after the call.
2111 // MIPS - using s0..s2, since we are not using CEntry Stub.
2112 Register subject = s0;
2113 Register regexp_data = s1;
2114 Register last_match_info_elements = s2;
2116 // Ensure that a RegExp stack is allocated.
2117 ExternalReference address_of_regexp_stack_memory_address =
2118 ExternalReference::address_of_regexp_stack_memory_address(
2120 ExternalReference address_of_regexp_stack_memory_size =
2121 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2122 __ li(a0, Operand(address_of_regexp_stack_memory_size));
2123 __ lw(a0, MemOperand(a0, 0));
2124 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2126 // Check that the first argument is a JSRegExp object.
2127 __ lw(a0, MemOperand(sp, kJSRegExpOffset));
2128 STATIC_ASSERT(kSmiTag == 0);
2129 __ JumpIfSmi(a0, &runtime);
2130 __ GetObjectType(a0, a1, a1);
2131 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2133 // Check that the RegExp has been compiled (data contains a fixed array).
2134 __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2135 if (FLAG_debug_code) {
2136 __ SmiTst(regexp_data, t0);
2138 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2141 __ GetObjectType(regexp_data, a0, a0);
2143 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2145 Operand(FIXED_ARRAY_TYPE));
2148 // regexp_data: RegExp data (FixedArray)
2149 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2150 __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2151 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2153 // regexp_data: RegExp data (FixedArray)
2154 // Check that the number of captures fit in the static offsets vector buffer.
2156 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2157 // Check (number_of_captures + 1) * 2 <= offsets vector size
2158 // Or number_of_captures * 2 <= offsets vector size - 2
2159 // Multiplying by 2 comes for free since a2 is smi-tagged.
2160 STATIC_ASSERT(kSmiTag == 0);
2161 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2162 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2164 &runtime, hi, a2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
2166 // Reset offset for possibly sliced string.
2167 __ mov(t0, zero_reg);
2168 __ lw(subject, MemOperand(sp, kSubjectOffset));
2169 __ JumpIfSmi(subject, &runtime);
2170 __ mov(a3, subject); // Make a copy of the original subject string.
2171 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2172 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2173 // subject: subject string
2174 // a3: subject string
2175 // a0: subject string instance type
2176 // regexp_data: RegExp data (FixedArray)
2177 // Handle subject string according to its encoding and representation:
2178 // (1) Sequential string? If yes, go to (5).
2179 // (2) Anything but sequential or cons? If yes, go to (6).
2180 // (3) Cons string. If the string is flat, replace subject with first string.
2181 // Otherwise bailout.
2182 // (4) Is subject external? If yes, go to (7).
2183 // (5) Sequential string. Load regexp code according to encoding.
2187 // Deferred code at the end of the stub:
2188 // (6) Not a long external string? If yes, go to (8).
2189 // (7) External string. Make it, offset-wise, look like a sequential string.
2191 // (8) Short external string or not a string? If yes, bail out to runtime.
2192 // (9) Sliced string. Replace subject with parent. Go to (4).
2194 Label seq_string /* 5 */, external_string /* 7 */,
2195 check_underlying /* 4 */, not_seq_nor_cons /* 6 */,
2196 not_long_external /* 8 */;
2198 // (1) Sequential string? If yes, go to (5).
2201 Operand(kIsNotStringMask |
2202 kStringRepresentationMask |
2203 kShortExternalStringMask));
2204 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2205 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2207 // (2) Anything but sequential or cons? If yes, go to (6).
2208 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2209 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2210 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2211 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2213 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2215 // (3) Cons string. Check that it's flat.
2216 // Replace subject with first string and reload instance type.
2217 __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2218 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2219 __ Branch(&runtime, ne, a0, Operand(a1));
2220 __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2222 // (4) Is subject external? If yes, go to (7).
2223 __ bind(&check_underlying);
2224 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2225 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2226 STATIC_ASSERT(kSeqStringTag == 0);
2227 __ And(at, a0, Operand(kStringRepresentationMask));
2228 // The underlying external string is never a short external string.
2229 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2230 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2231 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2233 // (5) Sequential string. Load regexp code according to encoding.
2234 __ bind(&seq_string);
2235 // subject: sequential subject string (or look-alike, external string)
2236 // a3: original subject string
2237 // Load previous index and check range before a3 is overwritten. We have to
2238 // use a3 instead of subject here because subject might have been only made
2239 // to look like a sequential string when it actually is an external string.
2240 __ lw(a1, MemOperand(sp, kPreviousIndexOffset));
2241 __ JumpIfNotSmi(a1, &runtime);
2242 __ lw(a3, FieldMemOperand(a3, String::kLengthOffset));
2243 __ Branch(&runtime, ls, a3, Operand(a1));
2244 __ sra(a1, a1, kSmiTagSize); // Untag the Smi.
2246 STATIC_ASSERT(kStringEncodingMask == 4);
2247 STATIC_ASSERT(kOneByteStringTag == 4);
2248 STATIC_ASSERT(kTwoByteStringTag == 0);
2249 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one-byte.
2250 __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2251 __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below).
2252 __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2253 __ Movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2255 // (E) Carry on. String handling is done.
2256 // t9: irregexp code
2257 // Check that the irregexp code has been generated for the actual string
2258 // encoding. If it has, the field contains a code object otherwise it contains
2259 // a smi (code flushing support).
2260 __ JumpIfSmi(t9, &runtime);
2262 // a1: previous index
2263 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2265 // subject: Subject string
2266 // regexp_data: RegExp data (FixedArray)
2267 // All checks done. Now push arguments for native regexp code.
2268 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2271 // Isolates: note we add an additional parameter here (isolate pointer).
2272 const int kRegExpExecuteArguments = 9;
2273 const int kParameterRegisters = 4;
2274 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2276 // Stack pointer now points to cell where return address is to be written.
2277 // Arguments are before that on the stack or in registers, meaning we
2278 // treat the return address as argument 5. Thus every argument after that
2279 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2280 // allocating space for the c argument slots, we don't need to calculate
2281 // that into the argument positions on the stack. This is how the stack will
2282 // look (sp meaning the value of sp at this moment):
2283 // [sp + 5] - Argument 9
2284 // [sp + 4] - Argument 8
2285 // [sp + 3] - Argument 7
2286 // [sp + 2] - Argument 6
2287 // [sp + 1] - Argument 5
2288 // [sp + 0] - saved ra
2290 // Argument 9: Pass current isolate address.
2291 // CFunctionArgumentOperand handles MIPS stack argument slots.
2292 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2293 __ sw(a0, MemOperand(sp, 5 * kPointerSize));
2295 // Argument 8: Indicate that this is a direct call from JavaScript.
2296 __ li(a0, Operand(1));
2297 __ sw(a0, MemOperand(sp, 4 * kPointerSize));
2299 // Argument 7: Start (high end) of backtracking stack memory area.
2300 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2301 __ lw(a0, MemOperand(a0, 0));
2302 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2303 __ lw(a2, MemOperand(a2, 0));
2304 __ addu(a0, a0, a2);
2305 __ sw(a0, MemOperand(sp, 3 * kPointerSize));
2307 // Argument 6: Set the number of capture registers to zero to force global
2308 // regexps to behave as non-global. This does not affect non-global regexps.
2309 __ mov(a0, zero_reg);
2310 __ sw(a0, MemOperand(sp, 2 * kPointerSize));
2312 // Argument 5: static offsets vector buffer.
2314 ExternalReference::address_of_static_offsets_vector(isolate())));
2315 __ sw(a0, MemOperand(sp, 1 * kPointerSize));
2317 // For arguments 4 and 3 get string length, calculate start of string data
2318 // calculate the shift of the index (0 for one-byte and 1 for two-byte).
2319 __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2320 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2321 // Load the length from the original subject string from the previous stack
2322 // frame. Therefore we have to use fp, which points exactly to two pointer
2323 // sizes below the previous sp. (Because creating a new stack frame pushes
2324 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2325 __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2326 // If slice offset is not 0, load the length from the original sliced string.
2327 // Argument 4, a3: End of string data
2328 // Argument 3, a2: Start of string data
2329 // Prepare start and end index of the input.
2330 __ sllv(t1, t0, a3);
2331 __ addu(t0, t2, t1);
2332 __ sllv(t1, a1, a3);
2333 __ addu(a2, t0, t1);
2335 __ lw(t2, FieldMemOperand(subject, String::kLengthOffset));
2336 __ sra(t2, t2, kSmiTagSize);
2337 __ sllv(t1, t2, a3);
2338 __ addu(a3, t0, t1);
2339 // Argument 2 (a1): Previous index.
2342 // Argument 1 (a0): Subject string.
2343 __ mov(a0, subject);
2345 // Locate the code entry and call it.
2346 __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2347 DirectCEntryStub stub(isolate());
2348 stub.GenerateCall(masm, t9);
2350 __ LeaveExitFrame(false, no_reg, true);
2353 // subject: subject string (callee saved)
2354 // regexp_data: RegExp data (callee saved)
2355 // last_match_info_elements: Last match info elements (callee saved)
2356 // Check the result.
2358 __ Branch(&success, eq, v0, Operand(1));
2359 // We expect exactly one result since we force the called regexp to behave
2362 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2363 // If not exception it can only be retry. Handle that in the runtime system.
2364 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2365 // Result must now be exception. If there is no pending exception already a
2366 // stack overflow (on the backtrack stack) was detected in RegExp code but
2367 // haven't created the exception yet. Handle that in the runtime system.
2368 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2369 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2370 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2372 __ lw(v0, MemOperand(a2, 0));
2373 __ Branch(&runtime, eq, v0, Operand(a1));
2375 // For exception, throw the exception again.
2376 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2379 // For failure and exception return null.
2380 __ li(v0, Operand(isolate()->factory()->null_value()));
2383 // Process the result from the native regexp code.
2386 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2387 // Calculate number of capture registers (number_of_captures + 1) * 2.
2388 // Multiplying by 2 comes for free since r1 is smi-tagged.
2389 STATIC_ASSERT(kSmiTag == 0);
2390 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2391 __ Addu(a1, a1, Operand(2)); // a1 was a smi.
2393 __ lw(a0, MemOperand(sp, kLastMatchInfoOffset));
2394 __ JumpIfSmi(a0, &runtime);
2395 __ GetObjectType(a0, a2, a2);
2396 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2397 // Check that the JSArray is in fast case.
2398 __ lw(last_match_info_elements,
2399 FieldMemOperand(a0, JSArray::kElementsOffset));
2400 __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2401 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2402 __ Branch(&runtime, ne, a0, Operand(at));
2403 // Check that the last match info has space for the capture registers and the
2404 // additional information.
2406 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2407 __ Addu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2408 __ sra(at, a0, kSmiTagSize);
2409 __ Branch(&runtime, gt, a2, Operand(at));
2411 // a1: number of capture registers
2412 // subject: subject string
2413 // Store the capture count.
2414 __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi.
2415 __ sw(a2, FieldMemOperand(last_match_info_elements,
2416 RegExpImpl::kLastCaptureCountOffset));
2417 // Store last subject and last input.
2419 FieldMemOperand(last_match_info_elements,
2420 RegExpImpl::kLastSubjectOffset));
2421 __ mov(a2, subject);
2422 __ RecordWriteField(last_match_info_elements,
2423 RegExpImpl::kLastSubjectOffset,
2428 __ mov(subject, a2);
2430 FieldMemOperand(last_match_info_elements,
2431 RegExpImpl::kLastInputOffset));
2432 __ RecordWriteField(last_match_info_elements,
2433 RegExpImpl::kLastInputOffset,
2439 // Get the static offsets vector filled by the native regexp code.
2440 ExternalReference address_of_static_offsets_vector =
2441 ExternalReference::address_of_static_offsets_vector(isolate());
2442 __ li(a2, Operand(address_of_static_offsets_vector));
2444 // a1: number of capture registers
2445 // a2: offsets vector
2446 Label next_capture, done;
2447 // Capture register counter starts from number of capture registers and
2448 // counts down until wrapping after zero.
2450 last_match_info_elements,
2451 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2452 __ bind(&next_capture);
2453 __ Subu(a1, a1, Operand(1));
2454 __ Branch(&done, lt, a1, Operand(zero_reg));
2455 // Read the value from the static offsets vector buffer.
2456 __ lw(a3, MemOperand(a2, 0));
2457 __ addiu(a2, a2, kPointerSize);
2458 // Store the smi value in the last match info.
2459 __ sll(a3, a3, kSmiTagSize); // Convert to Smi.
2460 __ sw(a3, MemOperand(a0, 0));
2461 __ Branch(&next_capture, USE_DELAY_SLOT);
2462 __ addiu(a0, a0, kPointerSize); // In branch delay slot.
2466 // Return last match info.
2467 __ lw(v0, MemOperand(sp, kLastMatchInfoOffset));
2470 // Do the runtime call to execute the regexp.
2472 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2474 // Deferred code for string handling.
2475 // (6) Not a long external string? If yes, go to (8).
2476 __ bind(¬_seq_nor_cons);
2478 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2480 // (7) External string. Make it, offset-wise, look like a sequential string.
2481 __ bind(&external_string);
2482 __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2483 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2484 if (FLAG_debug_code) {
2485 // Assert that we do not have a cons or slice (indirect strings) here.
2486 // Sequential strings have already been ruled out.
2487 __ And(at, a0, Operand(kIsIndirectStringMask));
2489 kExternalStringExpectedButNotFound,
2494 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2495 // Move the pointer so that offset-wise, it looks like a sequential string.
2496 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2499 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2500 __ jmp(&seq_string); // Go to (5).
2502 // (8) Short external string or not a string? If yes, bail out to runtime.
2503 __ bind(¬_long_external);
2504 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2505 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2506 __ Branch(&runtime, ne, at, Operand(zero_reg));
2508 // (9) Sliced string. Replace subject with parent. Go to (4).
2509 // Load offset into t0 and replace subject string with parent.
2510 __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2511 __ sra(t0, t0, kSmiTagSize);
2512 __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2513 __ jmp(&check_underlying); // Go to (4).
2514 #endif // V8_INTERPRETED_REGEXP
2518 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
2519 // a0 : number of arguments to the construct function
2520 // a2 : Feedback vector
2521 // a3 : slot in feedback vector (Smi)
2522 // a1 : the function to call
2523 FrameScope scope(masm, StackFrame::INTERNAL);
2524 const RegList kSavedRegs = 1 << 4 | // a0
2529 // Number-of-arguments register must be smi-tagged to call out.
2531 __ MultiPush(kSavedRegs);
2535 __ MultiPop(kSavedRegs);
2540 static void GenerateRecordCallTarget(MacroAssembler* masm) {
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 Label initialize, done, miss, megamorphic, not_array_function;
2550 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2551 masm->isolate()->heap()->megamorphic_symbol());
2552 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2553 masm->isolate()->heap()->uninitialized_symbol());
2555 // Load the cache state into t0.
2556 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2557 __ Addu(t0, a2, Operand(t0));
2558 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2560 // A monomorphic cache hit or an already megamorphic state: invoke the
2561 // function without changing the state.
2562 // We don't know if t0 is a WeakCell or a Symbol, but it's harmless to read at
2563 // this position in a symbol (see static asserts in type-feedback-vector.h).
2564 Label check_allocation_site;
2565 Register feedback_map = t1;
2566 Register weak_value = t4;
2567 __ lw(weak_value, FieldMemOperand(t0, WeakCell::kValueOffset));
2568 __ Branch(&done, eq, a1, Operand(weak_value));
2569 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2570 __ Branch(&done, eq, t0, Operand(at));
2571 __ lw(feedback_map, FieldMemOperand(t0, HeapObject::kMapOffset));
2572 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2573 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2574 feedback_map, Operand(at));
2576 // If the weak cell is cleared, we have a new chance to become monomorphic.
2577 __ JumpIfSmi(weak_value, &initialize);
2578 __ jmp(&megamorphic);
2580 if (!FLAG_pretenuring_call_new) {
2581 __ bind(&check_allocation_site);
2582 // If we came here, we need to see if we are the array function.
2583 // If we didn't have a matching function, and we didn't find the megamorph
2584 // sentinel, then we have in the slot either some other function or an
2586 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2587 __ Branch(&miss, ne, feedback_map, Operand(at));
2589 // Make sure the function is the Array() function
2590 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2591 __ Branch(&megamorphic, ne, a1, Operand(t0));
2597 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2599 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2600 __ Branch(&initialize, eq, t0, Operand(at));
2601 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2602 // write-barrier is needed.
2603 __ bind(&megamorphic);
2604 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2605 __ Addu(t0, a2, Operand(t0));
2606 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2607 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2610 // An uninitialized cache is patched with the function.
2611 __ bind(&initialize);
2612 if (!FLAG_pretenuring_call_new) {
2613 // Make sure the function is the Array() function.
2614 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2615 __ Branch(¬_array_function, ne, a1, Operand(t0));
2617 // The target function is the Array constructor,
2618 // Create an AllocationSite if we don't already have it, store it in the
2620 CreateAllocationSiteStub create_stub(masm->isolate());
2621 CallStubInRecordCallTarget(masm, &create_stub);
2624 __ bind(¬_array_function);
2627 CreateWeakCellStub create_stub(masm->isolate());
2628 CallStubInRecordCallTarget(masm, &create_stub);
2633 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2634 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2635 __ lw(t0, FieldMemOperand(a3, SharedFunctionInfo::kCompilerHintsOffset));
2637 // Do not transform the receiver for strict mode functions.
2638 int32_t strict_mode_function_mask =
2639 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
2640 // Do not transform the receiver for native (Compilerhints already in a3).
2641 int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize);
2642 __ And(at, t0, Operand(strict_mode_function_mask | native_mask));
2643 __ Branch(cont, ne, at, Operand(zero_reg));
2647 static void EmitSlowCase(MacroAssembler* masm,
2649 Label* non_function) {
2650 // Check for function proxy.
2651 __ Branch(non_function, ne, t0, Operand(JS_FUNCTION_PROXY_TYPE));
2652 __ push(a1); // put proxy as additional argument
2653 __ li(a0, Operand(argc + 1, RelocInfo::NONE32));
2654 __ mov(a2, zero_reg);
2655 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY);
2657 Handle<Code> adaptor =
2658 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2659 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2662 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2663 // of the original receiver from the call site).
2664 __ bind(non_function);
2665 __ sw(a1, MemOperand(sp, argc * kPointerSize));
2666 __ li(a0, Operand(argc)); // Set up the number of arguments.
2667 __ mov(a2, zero_reg);
2668 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION);
2669 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2670 RelocInfo::CODE_TARGET);
2674 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2675 // Wrap the receiver and patch it back onto the stack.
2676 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2678 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2681 __ Branch(USE_DELAY_SLOT, cont);
2682 __ sw(v0, MemOperand(sp, argc * kPointerSize));
2686 static void CallFunctionNoFeedback(MacroAssembler* masm,
2687 int argc, bool needs_checks,
2688 bool call_as_method) {
2689 // a1 : the function to call
2690 Label slow, non_function, wrap, cont;
2693 // Check that the function is really a JavaScript function.
2694 // a1: pushed function (to be verified)
2695 __ JumpIfSmi(a1, &non_function);
2697 // Goto slow case if we do not have a function.
2698 __ GetObjectType(a1, t0, t0);
2699 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
2702 // Fast-case: Invoke the function now.
2703 // a1: pushed function
2704 ParameterCount actual(argc);
2706 if (call_as_method) {
2708 EmitContinueIfStrictOrNative(masm, &cont);
2711 // Compute the receiver in sloppy mode.
2712 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2715 __ JumpIfSmi(a3, &wrap);
2716 __ GetObjectType(a3, t0, t0);
2717 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2725 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2728 // Slow-case: Non-function called.
2730 EmitSlowCase(masm, argc, &non_function);
2733 if (call_as_method) {
2735 // Wrap the receiver and patch it back onto the stack.
2736 EmitWrapCase(masm, argc, &cont);
2741 void CallFunctionStub::Generate(MacroAssembler* masm) {
2742 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2746 void CallConstructStub::Generate(MacroAssembler* masm) {
2747 // a0 : number of arguments
2748 // a1 : the function to call
2749 // a2 : feedback vector
2750 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2751 // t0 : original constructor (for IsSuperConstructorCall)
2752 Label slow, non_function_call;
2754 // Check that the function is not a smi.
2755 __ JumpIfSmi(a1, &non_function_call);
2756 // Check that the function is a JSFunction.
2757 __ GetObjectType(a1, t1, t1);
2758 __ Branch(&slow, ne, t1, Operand(JS_FUNCTION_TYPE));
2760 if (RecordCallTarget()) {
2761 if (IsSuperConstructorCall()) {
2764 GenerateRecordCallTarget(masm);
2765 if (IsSuperConstructorCall()) {
2769 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2770 __ Addu(t1, a2, at);
2771 if (FLAG_pretenuring_call_new) {
2772 // Put the AllocationSite from the feedback vector into a2.
2773 // By adding kPointerSize we encode that we know the AllocationSite
2774 // entry is at the feedback vector slot given by a3 + 1.
2775 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize + kPointerSize));
2777 Label feedback_register_initialized;
2778 // Put the AllocationSite from the feedback vector into a2, or undefined.
2779 __ lw(a2, FieldMemOperand(t1, FixedArray::kHeaderSize));
2780 __ lw(t1, FieldMemOperand(a2, AllocationSite::kMapOffset));
2781 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2782 __ Branch(&feedback_register_initialized, eq, t1, Operand(at));
2783 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2784 __ bind(&feedback_register_initialized);
2787 __ AssertUndefinedOrAllocationSite(a2, t1);
2790 // Pass function as original constructor.
2791 if (IsSuperConstructorCall()) {
2797 // Jump to the function-specific construct stub.
2798 Register jmp_reg = t0;
2799 __ lw(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2800 __ lw(jmp_reg, FieldMemOperand(jmp_reg,
2801 SharedFunctionInfo::kConstructStubOffset));
2802 __ Addu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2805 // a0: number of arguments
2806 // a1: called object
2810 __ Branch(&non_function_call, ne, t1, Operand(JS_FUNCTION_PROXY_TYPE));
2811 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2814 __ bind(&non_function_call);
2815 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2817 // Set expected number of arguments to zero (not changing r0).
2818 __ li(a2, Operand(0, RelocInfo::NONE32));
2819 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2820 RelocInfo::CODE_TARGET);
2824 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2825 __ lw(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2826 __ lw(vector, FieldMemOperand(vector,
2827 JSFunction::kSharedFunctionInfoOffset));
2828 __ lw(vector, FieldMemOperand(vector,
2829 SharedFunctionInfo::kFeedbackVectorOffset));
2833 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2839 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2840 __ Branch(&miss, ne, a1, Operand(at));
2842 __ li(a0, Operand(arg_count()));
2843 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2844 __ Addu(at, a2, Operand(at));
2845 __ lw(t0, FieldMemOperand(at, FixedArray::kHeaderSize));
2847 // Verify that t0 contains an AllocationSite
2848 __ lw(t1, FieldMemOperand(t0, HeapObject::kMapOffset));
2849 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2850 __ Branch(&miss, ne, t1, Operand(at));
2852 // Increment the call count for monomorphic function calls.
2853 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2854 __ Addu(at, a2, Operand(at));
2855 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2856 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2857 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2861 ArrayConstructorStub stub(masm->isolate(), arg_count());
2862 __ TailCallStub(&stub);
2867 // The slow case, we need this no matter what to complete a call after a miss.
2868 CallFunctionNoFeedback(masm,
2874 __ stop("Unexpected code address");
2878 void CallICStub::Generate(MacroAssembler* masm) {
2880 // a3 - slot id (Smi)
2882 const int with_types_offset =
2883 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2884 const int generic_offset =
2885 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2886 Label extra_checks_or_miss, slow_start;
2887 Label slow, non_function, wrap, cont;
2888 Label have_js_function;
2889 int argc = arg_count();
2890 ParameterCount actual(argc);
2892 // The checks. First, does r1 match the recorded monomorphic target?
2893 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2894 __ Addu(t0, a2, Operand(t0));
2895 __ lw(t0, FieldMemOperand(t0, FixedArray::kHeaderSize));
2897 // We don't know that we have a weak cell. We might have a private symbol
2898 // or an AllocationSite, but the memory is safe to examine.
2899 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2901 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2902 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2903 // computed, meaning that it can't appear to be a pointer. If the low bit is
2904 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2906 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2907 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2908 WeakCell::kValueOffset &&
2909 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2911 __ lw(t1, FieldMemOperand(t0, WeakCell::kValueOffset));
2912 __ Branch(&extra_checks_or_miss, ne, a1, Operand(t1));
2914 // The compare above could have been a SMI/SMI comparison. Guard against this
2915 // convincing us that we have a monomorphic JSFunction.
2916 __ JumpIfSmi(a1, &extra_checks_or_miss);
2918 // Increment the call count for monomorphic function calls.
2919 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
2920 __ Addu(at, a2, Operand(at));
2921 __ lw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2922 __ Addu(a3, a3, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2923 __ sw(a3, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2925 __ bind(&have_js_function);
2926 if (CallAsMethod()) {
2927 EmitContinueIfStrictOrNative(masm, &cont);
2928 // Compute the receiver in sloppy mode.
2929 __ lw(a3, MemOperand(sp, argc * kPointerSize));
2931 __ JumpIfSmi(a3, &wrap);
2932 __ GetObjectType(a3, t0, t0);
2933 __ Branch(&wrap, lt, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
2938 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2941 EmitSlowCase(masm, argc, &non_function);
2943 if (CallAsMethod()) {
2945 EmitWrapCase(masm, argc, &cont);
2948 __ bind(&extra_checks_or_miss);
2949 Label uninitialized, miss;
2951 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2952 __ Branch(&slow_start, eq, t0, Operand(at));
2954 // The following cases attempt to handle MISS cases without going to the
2956 if (FLAG_trace_ic) {
2960 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2961 __ Branch(&uninitialized, eq, t0, Operand(at));
2963 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2964 // to handle it here. More complex cases are dealt with in the runtime.
2965 __ AssertNotSmi(t0);
2966 __ GetObjectType(t0, t1, t1);
2967 __ Branch(&miss, ne, t1, Operand(JS_FUNCTION_TYPE));
2968 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize);
2969 __ Addu(t0, a2, Operand(t0));
2970 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2971 __ sw(at, FieldMemOperand(t0, FixedArray::kHeaderSize));
2972 // We have to update statistics for runtime profiling.
2973 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2974 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
2975 __ sw(t0, FieldMemOperand(a2, with_types_offset));
2976 __ lw(t0, FieldMemOperand(a2, generic_offset));
2977 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2978 __ Branch(USE_DELAY_SLOT, &slow_start);
2979 __ sw(t0, FieldMemOperand(a2, generic_offset)); // In delay slot.
2981 __ bind(&uninitialized);
2983 // We are going monomorphic, provided we actually have a JSFunction.
2984 __ JumpIfSmi(a1, &miss);
2986 // Goto miss case if we do not have a function.
2987 __ GetObjectType(a1, t0, t0);
2988 __ Branch(&miss, ne, t0, Operand(JS_FUNCTION_TYPE));
2990 // Make sure the function is not the Array() function, which requires special
2991 // behavior on MISS.
2992 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, t0);
2993 __ Branch(&miss, eq, a1, Operand(t0));
2996 __ lw(t0, FieldMemOperand(a2, with_types_offset));
2997 __ Addu(t0, t0, Operand(Smi::FromInt(1)));
2998 __ sw(t0, FieldMemOperand(a2, with_types_offset));
3000 // Initialize the call counter.
3001 __ sll(at, a3, kPointerSizeLog2 - kSmiTagSize);
3002 __ Addu(at, a2, Operand(at));
3003 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3004 __ sw(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
3006 // Store the function. Use a stub since we need a frame for allocation.
3011 FrameScope scope(masm, StackFrame::INTERNAL);
3012 CreateWeakCellStub create_stub(masm->isolate());
3014 __ CallStub(&create_stub);
3018 __ Branch(&have_js_function);
3020 // We are here because tracing is on or we encountered a MISS case we can't
3026 __ bind(&slow_start);
3027 // Check that the function is really a JavaScript function.
3028 // r1: pushed function (to be verified)
3029 __ JumpIfSmi(a1, &non_function);
3031 // Goto slow case if we do not have a function.
3032 __ GetObjectType(a1, t0, t0);
3033 __ Branch(&slow, ne, t0, Operand(JS_FUNCTION_TYPE));
3034 __ Branch(&have_js_function);
3038 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3039 FrameScope scope(masm, StackFrame::INTERNAL);
3041 // Push the receiver and the function and feedback info.
3042 __ Push(a1, a2, a3);
3045 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
3046 : IC::kCallIC_Customization_Miss;
3048 ExternalReference miss = ExternalReference(IC_Utility(id), masm->isolate());
3049 __ CallExternalReference(miss, 3);
3051 // Move result to a1 and exit the internal frame.
3056 // StringCharCodeAtGenerator.
3057 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3058 DCHECK(!t0.is(index_));
3059 DCHECK(!t0.is(result_));
3060 DCHECK(!t0.is(object_));
3061 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3062 // If the receiver is a smi trigger the non-string case.
3063 __ JumpIfSmi(object_, receiver_not_string_);
3065 // Fetch the instance type of the receiver into result register.
3066 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3067 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3068 // If the receiver is not a string trigger the non-string case.
3069 __ And(t0, result_, Operand(kIsNotStringMask));
3070 __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg));
3073 // If the index is non-smi trigger the non-smi case.
3074 __ JumpIfNotSmi(index_, &index_not_smi_);
3076 __ bind(&got_smi_index_);
3078 // Check for index out of range.
3079 __ lw(t0, FieldMemOperand(object_, String::kLengthOffset));
3080 __ Branch(index_out_of_range_, ls, t0, Operand(index_));
3082 __ sra(index_, index_, kSmiTagSize);
3084 StringCharLoadGenerator::Generate(masm,
3090 __ sll(result_, result_, kSmiTagSize);
3095 void StringCharCodeAtGenerator::GenerateSlow(
3096 MacroAssembler* masm, EmbedMode embed_mode,
3097 const RuntimeCallHelper& call_helper) {
3098 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3100 // Index is not a smi.
3101 __ bind(&index_not_smi_);
3102 // If index is a heap number, try converting it to an integer.
3105 Heap::kHeapNumberMapRootIndex,
3108 call_helper.BeforeCall(masm);
3109 // Consumed by runtime conversion function:
3110 if (embed_mode == PART_OF_IC_HANDLER) {
3111 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3112 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3114 __ Push(object_, index_);
3116 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3117 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3119 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3120 // NumberToSmi discards numbers that are not exact integers.
3121 __ CallRuntime(Runtime::kNumberToSmi, 1);
3124 // Save the conversion result before the pop instructions below
3125 // have a chance to overwrite it.
3126 __ Move(index_, v0);
3127 if (embed_mode == PART_OF_IC_HANDLER) {
3128 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3129 LoadWithVectorDescriptor::SlotRegister(), object_);
3133 // Reload the instance type.
3134 __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3135 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3136 call_helper.AfterCall(masm);
3137 // If index is still not a smi, it must be out of range.
3138 __ JumpIfNotSmi(index_, index_out_of_range_);
3139 // Otherwise, return to the fast path.
3140 __ Branch(&got_smi_index_);
3142 // Call runtime. We get here when the receiver is a string and the
3143 // index is a number, but the code of getting the actual character
3144 // is too complex (e.g., when the string needs to be flattened).
3145 __ bind(&call_runtime_);
3146 call_helper.BeforeCall(masm);
3147 __ sll(index_, index_, kSmiTagSize);
3148 __ Push(object_, index_);
3149 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3151 __ Move(result_, v0);
3153 call_helper.AfterCall(masm);
3156 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3160 // -------------------------------------------------------------------------
3161 // StringCharFromCodeGenerator
3163 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3164 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3166 DCHECK(!t0.is(result_));
3167 DCHECK(!t0.is(code_));
3169 STATIC_ASSERT(kSmiTag == 0);
3170 STATIC_ASSERT(kSmiShiftSize == 0);
3171 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
3172 __ And(t0, code_, Operand(kSmiTagMask |
3173 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
3174 __ Branch(&slow_case_, ne, t0, Operand(zero_reg));
3176 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3177 // At this point code register contains smi tagged one-byte char code.
3178 STATIC_ASSERT(kSmiTag == 0);
3179 __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize);
3180 __ Addu(result_, result_, t0);
3181 __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3182 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
3183 __ Branch(&slow_case_, eq, result_, Operand(t0));
3188 void StringCharFromCodeGenerator::GenerateSlow(
3189 MacroAssembler* masm,
3190 const RuntimeCallHelper& call_helper) {
3191 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3193 __ bind(&slow_case_);
3194 call_helper.BeforeCall(masm);
3196 __ CallRuntime(Runtime::kCharFromCode, 1);
3197 __ Move(result_, v0);
3199 call_helper.AfterCall(masm);
3202 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3206 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3209 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3214 String::Encoding encoding) {
3215 if (FLAG_debug_code) {
3216 // Check that destination is word aligned.
3217 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3219 kDestinationOfCopyNotAligned,
3224 // Assumes word reads and writes are little endian.
3225 // Nothing to do for zero characters.
3228 if (encoding == String::TWO_BYTE_ENCODING) {
3229 __ Addu(count, count, count);
3232 Register limit = count; // Read until dest equals this.
3233 __ Addu(limit, dest, Operand(count));
3235 Label loop_entry, loop;
3236 // Copy bytes from src to dest until dest hits limit.
3237 __ Branch(&loop_entry);
3239 __ lbu(scratch, MemOperand(src));
3240 __ Addu(src, src, Operand(1));
3241 __ sb(scratch, MemOperand(dest));
3242 __ Addu(dest, dest, Operand(1));
3243 __ bind(&loop_entry);
3244 __ Branch(&loop, lt, dest, Operand(limit));
3250 void SubStringStub::Generate(MacroAssembler* masm) {
3252 // Stack frame on entry.
3253 // ra: return address
3258 // This stub is called from the native-call %_SubString(...), so
3259 // nothing can be assumed about the arguments. It is tested that:
3260 // "string" is a sequential string,
3261 // both "from" and "to" are smis, and
3262 // 0 <= from <= to <= string.length.
3263 // If any of these assumptions fail, we call the runtime system.
3265 const int kToOffset = 0 * kPointerSize;
3266 const int kFromOffset = 1 * kPointerSize;
3267 const int kStringOffset = 2 * kPointerSize;
3269 __ lw(a2, MemOperand(sp, kToOffset));
3270 __ lw(a3, MemOperand(sp, kFromOffset));
3271 STATIC_ASSERT(kFromOffset == kToOffset + 4);
3272 STATIC_ASSERT(kSmiTag == 0);
3273 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
3275 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3276 // safe in this case.
3277 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
3278 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
3279 // Both a2 and a3 are untagged integers.
3281 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3283 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3284 __ Subu(a2, a2, a3);
3286 // Make sure first argument is a string.
3287 __ lw(v0, MemOperand(sp, kStringOffset));
3288 __ JumpIfSmi(v0, &runtime);
3289 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3290 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3291 __ And(t0, a1, Operand(kIsNotStringMask));
3293 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3296 __ Branch(&single_char, eq, a2, Operand(1));
3298 // Short-cut for the case of trivial substring.
3300 // v0: original string
3301 // a2: result string length
3302 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
3304 // Return original string.
3305 __ Branch(&return_v0, eq, a2, Operand(t0));
3306 // Longer than original string's length or negative: unsafe arguments.
3307 __ Branch(&runtime, hi, a2, Operand(t0));
3308 // Shorter than original string's length: an actual substring.
3310 // Deal with different string types: update the index if necessary
3311 // and put the underlying string into t1.
3312 // v0: original string
3313 // a1: instance type
3315 // a3: from index (untagged)
3316 Label underlying_unpacked, sliced_string, seq_or_external_string;
3317 // If the string is not indirect, it can only be sequential or external.
3318 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3319 STATIC_ASSERT(kIsIndirectStringMask != 0);
3320 __ And(t0, a1, Operand(kIsIndirectStringMask));
3321 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
3322 // t0 is used as a scratch register and can be overwritten in either case.
3323 __ And(t0, a1, Operand(kSlicedNotConsMask));
3324 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
3325 // Cons string. Check whether it is flat, then fetch first part.
3326 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
3327 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
3328 __ Branch(&runtime, ne, t1, Operand(t0));
3329 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
3330 // Update instance type.
3331 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3332 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3333 __ jmp(&underlying_unpacked);
3335 __ bind(&sliced_string);
3336 // Sliced string. Fetch parent and correct start index by offset.
3337 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3338 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3339 __ sra(t0, t0, 1); // Add offset to index.
3340 __ Addu(a3, a3, t0);
3341 // Update instance type.
3342 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
3343 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3344 __ jmp(&underlying_unpacked);
3346 __ bind(&seq_or_external_string);
3347 // Sequential or external string. Just move string to the expected register.
3350 __ bind(&underlying_unpacked);
3352 if (FLAG_string_slices) {
3354 // t1: underlying subject string
3355 // a1: instance type of underlying subject string
3357 // a3: adjusted start index (untagged)
3358 // Short slice. Copy instead of slicing.
3359 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3360 // Allocate new sliced string. At this point we do not reload the instance
3361 // type including the string encoding because we simply rely on the info
3362 // provided by the original string. It does not matter if the original
3363 // string's encoding is wrong because we always have to recheck encoding of
3364 // the newly created string's parent anyways due to externalized strings.
3365 Label two_byte_slice, set_slice_header;
3366 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3367 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3368 __ And(t0, a1, Operand(kStringEncodingMask));
3369 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
3370 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
3371 __ jmp(&set_slice_header);
3372 __ bind(&two_byte_slice);
3373 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
3374 __ bind(&set_slice_header);
3376 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
3377 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3380 __ bind(©_routine);
3383 // t1: underlying subject string
3384 // a1: instance type of underlying subject string
3386 // a3: adjusted start index (untagged)
3387 Label two_byte_sequential, sequential_string, allocate_result;
3388 STATIC_ASSERT(kExternalStringTag != 0);
3389 STATIC_ASSERT(kSeqStringTag == 0);
3390 __ And(t0, a1, Operand(kExternalStringTag));
3391 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
3393 // Handle external string.
3394 // Rule out short external strings.
3395 STATIC_ASSERT(kShortExternalStringTag != 0);
3396 __ And(t0, a1, Operand(kShortExternalStringTag));
3397 __ Branch(&runtime, ne, t0, Operand(zero_reg));
3398 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
3399 // t1 already points to the first character of underlying string.
3400 __ jmp(&allocate_result);
3402 __ bind(&sequential_string);
3403 // Locate first character of underlying subject string.
3404 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3405 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3407 __ bind(&allocate_result);
3408 // Sequential acii string. Allocate the result.
3409 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3410 __ And(t0, a1, Operand(kStringEncodingMask));
3411 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
3413 // Allocate and copy the resulting ASCII string.
3414 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
3416 // Locate first character of substring to copy.
3417 __ Addu(t1, t1, a3);
3419 // Locate first character of result.
3420 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3422 // v0: result string
3423 // a1: first character of result string
3424 // a2: result string length
3425 // t1: first character of substring to copy
3426 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3427 StringHelper::GenerateCopyCharacters(
3428 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
3431 // Allocate and copy the resulting two-byte string.
3432 __ bind(&two_byte_sequential);
3433 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
3435 // Locate first character of substring to copy.
3436 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3438 __ Addu(t1, t1, t0);
3439 // Locate first character of result.
3440 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3442 // v0: result string.
3443 // a1: first character of result.
3444 // a2: result length.
3445 // t1: first character of substring to copy.
3446 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3447 StringHelper::GenerateCopyCharacters(
3448 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
3450 __ bind(&return_v0);
3451 Counters* counters = isolate()->counters();
3452 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
3455 // Just jump to runtime to create the sub string.
3457 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3459 __ bind(&single_char);
3460 // v0: original string
3461 // a1: instance type
3463 // a3: from index (untagged)
3465 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3466 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3467 generator.GenerateFast(masm);
3469 generator.SkipSlow(masm, &runtime);
3473 void ToNumberStub::Generate(MacroAssembler* masm) {
3474 // The ToNumber stub takes one argument in a0.
3476 __ JumpIfNotSmi(a0, ¬_smi);
3477 __ Ret(USE_DELAY_SLOT);
3481 Label not_heap_number;
3482 __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3483 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3485 // a1: instance type.
3486 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3487 __ Ret(USE_DELAY_SLOT);
3489 __ bind(¬_heap_number);
3491 Label not_string, slow_string;
3492 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3493 // Check if string has a cached array index.
3494 __ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3495 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3496 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3497 __ IndexFromHash(a2, a0);
3498 __ Ret(USE_DELAY_SLOT);
3500 __ bind(&slow_string);
3501 __ push(a0); // Push argument.
3502 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3503 __ bind(¬_string);
3506 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3507 __ Ret(USE_DELAY_SLOT);
3508 __ lw(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3509 __ bind(¬_oddball);
3511 __ push(a0); // Push argument.
3512 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3516 void StringHelper::GenerateFlatOneByteStringEquals(
3517 MacroAssembler* masm, Register left, Register right, Register scratch1,
3518 Register scratch2, Register scratch3) {
3519 Register length = scratch1;
3522 Label strings_not_equal, check_zero_length;
3523 __ lw(length, FieldMemOperand(left, String::kLengthOffset));
3524 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3525 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3526 __ bind(&strings_not_equal);
3527 DCHECK(is_int16(NOT_EQUAL));
3528 __ Ret(USE_DELAY_SLOT);
3529 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3531 // Check if the length is zero.
3532 Label compare_chars;
3533 __ bind(&check_zero_length);
3534 STATIC_ASSERT(kSmiTag == 0);
3535 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3536 DCHECK(is_int16(EQUAL));
3537 __ Ret(USE_DELAY_SLOT);
3538 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3540 // Compare characters.
3541 __ bind(&compare_chars);
3543 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3544 v0, &strings_not_equal);
3546 // Characters are equal.
3547 __ Ret(USE_DELAY_SLOT);
3548 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3552 void StringHelper::GenerateCompareFlatOneByteStrings(
3553 MacroAssembler* masm, Register left, Register right, Register scratch1,
3554 Register scratch2, Register scratch3, Register scratch4) {
3555 Label result_not_equal, compare_lengths;
3556 // Find minimum length and length difference.
3557 __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset));
3558 __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset));
3559 __ Subu(scratch3, scratch1, Operand(scratch2));
3560 Register length_delta = scratch3;
3561 __ slt(scratch4, scratch2, scratch1);
3562 __ Movn(scratch1, scratch2, scratch4);
3563 Register min_length = scratch1;
3564 STATIC_ASSERT(kSmiTag == 0);
3565 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3568 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3569 scratch4, v0, &result_not_equal);
3571 // Compare lengths - strings up to min-length are equal.
3572 __ bind(&compare_lengths);
3573 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3574 // Use length_delta as result if it's zero.
3575 __ mov(scratch2, length_delta);
3576 __ mov(scratch4, zero_reg);
3577 __ mov(v0, zero_reg);
3579 __ bind(&result_not_equal);
3580 // Conditionally update the result based either on length_delta or
3581 // the last comparion performed in the loop above.
3583 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3584 __ li(v0, Operand(Smi::FromInt(GREATER)));
3585 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3586 __ li(v0, Operand(Smi::FromInt(LESS)));
3592 void StringHelper::GenerateOneByteCharsCompareLoop(
3593 MacroAssembler* masm, Register left, Register right, Register length,
3594 Register scratch1, Register scratch2, Register scratch3,
3595 Label* chars_not_equal) {
3596 // Change index to run from -length to -1 by adding length to string
3597 // start. This means that loop ends when index reaches zero, which
3598 // doesn't need an additional compare.
3599 __ SmiUntag(length);
3600 __ Addu(scratch1, length,
3601 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3602 __ Addu(left, left, Operand(scratch1));
3603 __ Addu(right, right, Operand(scratch1));
3604 __ Subu(length, zero_reg, length);
3605 Register index = length; // index = -length;
3611 __ Addu(scratch3, left, index);
3612 __ lbu(scratch1, MemOperand(scratch3));
3613 __ Addu(scratch3, right, index);
3614 __ lbu(scratch2, MemOperand(scratch3));
3615 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3616 __ Addu(index, index, 1);
3617 __ Branch(&loop, ne, index, Operand(zero_reg));
3621 void StringCompareStub::Generate(MacroAssembler* masm) {
3624 Counters* counters = isolate()->counters();
3626 // Stack frame on entry.
3627 // sp[0]: right string
3628 // sp[4]: left string
3629 __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3630 __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3633 __ Branch(¬_same, ne, a0, Operand(a1));
3634 STATIC_ASSERT(EQUAL == 0);
3635 STATIC_ASSERT(kSmiTag == 0);
3636 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3637 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3642 // Check that both objects are sequential one-byte strings.
3643 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3645 // Compare flat ASCII strings natively. Remove arguments from stack first.
3646 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3647 __ Addu(sp, sp, Operand(2 * kPointerSize));
3648 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3651 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3655 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3656 // ----------- S t a t e -------------
3659 // -- ra : return address
3660 // -----------------------------------
3662 // Load a2 with the allocation site. We stick an undefined dummy value here
3663 // and replace it with the real allocation site later when we instantiate this
3664 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3665 __ li(a2, handle(isolate()->heap()->undefined_value()));
3667 // Make sure that we actually patched the allocation site.
3668 if (FLAG_debug_code) {
3669 __ And(at, a2, Operand(kSmiTagMask));
3670 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3671 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
3672 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3673 __ Assert(eq, kExpectedAllocationSite, t0, Operand(at));
3676 // Tail call into the stub that handles binary operations with allocation
3678 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3679 __ TailCallStub(&stub);
3683 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3684 DCHECK(state() == CompareICState::SMI);
3687 __ JumpIfNotSmi(a2, &miss);
3689 if (GetCondition() == eq) {
3690 // For equality we do not care about the sign of the result.
3691 __ Ret(USE_DELAY_SLOT);
3692 __ Subu(v0, a0, a1);
3694 // Untag before subtracting to avoid handling overflow.
3697 __ Ret(USE_DELAY_SLOT);
3698 __ Subu(v0, a1, a0);
3706 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3707 DCHECK(state() == CompareICState::NUMBER);
3710 Label unordered, maybe_undefined1, maybe_undefined2;
3713 if (left() == CompareICState::SMI) {
3714 __ JumpIfNotSmi(a1, &miss);
3716 if (right() == CompareICState::SMI) {
3717 __ JumpIfNotSmi(a0, &miss);
3720 // Inlining the double comparison and falling back to the general compare
3721 // stub if NaN is involved.
3722 // Load left and right operand.
3723 Label done, left, left_smi, right_smi;
3724 __ JumpIfSmi(a0, &right_smi);
3725 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3727 __ Subu(a2, a0, Operand(kHeapObjectTag));
3728 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3730 __ bind(&right_smi);
3731 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3732 FPURegister single_scratch = f6;
3733 __ mtc1(a2, single_scratch);
3734 __ cvt_d_w(f2, single_scratch);
3737 __ JumpIfSmi(a1, &left_smi);
3738 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3740 __ Subu(a2, a1, Operand(kHeapObjectTag));
3741 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3744 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3745 single_scratch = f8;
3746 __ mtc1(a2, single_scratch);
3747 __ cvt_d_w(f0, single_scratch);
3751 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3752 Label fpu_eq, fpu_lt;
3753 // Test if equal, and also handle the unordered/NaN case.
3754 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3756 // Test if less (unordered case is already handled).
3757 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3759 // Otherwise it's greater, so just fall thru, and return.
3760 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3761 __ Ret(USE_DELAY_SLOT);
3762 __ li(v0, Operand(GREATER));
3765 __ Ret(USE_DELAY_SLOT);
3766 __ li(v0, Operand(EQUAL));
3769 __ Ret(USE_DELAY_SLOT);
3770 __ li(v0, Operand(LESS));
3772 __ bind(&unordered);
3773 __ bind(&generic_stub);
3774 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3775 CompareICState::GENERIC, CompareICState::GENERIC);
3776 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3778 __ bind(&maybe_undefined1);
3779 if (Token::IsOrderedRelationalCompareOp(op())) {
3780 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3781 __ Branch(&miss, ne, a0, Operand(at));
3782 __ JumpIfSmi(a1, &unordered);
3783 __ GetObjectType(a1, a2, a2);
3784 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3788 __ bind(&maybe_undefined2);
3789 if (Token::IsOrderedRelationalCompareOp(op())) {
3790 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3791 __ Branch(&unordered, eq, a1, Operand(at));
3799 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3800 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3803 // Registers containing left and right operands respectively.
3805 Register right = a0;
3809 // Check that both operands are heap objects.
3810 __ JumpIfEitherSmi(left, right, &miss);
3812 // Check that both operands are internalized strings.
3813 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3814 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3815 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3816 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3817 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3818 __ Or(tmp1, tmp1, Operand(tmp2));
3819 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3820 __ Branch(&miss, ne, at, Operand(zero_reg));
3822 // Make sure a0 is non-zero. At this point input operands are
3823 // guaranteed to be non-zero.
3824 DCHECK(right.is(a0));
3825 STATIC_ASSERT(EQUAL == 0);
3826 STATIC_ASSERT(kSmiTag == 0);
3828 // Internalized strings are compared by identity.
3829 __ Ret(ne, left, Operand(right));
3830 DCHECK(is_int16(EQUAL));
3831 __ Ret(USE_DELAY_SLOT);
3832 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3839 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3840 DCHECK(state() == CompareICState::UNIQUE_NAME);
3841 DCHECK(GetCondition() == eq);
3844 // Registers containing left and right operands respectively.
3846 Register right = a0;
3850 // Check that both operands are heap objects.
3851 __ JumpIfEitherSmi(left, right, &miss);
3853 // Check that both operands are unique names. This leaves the instance
3854 // types loaded in tmp1 and tmp2.
3855 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3856 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3857 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3858 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3860 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3861 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3866 // Unique names are compared by identity.
3868 __ Branch(&done, ne, left, Operand(right));
3869 // Make sure a0 is non-zero. At this point input operands are
3870 // guaranteed to be non-zero.
3871 DCHECK(right.is(a0));
3872 STATIC_ASSERT(EQUAL == 0);
3873 STATIC_ASSERT(kSmiTag == 0);
3874 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3883 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3884 DCHECK(state() == CompareICState::STRING);
3887 bool equality = Token::IsEqualityOp(op());
3889 // Registers containing left and right operands respectively.
3891 Register right = a0;
3898 // Check that both operands are heap objects.
3899 __ JumpIfEitherSmi(left, right, &miss);
3901 // Check that both operands are strings. This leaves the instance
3902 // types loaded in tmp1 and tmp2.
3903 __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3904 __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3905 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3906 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3907 STATIC_ASSERT(kNotStringTag != 0);
3908 __ Or(tmp3, tmp1, tmp2);
3909 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3910 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3912 // Fast check for identical strings.
3913 Label left_ne_right;
3914 STATIC_ASSERT(EQUAL == 0);
3915 STATIC_ASSERT(kSmiTag == 0);
3916 __ Branch(&left_ne_right, ne, left, Operand(right));
3917 __ Ret(USE_DELAY_SLOT);
3918 __ mov(v0, zero_reg); // In the delay slot.
3919 __ bind(&left_ne_right);
3921 // Handle not identical strings.
3923 // Check that both strings are internalized strings. If they are, we're done
3924 // because we already know they are not identical. We know they are both
3927 DCHECK(GetCondition() == eq);
3928 STATIC_ASSERT(kInternalizedTag == 0);
3929 __ Or(tmp3, tmp1, Operand(tmp2));
3930 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3932 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3933 // Make sure a0 is non-zero. At this point input operands are
3934 // guaranteed to be non-zero.
3935 DCHECK(right.is(a0));
3936 __ Ret(USE_DELAY_SLOT);
3937 __ mov(v0, a0); // In the delay slot.
3938 __ bind(&is_symbol);
3941 // Check that both strings are sequential one-byte.
3943 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3946 // Compare flat one-byte strings. Returns when done.
3948 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3951 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3955 // Handle more complex cases in runtime.
3957 __ Push(left, right);
3959 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3961 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3969 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3970 DCHECK(state() == CompareICState::OBJECT);
3972 __ And(a2, a1, Operand(a0));
3973 __ JumpIfSmi(a2, &miss);
3975 __ GetObjectType(a0, a2, a2);
3976 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3977 __ GetObjectType(a1, a2, a2);
3978 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3980 DCHECK(GetCondition() == eq);
3981 __ Ret(USE_DELAY_SLOT);
3982 __ subu(v0, a0, a1);
3989 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3991 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3993 __ JumpIfSmi(a2, &miss);
3994 __ GetWeakValue(t0, cell);
3995 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3996 __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3997 __ Branch(&miss, ne, a2, Operand(t0));
3998 __ Branch(&miss, ne, a3, Operand(t0));
4000 __ Ret(USE_DELAY_SLOT);
4001 __ subu(v0, a0, a1);
4008 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
4010 // Call the runtime system in a fresh internal frame.
4011 ExternalReference miss =
4012 ExternalReference(IC_Utility(IC::kCompareIC_Miss), isolate());
4013 FrameScope scope(masm, StackFrame::INTERNAL);
4015 __ Push(ra, a1, a0);
4016 __ li(t0, Operand(Smi::FromInt(op())));
4017 __ addiu(sp, sp, -kPointerSize);
4018 __ CallExternalReference(miss, 3, USE_DELAY_SLOT);
4019 __ sw(t0, MemOperand(sp)); // In the delay slot.
4020 // Compute the entry point of the rewritten stub.
4021 __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
4022 // Restore registers.
4029 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4030 // Make place for arguments to fit C calling convention. Most of the callers
4031 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
4032 // so they handle stack restoring and we don't have to do that here.
4033 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
4034 // kCArgsSlotsSize stack space after the call.
4035 __ Subu(sp, sp, Operand(kCArgsSlotsSize));
4036 // Place the return address on the stack, making the call
4037 // GC safe. The RegExp backend also relies on this.
4038 __ sw(ra, MemOperand(sp, kCArgsSlotsSize));
4039 __ Call(t9); // Call the C++ function.
4040 __ lw(t9, MemOperand(sp, kCArgsSlotsSize));
4042 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
4043 // In case of an error the return address may point to a memory area
4044 // filled with kZapValue by the GC.
4045 // Dereference the address and check for this.
4046 __ lw(t0, MemOperand(t9));
4047 __ Assert(ne, kReceivedInvalidReturnAddress, t0,
4048 Operand(reinterpret_cast<uint32_t>(kZapValue)));
4054 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4057 reinterpret_cast<intptr_t>(GetCode().location());
4058 __ Move(t9, target);
4059 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
4064 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4068 Register properties,
4070 Register scratch0) {
4071 DCHECK(name->IsUniqueName());
4072 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4073 // not equal to the name and kProbes-th slot is not used (its name is the
4074 // undefined value), it guarantees the hash table doesn't contain the
4075 // property. It's true even if some slots represent deleted properties
4076 // (their names are the hole value).
4077 for (int i = 0; i < kInlinedProbes; i++) {
4078 // scratch0 points to properties hash.
4079 // Compute the masked index: (hash + i + i * i) & mask.
4080 Register index = scratch0;
4081 // Capacity is smi 2^n.
4082 __ lw(index, FieldMemOperand(properties, kCapacityOffset));
4083 __ Subu(index, index, Operand(1));
4084 __ And(index, index, Operand(
4085 Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
4087 // Scale the index by multiplying by the entry size.
4088 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4089 __ sll(at, index, 1);
4090 __ Addu(index, index, at);
4092 Register entity_name = scratch0;
4093 // Having undefined at this place means the name is not contained.
4094 DCHECK_EQ(kSmiTagSize, 1);
4095 Register tmp = properties;
4096 __ sll(scratch0, index, 1);
4097 __ Addu(tmp, properties, scratch0);
4098 __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4100 DCHECK(!tmp.is(entity_name));
4101 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4102 __ Branch(done, eq, entity_name, Operand(tmp));
4104 // Load the hole ready for use below:
4105 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4107 // Stop if found the property.
4108 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4111 __ Branch(&good, eq, entity_name, Operand(tmp));
4113 // Check if the entry name is not a unique name.
4114 __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4116 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4117 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4120 // Restore the properties.
4122 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4125 const int spill_mask =
4126 (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() |
4127 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4129 __ MultiPush(spill_mask);
4130 __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4131 __ li(a1, Operand(Handle<Name>(name)));
4132 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4135 __ MultiPop(spill_mask);
4137 __ Branch(done, eq, at, Operand(zero_reg));
4138 __ Branch(miss, ne, at, Operand(zero_reg));
4142 // Probe the name dictionary in the |elements| register. Jump to the
4143 // |done| label if a property with the given name is found. Jump to
4144 // the |miss| label otherwise.
4145 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4146 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4152 Register scratch2) {
4153 DCHECK(!elements.is(scratch1));
4154 DCHECK(!elements.is(scratch2));
4155 DCHECK(!name.is(scratch1));
4156 DCHECK(!name.is(scratch2));
4158 __ AssertName(name);
4160 // Compute the capacity mask.
4161 __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset));
4162 __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int
4163 __ Subu(scratch1, scratch1, Operand(1));
4165 // Generate an unrolled loop that performs a few probes before
4166 // giving up. Measurements done on Gmail indicate that 2 probes
4167 // cover ~93% of loads from dictionaries.
4168 for (int i = 0; i < kInlinedProbes; i++) {
4169 // Compute the masked index: (hash + i + i * i) & mask.
4170 __ lw(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4172 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4173 // the hash in a separate instruction. The value hash + i + i * i is right
4174 // shifted in the following and instruction.
4175 DCHECK(NameDictionary::GetProbeOffset(i) <
4176 1 << (32 - Name::kHashFieldOffset));
4177 __ Addu(scratch2, scratch2, Operand(
4178 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4180 __ srl(scratch2, scratch2, Name::kHashShift);
4181 __ And(scratch2, scratch1, scratch2);
4183 // Scale the index by multiplying by the element size.
4184 DCHECK(NameDictionary::kEntrySize == 3);
4185 // scratch2 = scratch2 * 3.
4187 __ sll(at, scratch2, 1);
4188 __ Addu(scratch2, scratch2, at);
4190 // Check if the key is identical to the name.
4191 __ sll(at, scratch2, 2);
4192 __ Addu(scratch2, elements, at);
4193 __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset));
4194 __ Branch(done, eq, name, Operand(at));
4197 const int spill_mask =
4198 (ra.bit() | t2.bit() | t1.bit() | t0.bit() |
4199 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4200 ~(scratch1.bit() | scratch2.bit());
4202 __ MultiPush(spill_mask);
4204 DCHECK(!elements.is(a1));
4206 __ Move(a0, elements);
4208 __ Move(a0, elements);
4211 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4213 __ mov(scratch2, a2);
4215 __ MultiPop(spill_mask);
4217 __ Branch(done, ne, at, Operand(zero_reg));
4218 __ Branch(miss, eq, at, Operand(zero_reg));
4222 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4223 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4224 // we cannot call anything that could cause a GC from this stub.
4226 // result: NameDictionary to probe
4228 // dictionary: NameDictionary to probe.
4229 // index: will hold an index of entry if lookup is successful.
4230 // might alias with result_.
4232 // result_ is zero if lookup failed, non zero otherwise.
4234 Register result = v0;
4235 Register dictionary = a0;
4237 Register index = a2;
4240 Register undefined = t1;
4241 Register entry_key = t2;
4243 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4245 __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset));
4246 __ sra(mask, mask, kSmiTagSize);
4247 __ Subu(mask, mask, Operand(1));
4249 __ lw(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4251 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4253 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4254 // Compute the masked index: (hash + i + i * i) & mask.
4255 // Capacity is smi 2^n.
4257 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4258 // the hash in a separate instruction. The value hash + i + i * i is right
4259 // shifted in the following and instruction.
4260 DCHECK(NameDictionary::GetProbeOffset(i) <
4261 1 << (32 - Name::kHashFieldOffset));
4262 __ Addu(index, hash, Operand(
4263 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4265 __ mov(index, hash);
4267 __ srl(index, index, Name::kHashShift);
4268 __ And(index, mask, index);
4270 // Scale the index by multiplying by the entry size.
4271 DCHECK(NameDictionary::kEntrySize == 3);
4274 __ sll(index, index, 1);
4275 __ Addu(index, index, at);
4278 DCHECK_EQ(kSmiTagSize, 1);
4279 __ sll(index, index, 2);
4280 __ Addu(index, index, dictionary);
4281 __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset));
4283 // Having undefined at this place means the name is not contained.
4284 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4286 // Stop if found the property.
4287 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4289 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4290 // Check if the entry name is not a unique name.
4291 __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4293 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4294 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4298 __ bind(&maybe_in_dictionary);
4299 // If we are doing negative lookup then probing failure should be
4300 // treated as a lookup success. For positive lookup probing failure
4301 // should be treated as lookup failure.
4302 if (mode() == POSITIVE_LOOKUP) {
4303 __ Ret(USE_DELAY_SLOT);
4304 __ mov(result, zero_reg);
4307 __ bind(&in_dictionary);
4308 __ Ret(USE_DELAY_SLOT);
4311 __ bind(¬_in_dictionary);
4312 __ Ret(USE_DELAY_SLOT);
4313 __ mov(result, zero_reg);
4317 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4319 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4321 // Hydrogen code stubs need stub2 at snapshot time.
4322 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4327 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4328 // the value has just been written into the object, now this stub makes sure
4329 // we keep the GC informed. The word in the object where the value has been
4330 // written is in the address register.
4331 void RecordWriteStub::Generate(MacroAssembler* masm) {
4332 Label skip_to_incremental_noncompacting;
4333 Label skip_to_incremental_compacting;
4335 // The first two branch+nop instructions are generated with labels so as to
4336 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4337 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4338 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4339 // incremental heap marking.
4340 // See RecordWriteStub::Patch for details.
4341 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4343 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4346 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4347 __ RememberedSetHelper(object(),
4350 save_fp_regs_mode(),
4351 MacroAssembler::kReturnAtEnd);
4355 __ bind(&skip_to_incremental_noncompacting);
4356 GenerateIncremental(masm, INCREMENTAL);
4358 __ bind(&skip_to_incremental_compacting);
4359 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4361 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4362 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4364 PatchBranchIntoNop(masm, 0);
4365 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4369 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4372 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4373 Label dont_need_remembered_set;
4375 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4376 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4378 &dont_need_remembered_set);
4380 __ CheckPageFlag(regs_.object(),
4382 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4384 &dont_need_remembered_set);
4386 // First notify the incremental marker if necessary, then update the
4388 CheckNeedsToInformIncrementalMarker(
4389 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4390 InformIncrementalMarker(masm);
4391 regs_.Restore(masm);
4392 __ RememberedSetHelper(object(),
4395 save_fp_regs_mode(),
4396 MacroAssembler::kReturnAtEnd);
4398 __ bind(&dont_need_remembered_set);
4401 CheckNeedsToInformIncrementalMarker(
4402 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4403 InformIncrementalMarker(masm);
4404 regs_.Restore(masm);
4409 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4410 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4411 int argument_count = 3;
4412 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4414 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4415 DCHECK(!address.is(regs_.object()));
4416 DCHECK(!address.is(a0));
4417 __ Move(address, regs_.address());
4418 __ Move(a0, regs_.object());
4419 __ Move(a1, address);
4420 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4422 AllowExternalCallThatCantCauseGC scope(masm);
4424 ExternalReference::incremental_marking_record_write_function(isolate()),
4426 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4430 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4431 MacroAssembler* masm,
4432 OnNoNeedToInformIncrementalMarker on_no_need,
4435 Label need_incremental;
4436 Label need_incremental_pop_scratch;
4438 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4439 __ lw(regs_.scratch1(),
4440 MemOperand(regs_.scratch0(),
4441 MemoryChunk::kWriteBarrierCounterOffset));
4442 __ Subu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4443 __ sw(regs_.scratch1(),
4444 MemOperand(regs_.scratch0(),
4445 MemoryChunk::kWriteBarrierCounterOffset));
4446 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4448 // Let's look at the color of the object: If it is not black we don't have
4449 // to inform the incremental marker.
4450 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4452 regs_.Restore(masm);
4453 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4454 __ RememberedSetHelper(object(),
4457 save_fp_regs_mode(),
4458 MacroAssembler::kReturnAtEnd);
4465 // Get the value from the slot.
4466 __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0));
4468 if (mode == INCREMENTAL_COMPACTION) {
4469 Label ensure_not_white;
4471 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4472 regs_.scratch1(), // Scratch.
4473 MemoryChunk::kEvacuationCandidateMask,
4477 __ CheckPageFlag(regs_.object(),
4478 regs_.scratch1(), // Scratch.
4479 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4483 __ bind(&ensure_not_white);
4486 // We need extra registers for this, so we push the object and the address
4487 // register temporarily.
4488 __ Push(regs_.object(), regs_.address());
4489 __ EnsureNotWhite(regs_.scratch0(), // The value.
4490 regs_.scratch1(), // Scratch.
4491 regs_.object(), // Scratch.
4492 regs_.address(), // Scratch.
4493 &need_incremental_pop_scratch);
4494 __ Pop(regs_.object(), regs_.address());
4496 regs_.Restore(masm);
4497 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4498 __ RememberedSetHelper(object(),
4501 save_fp_regs_mode(),
4502 MacroAssembler::kReturnAtEnd);
4507 __ bind(&need_incremental_pop_scratch);
4508 __ Pop(regs_.object(), regs_.address());
4510 __ bind(&need_incremental);
4512 // Fall through when we need to inform the incremental marker.
4516 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4517 // ----------- S t a t e -------------
4518 // -- a0 : element value to store
4519 // -- a3 : element index as smi
4520 // -- sp[0] : array literal index in function as smi
4521 // -- sp[4] : array literal
4522 // clobbers a1, a2, t0
4523 // -----------------------------------
4526 Label double_elements;
4528 Label slow_elements;
4529 Label fast_elements;
4531 // Get array literal index, array literal and its map.
4532 __ lw(t0, MemOperand(sp, 0 * kPointerSize));
4533 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
4534 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4536 __ CheckFastElements(a2, t1, &double_elements);
4537 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4538 __ JumpIfSmi(a0, &smi_element);
4539 __ CheckFastSmiElements(a2, t1, &fast_elements);
4541 // Store into the array literal requires a elements transition. Call into
4543 __ bind(&slow_elements);
4545 __ Push(a1, a3, a0);
4546 __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4547 __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset));
4549 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4551 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4552 __ bind(&fast_elements);
4553 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4554 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4555 __ Addu(t2, t1, t2);
4556 __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4557 __ sw(a0, MemOperand(t2, 0));
4558 // Update the write barrier for the array store.
4559 __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4560 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4561 __ Ret(USE_DELAY_SLOT);
4564 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4565 // and value is Smi.
4566 __ bind(&smi_element);
4567 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4568 __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize);
4569 __ Addu(t2, t1, t2);
4570 __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize));
4571 __ Ret(USE_DELAY_SLOT);
4574 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4575 __ bind(&double_elements);
4576 __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset));
4577 __ StoreNumberToDoubleElements(a0, a3, t1, t3, t5, a2, &slow_elements);
4578 __ Ret(USE_DELAY_SLOT);
4583 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4584 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4585 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4586 int parameter_count_offset =
4587 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4588 __ lw(a1, MemOperand(fp, parameter_count_offset));
4589 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4590 __ Addu(a1, a1, Operand(1));
4592 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4593 __ sll(a1, a1, kPointerSizeLog2);
4594 __ Ret(USE_DELAY_SLOT);
4595 __ Addu(sp, sp, a1);
4599 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4600 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4601 LoadICStub stub(isolate(), state());
4602 stub.GenerateForTrampoline(masm);
4606 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4607 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4608 KeyedLoadICStub stub(isolate(), state());
4609 stub.GenerateForTrampoline(masm);
4613 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4614 EmitLoadTypeFeedbackVector(masm, a2);
4615 CallICStub stub(isolate(), state());
4616 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4620 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4621 EmitLoadTypeFeedbackVector(masm, a2);
4622 CallIC_ArrayStub stub(isolate(), state());
4623 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4627 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4630 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4631 GenerateImpl(masm, true);
4635 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4636 Register key, Register vector, Register slot,
4637 Register feedback, Register receiver_map,
4638 Register scratch1, Register scratch2,
4639 bool is_polymorphic, Label* miss) {
4640 // feedback initially contains the feedback array
4641 Label next_loop, prepare_next;
4642 Label start_polymorphic;
4644 Register cached_map = scratch1;
4647 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4648 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4649 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4650 // found, now call handler.
4651 Register handler = feedback;
4652 __ lw(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4653 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4657 Register length = scratch2;
4658 __ bind(&start_polymorphic);
4659 __ lw(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4660 if (!is_polymorphic) {
4661 // If the IC could be monomorphic we have to make sure we don't go past the
4662 // end of the feedback array.
4663 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4666 Register too_far = length;
4667 Register pointer_reg = feedback;
4669 // +-----+------+------+-----+-----+ ... ----+
4670 // | map | len | wm0 | h0 | wm1 | hN |
4671 // +-----+------+------+-----+-----+ ... ----+
4675 // pointer_reg too_far
4676 // aka feedback scratch2
4677 // also need receiver_map
4678 // use cached_map (scratch1) to look in the weak map values.
4679 __ sll(at, length, kPointerSizeLog2 - kSmiTagSize);
4680 __ Addu(too_far, feedback, Operand(at));
4681 __ Addu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4682 __ Addu(pointer_reg, feedback,
4683 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4685 __ bind(&next_loop);
4686 __ lw(cached_map, MemOperand(pointer_reg));
4687 __ lw(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4688 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4689 __ lw(handler, MemOperand(pointer_reg, kPointerSize));
4690 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4693 __ bind(&prepare_next);
4694 __ Addu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4695 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4697 // We exhausted our array of map handler pairs.
4702 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4703 Register receiver_map, Register feedback,
4704 Register vector, Register slot,
4705 Register scratch, Label* compare_map,
4706 Label* load_smi_map, Label* try_array) {
4707 __ JumpIfSmi(receiver, load_smi_map);
4708 __ lw(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4709 __ bind(compare_map);
4710 Register cached_map = scratch;
4711 // Move the weak map into the weak_cell register.
4712 __ lw(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4713 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4714 Register handler = feedback;
4716 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4717 __ Addu(handler, vector, Operand(at));
4719 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4720 __ Addu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4725 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4726 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4727 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4728 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4729 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4730 Register feedback = t0;
4731 Register receiver_map = t1;
4732 Register scratch1 = t4;
4734 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4735 __ Addu(feedback, vector, Operand(at));
4736 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4738 // Try to quickly handle the monomorphic case without knowing for sure
4739 // if we have a weak cell in feedback. We do know it's safe to look
4740 // at WeakCell::kValueOffset.
4741 Label try_array, load_smi_map, compare_map;
4742 Label not_array, miss;
4743 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4744 scratch1, &compare_map, &load_smi_map, &try_array);
4746 // Is it a fixed array?
4747 __ bind(&try_array);
4748 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4749 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4750 __ Branch(¬_array, ne, at, Operand(scratch1));
4751 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4752 scratch1, t5, true, &miss);
4754 __ bind(¬_array);
4755 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4756 __ Branch(&miss, ne, at, Operand(feedback));
4757 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4758 Code::ComputeHandlerFlags(Code::LOAD_IC));
4759 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4760 false, receiver, name, feedback,
4761 receiver_map, scratch1, t5);
4764 LoadIC::GenerateMiss(masm);
4766 __ bind(&load_smi_map);
4767 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4768 __ jmp(&compare_map);
4772 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4773 GenerateImpl(masm, false);
4777 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4778 GenerateImpl(masm, true);
4782 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4783 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4784 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4785 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4786 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4787 Register feedback = t0;
4788 Register receiver_map = t1;
4789 Register scratch1 = t4;
4791 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4792 __ Addu(feedback, vector, Operand(at));
4793 __ lw(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4795 // Try to quickly handle the monomorphic case without knowing for sure
4796 // if we have a weak cell in feedback. We do know it's safe to look
4797 // at WeakCell::kValueOffset.
4798 Label try_array, load_smi_map, compare_map;
4799 Label not_array, miss;
4800 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4801 scratch1, &compare_map, &load_smi_map, &try_array);
4803 __ bind(&try_array);
4804 // Is it a fixed array?
4805 __ lw(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4806 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4807 __ Branch(¬_array, ne, at, Operand(scratch1));
4808 // We have a polymorphic element handler.
4809 __ JumpIfNotSmi(key, &miss);
4811 Label polymorphic, try_poly_name;
4812 __ bind(&polymorphic);
4813 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4814 scratch1, t5, true, &miss);
4816 __ bind(¬_array);
4818 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4819 __ Branch(&try_poly_name, ne, at, Operand(feedback));
4820 Handle<Code> megamorphic_stub =
4821 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4822 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4824 __ bind(&try_poly_name);
4825 // We might have a name in feedback, and a fixed array in the next slot.
4826 __ Branch(&miss, ne, key, Operand(feedback));
4827 // If the name comparison succeeded, we know we have a fixed array with
4828 // at least one map/handler pair.
4829 __ sll(at, slot, kPointerSizeLog2 - kSmiTagSize);
4830 __ Addu(feedback, vector, Operand(at));
4832 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4833 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4834 scratch1, t5, false, &miss);
4837 KeyedLoadIC::GenerateMiss(masm);
4839 __ bind(&load_smi_map);
4840 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4841 __ jmp(&compare_map);
4845 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4846 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4847 VectorStoreICStub stub(isolate(), state());
4848 stub.GenerateForTrampoline(masm);
4852 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4853 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4854 VectorKeyedStoreICStub stub(isolate(), state());
4855 stub.GenerateForTrampoline(masm);
4859 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4860 GenerateImpl(masm, false);
4864 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4865 GenerateImpl(masm, true);
4869 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4872 // TODO(mvstanton): Implement.
4874 StoreIC::GenerateMiss(masm);
4878 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4879 GenerateImpl(masm, false);
4883 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4884 GenerateImpl(masm, true);
4888 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4891 // TODO(mvstanton): Implement.
4893 KeyedStoreIC::GenerateMiss(masm);
4897 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4898 if (masm->isolate()->function_entry_hook() != NULL) {
4899 ProfileEntryHookStub stub(masm->isolate());
4907 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4908 // The entry hook is a "push ra" instruction, followed by a call.
4909 // Note: on MIPS "push" is 2 instruction
4910 const int32_t kReturnAddressDistanceFromFunctionStart =
4911 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4913 // This should contain all kJSCallerSaved registers.
4914 const RegList kSavedRegs =
4915 kJSCallerSaved | // Caller saved registers.
4916 s5.bit(); // Saved stack pointer.
4918 // We also save ra, so the count here is one higher than the mask indicates.
4919 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4921 // Save all caller-save registers as this may be called from anywhere.
4922 __ MultiPush(kSavedRegs | ra.bit());
4924 // Compute the function's address for the first argument.
4925 __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4927 // The caller's return address is above the saved temporaries.
4928 // Grab that for the second argument to the hook.
4929 __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4931 // Align the stack if necessary.
4932 int frame_alignment = masm->ActivationFrameAlignment();
4933 if (frame_alignment > kPointerSize) {
4935 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4936 __ And(sp, sp, Operand(-frame_alignment));
4938 __ Subu(sp, sp, kCArgsSlotsSize);
4939 #if defined(V8_HOST_ARCH_MIPS)
4940 int32_t entry_hook =
4941 reinterpret_cast<int32_t>(isolate()->function_entry_hook());
4942 __ li(t9, Operand(entry_hook));
4944 // Under the simulator we need to indirect the entry hook through a
4945 // trampoline function at a known address.
4946 // It additionally takes an isolate as a third parameter.
4947 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4949 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4950 __ li(t9, Operand(ExternalReference(&dispatcher,
4951 ExternalReference::BUILTIN_CALL,
4954 // Call C function through t9 to conform ABI for PIC.
4957 // Restore the stack pointer if needed.
4958 if (frame_alignment > kPointerSize) {
4961 __ Addu(sp, sp, kCArgsSlotsSize);
4964 // Also pop ra to get Ret(0).
4965 __ MultiPop(kSavedRegs | ra.bit());
4971 static void CreateArrayDispatch(MacroAssembler* masm,
4972 AllocationSiteOverrideMode mode) {
4973 if (mode == DISABLE_ALLOCATION_SITES) {
4974 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
4975 __ TailCallStub(&stub);
4976 } else if (mode == DONT_OVERRIDE) {
4977 int last_index = GetSequenceIndexFromFastElementsKind(
4978 TERMINAL_FAST_ELEMENTS_KIND);
4979 for (int i = 0; i <= last_index; ++i) {
4980 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4981 T stub(masm->isolate(), kind);
4982 __ TailCallStub(&stub, eq, a3, Operand(kind));
4985 // If we reached this point there is a problem.
4986 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4993 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4994 AllocationSiteOverrideMode mode) {
4995 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4996 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
4997 // a0 - number of arguments
4998 // a1 - constructor?
4999 // sp[0] - last argument
5000 Label normal_sequence;
5001 if (mode == DONT_OVERRIDE) {
5002 DCHECK(FAST_SMI_ELEMENTS == 0);
5003 DCHECK(FAST_HOLEY_SMI_ELEMENTS == 1);
5004 DCHECK(FAST_ELEMENTS == 2);
5005 DCHECK(FAST_HOLEY_ELEMENTS == 3);
5006 DCHECK(FAST_DOUBLE_ELEMENTS == 4);
5007 DCHECK(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5009 // is the low bit set? If so, we are holey and that is good.
5010 __ And(at, a3, Operand(1));
5011 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5014 // look at the first argument
5015 __ lw(t1, MemOperand(sp, 0));
5016 __ Branch(&normal_sequence, eq, t1, Operand(zero_reg));
5018 if (mode == DISABLE_ALLOCATION_SITES) {
5019 ElementsKind initial = GetInitialFastElementsKind();
5020 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5022 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5024 DISABLE_ALLOCATION_SITES);
5025 __ TailCallStub(&stub_holey);
5027 __ bind(&normal_sequence);
5028 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5030 DISABLE_ALLOCATION_SITES);
5031 __ TailCallStub(&stub);
5032 } else if (mode == DONT_OVERRIDE) {
5033 // We are going to create a holey array, but our kind is non-holey.
5034 // Fix kind and retry (only if we have an allocation site in the slot).
5035 __ Addu(a3, a3, Operand(1));
5037 if (FLAG_debug_code) {
5038 __ lw(t1, FieldMemOperand(a2, 0));
5039 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5040 __ Assert(eq, kExpectedAllocationSite, t1, Operand(at));
5043 // Save the resulting elements kind in type info. We can't just store a3
5044 // in the AllocationSite::transition_info field because elements kind is
5045 // restricted to a portion of the field...upper bits need to be left alone.
5046 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5047 __ lw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5048 __ Addu(t0, t0, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5049 __ sw(t0, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5052 __ bind(&normal_sequence);
5053 int last_index = GetSequenceIndexFromFastElementsKind(
5054 TERMINAL_FAST_ELEMENTS_KIND);
5055 for (int i = 0; i <= last_index; ++i) {
5056 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5057 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5058 __ TailCallStub(&stub, eq, a3, Operand(kind));
5061 // If we reached this point there is a problem.
5062 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5070 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5071 int to_index = GetSequenceIndexFromFastElementsKind(
5072 TERMINAL_FAST_ELEMENTS_KIND);
5073 for (int i = 0; i <= to_index; ++i) {
5074 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5075 T stub(isolate, kind);
5077 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5078 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5085 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5086 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5088 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5090 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5095 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5097 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5098 for (int i = 0; i < 2; i++) {
5099 // For internal arrays we only need a few things.
5100 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5102 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5104 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5110 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5111 MacroAssembler* masm,
5112 AllocationSiteOverrideMode mode) {
5113 if (argument_count() == ANY) {
5114 Label not_zero_case, not_one_case;
5116 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5117 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5119 __ bind(¬_zero_case);
5120 __ Branch(¬_one_case, gt, a0, Operand(1));
5121 CreateArrayDispatchOneArgument(masm, mode);
5123 __ bind(¬_one_case);
5124 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5125 } else if (argument_count() == NONE) {
5126 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5127 } else if (argument_count() == ONE) {
5128 CreateArrayDispatchOneArgument(masm, mode);
5129 } else if (argument_count() == MORE_THAN_ONE) {
5130 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5137 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5138 // ----------- S t a t e -------------
5139 // -- a0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5140 // -- a1 : constructor
5141 // -- a2 : AllocationSite or undefined
5142 // -- a3 : Original constructor
5143 // -- sp[0] : last argument
5144 // -----------------------------------
5146 if (FLAG_debug_code) {
5147 // The array construct code is only set for the global and natives
5148 // builtin Array functions which always have maps.
5150 // Initial map for the builtin Array function should be a map.
5151 __ lw(t0, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5152 // Will both indicate a NULL and a Smi.
5154 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5155 at, Operand(zero_reg));
5156 __ GetObjectType(t0, t0, t1);
5157 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5158 t1, Operand(MAP_TYPE));
5160 // We should either have undefined in a2 or a valid AllocationSite
5161 __ AssertUndefinedOrAllocationSite(a2, t0);
5165 __ Branch(&subclassing, ne, a1, Operand(a3));
5168 // Get the elements kind and case on that.
5169 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5170 __ Branch(&no_info, eq, a2, Operand(at));
5172 __ lw(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5174 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5175 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5176 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5179 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5182 __ bind(&subclassing);
5187 switch (argument_count()) {
5190 __ li(at, Operand(2));
5191 __ addu(a0, a0, at);
5194 __ li(a0, Operand(2));
5197 __ li(a0, Operand(3));
5201 __ JumpToExternalReference(
5202 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5206 void InternalArrayConstructorStub::GenerateCase(
5207 MacroAssembler* masm, ElementsKind kind) {
5209 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5210 __ TailCallStub(&stub0, lo, a0, Operand(1));
5212 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5213 __ TailCallStub(&stubN, hi, a0, Operand(1));
5215 if (IsFastPackedElementsKind(kind)) {
5216 // We might need to create a holey array
5217 // look at the first argument.
5218 __ lw(at, MemOperand(sp, 0));
5220 InternalArraySingleArgumentConstructorStub
5221 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5222 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5225 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5226 __ TailCallStub(&stub1);
5230 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5231 // ----------- S t a t e -------------
5233 // -- a1 : constructor
5234 // -- sp[0] : return address
5235 // -- sp[4] : last argument
5236 // -----------------------------------
5238 if (FLAG_debug_code) {
5239 // The array construct code is only set for the global and natives
5240 // builtin Array functions which always have maps.
5242 // Initial map for the builtin Array function should be a map.
5243 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5244 // Will both indicate a NULL and a Smi.
5246 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5247 at, Operand(zero_reg));
5248 __ GetObjectType(a3, a3, t0);
5249 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5250 t0, Operand(MAP_TYPE));
5253 // Figure out the right elements kind.
5254 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5256 // Load the map's "bit field 2" into a3. We only need the first byte,
5257 // but the following bit field extraction takes care of that anyway.
5258 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5259 // Retrieve elements_kind from bit field 2.
5260 __ DecodeField<Map::ElementsKindBits>(a3);
5262 if (FLAG_debug_code) {
5264 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5266 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5267 a3, Operand(FAST_HOLEY_ELEMENTS));
5271 Label fast_elements_case;
5272 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5273 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5275 __ bind(&fast_elements_case);
5276 GenerateCase(masm, FAST_ELEMENTS);
5280 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5281 return ref0.address() - ref1.address();
5285 // Calls an API function. Allocates HandleScope, extracts returned value
5286 // from handle and propagates exceptions. Restores context. stack_space
5287 // - space to be unwound on exit (includes the call JS arguments space and
5288 // the additional space allocated for the fast call).
5289 static void CallApiFunctionAndReturn(
5290 MacroAssembler* masm, Register function_address,
5291 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5292 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5293 Isolate* isolate = masm->isolate();
5294 ExternalReference next_address =
5295 ExternalReference::handle_scope_next_address(isolate);
5296 const int kNextOffset = 0;
5297 const int kLimitOffset = AddressOffset(
5298 ExternalReference::handle_scope_limit_address(isolate), next_address);
5299 const int kLevelOffset = AddressOffset(
5300 ExternalReference::handle_scope_level_address(isolate), next_address);
5302 DCHECK(function_address.is(a1) || function_address.is(a2));
5304 Label profiler_disabled;
5305 Label end_profiler_check;
5306 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5307 __ lb(t9, MemOperand(t9, 0));
5308 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5310 // Additional parameter is the address of the actual callback.
5311 __ li(t9, Operand(thunk_ref));
5312 __ jmp(&end_profiler_check);
5314 __ bind(&profiler_disabled);
5315 __ mov(t9, function_address);
5316 __ bind(&end_profiler_check);
5318 // Allocate HandleScope in callee-save registers.
5319 __ li(s3, Operand(next_address));
5320 __ lw(s0, MemOperand(s3, kNextOffset));
5321 __ lw(s1, MemOperand(s3, kLimitOffset));
5322 __ lw(s2, MemOperand(s3, kLevelOffset));
5323 __ Addu(s2, s2, Operand(1));
5324 __ sw(s2, MemOperand(s3, kLevelOffset));
5326 if (FLAG_log_timer_events) {
5327 FrameScope frame(masm, StackFrame::MANUAL);
5328 __ PushSafepointRegisters();
5329 __ PrepareCallCFunction(1, a0);
5330 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5331 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5333 __ PopSafepointRegisters();
5336 // Native call returns to the DirectCEntry stub which redirects to the
5337 // return address pushed on stack (could have moved after GC).
5338 // DirectCEntry stub itself is generated early and never moves.
5339 DirectCEntryStub stub(isolate);
5340 stub.GenerateCall(masm, t9);
5342 if (FLAG_log_timer_events) {
5343 FrameScope frame(masm, StackFrame::MANUAL);
5344 __ PushSafepointRegisters();
5345 __ PrepareCallCFunction(1, a0);
5346 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5347 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5349 __ PopSafepointRegisters();
5352 Label promote_scheduled_exception;
5353 Label delete_allocated_handles;
5354 Label leave_exit_frame;
5355 Label return_value_loaded;
5357 // Load value from ReturnValue.
5358 __ lw(v0, return_value_operand);
5359 __ bind(&return_value_loaded);
5361 // No more valid handles (the result handle was the last one). Restore
5362 // previous handle scope.
5363 __ sw(s0, MemOperand(s3, kNextOffset));
5364 if (__ emit_debug_code()) {
5365 __ lw(a1, MemOperand(s3, kLevelOffset));
5366 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5368 __ Subu(s2, s2, Operand(1));
5369 __ sw(s2, MemOperand(s3, kLevelOffset));
5370 __ lw(at, MemOperand(s3, kLimitOffset));
5371 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5373 // Leave the API exit frame.
5374 __ bind(&leave_exit_frame);
5376 bool restore_context = context_restore_operand != NULL;
5377 if (restore_context) {
5378 __ lw(cp, *context_restore_operand);
5380 if (stack_space_offset != kInvalidStackOffset) {
5381 // ExitFrame contains four MIPS argument slots after DirectCEntryStub call
5382 // so this must be accounted for.
5383 __ lw(s0, MemOperand(sp, stack_space_offset + kCArgsSlotsSize));
5385 __ li(s0, Operand(stack_space));
5387 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5388 stack_space_offset != kInvalidStackOffset);
5390 // Check if the function scheduled an exception.
5391 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
5392 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5393 __ lw(t1, MemOperand(at));
5394 __ Branch(&promote_scheduled_exception, ne, t0, Operand(t1));
5398 // Re-throw by promoting a scheduled exception.
5399 __ bind(&promote_scheduled_exception);
5400 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5402 // HandleScope limit has changed. Delete allocated extensions.
5403 __ bind(&delete_allocated_handles);
5404 __ sw(s1, MemOperand(s3, kLimitOffset));
5407 __ PrepareCallCFunction(1, s1);
5408 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5409 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5412 __ jmp(&leave_exit_frame);
5416 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5417 const ParameterCount& argc,
5418 bool return_first_arg,
5419 bool call_data_undefined) {
5420 // ----------- S t a t e -------------
5422 // -- t0 : call_data
5424 // -- a1 : api_function_address
5425 // -- a3 : number of arguments if argc is a register
5428 // -- sp[0] : last argument
5430 // -- sp[(argc - 1)* 4] : first argument
5431 // -- sp[argc * 4] : receiver
5432 // -----------------------------------
5434 Register callee = a0;
5435 Register call_data = t0;
5436 Register holder = a2;
5437 Register api_function_address = a1;
5438 Register context = cp;
5440 typedef FunctionCallbackArguments FCA;
5442 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5443 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5444 STATIC_ASSERT(FCA::kDataIndex == 4);
5445 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5446 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5447 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5448 STATIC_ASSERT(FCA::kHolderIndex == 0);
5449 STATIC_ASSERT(FCA::kArgsLength == 7);
5451 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5453 // Save context, callee and call data.
5454 __ Push(context, callee, call_data);
5455 // Load context from callee.
5456 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5458 Register scratch = call_data;
5459 if (!call_data_undefined) {
5460 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5462 // Push return value and default return value.
5463 __ Push(scratch, scratch);
5464 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5465 // Push isolate and holder.
5466 __ Push(scratch, holder);
5468 // Prepare arguments.
5469 __ mov(scratch, sp);
5471 // Allocate the v8::Arguments structure in the arguments' space since
5472 // it's not controlled by GC.
5473 const int kApiStackSpace = 4;
5475 FrameScope frame_scope(masm, StackFrame::MANUAL);
5476 __ EnterExitFrame(false, kApiStackSpace);
5478 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5479 // a0 = FunctionCallbackInfo&
5480 // Arguments is after the return address.
5481 __ Addu(a0, sp, Operand(1 * kPointerSize));
5482 // FunctionCallbackInfo::implicit_args_
5483 __ sw(scratch, MemOperand(a0, 0 * kPointerSize));
5484 if (argc.is_immediate()) {
5485 // FunctionCallbackInfo::values_
5486 __ Addu(at, scratch,
5487 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5488 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5489 // FunctionCallbackInfo::length_ = argc
5490 __ li(at, Operand(argc.immediate()));
5491 __ sw(at, MemOperand(a0, 2 * kPointerSize));
5492 // FunctionCallbackInfo::is_construct_call_ = 0
5493 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
5495 // FunctionCallbackInfo::values_
5496 __ sll(at, argc.reg(), kPointerSizeLog2);
5497 __ Addu(at, at, scratch);
5498 __ Addu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5499 __ sw(at, MemOperand(a0, 1 * kPointerSize));
5500 // FunctionCallbackInfo::length_ = argc
5501 __ sw(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5502 // FunctionCallbackInfo::is_construct_call_
5503 __ Addu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5504 __ sll(at, argc.reg(), kPointerSizeLog2);
5505 __ sw(at, MemOperand(a0, 3 * kPointerSize));
5508 ExternalReference thunk_ref =
5509 ExternalReference::invoke_function_callback(masm->isolate());
5511 AllowExternalCallThatCantCauseGC scope(masm);
5512 MemOperand context_restore_operand(
5513 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5514 // Stores return the first js argument.
5515 int return_value_offset = 0;
5516 if (return_first_arg) {
5517 return_value_offset = 2 + FCA::kArgsLength;
5519 return_value_offset = 2 + FCA::kReturnValueOffset;
5521 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5522 int stack_space = 0;
5523 int32_t stack_space_offset = 4 * kPointerSize;
5524 if (argc.is_immediate()) {
5525 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5526 stack_space_offset = kInvalidStackOffset;
5528 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5529 stack_space_offset, return_value_operand,
5530 &context_restore_operand);
5534 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5535 bool call_data_undefined = this->call_data_undefined();
5536 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5537 call_data_undefined);
5541 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5542 bool is_store = this->is_store();
5543 int argc = this->argc();
5544 bool call_data_undefined = this->call_data_undefined();
5545 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5546 call_data_undefined);
5550 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5551 // ----------- S t a t e -------------
5553 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5555 // -- a2 : api_function_address
5556 // -----------------------------------
5558 Register api_function_address = ApiGetterDescriptor::function_address();
5559 DCHECK(api_function_address.is(a2));
5561 __ mov(a0, sp); // a0 = Handle<Name>
5562 __ Addu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5564 const int kApiStackSpace = 1;
5565 FrameScope frame_scope(masm, StackFrame::MANUAL);
5566 __ EnterExitFrame(false, kApiStackSpace);
5568 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5569 // a1 (internal::Object** args_) as the data.
5570 __ sw(a1, MemOperand(sp, 1 * kPointerSize));
5571 __ Addu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5573 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5575 ExternalReference thunk_ref =
5576 ExternalReference::invoke_accessor_getter_callback(isolate());
5577 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5578 kStackUnwindSpace, kInvalidStackOffset,
5579 MemOperand(fp, 6 * kPointerSize), NULL);
5585 } // namespace internal
5588 #endif // V8_TARGET_ARCH_MIPS