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_MIPS64
9 #include "src/bootstrapper.h"
10 #include "src/code-stubs.h"
11 #include "src/codegen.h"
12 #include "src/ic/handler-compiler.h"
13 #include "src/ic/ic.h"
14 #include "src/ic/stub-cache.h"
15 #include "src/isolate.h"
16 #include "src/jsregexp.h"
17 #include "src/regexp-macro-assembler.h"
18 #include "src/runtime/runtime.h"
24 static void InitializeArrayConstructorDescriptor(
25 Isolate* isolate, CodeStubDescriptor* descriptor,
26 int constant_stack_parameter_count) {
27 Address deopt_handler = Runtime::FunctionForId(
28 Runtime::kArrayConstructor)->entry;
30 if (constant_stack_parameter_count == 0) {
31 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
32 JS_FUNCTION_STUB_MODE);
34 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
35 JS_FUNCTION_STUB_MODE);
40 static void InitializeInternalArrayConstructorDescriptor(
41 Isolate* isolate, CodeStubDescriptor* descriptor,
42 int constant_stack_parameter_count) {
43 Address deopt_handler = Runtime::FunctionForId(
44 Runtime::kInternalArrayConstructor)->entry;
46 if (constant_stack_parameter_count == 0) {
47 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
48 JS_FUNCTION_STUB_MODE);
50 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
51 JS_FUNCTION_STUB_MODE);
56 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
57 CodeStubDescriptor* descriptor) {
58 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
62 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
63 CodeStubDescriptor* descriptor) {
64 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
68 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
69 CodeStubDescriptor* descriptor) {
70 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
74 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
75 CodeStubDescriptor* descriptor) {
76 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
80 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
81 CodeStubDescriptor* descriptor) {
82 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
86 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
87 CodeStubDescriptor* descriptor) {
88 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
92 #define __ ACCESS_MASM(masm)
95 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
96 Condition cc, Strength strength);
97 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
103 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
108 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
109 ExternalReference miss) {
110 // Update the static counter each time a new code stub is generated.
111 isolate()->counters()->code_stubs()->Increment();
113 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
114 int param_count = descriptor.GetRegisterParameterCount();
116 // Call the runtime system in a fresh internal frame.
117 FrameScope scope(masm, StackFrame::INTERNAL);
118 DCHECK((param_count == 0) ||
119 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
120 // Push arguments, adjust sp.
121 __ Dsubu(sp, sp, Operand(param_count * kPointerSize));
122 for (int i = 0; i < param_count; ++i) {
123 // Store argument to stack.
124 __ sd(descriptor.GetRegisterParameter(i),
125 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
127 __ CallExternalReference(miss, param_count);
134 void DoubleToIStub::Generate(MacroAssembler* masm) {
135 Label out_of_range, only_low, negate, done;
136 Register input_reg = source();
137 Register result_reg = destination();
139 int double_offset = offset();
140 // Account for saved regs if input is sp.
141 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
144 GetRegisterThatIsNotOneOf(input_reg, result_reg);
146 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
148 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
149 DoubleRegister double_scratch = kLithiumScratchDouble;
151 __ Push(scratch, scratch2, scratch3);
152 if (!skip_fastpath()) {
153 // Load double input.
154 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
156 // Clear cumulative exception flags and save the FCSR.
157 __ cfc1(scratch2, FCSR);
158 __ ctc1(zero_reg, FCSR);
160 // Try a conversion to a signed integer.
161 __ Trunc_w_d(double_scratch, double_scratch);
162 // Move the converted value into the result register.
163 __ mfc1(scratch3, double_scratch);
165 // Retrieve and restore the FCSR.
166 __ cfc1(scratch, FCSR);
167 __ ctc1(scratch2, FCSR);
169 // Check for overflow and NaNs.
172 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
173 | kFCSRInvalidOpFlagMask);
174 // If we had no exceptions then set result_reg and we are done.
176 __ Branch(&error, ne, scratch, Operand(zero_reg));
177 __ Move(result_reg, scratch3);
182 // Load the double value and perform a manual truncation.
183 Register input_high = scratch2;
184 Register input_low = scratch3;
186 __ lw(input_low, MemOperand(input_reg, double_offset));
187 __ lw(input_high, MemOperand(input_reg, double_offset + kIntSize));
189 Label normal_exponent, restore_sign;
190 // Extract the biased exponent in result.
193 HeapNumber::kExponentShift,
194 HeapNumber::kExponentBits);
196 // Check for Infinity and NaNs, which should return 0.
197 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
198 __ Movz(result_reg, zero_reg, scratch);
199 __ Branch(&done, eq, scratch, Operand(zero_reg));
201 // Express exponent as delta to (number of mantissa bits + 31).
204 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
206 // If the delta is strictly positive, all bits would be shifted away,
207 // which means that we can return 0.
208 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
209 __ mov(result_reg, zero_reg);
212 __ bind(&normal_exponent);
213 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
215 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
218 Register sign = result_reg;
220 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
222 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
223 // to check for this specific case.
224 Label high_shift_needed, high_shift_done;
225 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
226 __ mov(input_high, zero_reg);
227 __ Branch(&high_shift_done);
228 __ bind(&high_shift_needed);
230 // Set the implicit 1 before the mantissa part in input_high.
233 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
234 // Shift the mantissa bits to the correct position.
235 // We don't need to clear non-mantissa bits as they will be shifted away.
236 // If they weren't, it would mean that the answer is in the 32bit range.
237 __ sllv(input_high, input_high, scratch);
239 __ bind(&high_shift_done);
241 // Replace the shifted bits with bits from the lower mantissa word.
242 Label pos_shift, shift_done;
244 __ subu(scratch, at, scratch);
245 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
248 __ Subu(scratch, zero_reg, scratch);
249 __ sllv(input_low, input_low, scratch);
250 __ Branch(&shift_done);
253 __ srlv(input_low, input_low, scratch);
255 __ bind(&shift_done);
256 __ Or(input_high, input_high, Operand(input_low));
257 // Restore sign if necessary.
258 __ mov(scratch, sign);
261 __ Subu(result_reg, zero_reg, input_high);
262 __ Movz(result_reg, input_high, scratch);
266 __ Pop(scratch, scratch2, scratch3);
271 // Handle the case where the lhs and rhs are the same object.
272 // Equality is almost reflexive (everything but NaN), so this is a test
273 // for "identity and not NaN".
274 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
275 Condition cc, Strength strength) {
277 Label heap_number, return_equal;
278 Register exp_mask_reg = t1;
280 __ Branch(¬_identical, ne, a0, Operand(a1));
282 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
284 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
285 // so we do the second best thing - test it ourselves.
286 // They are both equal and they are not both Smis so both of them are not
287 // Smis. If it's not a heap number, then return equal.
288 __ GetObjectType(a0, t0, t0);
289 if (cc == less || cc == greater) {
290 // Call runtime on identical JSObjects.
291 __ Branch(slow, greater, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
292 // Call runtime on identical symbols since we need to throw a TypeError.
293 __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE));
294 // Call runtime on identical SIMD values since we must throw a TypeError.
295 __ Branch(slow, eq, t0, Operand(FLOAT32X4_TYPE));
296 if (is_strong(strength)) {
297 // Call the runtime on anything that is converted in the semantics, since
298 // we need to throw a TypeError. Smis have already been ruled out.
299 __ Branch(&return_equal, eq, t0, Operand(HEAP_NUMBER_TYPE));
300 __ And(t0, t0, Operand(kIsNotStringMask));
301 __ Branch(slow, ne, t0, Operand(zero_reg));
304 __ Branch(&heap_number, eq, t0, Operand(HEAP_NUMBER_TYPE));
305 // Comparing JS objects with <=, >= is complicated.
307 __ Branch(slow, greater, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
308 // Call runtime on identical symbols since we need to throw a TypeError.
309 __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE));
310 // Call runtime on identical SIMD values since we must throw a TypeError.
311 __ Branch(slow, eq, t0, Operand(FLOAT32X4_TYPE));
312 if (is_strong(strength)) {
313 // Call the runtime on anything that is converted in the semantics,
314 // since we need to throw a TypeError. Smis and heap numbers have
315 // already been ruled out.
316 __ And(t0, t0, Operand(kIsNotStringMask));
317 __ Branch(slow, ne, t0, Operand(zero_reg));
319 // Normally here we fall through to return_equal, but undefined is
320 // special: (undefined == undefined) == true, but
321 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
322 if (cc == less_equal || cc == greater_equal) {
323 __ Branch(&return_equal, ne, t0, Operand(ODDBALL_TYPE));
324 __ LoadRoot(a6, Heap::kUndefinedValueRootIndex);
325 __ Branch(&return_equal, ne, a0, Operand(a6));
326 DCHECK(is_int16(GREATER) && is_int16(LESS));
327 __ Ret(USE_DELAY_SLOT);
329 // undefined <= undefined should fail.
330 __ li(v0, Operand(GREATER));
332 // undefined >= undefined should fail.
333 __ li(v0, Operand(LESS));
339 __ bind(&return_equal);
340 DCHECK(is_int16(GREATER) && is_int16(LESS));
341 __ Ret(USE_DELAY_SLOT);
343 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
344 } else if (cc == greater) {
345 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
347 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
349 // For less and greater we don't have to check for NaN since the result of
350 // x < x is false regardless. For the others here is some code to check
352 if (cc != lt && cc != gt) {
353 __ bind(&heap_number);
354 // It is a heap number, so return non-equal if it's NaN and equal if it's
357 // The representation of NaN values has all exponent bits (52..62) set,
358 // and not all mantissa bits (0..51) clear.
359 // Read top bits of double representation (second word of value).
360 __ lwu(a6, FieldMemOperand(a0, HeapNumber::kExponentOffset));
361 // Test that exponent bits are all set.
362 __ And(a7, a6, Operand(exp_mask_reg));
363 // If all bits not set (ne cond), then not a NaN, objects are equal.
364 __ Branch(&return_equal, ne, a7, Operand(exp_mask_reg));
366 // Shift out flag and all exponent bits, retaining only mantissa.
367 __ sll(a6, a6, HeapNumber::kNonMantissaBitsInTopWord);
368 // Or with all low-bits of mantissa.
369 __ lwu(a7, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
370 __ Or(v0, a7, Operand(a6));
371 // For equal we already have the right value in v0: Return zero (equal)
372 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
373 // not (it's a NaN). For <= and >= we need to load v0 with the failing
374 // value if it's a NaN.
376 // All-zero means Infinity means equal.
377 __ Ret(eq, v0, Operand(zero_reg));
378 DCHECK(is_int16(GREATER) && is_int16(LESS));
379 __ Ret(USE_DELAY_SLOT);
381 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
383 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
387 // No fall through here.
389 __ bind(¬_identical);
393 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
396 Label* both_loaded_as_doubles,
399 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
400 (lhs.is(a1) && rhs.is(a0)));
403 __ JumpIfSmi(lhs, &lhs_is_smi);
405 // Check whether the non-smi is a heap number.
406 __ GetObjectType(lhs, t0, t0);
408 // If lhs was not a number and rhs was a Smi then strict equality cannot
409 // succeed. Return non-equal (lhs is already not zero).
410 __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE));
413 // Smi compared non-strictly with a non-Smi non-heap-number. Call
415 __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE));
417 // Rhs is a smi, lhs is a number.
418 // Convert smi rhs to double.
419 __ SmiUntag(at, rhs);
421 __ cvt_d_w(f14, f14);
422 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
424 // We now have both loaded as doubles.
425 __ jmp(both_loaded_as_doubles);
427 __ bind(&lhs_is_smi);
428 // Lhs is a Smi. Check whether the non-smi is a heap number.
429 __ GetObjectType(rhs, t0, t0);
431 // If lhs was not a number and rhs was a Smi then strict equality cannot
432 // succeed. Return non-equal.
433 __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE));
434 __ li(v0, Operand(1));
436 // Smi compared non-strictly with a non-Smi non-heap-number. Call
438 __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE));
441 // Lhs is a smi, rhs is a number.
442 // Convert smi lhs to double.
443 __ SmiUntag(at, lhs);
445 __ cvt_d_w(f12, f12);
446 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
447 // Fall through to both_loaded_as_doubles.
451 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
454 // If either operand is a JS object or an oddball value, then they are
455 // not equal since their pointers are different.
456 // There is no test for undetectability in strict equality.
457 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
458 Label first_non_object;
459 // Get the type of the first operand into a2 and compare it with
460 // FIRST_SPEC_OBJECT_TYPE.
461 __ GetObjectType(lhs, a2, a2);
462 __ Branch(&first_non_object, less, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
465 Label return_not_equal;
466 __ bind(&return_not_equal);
467 __ Ret(USE_DELAY_SLOT);
468 __ li(v0, Operand(1));
470 __ bind(&first_non_object);
471 // Check for oddballs: true, false, null, undefined.
472 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
474 __ GetObjectType(rhs, a3, a3);
475 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
477 // Check for oddballs: true, false, null, undefined.
478 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
480 // Now that we have the types we might as well check for
481 // internalized-internalized.
482 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
483 __ Or(a2, a2, Operand(a3));
484 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
485 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
489 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
492 Label* both_loaded_as_doubles,
493 Label* not_heap_numbers,
495 __ GetObjectType(lhs, a3, a2);
496 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
497 __ ld(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
498 // If first was a heap number & second wasn't, go to slow case.
499 __ Branch(slow, ne, a3, Operand(a2));
501 // Both are heap numbers. Load them up then jump to the code we have
503 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
504 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
506 __ jmp(both_loaded_as_doubles);
510 // Fast negative check for internalized-to-internalized equality.
511 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
514 Label* possible_strings,
515 Label* not_both_strings) {
516 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
517 (lhs.is(a1) && rhs.is(a0)));
519 // a2 is object type of rhs.
521 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
522 __ And(at, a2, Operand(kIsNotStringMask));
523 __ Branch(&object_test, ne, at, Operand(zero_reg));
524 __ And(at, a2, Operand(kIsNotInternalizedMask));
525 __ Branch(possible_strings, ne, at, Operand(zero_reg));
526 __ GetObjectType(rhs, a3, a3);
527 __ Branch(not_both_strings, ge, a3, Operand(FIRST_NONSTRING_TYPE));
528 __ And(at, a3, Operand(kIsNotInternalizedMask));
529 __ Branch(possible_strings, ne, at, Operand(zero_reg));
531 // Both are internalized strings. We already checked they weren't the same
532 // pointer so they are not equal.
533 __ Ret(USE_DELAY_SLOT);
534 __ li(v0, Operand(1)); // Non-zero indicates not equal.
536 __ bind(&object_test);
537 __ Branch(not_both_strings, lt, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
538 __ GetObjectType(rhs, a2, a3);
539 __ Branch(not_both_strings, lt, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
541 // If both objects are undetectable, they are equal. Otherwise, they
542 // are not equal, since they are different objects and an object is not
543 // equal to undefined.
544 __ ld(a3, FieldMemOperand(lhs, HeapObject::kMapOffset));
545 __ lbu(a2, FieldMemOperand(a2, Map::kBitFieldOffset));
546 __ lbu(a3, FieldMemOperand(a3, Map::kBitFieldOffset));
548 __ And(a0, a0, Operand(1 << Map::kIsUndetectable));
549 __ Ret(USE_DELAY_SLOT);
550 __ xori(v0, a0, 1 << Map::kIsUndetectable);
554 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
556 CompareICState::State expected,
559 if (expected == CompareICState::SMI) {
560 __ JumpIfNotSmi(input, fail);
561 } else if (expected == CompareICState::NUMBER) {
562 __ JumpIfSmi(input, &ok);
563 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
566 // We could be strict about internalized/string here, but as long as
567 // hydrogen doesn't care, the stub doesn't have to care either.
572 // On entry a1 and a2 are the values to be compared.
573 // On exit a0 is 0, positive or negative to indicate the result of
575 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
578 Condition cc = GetCondition();
581 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
582 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
584 Label slow; // Call builtin.
585 Label not_smis, both_loaded_as_doubles;
587 Label not_two_smis, smi_done;
589 __ JumpIfNotSmi(a2, ¬_two_smis);
593 __ Ret(USE_DELAY_SLOT);
594 __ dsubu(v0, a1, a0);
595 __ bind(¬_two_smis);
597 // NOTICE! This code is only reached after a smi-fast-case check, so
598 // it is certain that at least one operand isn't a smi.
600 // Handle the case where the objects are identical. Either returns the answer
601 // or goes to slow. Only falls through if the objects were not identical.
602 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
604 // If either is a Smi (we know that not both are), then they can only
605 // be strictly equal if the other is a HeapNumber.
606 STATIC_ASSERT(kSmiTag == 0);
607 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
608 __ And(a6, lhs, Operand(rhs));
609 __ JumpIfNotSmi(a6, ¬_smis, a4);
610 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
611 // 1) Return the answer.
613 // 3) Fall through to both_loaded_as_doubles.
614 // 4) Jump to rhs_not_nan.
615 // In cases 3 and 4 we have found out we were dealing with a number-number
616 // comparison and the numbers have been loaded into f12 and f14 as doubles,
617 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
618 EmitSmiNonsmiComparison(masm, lhs, rhs,
619 &both_loaded_as_doubles, &slow, strict());
621 __ bind(&both_loaded_as_doubles);
622 // f12, f14 are the double representations of the left hand side
623 // and the right hand side if we have FPU. Otherwise a2, a3 represent
624 // left hand side and a0, a1 represent right hand side.
627 __ li(a4, Operand(LESS));
628 __ li(a5, Operand(GREATER));
629 __ li(a6, Operand(EQUAL));
631 // Check if either rhs or lhs is NaN.
632 __ BranchF(NULL, &nan, eq, f12, f14);
634 // Check if LESS condition is satisfied. If true, move conditionally
636 if (kArchVariant != kMips64r6) {
637 __ c(OLT, D, f12, f14);
639 // Use previous check to store conditionally to v0 oposite condition
640 // (GREATER). If rhs is equal to lhs, this will be corrected in next
643 // Check if EQUAL condition is satisfied. If true, move conditionally
645 __ c(EQ, D, f12, f14);
649 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
650 __ mov(v0, a4); // Return LESS as result.
652 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
653 __ mov(v0, a6); // Return EQUAL as result.
655 __ mov(v0, a5); // Return GREATER as result.
661 // NaN comparisons always fail.
662 // Load whatever we need in v0 to make the comparison fail.
663 DCHECK(is_int16(GREATER) && is_int16(LESS));
664 __ Ret(USE_DELAY_SLOT);
665 if (cc == lt || cc == le) {
666 __ li(v0, Operand(GREATER));
668 __ li(v0, Operand(LESS));
673 // At this point we know we are dealing with two different objects,
674 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
676 // This returns non-equal for some object types, or falls through if it
678 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
681 Label check_for_internalized_strings;
682 Label flat_string_check;
683 // Check for heap-number-heap-number comparison. Can jump to slow case,
684 // or load both doubles and jump to the code that handles
685 // that case. If the inputs are not doubles then jumps to
686 // check_for_internalized_strings.
687 // In this case a2 will contain the type of lhs_.
688 EmitCheckForTwoHeapNumbers(masm,
691 &both_loaded_as_doubles,
692 &check_for_internalized_strings,
695 __ bind(&check_for_internalized_strings);
696 if (cc == eq && !strict()) {
697 // Returns an answer for two internalized strings or two
698 // detectable objects.
699 // Otherwise jumps to string case or not both strings case.
700 // Assumes that a2 is the type of lhs_ on entry.
701 EmitCheckForInternalizedStringsOrObjects(
702 masm, lhs, rhs, &flat_string_check, &slow);
705 // Check for both being sequential one-byte strings,
706 // and inline if that is the case.
707 __ bind(&flat_string_check);
709 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
711 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
714 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, a4);
716 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, a4,
719 // Never falls through to here.
722 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
725 // Figure out which native to call and setup the arguments.
726 Builtins::JavaScript native;
728 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
731 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
732 int ncr; // NaN compare result.
733 if (cc == lt || cc == le) {
736 DCHECK(cc == gt || cc == ge); // Remaining cases.
739 __ li(a0, Operand(Smi::FromInt(ncr)));
743 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
744 // tagged as a small integer.
745 __ InvokeBuiltin(native, JUMP_FUNCTION);
752 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
755 __ PushSafepointRegisters();
760 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
763 __ PopSafepointRegisters();
768 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
769 // We don't allow a GC during a store buffer overflow so there is no need to
770 // store the registers in any particular way, but we do have to store and
772 __ MultiPush(kJSCallerSaved | ra.bit());
773 if (save_doubles()) {
774 __ MultiPushFPU(kCallerSavedFPU);
776 const int argument_count = 1;
777 const int fp_argument_count = 0;
778 const Register scratch = a1;
780 AllowExternalCallThatCantCauseGC scope(masm);
781 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
782 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
784 ExternalReference::store_buffer_overflow_function(isolate()),
786 if (save_doubles()) {
787 __ MultiPopFPU(kCallerSavedFPU);
790 __ MultiPop(kJSCallerSaved | ra.bit());
795 void MathPowStub::Generate(MacroAssembler* masm) {
796 const Register base = a1;
797 const Register exponent = MathPowTaggedDescriptor::exponent();
798 DCHECK(exponent.is(a2));
799 const Register heapnumbermap = a5;
800 const Register heapnumber = v0;
801 const DoubleRegister double_base = f2;
802 const DoubleRegister double_exponent = f4;
803 const DoubleRegister double_result = f0;
804 const DoubleRegister double_scratch = f6;
805 const FPURegister single_scratch = f8;
806 const Register scratch = t1;
807 const Register scratch2 = a7;
809 Label call_runtime, done, int_exponent;
810 if (exponent_type() == ON_STACK) {
811 Label base_is_smi, unpack_exponent;
812 // The exponent and base are supplied as arguments on the stack.
813 // This can only happen if the stub is called from non-optimized code.
814 // Load input parameters from stack to double registers.
815 __ ld(base, MemOperand(sp, 1 * kPointerSize));
816 __ ld(exponent, MemOperand(sp, 0 * kPointerSize));
818 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
820 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
821 __ ld(scratch, FieldMemOperand(base, JSObject::kMapOffset));
822 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
824 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
825 __ jmp(&unpack_exponent);
827 __ bind(&base_is_smi);
828 __ mtc1(scratch, single_scratch);
829 __ cvt_d_w(double_base, single_scratch);
830 __ bind(&unpack_exponent);
832 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
834 __ ld(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
835 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
836 __ ldc1(double_exponent,
837 FieldMemOperand(exponent, HeapNumber::kValueOffset));
838 } else if (exponent_type() == TAGGED) {
839 // Base is already in double_base.
840 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
842 __ ldc1(double_exponent,
843 FieldMemOperand(exponent, HeapNumber::kValueOffset));
846 if (exponent_type() != INTEGER) {
847 Label int_exponent_convert;
848 // Detect integer exponents stored as double.
849 __ EmitFPUTruncate(kRoundToMinusInf,
855 kCheckForInexactConversion);
856 // scratch2 == 0 means there was no conversion error.
857 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
859 if (exponent_type() == ON_STACK) {
860 // Detect square root case. Crankshaft detects constant +/-0.5 at
861 // compile time and uses DoMathPowHalf instead. We then skip this check
862 // for non-constant cases of +/-0.5 as these hardly occur.
866 __ Move(double_scratch, 0.5);
867 __ BranchF(USE_DELAY_SLOT,
873 // double_scratch can be overwritten in the delay slot.
874 // Calculates square root of base. Check for the special case of
875 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
876 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
877 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
878 __ neg_d(double_result, double_scratch);
880 // Add +0 to convert -0 to +0.
881 __ add_d(double_scratch, double_base, kDoubleRegZero);
882 __ sqrt_d(double_result, double_scratch);
885 __ bind(¬_plus_half);
886 __ Move(double_scratch, -0.5);
887 __ BranchF(USE_DELAY_SLOT,
893 // double_scratch can be overwritten in the delay slot.
894 // Calculates square root of base. Check for the special case of
895 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
896 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
897 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
898 __ Move(double_result, kDoubleRegZero);
900 // Add +0 to convert -0 to +0.
901 __ add_d(double_scratch, double_base, kDoubleRegZero);
902 __ Move(double_result, 1.);
903 __ sqrt_d(double_scratch, double_scratch);
904 __ div_d(double_result, double_result, double_scratch);
910 AllowExternalCallThatCantCauseGC scope(masm);
911 __ PrepareCallCFunction(0, 2, scratch2);
912 __ MovToFloatParameters(double_base, double_exponent);
914 ExternalReference::power_double_double_function(isolate()),
918 __ MovFromFloatResult(double_result);
921 __ bind(&int_exponent_convert);
924 // Calculate power with integer exponent.
925 __ bind(&int_exponent);
927 // Get two copies of exponent in the registers scratch and exponent.
928 if (exponent_type() == INTEGER) {
929 __ mov(scratch, exponent);
931 // Exponent has previously been stored into scratch as untagged integer.
932 __ mov(exponent, scratch);
935 __ mov_d(double_scratch, double_base); // Back up base.
936 __ Move(double_result, 1.0);
938 // Get absolute value of exponent.
939 Label positive_exponent;
940 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
941 __ Dsubu(scratch, zero_reg, scratch);
942 __ bind(&positive_exponent);
944 Label while_true, no_carry, loop_end;
945 __ bind(&while_true);
947 __ And(scratch2, scratch, 1);
949 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
950 __ mul_d(double_result, double_result, double_scratch);
953 __ dsra(scratch, scratch, 1);
955 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
956 __ mul_d(double_scratch, double_scratch, double_scratch);
958 __ Branch(&while_true);
962 __ Branch(&done, ge, exponent, Operand(zero_reg));
963 __ Move(double_scratch, 1.0);
964 __ div_d(double_result, double_scratch, double_result);
965 // Test whether result is zero. Bail out to check for subnormal result.
966 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
967 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
969 // double_exponent may not contain the exponent value if the input was a
970 // smi. We set it with exponent value before bailing out.
971 __ mtc1(exponent, single_scratch);
972 __ cvt_d_w(double_exponent, single_scratch);
974 // Returning or bailing out.
975 Counters* counters = isolate()->counters();
976 if (exponent_type() == ON_STACK) {
977 // The arguments are still on the stack.
978 __ bind(&call_runtime);
979 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
981 // The stub is called from non-optimized code, which expects the result
982 // as heap number in exponent.
984 __ AllocateHeapNumber(
985 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
986 __ sdc1(double_result,
987 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
988 DCHECK(heapnumber.is(v0));
989 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
994 AllowExternalCallThatCantCauseGC scope(masm);
995 __ PrepareCallCFunction(0, 2, scratch);
996 __ MovToFloatParameters(double_base, double_exponent);
998 ExternalReference::power_double_double_function(isolate()),
1002 __ MovFromFloatResult(double_result);
1005 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1011 bool CEntryStub::NeedsImmovableCode() {
1016 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1017 CEntryStub::GenerateAheadOfTime(isolate);
1018 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1019 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1020 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1021 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1022 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1023 BinaryOpICStub::GenerateAheadOfTime(isolate);
1024 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1025 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1026 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1027 StoreFastElementStub::GenerateAheadOfTime(isolate);
1028 TypeofStub::GenerateAheadOfTime(isolate);
1032 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1033 StoreRegistersStateStub stub(isolate);
1038 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1039 RestoreRegistersStateStub stub(isolate);
1044 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1045 // Generate if not already in cache.
1046 SaveFPRegsMode mode = kSaveFPRegs;
1047 CEntryStub(isolate, 1, mode).GetCode();
1048 StoreBufferOverflowStub(isolate, mode).GetCode();
1049 isolate->set_fp_stubs_generated(true);
1053 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1054 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1059 void CEntryStub::Generate(MacroAssembler* masm) {
1060 // Called from JavaScript; parameters are on stack as if calling JS function
1061 // a0: number of arguments including receiver
1062 // a1: pointer to builtin function
1063 // fp: frame pointer (restored after C call)
1064 // sp: stack pointer (restored as callee's sp after C call)
1065 // cp: current context (C callee-saved)
1067 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1069 // Compute the argv pointer in a callee-saved register.
1070 __ dsll(s1, a0, kPointerSizeLog2);
1071 __ Daddu(s1, sp, s1);
1072 __ Dsubu(s1, s1, kPointerSize);
1074 // Enter the exit frame that transitions from JavaScript to C++.
1075 FrameScope scope(masm, StackFrame::MANUAL);
1076 __ EnterExitFrame(save_doubles());
1078 // s0: number of arguments including receiver (C callee-saved)
1079 // s1: pointer to first argument (C callee-saved)
1080 // s2: pointer to builtin function (C callee-saved)
1082 // Prepare arguments for C routine.
1086 // a1 = argv (set in the delay slot after find_ra below).
1088 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1089 // also need to reserve the 4 argument slots on the stack.
1091 __ AssertStackIsAligned();
1093 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1095 // To let the GC traverse the return address of the exit frames, we need to
1096 // know where the return address is. The CEntryStub is unmovable, so
1097 // we can store the address on the stack to be able to find it again and
1098 // we never have to restore it, because it will not change.
1099 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1100 // This branch-and-link sequence is needed to find the current PC on mips,
1101 // saved to the ra register.
1102 // Use masm-> here instead of the double-underscore macro since extra
1103 // coverage code can interfere with the proper calculation of ra.
1105 masm->bal(&find_ra); // bal exposes branch delay slot.
1107 masm->bind(&find_ra);
1109 // Adjust the value in ra to point to the correct return location, 2nd
1110 // instruction past the real call into C code (the jalr(t9)), and push it.
1111 // This is the return address of the exit frame.
1112 const int kNumInstructionsToJump = 5;
1113 masm->Daddu(ra, ra, kNumInstructionsToJump * kInt32Size);
1114 masm->sd(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1115 // Stack space reservation moved to the branch delay slot below.
1116 // Stack is still aligned.
1118 // Call the C routine.
1119 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1121 // Set up sp in the delay slot.
1122 masm->daddiu(sp, sp, -kCArgsSlotsSize);
1123 // Make sure the stored 'ra' points to this position.
1124 DCHECK_EQ(kNumInstructionsToJump,
1125 masm->InstructionsGeneratedSince(&find_ra));
1128 // Check result for exception sentinel.
1129 Label exception_returned;
1130 __ LoadRoot(a4, Heap::kExceptionRootIndex);
1131 __ Branch(&exception_returned, eq, a4, Operand(v0));
1133 // Check that there is no pending exception, otherwise we
1134 // should have returned the exception sentinel.
1135 if (FLAG_debug_code) {
1137 ExternalReference pending_exception_address(
1138 Isolate::kPendingExceptionAddress, isolate());
1139 __ li(a2, Operand(pending_exception_address));
1140 __ ld(a2, MemOperand(a2));
1141 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
1142 // Cannot use check here as it attempts to generate call into runtime.
1143 __ Branch(&okay, eq, a4, Operand(a2));
1144 __ stop("Unexpected pending exception");
1148 // Exit C frame and return.
1150 // sp: stack pointer
1151 // fp: frame pointer
1152 // s0: still holds argc (callee-saved).
1153 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1155 // Handling of exception.
1156 __ bind(&exception_returned);
1158 ExternalReference pending_handler_context_address(
1159 Isolate::kPendingHandlerContextAddress, isolate());
1160 ExternalReference pending_handler_code_address(
1161 Isolate::kPendingHandlerCodeAddress, isolate());
1162 ExternalReference pending_handler_offset_address(
1163 Isolate::kPendingHandlerOffsetAddress, isolate());
1164 ExternalReference pending_handler_fp_address(
1165 Isolate::kPendingHandlerFPAddress, isolate());
1166 ExternalReference pending_handler_sp_address(
1167 Isolate::kPendingHandlerSPAddress, isolate());
1169 // Ask the runtime for help to determine the handler. This will set v0 to
1170 // contain the current pending exception, don't clobber it.
1171 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1174 FrameScope scope(masm, StackFrame::MANUAL);
1175 __ PrepareCallCFunction(3, 0, a0);
1176 __ mov(a0, zero_reg);
1177 __ mov(a1, zero_reg);
1178 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1179 __ CallCFunction(find_handler, 3);
1182 // Retrieve the handler context, SP and FP.
1183 __ li(cp, Operand(pending_handler_context_address));
1184 __ ld(cp, MemOperand(cp));
1185 __ li(sp, Operand(pending_handler_sp_address));
1186 __ ld(sp, MemOperand(sp));
1187 __ li(fp, Operand(pending_handler_fp_address));
1188 __ ld(fp, MemOperand(fp));
1190 // If the handler is a JS frame, restore the context to the frame. Note that
1191 // the context will be set to (cp == 0) for non-JS frames.
1193 __ Branch(&zero, eq, cp, Operand(zero_reg));
1194 __ sd(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1197 // Compute the handler entry address and jump to it.
1198 __ li(a1, Operand(pending_handler_code_address));
1199 __ ld(a1, MemOperand(a1));
1200 __ li(a2, Operand(pending_handler_offset_address));
1201 __ ld(a2, MemOperand(a2));
1202 __ Daddu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1203 __ Daddu(t9, a1, a2);
1208 void JSEntryStub::Generate(MacroAssembler* masm) {
1209 Label invoke, handler_entry, exit;
1210 Isolate* isolate = masm->isolate();
1212 // TODO(plind): unify the ABI description here.
1214 // a0: entry address
1218 // a4 (a4): on mips64
1221 // 0 arg slots on mips64 (4 args slots on mips)
1222 // args -- in a4/a4 on mips64, on stack on mips
1224 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1226 // Save callee saved registers on the stack.
1227 __ MultiPush(kCalleeSaved | ra.bit());
1229 // Save callee-saved FPU registers.
1230 __ MultiPushFPU(kCalleeSavedFPU);
1231 // Set up the reserved register for 0.0.
1232 __ Move(kDoubleRegZero, 0.0);
1234 // Load argv in s0 register.
1235 if (kMipsAbi == kN64) {
1236 __ mov(s0, a4); // 5th parameter in mips64 a4 (a4) register.
1237 } else { // Abi O32.
1238 // 5th parameter on stack for O32 abi.
1239 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1240 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1241 __ ld(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1244 __ InitializeRootRegister();
1246 // We build an EntryFrame.
1247 __ li(a7, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1248 int marker = type();
1249 __ li(a6, Operand(Smi::FromInt(marker)));
1250 __ li(a5, Operand(Smi::FromInt(marker)));
1251 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate);
1252 __ li(a4, Operand(c_entry_fp));
1253 __ ld(a4, MemOperand(a4));
1254 __ Push(a7, a6, a5, a4);
1255 // Set up frame pointer for the frame to be pushed.
1256 __ daddiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1259 // a0: entry_address
1261 // a2: receiver_pointer
1267 // function slot | entry frame
1269 // bad fp (0xff...f) |
1270 // callee saved registers + ra
1271 // [ O32: 4 args slots]
1274 // If this is the outermost JS call, set js_entry_sp value.
1275 Label non_outermost_js;
1276 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1277 __ li(a5, Operand(ExternalReference(js_entry_sp)));
1278 __ ld(a6, MemOperand(a5));
1279 __ Branch(&non_outermost_js, ne, a6, Operand(zero_reg));
1280 __ sd(fp, MemOperand(a5));
1281 __ li(a4, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1284 __ nop(); // Branch delay slot nop.
1285 __ bind(&non_outermost_js);
1286 __ li(a4, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1290 // Jump to a faked try block that does the invoke, with a faked catch
1291 // block that sets the pending exception.
1293 __ bind(&handler_entry);
1294 handler_offset_ = handler_entry.pos();
1295 // Caught exception: Store result (exception) in the pending exception
1296 // field in the JSEnv and return a failure sentinel. Coming in here the
1297 // fp will be invalid because the PushStackHandler below sets it to 0 to
1298 // signal the existence of the JSEntry frame.
1299 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1301 __ sd(v0, MemOperand(a4)); // We come back from 'invoke'. result is in v0.
1302 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1303 __ b(&exit); // b exposes branch delay slot.
1304 __ nop(); // Branch delay slot nop.
1306 // Invoke: Link this frame into the handler chain.
1308 __ PushStackHandler();
1309 // If an exception not caught by another handler occurs, this handler
1310 // returns control to the code after the bal(&invoke) above, which
1311 // restores all kCalleeSaved registers (including cp and fp) to their
1312 // saved values before returning a failure to C.
1314 // Clear any pending exceptions.
1315 __ LoadRoot(a5, Heap::kTheHoleValueRootIndex);
1316 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1318 __ sd(a5, MemOperand(a4));
1320 // Invoke the function by calling through JS entry trampoline builtin.
1321 // Notice that we cannot store a reference to the trampoline code directly in
1322 // this stub, because runtime stubs are not traversed when doing GC.
1325 // a0: entry_address
1327 // a2: receiver_pointer
1334 // callee saved registers + ra
1335 // [ O32: 4 args slots]
1338 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1339 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1341 __ li(a4, Operand(construct_entry));
1343 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1344 __ li(a4, Operand(entry));
1346 __ ld(t9, MemOperand(a4)); // Deref address.
1347 // Call JSEntryTrampoline.
1348 __ daddiu(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(a5, Operand(ExternalReference(js_entry_sp)));
1363 __ sd(zero_reg, MemOperand(a5));
1364 __ bind(&non_outermost_js_2);
1366 // Restore the top frame descriptors from the stack.
1368 __ li(a4, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1370 __ sd(a5, MemOperand(a4));
1372 // Reset the stack to the callee saved registers.
1373 __ daddiu(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 = a5;
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 a4.
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 a4.
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 = a4; // Prototype of the function.
1431 const Register inline_site = t1;
1432 const Register scratch = a2;
1434 const int32_t kDeltaToLoadBoolResult = 7 * Assembler::kInstrSize;
1436 Label slow, loop, is_instance, is_not_instance, not_js_object;
1438 if (!HasArgsInRegisters()) {
1439 __ ld(object, MemOperand(sp, 1 * kPointerSize));
1440 __ ld(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 a4 safepoint slot.
1478 // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
1479 __ LoadFromSafepointRegisterSlot(scratch, a4);
1480 __ Dsubu(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 __ sd(map, FieldMemOperand(scratch, Cell::kValueOffset));
1486 // |scratch| points at the beginning of the cell. Calculate the
1487 // field containing the map.
1488 __ Daddu(function, scratch, Operand(Cell::kValueOffset - 1));
1489 __ RecordWriteField(scratch, Cell::kValueOffset, t0, function,
1490 kRAHasNotBeenSaved, kDontSaveFPRegs,
1491 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1494 // Register mapping: a3 is object map and a4 is function prototype.
1495 // Get prototype of object into a2.
1496 __ ld(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 __ ld(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
1508 __ ld(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 __ Daddu(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 __ Daddu(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(a4, a5, LoadWithVectorDescriptor::VectorRegister(),
1619 LoadWithVectorDescriptor::SlotRegister()));
1621 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, a4,
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 __ ld(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1644 __ ld(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 __ dsubu(a3, a0, a1);
1657 __ SmiScale(a7, a3, kPointerSizeLog2);
1658 __ Daddu(a3, fp, Operand(a7));
1659 __ Ret(USE_DELAY_SLOT);
1660 __ ld(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 __ ld(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 __ dsubu(a3, a0, a1);
1671 __ SmiScale(a7, a3, kPointerSizeLog2);
1672 __ Daddu(a3, a2, Operand(a7));
1673 __ Ret(USE_DELAY_SLOT);
1674 __ ld(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 __ ld(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1692 __ ld(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 __ ld(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1700 __ sd(a2, MemOperand(sp, 0 * kPointerSize));
1701 __ SmiScale(a7, a2, kPointerSizeLog2);
1702 __ Daddu(a3, a3, Operand(a7));
1703 __ daddiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1704 __ sd(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 // a6 : allocated object (tagged)
1718 // t1 : mapped parameter count (tagged)
1720 __ ld(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 __ ld(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1727 __ ld(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1728 __ Branch(&adaptor_frame,
1731 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1733 // No adaptor, parameter count = argument count.
1735 __ Branch(&try_allocate);
1737 // We have an adaptor frame. Patch the parameters pointer.
1738 __ bind(&adaptor_frame);
1739 __ ld(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1740 __ SmiScale(t2, a2, kPointerSizeLog2);
1741 __ Daddu(a3, a3, Operand(t2));
1742 __ Daddu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1743 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1745 // a1 = parameter count (tagged)
1746 // a2 = argument count (tagged)
1747 // Compute the mapped parameter count = min(a1, a2) in a1.
1749 __ Branch(&skip_min, lt, a1, Operand(a2));
1753 __ bind(&try_allocate);
1755 // Compute the sizes of backing store, parameter map, and arguments object.
1756 // 1. Parameter map, has 2 extra words containing context and backing store.
1757 const int kParameterMapHeaderSize =
1758 FixedArray::kHeaderSize + 2 * kPointerSize;
1759 // If there are no mapped parameters, we do not need the parameter_map.
1760 Label param_map_size;
1761 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1762 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1763 __ mov(t1, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1764 __ SmiScale(t1, a1, kPointerSizeLog2);
1765 __ daddiu(t1, t1, kParameterMapHeaderSize);
1766 __ bind(¶m_map_size);
1768 // 2. Backing store.
1769 __ SmiScale(t2, a2, kPointerSizeLog2);
1770 __ Daddu(t1, t1, Operand(t2));
1771 __ Daddu(t1, t1, Operand(FixedArray::kHeaderSize));
1773 // 3. Arguments object.
1774 __ Daddu(t1, t1, Operand(Heap::kSloppyArgumentsObjectSize));
1776 // Do the allocation of all three objects in one go.
1777 __ Allocate(t1, v0, a3, a4, &runtime, TAG_OBJECT);
1779 // v0 = address of new object(s) (tagged)
1780 // a2 = argument count (smi-tagged)
1781 // Get the arguments boilerplate from the current native context into a4.
1782 const int kNormalOffset =
1783 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1784 const int kAliasedOffset =
1785 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1787 __ ld(a4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1788 __ ld(a4, FieldMemOperand(a4, GlobalObject::kNativeContextOffset));
1789 Label skip2_ne, skip2_eq;
1790 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1791 __ ld(a4, MemOperand(a4, kNormalOffset));
1794 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1795 __ ld(a4, MemOperand(a4, kAliasedOffset));
1798 // v0 = address of new object (tagged)
1799 // a1 = mapped parameter count (tagged)
1800 // a2 = argument count (smi-tagged)
1801 // a4 = address of arguments map (tagged)
1802 __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset));
1803 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1804 __ sd(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1805 __ sd(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1807 // Set up the callee in-object property.
1808 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1809 __ ld(a3, MemOperand(sp, 2 * kPointerSize));
1810 __ AssertNotSmi(a3);
1811 const int kCalleeOffset = JSObject::kHeaderSize +
1812 Heap::kArgumentsCalleeIndex * kPointerSize;
1813 __ sd(a3, FieldMemOperand(v0, kCalleeOffset));
1815 // Use the length (smi tagged) and set that as an in-object property too.
1816 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1817 const int kLengthOffset = JSObject::kHeaderSize +
1818 Heap::kArgumentsLengthIndex * kPointerSize;
1819 __ sd(a2, FieldMemOperand(v0, kLengthOffset));
1821 // Set up the elements pointer in the allocated arguments object.
1822 // If we allocated a parameter map, a4 will point there, otherwise
1823 // it will point to the backing store.
1824 __ Daddu(a4, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1825 __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset));
1827 // v0 = address of new object (tagged)
1828 // a1 = mapped parameter count (tagged)
1829 // a2 = argument count (tagged)
1830 // a4 = address of parameter map or backing store (tagged)
1831 // Initialize parameter map. If there are no mapped arguments, we're done.
1832 Label skip_parameter_map;
1834 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1835 // Move backing store address to a3, because it is
1836 // expected there when filling in the unmapped arguments.
1840 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1842 __ LoadRoot(a6, Heap::kSloppyArgumentsElementsMapRootIndex);
1843 __ sd(a6, FieldMemOperand(a4, FixedArray::kMapOffset));
1844 __ Daddu(a6, a1, Operand(Smi::FromInt(2)));
1845 __ sd(a6, FieldMemOperand(a4, FixedArray::kLengthOffset));
1846 __ sd(cp, FieldMemOperand(a4, FixedArray::kHeaderSize + 0 * kPointerSize));
1847 __ SmiScale(t2, a1, kPointerSizeLog2);
1848 __ Daddu(a6, a4, Operand(t2));
1849 __ Daddu(a6, a6, Operand(kParameterMapHeaderSize));
1850 __ sd(a6, FieldMemOperand(a4, FixedArray::kHeaderSize + 1 * kPointerSize));
1852 // Copy the parameter slots and the holes in the arguments.
1853 // We need to fill in mapped_parameter_count slots. They index the context,
1854 // where parameters are stored in reverse order, at
1855 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1856 // The mapped parameter thus need to get indices
1857 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1858 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1859 // We loop from right to left.
1860 Label parameters_loop, parameters_test;
1862 __ ld(t1, MemOperand(sp, 0 * kPointerSize));
1863 __ Daddu(t1, t1, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1864 __ Dsubu(t1, t1, Operand(a1));
1865 __ LoadRoot(a7, Heap::kTheHoleValueRootIndex);
1866 __ SmiScale(t2, a6, kPointerSizeLog2);
1867 __ Daddu(a3, a4, Operand(t2));
1868 __ Daddu(a3, a3, Operand(kParameterMapHeaderSize));
1870 // a6 = loop variable (tagged)
1871 // a1 = mapping index (tagged)
1872 // a3 = address of backing store (tagged)
1873 // a4 = address of parameter map (tagged)
1874 // a5 = temporary scratch (a.o., for address calculation)
1875 // a7 = the hole value
1876 __ jmp(¶meters_test);
1878 __ bind(¶meters_loop);
1880 __ Dsubu(a6, a6, Operand(Smi::FromInt(1)));
1881 __ SmiScale(a5, a6, kPointerSizeLog2);
1882 __ Daddu(a5, a5, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1883 __ Daddu(t2, a4, a5);
1884 __ sd(t1, MemOperand(t2));
1885 __ Dsubu(a5, a5, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1886 __ Daddu(t2, a3, a5);
1887 __ sd(a7, MemOperand(t2));
1888 __ Daddu(t1, t1, Operand(Smi::FromInt(1)));
1889 __ bind(¶meters_test);
1890 __ Branch(¶meters_loop, ne, a6, Operand(Smi::FromInt(0)));
1892 __ bind(&skip_parameter_map);
1893 // a2 = argument count (tagged)
1894 // a3 = address of backing store (tagged)
1896 // Copy arguments header and remaining slots (if there are any).
1897 __ LoadRoot(a5, Heap::kFixedArrayMapRootIndex);
1898 __ sd(a5, FieldMemOperand(a3, FixedArray::kMapOffset));
1899 __ sd(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1901 Label arguments_loop, arguments_test;
1903 __ ld(a4, MemOperand(sp, 1 * kPointerSize));
1904 __ SmiScale(t2, t1, kPointerSizeLog2);
1905 __ Dsubu(a4, a4, Operand(t2));
1906 __ jmp(&arguments_test);
1908 __ bind(&arguments_loop);
1909 __ Dsubu(a4, a4, Operand(kPointerSize));
1910 __ ld(a6, MemOperand(a4, 0));
1911 __ SmiScale(t2, t1, kPointerSizeLog2);
1912 __ Daddu(a5, a3, Operand(t2));
1913 __ sd(a6, FieldMemOperand(a5, FixedArray::kHeaderSize));
1914 __ Daddu(t1, t1, Operand(Smi::FromInt(1)));
1916 __ bind(&arguments_test);
1917 __ Branch(&arguments_loop, lt, t1, Operand(a2));
1919 // Return and remove the on-stack parameters.
1922 // Do the runtime call to allocate the arguments object.
1923 // a2 = argument count (tagged)
1925 __ sd(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1926 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1930 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1931 // Return address is in ra.
1934 Register receiver = LoadDescriptor::ReceiverRegister();
1935 Register key = LoadDescriptor::NameRegister();
1937 // Check that the key is an array index, that is Uint32.
1938 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1939 __ Branch(&slow, ne, t0, Operand(zero_reg));
1941 // Everything is fine, call runtime.
1942 __ Push(receiver, key); // Receiver, key.
1944 // Perform tail call to the entry.
1945 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1948 PropertyAccessCompiler::TailCallBuiltin(
1949 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1953 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1954 // sp[0] : number of parameters
1955 // sp[4] : receiver displacement
1957 // Check if the calling frame is an arguments adaptor frame.
1958 Label adaptor_frame, try_allocate, runtime;
1959 __ ld(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1960 __ ld(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1961 __ Branch(&adaptor_frame,
1964 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1966 // Get the length from the frame.
1967 __ ld(a1, MemOperand(sp, 0));
1968 __ Branch(&try_allocate);
1970 // Patch the arguments.length and the parameters pointer.
1971 __ bind(&adaptor_frame);
1972 __ ld(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1973 __ sd(a1, MemOperand(sp, 0));
1974 __ SmiScale(at, a1, kPointerSizeLog2);
1976 __ Daddu(a3, a2, Operand(at));
1978 __ Daddu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1979 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1981 // Try the new space allocation. Start out with computing the size
1982 // of the arguments object and the elements array in words.
1983 Label add_arguments_object;
1984 __ bind(&try_allocate);
1985 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1988 __ Daddu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1989 __ bind(&add_arguments_object);
1990 __ Daddu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1992 // Do the allocation of both objects in one go.
1993 __ Allocate(a1, v0, a2, a3, &runtime,
1994 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1996 // Get the arguments boilerplate from the current native context.
1997 __ ld(a4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1998 __ ld(a4, FieldMemOperand(a4, GlobalObject::kNativeContextOffset));
1999 __ ld(a4, MemOperand(a4, Context::SlotOffset(
2000 Context::STRICT_ARGUMENTS_MAP_INDEX)));
2002 __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset));
2003 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
2004 __ sd(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
2005 __ sd(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
2007 // Get the length (smi tagged) and set that as an in-object property too.
2008 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2009 __ ld(a1, MemOperand(sp, 0 * kPointerSize));
2011 __ sd(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
2012 Heap::kArgumentsLengthIndex * kPointerSize));
2015 __ Branch(&done, eq, a1, Operand(zero_reg));
2017 // Get the parameters pointer from the stack.
2018 __ ld(a2, MemOperand(sp, 1 * kPointerSize));
2020 // Set up the elements pointer in the allocated arguments object and
2021 // initialize the header in the elements fixed array.
2022 __ Daddu(a4, v0, Operand(Heap::kStrictArgumentsObjectSize));
2023 __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset));
2024 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
2025 __ sd(a3, FieldMemOperand(a4, FixedArray::kMapOffset));
2026 __ sd(a1, FieldMemOperand(a4, FixedArray::kLengthOffset));
2027 // Untag the length for the loop.
2031 // Copy the fixed array slots.
2033 // Set up a4 to point to the first array slot.
2034 __ Daddu(a4, a4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2036 // Pre-decrement a2 with kPointerSize on each iteration.
2037 // Pre-decrement in order to skip receiver.
2038 __ Daddu(a2, a2, Operand(-kPointerSize));
2039 __ ld(a3, MemOperand(a2));
2040 // Post-increment a4 with kPointerSize on each iteration.
2041 __ sd(a3, MemOperand(a4));
2042 __ Daddu(a4, a4, Operand(kPointerSize));
2043 __ Dsubu(a1, a1, Operand(1));
2044 __ Branch(&loop, ne, a1, Operand(zero_reg));
2046 // Return and remove the on-stack parameters.
2050 // Do the runtime call to allocate the arguments object.
2052 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2056 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2057 // sp[0] : language mode
2058 // sp[4] : index of rest parameter
2059 // sp[8] : number of parameters
2060 // sp[12] : receiver displacement
2061 // Check if the calling frame is an arguments adaptor frame.
2064 __ ld(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2065 __ ld(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
2066 __ Branch(&runtime, ne, a3,
2067 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2069 // Patch the arguments.length and the parameters pointer.
2070 __ ld(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
2071 __ sd(a1, MemOperand(sp, 2 * kPointerSize));
2072 __ SmiScale(at, a1, kPointerSizeLog2);
2074 __ Daddu(a3, a2, Operand(at));
2076 __ Daddu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
2077 __ sd(a3, MemOperand(sp, 3 * kPointerSize));
2079 // Do the runtime call to allocate the arguments object.
2081 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2085 void RegExpExecStub::Generate(MacroAssembler* masm) {
2086 // Just jump directly to runtime if native RegExp is not selected at compile
2087 // time or if regexp entry in generated code is turned off runtime switch or
2089 #ifdef V8_INTERPRETED_REGEXP
2090 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2091 #else // V8_INTERPRETED_REGEXP
2093 // Stack frame on entry.
2094 // sp[0]: last_match_info (expected JSArray)
2095 // sp[4]: previous index
2096 // sp[8]: subject string
2097 // sp[12]: JSRegExp object
2099 const int kLastMatchInfoOffset = 0 * kPointerSize;
2100 const int kPreviousIndexOffset = 1 * kPointerSize;
2101 const int kSubjectOffset = 2 * kPointerSize;
2102 const int kJSRegExpOffset = 3 * kPointerSize;
2105 // Allocation of registers for this function. These are in callee save
2106 // registers and will be preserved by the call to the native RegExp code, as
2107 // this code is called using the normal C calling convention. When calling
2108 // directly from generated code the native RegExp code will not do a GC and
2109 // therefore the content of these registers are safe to use after the call.
2110 // MIPS - using s0..s2, since we are not using CEntry Stub.
2111 Register subject = s0;
2112 Register regexp_data = s1;
2113 Register last_match_info_elements = s2;
2115 // Ensure that a RegExp stack is allocated.
2116 ExternalReference address_of_regexp_stack_memory_address =
2117 ExternalReference::address_of_regexp_stack_memory_address(
2119 ExternalReference address_of_regexp_stack_memory_size =
2120 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2121 __ li(a0, Operand(address_of_regexp_stack_memory_size));
2122 __ ld(a0, MemOperand(a0, 0));
2123 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2125 // Check that the first argument is a JSRegExp object.
2126 __ ld(a0, MemOperand(sp, kJSRegExpOffset));
2127 STATIC_ASSERT(kSmiTag == 0);
2128 __ JumpIfSmi(a0, &runtime);
2129 __ GetObjectType(a0, a1, a1);
2130 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2132 // Check that the RegExp has been compiled (data contains a fixed array).
2133 __ ld(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2134 if (FLAG_debug_code) {
2135 __ SmiTst(regexp_data, a4);
2137 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2140 __ GetObjectType(regexp_data, a0, a0);
2142 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2144 Operand(FIXED_ARRAY_TYPE));
2147 // regexp_data: RegExp data (FixedArray)
2148 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2149 __ ld(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2150 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2152 // regexp_data: RegExp data (FixedArray)
2153 // Check that the number of captures fit in the static offsets vector buffer.
2155 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2156 // Check (number_of_captures + 1) * 2 <= offsets vector size
2157 // Or number_of_captures * 2 <= offsets vector size - 2
2158 // Or number_of_captures <= offsets vector size / 2 - 1
2159 // Multiplying by 2 comes for free since a2 is smi-tagged.
2160 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2161 int temp = Isolate::kJSRegexpStaticOffsetsVectorSize / 2 - 1;
2162 __ Branch(&runtime, hi, a2, Operand(Smi::FromInt(temp)));
2164 // Reset offset for possibly sliced string.
2165 __ mov(t0, zero_reg);
2166 __ ld(subject, MemOperand(sp, kSubjectOffset));
2167 __ JumpIfSmi(subject, &runtime);
2168 __ mov(a3, subject); // Make a copy of the original subject string.
2169 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2170 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2171 // subject: subject string
2172 // a3: subject string
2173 // a0: subject string instance type
2174 // regexp_data: RegExp data (FixedArray)
2175 // Handle subject string according to its encoding and representation:
2176 // (1) Sequential string? If yes, go to (5).
2177 // (2) Anything but sequential or cons? If yes, go to (6).
2178 // (3) Cons string. If the string is flat, replace subject with first string.
2179 // Otherwise bailout.
2180 // (4) Is subject external? If yes, go to (7).
2181 // (5) Sequential string. Load regexp code according to encoding.
2185 // Deferred code at the end of the stub:
2186 // (6) Not a long external string? If yes, go to (8).
2187 // (7) External string. Make it, offset-wise, look like a sequential string.
2189 // (8) Short external string or not a string? If yes, bail out to runtime.
2190 // (9) Sliced string. Replace subject with parent. Go to (4).
2192 Label check_underlying; // (4)
2193 Label seq_string; // (5)
2194 Label not_seq_nor_cons; // (6)
2195 Label external_string; // (7)
2196 Label 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 __ ld(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2218 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2219 __ Branch(&runtime, ne, a0, Operand(a1));
2220 __ ld(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2222 // (4) Is subject external? If yes, go to (7).
2223 __ bind(&check_underlying);
2224 __ ld(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 __ ld(a1, MemOperand(sp, kPreviousIndexOffset));
2241 __ JumpIfNotSmi(a1, &runtime);
2242 __ ld(a3, FieldMemOperand(a3, String::kLengthOffset));
2243 __ Branch(&runtime, ls, a3, Operand(a1));
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 __ ld(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2251 __ dsra(a3, a0, 2); // a3 is 1 for one_byte, 0 for UC16 (used below).
2252 __ ld(a5, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2253 __ Movz(t9, a5, 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 = (kMipsAbi == kN64) ? 8 : 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):
2284 // [sp + 1] - Argument 9
2285 // [sp + 0] - saved ra
2287 // [sp + 5] - Argument 9
2288 // [sp + 4] - Argument 8
2289 // [sp + 3] - Argument 7
2290 // [sp + 2] - Argument 6
2291 // [sp + 1] - Argument 5
2292 // [sp + 0] - saved ra
2294 if (kMipsAbi == kN64) {
2295 // Argument 9: Pass current isolate address.
2296 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2297 __ sd(a0, MemOperand(sp, 1 * kPointerSize));
2299 // Argument 8: Indicate that this is a direct call from JavaScript.
2300 __ li(a7, Operand(1));
2302 // Argument 7: Start (high end) of backtracking stack memory area.
2303 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2304 __ ld(a0, MemOperand(a0, 0));
2305 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2306 __ ld(a2, MemOperand(a2, 0));
2307 __ daddu(a6, a0, a2);
2309 // Argument 6: Set the number of capture registers to zero to force global
2310 // regexps to behave as non-global. This does not affect non-global regexps.
2311 __ mov(a5, zero_reg);
2313 // Argument 5: static offsets vector buffer.
2315 ExternalReference::address_of_static_offsets_vector(isolate())));
2317 DCHECK(kMipsAbi == kO32);
2319 // Argument 9: Pass current isolate address.
2320 // CFunctionArgumentOperand handles MIPS stack argument slots.
2321 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2322 __ sd(a0, MemOperand(sp, 5 * kPointerSize));
2324 // Argument 8: Indicate that this is a direct call from JavaScript.
2325 __ li(a0, Operand(1));
2326 __ sd(a0, MemOperand(sp, 4 * kPointerSize));
2328 // Argument 7: Start (high end) of backtracking stack memory area.
2329 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2330 __ ld(a0, MemOperand(a0, 0));
2331 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2332 __ ld(a2, MemOperand(a2, 0));
2333 __ daddu(a0, a0, a2);
2334 __ sd(a0, MemOperand(sp, 3 * kPointerSize));
2336 // Argument 6: Set the number of capture registers to zero to force global
2337 // regexps to behave as non-global. This does not affect non-global regexps.
2338 __ mov(a0, zero_reg);
2339 __ sd(a0, MemOperand(sp, 2 * kPointerSize));
2341 // Argument 5: static offsets vector buffer.
2343 ExternalReference::address_of_static_offsets_vector(isolate())));
2344 __ sd(a0, MemOperand(sp, 1 * kPointerSize));
2347 // For arguments 4 and 3 get string length, calculate start of string data
2348 // and calculate the shift of the index (0 for one_byte and 1 for two byte).
2349 __ Daddu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2350 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2351 // Load the length from the original subject string from the previous stack
2352 // frame. Therefore we have to use fp, which points exactly to two pointer
2353 // sizes below the previous sp. (Because creating a new stack frame pushes
2354 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2355 __ ld(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2356 // If slice offset is not 0, load the length from the original sliced string.
2357 // Argument 4, a3: End of string data
2358 // Argument 3, a2: Start of string data
2359 // Prepare start and end index of the input.
2360 __ dsllv(t1, t0, a3);
2361 __ daddu(t0, t2, t1);
2362 __ dsllv(t1, a1, a3);
2363 __ daddu(a2, t0, t1);
2365 __ ld(t2, FieldMemOperand(subject, String::kLengthOffset));
2368 __ dsllv(t1, t2, a3);
2369 __ daddu(a3, t0, t1);
2370 // Argument 2 (a1): Previous index.
2373 // Argument 1 (a0): Subject string.
2374 __ mov(a0, subject);
2376 // Locate the code entry and call it.
2377 __ Daddu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2378 DirectCEntryStub stub(isolate());
2379 stub.GenerateCall(masm, t9);
2381 __ LeaveExitFrame(false, no_reg, true);
2384 // subject: subject string (callee saved)
2385 // regexp_data: RegExp data (callee saved)
2386 // last_match_info_elements: Last match info elements (callee saved)
2387 // Check the result.
2389 __ Branch(&success, eq, v0, Operand(1));
2390 // We expect exactly one result since we force the called regexp to behave
2393 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2394 // If not exception it can only be retry. Handle that in the runtime system.
2395 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2396 // Result must now be exception. If there is no pending exception already a
2397 // stack overflow (on the backtrack stack) was detected in RegExp code but
2398 // haven't created the exception yet. Handle that in the runtime system.
2399 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2400 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2401 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2403 __ ld(v0, MemOperand(a2, 0));
2404 __ Branch(&runtime, eq, v0, Operand(a1));
2406 // For exception, throw the exception again.
2407 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2410 // For failure and exception return null.
2411 __ li(v0, Operand(isolate()->factory()->null_value()));
2414 // Process the result from the native regexp code.
2417 __ lw(a1, UntagSmiFieldMemOperand(
2418 regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2419 // Calculate number of capture registers (number_of_captures + 1) * 2.
2420 __ Daddu(a1, a1, Operand(1));
2421 __ dsll(a1, a1, 1); // Multiply by 2.
2423 __ ld(a0, MemOperand(sp, kLastMatchInfoOffset));
2424 __ JumpIfSmi(a0, &runtime);
2425 __ GetObjectType(a0, a2, a2);
2426 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2427 // Check that the JSArray is in fast case.
2428 __ ld(last_match_info_elements,
2429 FieldMemOperand(a0, JSArray::kElementsOffset));
2430 __ ld(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2431 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2432 __ Branch(&runtime, ne, a0, Operand(at));
2433 // Check that the last match info has space for the capture registers and the
2434 // additional information.
2436 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2437 __ Daddu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2439 __ SmiUntag(at, a0);
2440 __ Branch(&runtime, gt, a2, Operand(at));
2442 // a1: number of capture registers
2443 // subject: subject string
2444 // Store the capture count.
2445 __ SmiTag(a2, a1); // To smi.
2446 __ sd(a2, FieldMemOperand(last_match_info_elements,
2447 RegExpImpl::kLastCaptureCountOffset));
2448 // Store last subject and last input.
2450 FieldMemOperand(last_match_info_elements,
2451 RegExpImpl::kLastSubjectOffset));
2452 __ mov(a2, subject);
2453 __ RecordWriteField(last_match_info_elements,
2454 RegExpImpl::kLastSubjectOffset,
2459 __ mov(subject, a2);
2461 FieldMemOperand(last_match_info_elements,
2462 RegExpImpl::kLastInputOffset));
2463 __ RecordWriteField(last_match_info_elements,
2464 RegExpImpl::kLastInputOffset,
2470 // Get the static offsets vector filled by the native regexp code.
2471 ExternalReference address_of_static_offsets_vector =
2472 ExternalReference::address_of_static_offsets_vector(isolate());
2473 __ li(a2, Operand(address_of_static_offsets_vector));
2475 // a1: number of capture registers
2476 // a2: offsets vector
2477 Label next_capture, done;
2478 // Capture register counter starts from number of capture registers and
2479 // counts down until wrapping after zero.
2481 last_match_info_elements,
2482 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2483 __ bind(&next_capture);
2484 __ Dsubu(a1, a1, Operand(1));
2485 __ Branch(&done, lt, a1, Operand(zero_reg));
2486 // Read the value from the static offsets vector buffer.
2487 __ lw(a3, MemOperand(a2, 0));
2488 __ daddiu(a2, a2, kIntSize);
2489 // Store the smi value in the last match info.
2491 __ sd(a3, MemOperand(a0, 0));
2492 __ Branch(&next_capture, USE_DELAY_SLOT);
2493 __ daddiu(a0, a0, kPointerSize); // In branch delay slot.
2497 // Return last match info.
2498 __ ld(v0, MemOperand(sp, kLastMatchInfoOffset));
2501 // Do the runtime call to execute the regexp.
2503 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2505 // Deferred code for string handling.
2506 // (6) Not a long external string? If yes, go to (8).
2507 __ bind(¬_seq_nor_cons);
2509 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2511 // (7) External string. Make it, offset-wise, look like a sequential string.
2512 __ bind(&external_string);
2513 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2514 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2515 if (FLAG_debug_code) {
2516 // Assert that we do not have a cons or slice (indirect strings) here.
2517 // Sequential strings have already been ruled out.
2518 __ And(at, a0, Operand(kIsIndirectStringMask));
2520 kExternalStringExpectedButNotFound,
2525 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2526 // Move the pointer so that offset-wise, it looks like a sequential string.
2527 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2530 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2531 __ jmp(&seq_string); // Go to (5).
2533 // (8) Short external string or not a string? If yes, bail out to runtime.
2534 __ bind(¬_long_external);
2535 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2536 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2537 __ Branch(&runtime, ne, at, Operand(zero_reg));
2539 // (9) Sliced string. Replace subject with parent. Go to (4).
2540 // Load offset into t0 and replace subject string with parent.
2541 __ ld(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2543 __ ld(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2544 __ jmp(&check_underlying); // Go to (4).
2545 #endif // V8_INTERPRETED_REGEXP
2549 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2551 // a0 : number of arguments to the construct function
2552 // a2 : feedback vector
2553 // a3 : slot in feedback vector (Smi)
2554 // a1 : the function to call
2555 // a4 : original constructor (for IsSuperConstructorCall)
2556 FrameScope scope(masm, StackFrame::INTERNAL);
2557 const RegList kSavedRegs = 1 << 4 | // a0
2561 BoolToInt(is_super) << 8; // a4
2564 // Number-of-arguments register must be smi-tagged to call out.
2566 __ MultiPush(kSavedRegs);
2570 __ MultiPop(kSavedRegs);
2575 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2576 // Cache the called function in a feedback vector slot. Cache states
2577 // are uninitialized, monomorphic (indicated by a JSFunction), and
2579 // a0 : number of arguments to the construct function
2580 // a1 : the function to call
2581 // a2 : feedback vector
2582 // a3 : slot in feedback vector (Smi)
2583 // a4 : original constructor (for IsSuperConstructorCall)
2584 Label initialize, done, miss, megamorphic, not_array_function;
2586 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2587 masm->isolate()->heap()->megamorphic_symbol());
2588 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2589 masm->isolate()->heap()->uninitialized_symbol());
2591 // Load the cache state into a5.
2592 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2593 __ Daddu(a5, a2, Operand(a5));
2594 __ ld(a5, FieldMemOperand(a5, FixedArray::kHeaderSize));
2596 // A monomorphic cache hit or an already megamorphic state: invoke the
2597 // function without changing the state.
2598 // We don't know if a5 is a WeakCell or a Symbol, but it's harmless to read at
2599 // this position in a symbol (see static asserts in type-feedback-vector.h).
2600 Label check_allocation_site;
2601 Register feedback_map = a6;
2602 Register weak_value = t0;
2603 __ ld(weak_value, FieldMemOperand(a5, WeakCell::kValueOffset));
2604 __ Branch(&done, eq, a1, Operand(weak_value));
2605 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2606 __ Branch(&done, eq, a5, Operand(at));
2607 __ ld(feedback_map, FieldMemOperand(a5, HeapObject::kMapOffset));
2608 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2609 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2610 feedback_map, Operand(at));
2612 // If the weak cell is cleared, we have a new chance to become monomorphic.
2613 __ JumpIfSmi(weak_value, &initialize);
2614 __ jmp(&megamorphic);
2616 if (!FLAG_pretenuring_call_new) {
2617 __ bind(&check_allocation_site);
2618 // If we came here, we need to see if we are the array function.
2619 // If we didn't have a matching function, and we didn't find the megamorph
2620 // sentinel, then we have in the slot either some other function or an
2622 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2623 __ Branch(&miss, ne, feedback_map, Operand(at));
2625 // Make sure the function is the Array() function
2626 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a5);
2627 __ Branch(&megamorphic, ne, a1, Operand(a5));
2633 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2635 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2636 __ Branch(&initialize, eq, a5, Operand(at));
2637 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2638 // write-barrier is needed.
2639 __ bind(&megamorphic);
2640 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2641 __ Daddu(a5, a2, Operand(a5));
2642 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2643 __ sd(at, FieldMemOperand(a5, FixedArray::kHeaderSize));
2646 // An uninitialized cache is patched with the function.
2647 __ bind(&initialize);
2648 if (!FLAG_pretenuring_call_new) {
2649 // Make sure the function is the Array() function.
2650 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a5);
2651 __ Branch(¬_array_function, ne, a1, Operand(a5));
2653 // The target function is the Array constructor,
2654 // Create an AllocationSite if we don't already have it, store it in the
2656 CreateAllocationSiteStub create_stub(masm->isolate());
2657 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2660 __ bind(¬_array_function);
2663 CreateWeakCellStub create_stub(masm->isolate());
2664 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2669 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2670 __ ld(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2672 // Do not transform the receiver for strict mode functions.
2673 int32_t strict_mode_function_mask =
2674 1 << SharedFunctionInfo::kStrictModeBitWithinByte ;
2675 // Do not transform the receiver for native (Compilerhints already in a3).
2676 int32_t native_mask = 1 << SharedFunctionInfo::kNativeBitWithinByte;
2678 __ lbu(a4, FieldMemOperand(a3, SharedFunctionInfo::kStrictModeByteOffset));
2679 __ And(at, a4, Operand(strict_mode_function_mask));
2680 __ Branch(cont, ne, at, Operand(zero_reg));
2681 __ lbu(a4, FieldMemOperand(a3, SharedFunctionInfo::kNativeByteOffset));
2682 __ And(at, a4, Operand(native_mask));
2683 __ Branch(cont, ne, at, Operand(zero_reg));
2687 static void EmitSlowCase(MacroAssembler* masm,
2689 Label* non_function) {
2690 // Check for function proxy.
2691 __ Branch(non_function, ne, a4, Operand(JS_FUNCTION_PROXY_TYPE));
2692 __ push(a1); // put proxy as additional argument
2693 __ li(a0, Operand(argc + 1, RelocInfo::NONE32));
2694 __ mov(a2, zero_reg);
2695 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY);
2697 Handle<Code> adaptor =
2698 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2699 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2702 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2703 // of the original receiver from the call site).
2704 __ bind(non_function);
2705 __ sd(a1, MemOperand(sp, argc * kPointerSize));
2706 __ li(a0, Operand(argc)); // Set up the number of arguments.
2707 __ mov(a2, zero_reg);
2708 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION);
2709 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2710 RelocInfo::CODE_TARGET);
2714 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2715 // Wrap the receiver and patch it back onto the stack.
2716 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2718 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2721 __ Branch(USE_DELAY_SLOT, cont);
2722 __ sd(v0, MemOperand(sp, argc * kPointerSize));
2726 static void CallFunctionNoFeedback(MacroAssembler* masm,
2727 int argc, bool needs_checks,
2728 bool call_as_method) {
2729 // a1 : the function to call
2730 Label slow, non_function, wrap, cont;
2733 // Check that the function is really a JavaScript function.
2734 // a1: pushed function (to be verified)
2735 __ JumpIfSmi(a1, &non_function);
2737 // Goto slow case if we do not have a function.
2738 __ GetObjectType(a1, a4, a4);
2739 __ Branch(&slow, ne, a4, Operand(JS_FUNCTION_TYPE));
2742 // Fast-case: Invoke the function now.
2743 // a1: pushed function
2744 ParameterCount actual(argc);
2746 if (call_as_method) {
2748 EmitContinueIfStrictOrNative(masm, &cont);
2751 // Compute the receiver in sloppy mode.
2752 __ ld(a3, MemOperand(sp, argc * kPointerSize));
2755 __ JumpIfSmi(a3, &wrap);
2756 __ GetObjectType(a3, a4, a4);
2757 __ Branch(&wrap, lt, a4, Operand(FIRST_SPEC_OBJECT_TYPE));
2764 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2767 // Slow-case: Non-function called.
2769 EmitSlowCase(masm, argc, &non_function);
2772 if (call_as_method) {
2774 // Wrap the receiver and patch it back onto the stack.
2775 EmitWrapCase(masm, argc, &cont);
2780 void CallFunctionStub::Generate(MacroAssembler* masm) {
2781 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2785 void CallConstructStub::Generate(MacroAssembler* masm) {
2786 // a0 : number of arguments
2787 // a1 : the function to call
2788 // a2 : feedback vector
2789 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2790 // a4 : original constructor (for IsSuperConstructorCall)
2791 Label slow, non_function_call;
2792 // Check that the function is not a smi.
2793 __ JumpIfSmi(a1, &non_function_call);
2794 // Check that the function is a JSFunction.
2795 __ GetObjectType(a1, a5, a5);
2796 __ Branch(&slow, ne, a5, Operand(JS_FUNCTION_TYPE));
2798 if (RecordCallTarget()) {
2799 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2801 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2802 __ Daddu(a5, a2, at);
2803 if (FLAG_pretenuring_call_new) {
2804 // Put the AllocationSite from the feedback vector into a2.
2805 // By adding kPointerSize we encode that we know the AllocationSite
2806 // entry is at the feedback vector slot given by a3 + 1.
2807 __ ld(a2, FieldMemOperand(a5, FixedArray::kHeaderSize + kPointerSize));
2809 Label feedback_register_initialized;
2810 // Put the AllocationSite from the feedback vector into a2, or undefined.
2811 __ ld(a2, FieldMemOperand(a5, FixedArray::kHeaderSize));
2812 __ ld(a5, FieldMemOperand(a2, AllocationSite::kMapOffset));
2813 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2814 __ Branch(&feedback_register_initialized, eq, a5, Operand(at));
2815 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2816 __ bind(&feedback_register_initialized);
2819 __ AssertUndefinedOrAllocationSite(a2, a5);
2822 // Pass function as original constructor.
2823 if (IsSuperConstructorCall()) {
2829 // Jump to the function-specific construct stub.
2830 Register jmp_reg = a4;
2831 __ ld(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2832 __ ld(jmp_reg, FieldMemOperand(jmp_reg,
2833 SharedFunctionInfo::kConstructStubOffset));
2834 __ Daddu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2837 // a0: number of arguments
2838 // a1: called object
2842 __ Branch(&non_function_call, ne, a5, Operand(JS_FUNCTION_PROXY_TYPE));
2843 __ GetBuiltinFunction(a1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
2846 __ bind(&non_function_call);
2847 __ GetBuiltinFunction(a1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
2849 // Set expected number of arguments to zero (not changing r0).
2850 __ li(a2, Operand(0, RelocInfo::NONE32));
2851 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2852 RelocInfo::CODE_TARGET);
2856 // StringCharCodeAtGenerator.
2857 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2858 DCHECK(!a4.is(index_));
2859 DCHECK(!a4.is(result_));
2860 DCHECK(!a4.is(object_));
2862 // If the receiver is a smi trigger the non-string case.
2863 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2864 __ JumpIfSmi(object_, receiver_not_string_);
2866 // Fetch the instance type of the receiver into result register.
2867 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2868 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2869 // If the receiver is not a string trigger the non-string case.
2870 __ And(a4, result_, Operand(kIsNotStringMask));
2871 __ Branch(receiver_not_string_, ne, a4, Operand(zero_reg));
2874 // If the index is non-smi trigger the non-smi case.
2875 __ JumpIfNotSmi(index_, &index_not_smi_);
2877 __ bind(&got_smi_index_);
2879 // Check for index out of range.
2880 __ ld(a4, FieldMemOperand(object_, String::kLengthOffset));
2881 __ Branch(index_out_of_range_, ls, a4, Operand(index_));
2883 __ SmiUntag(index_);
2885 StringCharLoadGenerator::Generate(masm,
2896 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2897 __ ld(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2898 __ ld(vector, FieldMemOperand(vector,
2899 JSFunction::kSharedFunctionInfoOffset));
2900 __ ld(vector, FieldMemOperand(vector,
2901 SharedFunctionInfo::kFeedbackVectorOffset));
2905 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2911 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2912 __ Branch(&miss, ne, a1, Operand(at));
2914 __ li(a0, Operand(arg_count()));
2915 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2916 __ Daddu(at, a2, Operand(at));
2917 __ ld(a4, FieldMemOperand(at, FixedArray::kHeaderSize));
2919 // Verify that a4 contains an AllocationSite
2920 __ ld(a5, FieldMemOperand(a4, HeapObject::kMapOffset));
2921 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2922 __ Branch(&miss, ne, a5, Operand(at));
2924 // Increment the call count for monomorphic function calls.
2925 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2926 __ Daddu(a3, a2, Operand(t0));
2927 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2928 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2929 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2933 ArrayConstructorStub stub(masm->isolate(), arg_count());
2934 __ TailCallStub(&stub);
2939 // The slow case, we need this no matter what to complete a call after a miss.
2940 CallFunctionNoFeedback(masm,
2946 __ stop("Unexpected code address");
2950 void CallICStub::Generate(MacroAssembler* masm) {
2952 // a3 - slot id (Smi)
2954 const int with_types_offset =
2955 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2956 const int generic_offset =
2957 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2958 Label extra_checks_or_miss, slow_start;
2959 Label slow, non_function, wrap, cont;
2960 Label have_js_function;
2961 int argc = arg_count();
2962 ParameterCount actual(argc);
2964 // The checks. First, does r1 match the recorded monomorphic target?
2965 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
2966 __ Daddu(a4, a2, Operand(a4));
2967 __ ld(a4, FieldMemOperand(a4, FixedArray::kHeaderSize));
2969 // We don't know that we have a weak cell. We might have a private symbol
2970 // or an AllocationSite, but the memory is safe to examine.
2971 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2973 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2974 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2975 // computed, meaning that it can't appear to be a pointer. If the low bit is
2976 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2978 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2979 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2980 WeakCell::kValueOffset &&
2981 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2983 __ ld(a5, FieldMemOperand(a4, WeakCell::kValueOffset));
2984 __ Branch(&extra_checks_or_miss, ne, a1, Operand(a5));
2986 // The compare above could have been a SMI/SMI comparison. Guard against this
2987 // convincing us that we have a monomorphic JSFunction.
2988 __ JumpIfSmi(a1, &extra_checks_or_miss);
2990 // Increment the call count for monomorphic function calls.
2991 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2992 __ Daddu(a3, a2, Operand(t0));
2993 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2994 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2995 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2997 __ bind(&have_js_function);
2998 if (CallAsMethod()) {
2999 EmitContinueIfStrictOrNative(masm, &cont);
3000 // Compute the receiver in sloppy mode.
3001 __ ld(a3, MemOperand(sp, argc * kPointerSize));
3003 __ JumpIfSmi(a3, &wrap);
3004 __ GetObjectType(a3, a4, a4);
3005 __ Branch(&wrap, lt, a4, Operand(FIRST_SPEC_OBJECT_TYPE));
3010 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
3013 EmitSlowCase(masm, argc, &non_function);
3015 if (CallAsMethod()) {
3017 EmitWrapCase(masm, argc, &cont);
3020 __ bind(&extra_checks_or_miss);
3021 Label uninitialized, miss;
3023 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
3024 __ Branch(&slow_start, eq, a4, Operand(at));
3026 // The following cases attempt to handle MISS cases without going to the
3028 if (FLAG_trace_ic) {
3032 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
3033 __ Branch(&uninitialized, eq, a4, Operand(at));
3035 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3036 // to handle it here. More complex cases are dealt with in the runtime.
3037 __ AssertNotSmi(a4);
3038 __ GetObjectType(a4, a5, a5);
3039 __ Branch(&miss, ne, a5, Operand(JS_FUNCTION_TYPE));
3040 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
3041 __ Daddu(a4, a2, Operand(a4));
3042 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
3043 __ sd(at, FieldMemOperand(a4, FixedArray::kHeaderSize));
3044 // We have to update statistics for runtime profiling.
3045 __ ld(a4, FieldMemOperand(a2, with_types_offset));
3046 __ Dsubu(a4, a4, Operand(Smi::FromInt(1)));
3047 __ sd(a4, FieldMemOperand(a2, with_types_offset));
3048 __ ld(a4, FieldMemOperand(a2, generic_offset));
3049 __ Daddu(a4, a4, Operand(Smi::FromInt(1)));
3050 __ Branch(USE_DELAY_SLOT, &slow_start);
3051 __ sd(a4, FieldMemOperand(a2, generic_offset)); // In delay slot.
3053 __ bind(&uninitialized);
3055 // We are going monomorphic, provided we actually have a JSFunction.
3056 __ JumpIfSmi(a1, &miss);
3058 // Goto miss case if we do not have a function.
3059 __ GetObjectType(a1, a4, a4);
3060 __ Branch(&miss, ne, a4, Operand(JS_FUNCTION_TYPE));
3062 // Make sure the function is not the Array() function, which requires special
3063 // behavior on MISS.
3064 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a4);
3065 __ Branch(&miss, eq, a1, Operand(a4));
3068 __ ld(a4, FieldMemOperand(a2, with_types_offset));
3069 __ Daddu(a4, a4, Operand(Smi::FromInt(1)));
3070 __ sd(a4, FieldMemOperand(a2, with_types_offset));
3072 // Initialize the call counter.
3073 __ dsrl(at, a3, 32 - kPointerSizeLog2);
3074 __ Daddu(at, a2, Operand(at));
3075 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3076 __ sd(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
3078 // Store the function. Use a stub since we need a frame for allocation.
3083 FrameScope scope(masm, StackFrame::INTERNAL);
3084 CreateWeakCellStub create_stub(masm->isolate());
3086 __ CallStub(&create_stub);
3090 __ Branch(&have_js_function);
3092 // We are here because tracing is on or we encountered a MISS case we can't
3098 __ bind(&slow_start);
3099 // Check that the function is really a JavaScript function.
3100 // r1: pushed function (to be verified)
3101 __ JumpIfSmi(a1, &non_function);
3103 // Goto slow case if we do not have a function.
3104 __ GetObjectType(a1, a4, a4);
3105 __ Branch(&slow, ne, a4, Operand(JS_FUNCTION_TYPE));
3106 __ Branch(&have_js_function);
3110 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3111 FrameScope scope(masm, StackFrame::INTERNAL);
3113 // Push the receiver and the function and feedback info.
3114 __ Push(a1, a2, a3);
3117 Runtime::FunctionId id = GetICState() == DEFAULT
3118 ? Runtime::kCallIC_Miss //
3119 : Runtime::kCallIC_Customization_Miss;
3120 __ CallRuntime(id, 3);
3122 // Move result to a1 and exit the internal frame.
3127 void StringCharCodeAtGenerator::GenerateSlow(
3128 MacroAssembler* masm, EmbedMode embed_mode,
3129 const RuntimeCallHelper& call_helper) {
3130 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3132 // Index is not a smi.
3133 __ bind(&index_not_smi_);
3134 // If index is a heap number, try converting it to an integer.
3137 Heap::kHeapNumberMapRootIndex,
3140 call_helper.BeforeCall(masm);
3141 // Consumed by runtime conversion function:
3142 if (embed_mode == PART_OF_IC_HANDLER) {
3143 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3144 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3146 __ Push(object_, index_);
3148 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3149 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3151 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3152 // NumberToSmi discards numbers that are not exact integers.
3153 __ CallRuntime(Runtime::kNumberToSmi, 1);
3156 // Save the conversion result before the pop instructions below
3157 // have a chance to overwrite it.
3159 __ Move(index_, v0);
3160 if (embed_mode == PART_OF_IC_HANDLER) {
3161 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3162 LoadWithVectorDescriptor::SlotRegister(), object_);
3166 // Reload the instance type.
3167 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3168 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3169 call_helper.AfterCall(masm);
3170 // If index is still not a smi, it must be out of range.
3171 __ JumpIfNotSmi(index_, index_out_of_range_);
3172 // Otherwise, return to the fast path.
3173 __ Branch(&got_smi_index_);
3175 // Call runtime. We get here when the receiver is a string and the
3176 // index is a number, but the code of getting the actual character
3177 // is too complex (e.g., when the string needs to be flattened).
3178 __ bind(&call_runtime_);
3179 call_helper.BeforeCall(masm);
3181 __ Push(object_, index_);
3182 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3184 __ Move(result_, v0);
3186 call_helper.AfterCall(masm);
3189 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3193 // -------------------------------------------------------------------------
3194 // StringCharFromCodeGenerator
3196 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3197 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3198 __ JumpIfNotSmi(code_, &slow_case_);
3199 __ Branch(&slow_case_, hi, code_,
3200 Operand(Smi::FromInt(String::kMaxOneByteCharCode)));
3202 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3203 // At this point code register contains smi tagged one_byte char code.
3204 __ SmiScale(at, code_, kPointerSizeLog2);
3205 __ Daddu(result_, result_, at);
3206 __ ld(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3207 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3208 __ Branch(&slow_case_, eq, result_, Operand(at));
3213 void StringCharFromCodeGenerator::GenerateSlow(
3214 MacroAssembler* masm,
3215 const RuntimeCallHelper& call_helper) {
3216 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3218 __ bind(&slow_case_);
3219 call_helper.BeforeCall(masm);
3221 __ CallRuntime(Runtime::kCharFromCode, 1);
3222 __ Move(result_, v0);
3224 call_helper.AfterCall(masm);
3227 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3231 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3234 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3239 String::Encoding encoding) {
3240 if (FLAG_debug_code) {
3241 // Check that destination is word aligned.
3242 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3244 kDestinationOfCopyNotAligned,
3249 // Assumes word reads and writes are little endian.
3250 // Nothing to do for zero characters.
3253 if (encoding == String::TWO_BYTE_ENCODING) {
3254 __ Daddu(count, count, count);
3257 Register limit = count; // Read until dest equals this.
3258 __ Daddu(limit, dest, Operand(count));
3260 Label loop_entry, loop;
3261 // Copy bytes from src to dest until dest hits limit.
3262 __ Branch(&loop_entry);
3264 __ lbu(scratch, MemOperand(src));
3265 __ daddiu(src, src, 1);
3266 __ sb(scratch, MemOperand(dest));
3267 __ daddiu(dest, dest, 1);
3268 __ bind(&loop_entry);
3269 __ Branch(&loop, lt, dest, Operand(limit));
3275 void SubStringStub::Generate(MacroAssembler* masm) {
3277 // Stack frame on entry.
3278 // ra: return address
3283 // This stub is called from the native-call %_SubString(...), so
3284 // nothing can be assumed about the arguments. It is tested that:
3285 // "string" is a sequential string,
3286 // both "from" and "to" are smis, and
3287 // 0 <= from <= to <= string.length.
3288 // If any of these assumptions fail, we call the runtime system.
3290 const int kToOffset = 0 * kPointerSize;
3291 const int kFromOffset = 1 * kPointerSize;
3292 const int kStringOffset = 2 * kPointerSize;
3294 __ ld(a2, MemOperand(sp, kToOffset));
3295 __ ld(a3, MemOperand(sp, kFromOffset));
3297 STATIC_ASSERT(kSmiTag == 0);
3299 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3300 // safe in this case.
3301 __ JumpIfNotSmi(a2, &runtime);
3302 __ JumpIfNotSmi(a3, &runtime);
3303 // Both a2 and a3 are untagged integers.
3305 __ SmiUntag(a2, a2);
3306 __ SmiUntag(a3, a3);
3307 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3309 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3310 __ Dsubu(a2, a2, a3);
3312 // Make sure first argument is a string.
3313 __ ld(v0, MemOperand(sp, kStringOffset));
3314 __ JumpIfSmi(v0, &runtime);
3315 __ ld(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3316 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3317 __ And(a4, a1, Operand(kIsNotStringMask));
3319 __ Branch(&runtime, ne, a4, Operand(zero_reg));
3322 __ Branch(&single_char, eq, a2, Operand(1));
3324 // Short-cut for the case of trivial substring.
3326 // v0: original string
3327 // a2: result string length
3328 __ ld(a4, FieldMemOperand(v0, String::kLengthOffset));
3330 // Return original string.
3331 __ Branch(&return_v0, eq, a2, Operand(a4));
3332 // Longer than original string's length or negative: unsafe arguments.
3333 __ Branch(&runtime, hi, a2, Operand(a4));
3334 // Shorter than original string's length: an actual substring.
3336 // Deal with different string types: update the index if necessary
3337 // and put the underlying string into a5.
3338 // v0: original string
3339 // a1: instance type
3341 // a3: from index (untagged)
3342 Label underlying_unpacked, sliced_string, seq_or_external_string;
3343 // If the string is not indirect, it can only be sequential or external.
3344 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3345 STATIC_ASSERT(kIsIndirectStringMask != 0);
3346 __ And(a4, a1, Operand(kIsIndirectStringMask));
3347 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, a4, Operand(zero_reg));
3348 // a4 is used as a scratch register and can be overwritten in either case.
3349 __ And(a4, a1, Operand(kSlicedNotConsMask));
3350 __ Branch(&sliced_string, ne, a4, Operand(zero_reg));
3351 // Cons string. Check whether it is flat, then fetch first part.
3352 __ ld(a5, FieldMemOperand(v0, ConsString::kSecondOffset));
3353 __ LoadRoot(a4, Heap::kempty_stringRootIndex);
3354 __ Branch(&runtime, ne, a5, Operand(a4));
3355 __ ld(a5, FieldMemOperand(v0, ConsString::kFirstOffset));
3356 // Update instance type.
3357 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
3358 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3359 __ jmp(&underlying_unpacked);
3361 __ bind(&sliced_string);
3362 // Sliced string. Fetch parent and correct start index by offset.
3363 __ ld(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
3364 __ ld(a4, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3365 __ SmiUntag(a4); // Add offset to index.
3366 __ Daddu(a3, a3, a4);
3367 // Update instance type.
3368 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
3369 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3370 __ jmp(&underlying_unpacked);
3372 __ bind(&seq_or_external_string);
3373 // Sequential or external string. Just move string to the expected register.
3376 __ bind(&underlying_unpacked);
3378 if (FLAG_string_slices) {
3380 // a5: underlying subject string
3381 // a1: instance type of underlying subject string
3383 // a3: adjusted start index (untagged)
3384 // Short slice. Copy instead of slicing.
3385 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3386 // Allocate new sliced string. At this point we do not reload the instance
3387 // type including the string encoding because we simply rely on the info
3388 // provided by the original string. It does not matter if the original
3389 // string's encoding is wrong because we always have to recheck encoding of
3390 // the newly created string's parent anyways due to externalized strings.
3391 Label two_byte_slice, set_slice_header;
3392 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3393 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3394 __ And(a4, a1, Operand(kStringEncodingMask));
3395 __ Branch(&two_byte_slice, eq, a4, Operand(zero_reg));
3396 __ AllocateOneByteSlicedString(v0, a2, a6, a7, &runtime);
3397 __ jmp(&set_slice_header);
3398 __ bind(&two_byte_slice);
3399 __ AllocateTwoByteSlicedString(v0, a2, a6, a7, &runtime);
3400 __ bind(&set_slice_header);
3402 __ sd(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
3403 __ sd(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3406 __ bind(©_routine);
3409 // a5: underlying subject string
3410 // a1: instance type of underlying subject string
3412 // a3: adjusted start index (untagged)
3413 Label two_byte_sequential, sequential_string, allocate_result;
3414 STATIC_ASSERT(kExternalStringTag != 0);
3415 STATIC_ASSERT(kSeqStringTag == 0);
3416 __ And(a4, a1, Operand(kExternalStringTag));
3417 __ Branch(&sequential_string, eq, a4, Operand(zero_reg));
3419 // Handle external string.
3420 // Rule out short external strings.
3421 STATIC_ASSERT(kShortExternalStringTag != 0);
3422 __ And(a4, a1, Operand(kShortExternalStringTag));
3423 __ Branch(&runtime, ne, a4, Operand(zero_reg));
3424 __ ld(a5, FieldMemOperand(a5, ExternalString::kResourceDataOffset));
3425 // a5 already points to the first character of underlying string.
3426 __ jmp(&allocate_result);
3428 __ bind(&sequential_string);
3429 // Locate first character of underlying subject string.
3430 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3431 __ Daddu(a5, a5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3433 __ bind(&allocate_result);
3434 // Sequential acii string. Allocate the result.
3435 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3436 __ And(a4, a1, Operand(kStringEncodingMask));
3437 __ Branch(&two_byte_sequential, eq, a4, Operand(zero_reg));
3439 // Allocate and copy the resulting one_byte string.
3440 __ AllocateOneByteString(v0, a2, a4, a6, a7, &runtime);
3442 // Locate first character of substring to copy.
3443 __ Daddu(a5, a5, a3);
3445 // Locate first character of result.
3446 __ Daddu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3448 // v0: result string
3449 // a1: first character of result string
3450 // a2: result string length
3451 // a5: first character of substring to copy
3452 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3453 StringHelper::GenerateCopyCharacters(
3454 masm, a1, a5, a2, a3, String::ONE_BYTE_ENCODING);
3457 // Allocate and copy the resulting two-byte string.
3458 __ bind(&two_byte_sequential);
3459 __ AllocateTwoByteString(v0, a2, a4, a6, a7, &runtime);
3461 // Locate first character of substring to copy.
3462 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3464 __ Daddu(a5, a5, a4);
3465 // Locate first character of result.
3466 __ Daddu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3468 // v0: result string.
3469 // a1: first character of result.
3470 // a2: result length.
3471 // a5: first character of substring to copy.
3472 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3473 StringHelper::GenerateCopyCharacters(
3474 masm, a1, a5, a2, a3, String::TWO_BYTE_ENCODING);
3476 __ bind(&return_v0);
3477 Counters* counters = isolate()->counters();
3478 __ IncrementCounter(counters->sub_string_native(), 1, a3, a4);
3481 // Just jump to runtime to create the sub string.
3483 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3485 __ bind(&single_char);
3486 // v0: original string
3487 // a1: instance type
3489 // a3: from index (untagged)
3491 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3492 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3493 generator.GenerateFast(masm);
3495 generator.SkipSlow(masm, &runtime);
3499 void ToNumberStub::Generate(MacroAssembler* masm) {
3500 // The ToNumber stub takes one argument in a0.
3502 __ JumpIfNotSmi(a0, ¬_smi);
3503 __ Ret(USE_DELAY_SLOT);
3507 Label not_heap_number;
3508 __ ld(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3509 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3511 // a1: instance type.
3512 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3513 __ Ret(USE_DELAY_SLOT);
3515 __ bind(¬_heap_number);
3517 Label not_string, slow_string;
3518 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3519 // Check if string has a cached array index.
3520 __ ld(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3521 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3522 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3523 __ IndexFromHash(a2, a0);
3524 __ Ret(USE_DELAY_SLOT);
3526 __ bind(&slow_string);
3527 __ push(a0); // Push argument.
3528 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3529 __ bind(¬_string);
3532 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3533 __ Ret(USE_DELAY_SLOT);
3534 __ ld(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3535 __ bind(¬_oddball);
3537 __ push(a0); // Push argument.
3538 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3542 void StringHelper::GenerateFlatOneByteStringEquals(
3543 MacroAssembler* masm, Register left, Register right, Register scratch1,
3544 Register scratch2, Register scratch3) {
3545 Register length = scratch1;
3548 Label strings_not_equal, check_zero_length;
3549 __ ld(length, FieldMemOperand(left, String::kLengthOffset));
3550 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
3551 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3552 __ bind(&strings_not_equal);
3553 // Can not put li in delayslot, it has multi instructions.
3554 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3557 // Check if the length is zero.
3558 Label compare_chars;
3559 __ bind(&check_zero_length);
3560 STATIC_ASSERT(kSmiTag == 0);
3561 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3562 DCHECK(is_int16((intptr_t)Smi::FromInt(EQUAL)));
3563 __ Ret(USE_DELAY_SLOT);
3564 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3566 // Compare characters.
3567 __ bind(&compare_chars);
3569 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3570 v0, &strings_not_equal);
3572 // Characters are equal.
3573 __ Ret(USE_DELAY_SLOT);
3574 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3578 void StringHelper::GenerateCompareFlatOneByteStrings(
3579 MacroAssembler* masm, Register left, Register right, Register scratch1,
3580 Register scratch2, Register scratch3, Register scratch4) {
3581 Label result_not_equal, compare_lengths;
3582 // Find minimum length and length difference.
3583 __ ld(scratch1, FieldMemOperand(left, String::kLengthOffset));
3584 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
3585 __ Dsubu(scratch3, scratch1, Operand(scratch2));
3586 Register length_delta = scratch3;
3587 __ slt(scratch4, scratch2, scratch1);
3588 __ Movn(scratch1, scratch2, scratch4);
3589 Register min_length = scratch1;
3590 STATIC_ASSERT(kSmiTag == 0);
3591 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3594 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3595 scratch4, v0, &result_not_equal);
3597 // Compare lengths - strings up to min-length are equal.
3598 __ bind(&compare_lengths);
3599 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3600 // Use length_delta as result if it's zero.
3601 __ mov(scratch2, length_delta);
3602 __ mov(scratch4, zero_reg);
3603 __ mov(v0, zero_reg);
3605 __ bind(&result_not_equal);
3606 // Conditionally update the result based either on length_delta or
3607 // the last comparion performed in the loop above.
3609 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3610 __ li(v0, Operand(Smi::FromInt(GREATER)));
3611 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3612 __ li(v0, Operand(Smi::FromInt(LESS)));
3618 void StringHelper::GenerateOneByteCharsCompareLoop(
3619 MacroAssembler* masm, Register left, Register right, Register length,
3620 Register scratch1, Register scratch2, Register scratch3,
3621 Label* chars_not_equal) {
3622 // Change index to run from -length to -1 by adding length to string
3623 // start. This means that loop ends when index reaches zero, which
3624 // doesn't need an additional compare.
3625 __ SmiUntag(length);
3626 __ Daddu(scratch1, length,
3627 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3628 __ Daddu(left, left, Operand(scratch1));
3629 __ Daddu(right, right, Operand(scratch1));
3630 __ Dsubu(length, zero_reg, length);
3631 Register index = length; // index = -length;
3637 __ Daddu(scratch3, left, index);
3638 __ lbu(scratch1, MemOperand(scratch3));
3639 __ Daddu(scratch3, right, index);
3640 __ lbu(scratch2, MemOperand(scratch3));
3641 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3642 __ Daddu(index, index, 1);
3643 __ Branch(&loop, ne, index, Operand(zero_reg));
3647 void StringCompareStub::Generate(MacroAssembler* masm) {
3650 Counters* counters = isolate()->counters();
3652 // Stack frame on entry.
3653 // sp[0]: right string
3654 // sp[4]: left string
3655 __ ld(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3656 __ ld(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3659 __ Branch(¬_same, ne, a0, Operand(a1));
3660 STATIC_ASSERT(EQUAL == 0);
3661 STATIC_ASSERT(kSmiTag == 0);
3662 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3663 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3668 // Check that both objects are sequential one_byte strings.
3669 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3671 // Compare flat one_byte strings natively. Remove arguments from stack first.
3672 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3673 __ Daddu(sp, sp, Operand(2 * kPointerSize));
3674 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, a4, a5);
3677 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3681 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3682 // ----------- S t a t e -------------
3685 // -- ra : return address
3686 // -----------------------------------
3688 // Load a2 with the allocation site. We stick an undefined dummy value here
3689 // and replace it with the real allocation site later when we instantiate this
3690 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3691 __ li(a2, handle(isolate()->heap()->undefined_value()));
3693 // Make sure that we actually patched the allocation site.
3694 if (FLAG_debug_code) {
3695 __ And(at, a2, Operand(kSmiTagMask));
3696 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3697 __ ld(a4, FieldMemOperand(a2, HeapObject::kMapOffset));
3698 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3699 __ Assert(eq, kExpectedAllocationSite, a4, Operand(at));
3702 // Tail call into the stub that handles binary operations with allocation
3704 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3705 __ TailCallStub(&stub);
3709 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3710 DCHECK(state() == CompareICState::SMI);
3713 __ JumpIfNotSmi(a2, &miss);
3715 if (GetCondition() == eq) {
3716 // For equality we do not care about the sign of the result.
3717 __ Ret(USE_DELAY_SLOT);
3718 __ Dsubu(v0, a0, a1);
3720 // Untag before subtracting to avoid handling overflow.
3723 __ Ret(USE_DELAY_SLOT);
3724 __ Dsubu(v0, a1, a0);
3732 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3733 DCHECK(state() == CompareICState::NUMBER);
3736 Label unordered, maybe_undefined1, maybe_undefined2;
3739 if (left() == CompareICState::SMI) {
3740 __ JumpIfNotSmi(a1, &miss);
3742 if (right() == CompareICState::SMI) {
3743 __ JumpIfNotSmi(a0, &miss);
3746 // Inlining the double comparison and falling back to the general compare
3747 // stub if NaN is involved.
3748 // Load left and right operand.
3749 Label done, left, left_smi, right_smi;
3750 __ JumpIfSmi(a0, &right_smi);
3751 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3753 __ Dsubu(a2, a0, Operand(kHeapObjectTag));
3754 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3756 __ bind(&right_smi);
3757 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3758 FPURegister single_scratch = f6;
3759 __ mtc1(a2, single_scratch);
3760 __ cvt_d_w(f2, single_scratch);
3763 __ JumpIfSmi(a1, &left_smi);
3764 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3766 __ Dsubu(a2, a1, Operand(kHeapObjectTag));
3767 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3770 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3771 single_scratch = f8;
3772 __ mtc1(a2, single_scratch);
3773 __ cvt_d_w(f0, single_scratch);
3777 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3778 Label fpu_eq, fpu_lt;
3779 // Test if equal, and also handle the unordered/NaN case.
3780 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3782 // Test if less (unordered case is already handled).
3783 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3785 // Otherwise it's greater, so just fall thru, and return.
3786 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3787 __ Ret(USE_DELAY_SLOT);
3788 __ li(v0, Operand(GREATER));
3791 __ Ret(USE_DELAY_SLOT);
3792 __ li(v0, Operand(EQUAL));
3795 __ Ret(USE_DELAY_SLOT);
3796 __ li(v0, Operand(LESS));
3798 __ bind(&unordered);
3799 __ bind(&generic_stub);
3800 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3801 CompareICState::GENERIC, CompareICState::GENERIC);
3802 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3804 __ bind(&maybe_undefined1);
3805 if (Token::IsOrderedRelationalCompareOp(op())) {
3806 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3807 __ Branch(&miss, ne, a0, Operand(at));
3808 __ JumpIfSmi(a1, &unordered);
3809 __ GetObjectType(a1, a2, a2);
3810 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3814 __ bind(&maybe_undefined2);
3815 if (Token::IsOrderedRelationalCompareOp(op())) {
3816 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3817 __ Branch(&unordered, eq, a1, Operand(at));
3825 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3826 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3829 // Registers containing left and right operands respectively.
3831 Register right = a0;
3835 // Check that both operands are heap objects.
3836 __ JumpIfEitherSmi(left, right, &miss);
3838 // Check that both operands are internalized strings.
3839 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3840 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3841 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3842 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3843 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3844 __ Or(tmp1, tmp1, Operand(tmp2));
3845 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3846 __ Branch(&miss, ne, at, Operand(zero_reg));
3848 // Make sure a0 is non-zero. At this point input operands are
3849 // guaranteed to be non-zero.
3850 DCHECK(right.is(a0));
3851 STATIC_ASSERT(EQUAL == 0);
3852 STATIC_ASSERT(kSmiTag == 0);
3854 // Internalized strings are compared by identity.
3855 __ Ret(ne, left, Operand(right));
3856 DCHECK(is_int16(EQUAL));
3857 __ Ret(USE_DELAY_SLOT);
3858 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3865 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3866 DCHECK(state() == CompareICState::UNIQUE_NAME);
3867 DCHECK(GetCondition() == eq);
3870 // Registers containing left and right operands respectively.
3872 Register right = a0;
3876 // Check that both operands are heap objects.
3877 __ JumpIfEitherSmi(left, right, &miss);
3879 // Check that both operands are unique names. This leaves the instance
3880 // types loaded in tmp1 and tmp2.
3881 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3882 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3883 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3884 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3886 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3887 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3892 // Unique names are compared by identity.
3894 __ Branch(&done, ne, left, Operand(right));
3895 // Make sure a0 is non-zero. At this point input operands are
3896 // guaranteed to be non-zero.
3897 DCHECK(right.is(a0));
3898 STATIC_ASSERT(EQUAL == 0);
3899 STATIC_ASSERT(kSmiTag == 0);
3900 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3909 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3910 DCHECK(state() == CompareICState::STRING);
3913 bool equality = Token::IsEqualityOp(op());
3915 // Registers containing left and right operands respectively.
3917 Register right = a0;
3924 // Check that both operands are heap objects.
3925 __ JumpIfEitherSmi(left, right, &miss);
3927 // Check that both operands are strings. This leaves the instance
3928 // types loaded in tmp1 and tmp2.
3929 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3930 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3931 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3932 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3933 STATIC_ASSERT(kNotStringTag != 0);
3934 __ Or(tmp3, tmp1, tmp2);
3935 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3936 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3938 // Fast check for identical strings.
3939 Label left_ne_right;
3940 STATIC_ASSERT(EQUAL == 0);
3941 STATIC_ASSERT(kSmiTag == 0);
3942 __ Branch(&left_ne_right, ne, left, Operand(right));
3943 __ Ret(USE_DELAY_SLOT);
3944 __ mov(v0, zero_reg); // In the delay slot.
3945 __ bind(&left_ne_right);
3947 // Handle not identical strings.
3949 // Check that both strings are internalized strings. If they are, we're done
3950 // because we already know they are not identical. We know they are both
3953 DCHECK(GetCondition() == eq);
3954 STATIC_ASSERT(kInternalizedTag == 0);
3955 __ Or(tmp3, tmp1, Operand(tmp2));
3956 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3958 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3959 // Make sure a0 is non-zero. At this point input operands are
3960 // guaranteed to be non-zero.
3961 DCHECK(right.is(a0));
3962 __ Ret(USE_DELAY_SLOT);
3963 __ mov(v0, a0); // In the delay slot.
3964 __ bind(&is_symbol);
3967 // Check that both strings are sequential one_byte.
3969 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3972 // Compare flat one_byte strings. Returns when done.
3974 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3977 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3981 // Handle more complex cases in runtime.
3983 __ Push(left, right);
3985 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3987 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3995 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3996 DCHECK(state() == CompareICState::OBJECT);
3998 __ And(a2, a1, Operand(a0));
3999 __ JumpIfSmi(a2, &miss);
4001 __ GetObjectType(a0, a2, a2);
4002 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
4003 __ GetObjectType(a1, a2, a2);
4004 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
4006 DCHECK(GetCondition() == eq);
4007 __ Ret(USE_DELAY_SLOT);
4008 __ dsubu(v0, a0, a1);
4015 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
4017 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
4019 __ JumpIfSmi(a2, &miss);
4020 __ GetWeakValue(a4, cell);
4021 __ ld(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
4022 __ ld(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
4023 __ Branch(&miss, ne, a2, Operand(a4));
4024 __ Branch(&miss, ne, a3, Operand(a4));
4026 __ Ret(USE_DELAY_SLOT);
4027 __ dsubu(v0, a0, a1);
4034 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
4036 // Call the runtime system in a fresh internal frame.
4037 FrameScope scope(masm, StackFrame::INTERNAL);
4039 __ Push(ra, a1, a0);
4040 __ li(a4, Operand(Smi::FromInt(op())));
4041 __ daddiu(sp, sp, -kPointerSize);
4042 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
4044 __ sd(a4, MemOperand(sp)); // In the delay slot.
4045 // Compute the entry point of the rewritten stub.
4046 __ Daddu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
4047 // Restore registers.
4054 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4055 // Make place for arguments to fit C calling convention. Most of the callers
4056 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
4057 // so they handle stack restoring and we don't have to do that here.
4058 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
4059 // kCArgsSlotsSize stack space after the call.
4060 __ daddiu(sp, sp, -kCArgsSlotsSize);
4061 // Place the return address on the stack, making the call
4062 // GC safe. The RegExp backend also relies on this.
4063 __ sd(ra, MemOperand(sp, kCArgsSlotsSize));
4064 __ Call(t9); // Call the C++ function.
4065 __ ld(t9, MemOperand(sp, kCArgsSlotsSize));
4067 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
4068 // In case of an error the return address may point to a memory area
4069 // filled with kZapValue by the GC.
4070 // Dereference the address and check for this.
4071 __ Uld(a4, MemOperand(t9));
4072 __ Assert(ne, kReceivedInvalidReturnAddress, a4,
4073 Operand(reinterpret_cast<uint64_t>(kZapValue)));
4079 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4082 reinterpret_cast<intptr_t>(GetCode().location());
4083 __ Move(t9, target);
4084 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
4089 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4093 Register properties,
4095 Register scratch0) {
4096 DCHECK(name->IsUniqueName());
4097 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4098 // not equal to the name and kProbes-th slot is not used (its name is the
4099 // undefined value), it guarantees the hash table doesn't contain the
4100 // property. It's true even if some slots represent deleted properties
4101 // (their names are the hole value).
4102 for (int i = 0; i < kInlinedProbes; i++) {
4103 // scratch0 points to properties hash.
4104 // Compute the masked index: (hash + i + i * i) & mask.
4105 Register index = scratch0;
4106 // Capacity is smi 2^n.
4107 __ SmiLoadUntag(index, FieldMemOperand(properties, kCapacityOffset));
4108 __ Dsubu(index, index, Operand(1));
4109 __ And(index, index,
4110 Operand(name->Hash() + NameDictionary::GetProbeOffset(i)));
4112 // Scale the index by multiplying by the entry size.
4113 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4114 __ dsll(at, index, 1);
4115 __ Daddu(index, index, at); // index *= 3.
4117 Register entity_name = scratch0;
4118 // Having undefined at this place means the name is not contained.
4119 STATIC_ASSERT(kSmiTagSize == 1);
4120 Register tmp = properties;
4122 __ dsll(scratch0, index, kPointerSizeLog2);
4123 __ Daddu(tmp, properties, scratch0);
4124 __ ld(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4126 DCHECK(!tmp.is(entity_name));
4127 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4128 __ Branch(done, eq, entity_name, Operand(tmp));
4130 // Load the hole ready for use below:
4131 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4133 // Stop if found the property.
4134 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4137 __ Branch(&good, eq, entity_name, Operand(tmp));
4139 // Check if the entry name is not a unique name.
4140 __ ld(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4142 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4143 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4146 // Restore the properties.
4148 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4151 const int spill_mask =
4152 (ra.bit() | a6.bit() | a5.bit() | a4.bit() | a3.bit() |
4153 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4155 __ MultiPush(spill_mask);
4156 __ ld(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4157 __ li(a1, Operand(Handle<Name>(name)));
4158 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4161 __ MultiPop(spill_mask);
4163 __ Branch(done, eq, at, Operand(zero_reg));
4164 __ Branch(miss, ne, at, Operand(zero_reg));
4168 // Probe the name dictionary in the |elements| register. Jump to the
4169 // |done| label if a property with the given name is found. Jump to
4170 // the |miss| label otherwise.
4171 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4172 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4178 Register scratch2) {
4179 DCHECK(!elements.is(scratch1));
4180 DCHECK(!elements.is(scratch2));
4181 DCHECK(!name.is(scratch1));
4182 DCHECK(!name.is(scratch2));
4184 __ AssertName(name);
4186 // Compute the capacity mask.
4187 __ ld(scratch1, FieldMemOperand(elements, kCapacityOffset));
4188 __ SmiUntag(scratch1);
4189 __ Dsubu(scratch1, scratch1, Operand(1));
4191 // Generate an unrolled loop that performs a few probes before
4192 // giving up. Measurements done on Gmail indicate that 2 probes
4193 // cover ~93% of loads from dictionaries.
4194 for (int i = 0; i < kInlinedProbes; i++) {
4195 // Compute the masked index: (hash + i + i * i) & mask.
4196 __ lwu(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4198 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4199 // the hash in a separate instruction. The value hash + i + i * i is right
4200 // shifted in the following and instruction.
4201 DCHECK(NameDictionary::GetProbeOffset(i) <
4202 1 << (32 - Name::kHashFieldOffset));
4203 __ Daddu(scratch2, scratch2, Operand(
4204 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4206 __ dsrl(scratch2, scratch2, Name::kHashShift);
4207 __ And(scratch2, scratch1, scratch2);
4209 // Scale the index by multiplying by the entry size.
4210 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4211 // scratch2 = scratch2 * 3.
4213 __ dsll(at, scratch2, 1);
4214 __ Daddu(scratch2, scratch2, at);
4216 // Check if the key is identical to the name.
4217 __ dsll(at, scratch2, kPointerSizeLog2);
4218 __ Daddu(scratch2, elements, at);
4219 __ ld(at, FieldMemOperand(scratch2, kElementsStartOffset));
4220 __ Branch(done, eq, name, Operand(at));
4223 const int spill_mask =
4224 (ra.bit() | a6.bit() | a5.bit() | a4.bit() |
4225 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4226 ~(scratch1.bit() | scratch2.bit());
4228 __ MultiPush(spill_mask);
4230 DCHECK(!elements.is(a1));
4232 __ Move(a0, elements);
4234 __ Move(a0, elements);
4237 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4239 __ mov(scratch2, a2);
4241 __ MultiPop(spill_mask);
4243 __ Branch(done, ne, at, Operand(zero_reg));
4244 __ Branch(miss, eq, at, Operand(zero_reg));
4248 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4249 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4250 // we cannot call anything that could cause a GC from this stub.
4252 // result: NameDictionary to probe
4254 // dictionary: NameDictionary to probe.
4255 // index: will hold an index of entry if lookup is successful.
4256 // might alias with result_.
4258 // result_ is zero if lookup failed, non zero otherwise.
4260 Register result = v0;
4261 Register dictionary = a0;
4263 Register index = a2;
4266 Register undefined = a5;
4267 Register entry_key = a6;
4269 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4271 __ ld(mask, FieldMemOperand(dictionary, kCapacityOffset));
4273 __ Dsubu(mask, mask, Operand(1));
4275 __ lwu(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4277 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4279 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4280 // Compute the masked index: (hash + i + i * i) & mask.
4281 // Capacity is smi 2^n.
4283 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4284 // the hash in a separate instruction. The value hash + i + i * i is right
4285 // shifted in the following and instruction.
4286 DCHECK(NameDictionary::GetProbeOffset(i) <
4287 1 << (32 - Name::kHashFieldOffset));
4288 __ Daddu(index, hash, Operand(
4289 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4291 __ mov(index, hash);
4293 __ dsrl(index, index, Name::kHashShift);
4294 __ And(index, mask, index);
4296 // Scale the index by multiplying by the entry size.
4297 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4300 __ dsll(index, index, 1);
4301 __ Daddu(index, index, at);
4304 STATIC_ASSERT(kSmiTagSize == 1);
4305 __ dsll(index, index, kPointerSizeLog2);
4306 __ Daddu(index, index, dictionary);
4307 __ ld(entry_key, FieldMemOperand(index, kElementsStartOffset));
4309 // Having undefined at this place means the name is not contained.
4310 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4312 // Stop if found the property.
4313 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4315 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4316 // Check if the entry name is not a unique name.
4317 __ ld(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4319 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4320 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4324 __ bind(&maybe_in_dictionary);
4325 // If we are doing negative lookup then probing failure should be
4326 // treated as a lookup success. For positive lookup probing failure
4327 // should be treated as lookup failure.
4328 if (mode() == POSITIVE_LOOKUP) {
4329 __ Ret(USE_DELAY_SLOT);
4330 __ mov(result, zero_reg);
4333 __ bind(&in_dictionary);
4334 __ Ret(USE_DELAY_SLOT);
4337 __ bind(¬_in_dictionary);
4338 __ Ret(USE_DELAY_SLOT);
4339 __ mov(result, zero_reg);
4343 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4345 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4347 // Hydrogen code stubs need stub2 at snapshot time.
4348 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4353 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4354 // the value has just been written into the object, now this stub makes sure
4355 // we keep the GC informed. The word in the object where the value has been
4356 // written is in the address register.
4357 void RecordWriteStub::Generate(MacroAssembler* masm) {
4358 Label skip_to_incremental_noncompacting;
4359 Label skip_to_incremental_compacting;
4361 // The first two branch+nop instructions are generated with labels so as to
4362 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4363 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4364 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4365 // incremental heap marking.
4366 // See RecordWriteStub::Patch for details.
4367 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4369 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4372 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4373 __ RememberedSetHelper(object(),
4376 save_fp_regs_mode(),
4377 MacroAssembler::kReturnAtEnd);
4381 __ bind(&skip_to_incremental_noncompacting);
4382 GenerateIncremental(masm, INCREMENTAL);
4384 __ bind(&skip_to_incremental_compacting);
4385 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4387 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4388 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4390 PatchBranchIntoNop(masm, 0);
4391 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4395 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4398 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4399 Label dont_need_remembered_set;
4401 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
4402 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4404 &dont_need_remembered_set);
4406 __ CheckPageFlag(regs_.object(),
4408 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4410 &dont_need_remembered_set);
4412 // First notify the incremental marker if necessary, then update the
4414 CheckNeedsToInformIncrementalMarker(
4415 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4416 InformIncrementalMarker(masm);
4417 regs_.Restore(masm);
4418 __ RememberedSetHelper(object(),
4421 save_fp_regs_mode(),
4422 MacroAssembler::kReturnAtEnd);
4424 __ bind(&dont_need_remembered_set);
4427 CheckNeedsToInformIncrementalMarker(
4428 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4429 InformIncrementalMarker(masm);
4430 regs_.Restore(masm);
4435 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4436 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4437 int argument_count = 3;
4438 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4440 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4441 DCHECK(!address.is(regs_.object()));
4442 DCHECK(!address.is(a0));
4443 __ Move(address, regs_.address());
4444 __ Move(a0, regs_.object());
4445 __ Move(a1, address);
4446 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4448 AllowExternalCallThatCantCauseGC scope(masm);
4450 ExternalReference::incremental_marking_record_write_function(isolate()),
4452 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4456 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4457 MacroAssembler* masm,
4458 OnNoNeedToInformIncrementalMarker on_no_need,
4461 Label need_incremental;
4462 Label need_incremental_pop_scratch;
4464 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4465 __ ld(regs_.scratch1(),
4466 MemOperand(regs_.scratch0(),
4467 MemoryChunk::kWriteBarrierCounterOffset));
4468 __ Dsubu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4469 __ sd(regs_.scratch1(),
4470 MemOperand(regs_.scratch0(),
4471 MemoryChunk::kWriteBarrierCounterOffset));
4472 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4474 // Let's look at the color of the object: If it is not black we don't have
4475 // to inform the incremental marker.
4476 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4478 regs_.Restore(masm);
4479 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4480 __ RememberedSetHelper(object(),
4483 save_fp_regs_mode(),
4484 MacroAssembler::kReturnAtEnd);
4491 // Get the value from the slot.
4492 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
4494 if (mode == INCREMENTAL_COMPACTION) {
4495 Label ensure_not_white;
4497 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4498 regs_.scratch1(), // Scratch.
4499 MemoryChunk::kEvacuationCandidateMask,
4503 __ CheckPageFlag(regs_.object(),
4504 regs_.scratch1(), // Scratch.
4505 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4509 __ bind(&ensure_not_white);
4512 // We need extra registers for this, so we push the object and the address
4513 // register temporarily.
4514 __ Push(regs_.object(), regs_.address());
4515 __ EnsureNotWhite(regs_.scratch0(), // The value.
4516 regs_.scratch1(), // Scratch.
4517 regs_.object(), // Scratch.
4518 regs_.address(), // Scratch.
4519 &need_incremental_pop_scratch);
4520 __ Pop(regs_.object(), regs_.address());
4522 regs_.Restore(masm);
4523 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4524 __ RememberedSetHelper(object(),
4527 save_fp_regs_mode(),
4528 MacroAssembler::kReturnAtEnd);
4533 __ bind(&need_incremental_pop_scratch);
4534 __ Pop(regs_.object(), regs_.address());
4536 __ bind(&need_incremental);
4538 // Fall through when we need to inform the incremental marker.
4542 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4543 // ----------- S t a t e -------------
4544 // -- a0 : element value to store
4545 // -- a3 : element index as smi
4546 // -- sp[0] : array literal index in function as smi
4547 // -- sp[4] : array literal
4548 // clobbers a1, a2, a4
4549 // -----------------------------------
4552 Label double_elements;
4554 Label slow_elements;
4555 Label fast_elements;
4557 // Get array literal index, array literal and its map.
4558 __ ld(a4, MemOperand(sp, 0 * kPointerSize));
4559 __ ld(a1, MemOperand(sp, 1 * kPointerSize));
4560 __ ld(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4562 __ CheckFastElements(a2, a5, &double_elements);
4563 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4564 __ JumpIfSmi(a0, &smi_element);
4565 __ CheckFastSmiElements(a2, a5, &fast_elements);
4567 // Store into the array literal requires a elements transition. Call into
4569 __ bind(&slow_elements);
4571 __ Push(a1, a3, a0);
4572 __ ld(a5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4573 __ ld(a5, FieldMemOperand(a5, JSFunction::kLiteralsOffset));
4575 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4577 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4578 __ bind(&fast_elements);
4579 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4580 __ SmiScale(a6, a3, kPointerSizeLog2);
4581 __ Daddu(a6, a5, a6);
4582 __ Daddu(a6, a6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4583 __ sd(a0, MemOperand(a6, 0));
4584 // Update the write barrier for the array store.
4585 __ RecordWrite(a5, a6, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4586 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4587 __ Ret(USE_DELAY_SLOT);
4590 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4591 // and value is Smi.
4592 __ bind(&smi_element);
4593 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4594 __ SmiScale(a6, a3, kPointerSizeLog2);
4595 __ Daddu(a6, a5, a6);
4596 __ sd(a0, FieldMemOperand(a6, FixedArray::kHeaderSize));
4597 __ Ret(USE_DELAY_SLOT);
4600 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4601 __ bind(&double_elements);
4602 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4603 __ StoreNumberToDoubleElements(a0, a3, a5, a7, t1, &slow_elements);
4604 __ Ret(USE_DELAY_SLOT);
4609 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4610 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4611 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4612 int parameter_count_offset =
4613 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4614 __ ld(a1, MemOperand(fp, parameter_count_offset));
4615 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4616 __ Daddu(a1, a1, Operand(1));
4618 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4619 __ dsll(a1, a1, kPointerSizeLog2);
4620 __ Ret(USE_DELAY_SLOT);
4621 __ Daddu(sp, sp, a1);
4625 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4626 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4627 LoadICStub stub(isolate(), state());
4628 stub.GenerateForTrampoline(masm);
4632 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4633 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4634 KeyedLoadICStub stub(isolate(), state());
4635 stub.GenerateForTrampoline(masm);
4639 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4640 EmitLoadTypeFeedbackVector(masm, a2);
4641 CallICStub stub(isolate(), state());
4642 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4646 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4647 EmitLoadTypeFeedbackVector(masm, a2);
4648 CallIC_ArrayStub stub(isolate(), state());
4649 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4653 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4656 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4657 GenerateImpl(masm, true);
4661 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4662 Register key, Register vector, Register slot,
4663 Register feedback, Register receiver_map,
4664 Register scratch1, Register scratch2,
4665 bool is_polymorphic, Label* miss) {
4666 // feedback initially contains the feedback array
4667 Label next_loop, prepare_next;
4668 Label start_polymorphic;
4670 Register cached_map = scratch1;
4673 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4674 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4675 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4676 // found, now call handler.
4677 Register handler = feedback;
4678 __ ld(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4679 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4682 Register length = scratch2;
4683 __ bind(&start_polymorphic);
4684 __ ld(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4685 if (!is_polymorphic) {
4686 // If the IC could be monomorphic we have to make sure we don't go past the
4687 // end of the feedback array.
4688 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4691 Register too_far = length;
4692 Register pointer_reg = feedback;
4694 // +-----+------+------+-----+-----+ ... ----+
4695 // | map | len | wm0 | h0 | wm1 | hN |
4696 // +-----+------+------+-----+-----+ ... ----+
4700 // pointer_reg too_far
4701 // aka feedback scratch2
4702 // also need receiver_map
4703 // use cached_map (scratch1) to look in the weak map values.
4704 __ SmiScale(too_far, length, kPointerSizeLog2);
4705 __ Daddu(too_far, feedback, Operand(too_far));
4706 __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4707 __ Daddu(pointer_reg, feedback,
4708 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4710 __ bind(&next_loop);
4711 __ ld(cached_map, MemOperand(pointer_reg));
4712 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4713 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4714 __ ld(handler, MemOperand(pointer_reg, kPointerSize));
4715 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4718 __ bind(&prepare_next);
4719 __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4720 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4722 // We exhausted our array of map handler pairs.
4727 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4728 Register receiver_map, Register feedback,
4729 Register vector, Register slot,
4730 Register scratch, Label* compare_map,
4731 Label* load_smi_map, Label* try_array) {
4732 __ JumpIfSmi(receiver, load_smi_map);
4733 __ ld(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4734 __ bind(compare_map);
4735 Register cached_map = scratch;
4736 // Move the weak map into the weak_cell register.
4737 __ ld(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4738 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4739 Register handler = feedback;
4740 __ SmiScale(handler, slot, kPointerSizeLog2);
4741 __ Daddu(handler, vector, Operand(handler));
4743 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4744 __ Daddu(t9, handler, Code::kHeaderSize - kHeapObjectTag);
4749 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4750 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4751 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4752 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4753 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4754 Register feedback = a4;
4755 Register receiver_map = a5;
4756 Register scratch1 = a6;
4758 __ SmiScale(feedback, slot, kPointerSizeLog2);
4759 __ Daddu(feedback, vector, Operand(feedback));
4760 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4762 // Try to quickly handle the monomorphic case without knowing for sure
4763 // if we have a weak cell in feedback. We do know it's safe to look
4764 // at WeakCell::kValueOffset.
4765 Label try_array, load_smi_map, compare_map;
4766 Label not_array, miss;
4767 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4768 scratch1, &compare_map, &load_smi_map, &try_array);
4770 // Is it a fixed array?
4771 __ bind(&try_array);
4772 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4773 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4774 __ Branch(¬_array, ne, scratch1, Operand(at));
4775 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4776 scratch1, a7, true, &miss);
4778 __ bind(¬_array);
4779 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4780 __ Branch(&miss, ne, feedback, Operand(at));
4781 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4782 Code::ComputeHandlerFlags(Code::LOAD_IC));
4783 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4784 false, receiver, name, feedback,
4785 receiver_map, scratch1, a7);
4788 LoadIC::GenerateMiss(masm);
4790 __ bind(&load_smi_map);
4791 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4792 __ Branch(&compare_map);
4796 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4797 GenerateImpl(masm, false);
4801 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4802 GenerateImpl(masm, true);
4806 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4807 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4808 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4809 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4810 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4811 Register feedback = a4;
4812 Register receiver_map = a5;
4813 Register scratch1 = a6;
4815 __ SmiScale(feedback, slot, kPointerSizeLog2);
4816 __ Daddu(feedback, vector, Operand(feedback));
4817 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4819 // Try to quickly handle the monomorphic case without knowing for sure
4820 // if we have a weak cell in feedback. We do know it's safe to look
4821 // at WeakCell::kValueOffset.
4822 Label try_array, load_smi_map, compare_map;
4823 Label not_array, miss;
4824 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4825 scratch1, &compare_map, &load_smi_map, &try_array);
4827 __ bind(&try_array);
4828 // Is it a fixed array?
4829 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4830 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4831 __ Branch(¬_array, ne, scratch1, Operand(at));
4832 // We have a polymorphic element handler.
4833 __ JumpIfNotSmi(key, &miss);
4835 Label polymorphic, try_poly_name;
4836 __ bind(&polymorphic);
4837 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4838 scratch1, a7, true, &miss);
4840 __ bind(¬_array);
4842 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4843 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4844 Handle<Code> megamorphic_stub =
4845 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4846 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4848 __ bind(&try_poly_name);
4849 // We might have a name in feedback, and a fixed array in the next slot.
4850 __ Branch(&miss, ne, key, Operand(feedback));
4851 // If the name comparison succeeded, we know we have a fixed array with
4852 // at least one map/handler pair.
4853 __ SmiScale(feedback, slot, kPointerSizeLog2);
4854 __ Daddu(feedback, vector, Operand(feedback));
4856 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4857 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4858 scratch1, a7, false, &miss);
4861 KeyedLoadIC::GenerateMiss(masm);
4863 __ bind(&load_smi_map);
4864 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4865 __ Branch(&compare_map);
4869 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4870 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4871 VectorStoreICStub stub(isolate(), state());
4872 stub.GenerateForTrampoline(masm);
4876 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4877 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4878 VectorKeyedStoreICStub stub(isolate(), state());
4879 stub.GenerateForTrampoline(masm);
4883 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4884 GenerateImpl(masm, false);
4888 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4889 GenerateImpl(masm, true);
4893 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4896 // TODO(mvstanton): Implement.
4898 StoreIC::GenerateMiss(masm);
4902 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4903 GenerateImpl(masm, false);
4907 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4908 GenerateImpl(masm, true);
4912 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4915 // TODO(mvstanton): Implement.
4917 KeyedStoreIC::GenerateMiss(masm);
4921 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4922 if (masm->isolate()->function_entry_hook() != NULL) {
4923 ProfileEntryHookStub stub(masm->isolate());
4931 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4932 // The entry hook is a "push ra" instruction, followed by a call.
4933 // Note: on MIPS "push" is 2 instruction
4934 const int32_t kReturnAddressDistanceFromFunctionStart =
4935 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4937 // This should contain all kJSCallerSaved registers.
4938 const RegList kSavedRegs =
4939 kJSCallerSaved | // Caller saved registers.
4940 s5.bit(); // Saved stack pointer.
4942 // We also save ra, so the count here is one higher than the mask indicates.
4943 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4945 // Save all caller-save registers as this may be called from anywhere.
4946 __ MultiPush(kSavedRegs | ra.bit());
4948 // Compute the function's address for the first argument.
4949 __ Dsubu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4951 // The caller's return address is above the saved temporaries.
4952 // Grab that for the second argument to the hook.
4953 __ Daddu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4955 // Align the stack if necessary.
4956 int frame_alignment = masm->ActivationFrameAlignment();
4957 if (frame_alignment > kPointerSize) {
4959 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4960 __ And(sp, sp, Operand(-frame_alignment));
4963 __ Dsubu(sp, sp, kCArgsSlotsSize);
4964 #if defined(V8_HOST_ARCH_MIPS) || defined(V8_HOST_ARCH_MIPS64)
4965 int64_t entry_hook =
4966 reinterpret_cast<int64_t>(isolate()->function_entry_hook());
4967 __ li(t9, Operand(entry_hook));
4969 // Under the simulator we need to indirect the entry hook through a
4970 // trampoline function at a known address.
4971 // It additionally takes an isolate as a third parameter.
4972 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4974 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4975 __ li(t9, Operand(ExternalReference(&dispatcher,
4976 ExternalReference::BUILTIN_CALL,
4979 // Call C function through t9 to conform ABI for PIC.
4982 // Restore the stack pointer if needed.
4983 if (frame_alignment > kPointerSize) {
4986 __ Daddu(sp, sp, kCArgsSlotsSize);
4989 // Also pop ra to get Ret(0).
4990 __ MultiPop(kSavedRegs | ra.bit());
4996 static void CreateArrayDispatch(MacroAssembler* masm,
4997 AllocationSiteOverrideMode mode) {
4998 if (mode == DISABLE_ALLOCATION_SITES) {
4999 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5000 __ TailCallStub(&stub);
5001 } else if (mode == DONT_OVERRIDE) {
5002 int last_index = GetSequenceIndexFromFastElementsKind(
5003 TERMINAL_FAST_ELEMENTS_KIND);
5004 for (int i = 0; i <= last_index; ++i) {
5005 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5006 T stub(masm->isolate(), kind);
5007 __ TailCallStub(&stub, eq, a3, Operand(kind));
5010 // If we reached this point there is a problem.
5011 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5018 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5019 AllocationSiteOverrideMode mode) {
5020 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5021 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5022 // a0 - number of arguments
5023 // a1 - constructor?
5024 // sp[0] - last argument
5025 Label normal_sequence;
5026 if (mode == DONT_OVERRIDE) {
5027 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5028 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5029 STATIC_ASSERT(FAST_ELEMENTS == 2);
5030 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5031 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5032 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5034 // is the low bit set? If so, we are holey and that is good.
5035 __ And(at, a3, Operand(1));
5036 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5038 // look at the first argument
5039 __ ld(a5, MemOperand(sp, 0));
5040 __ Branch(&normal_sequence, eq, a5, Operand(zero_reg));
5042 if (mode == DISABLE_ALLOCATION_SITES) {
5043 ElementsKind initial = GetInitialFastElementsKind();
5044 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5046 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5048 DISABLE_ALLOCATION_SITES);
5049 __ TailCallStub(&stub_holey);
5051 __ bind(&normal_sequence);
5052 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5054 DISABLE_ALLOCATION_SITES);
5055 __ TailCallStub(&stub);
5056 } else if (mode == DONT_OVERRIDE) {
5057 // We are going to create a holey array, but our kind is non-holey.
5058 // Fix kind and retry (only if we have an allocation site in the slot).
5059 __ Daddu(a3, a3, Operand(1));
5061 if (FLAG_debug_code) {
5062 __ ld(a5, FieldMemOperand(a2, 0));
5063 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5064 __ Assert(eq, kExpectedAllocationSite, a5, Operand(at));
5067 // Save the resulting elements kind in type info. We can't just store a3
5068 // in the AllocationSite::transition_info field because elements kind is
5069 // restricted to a portion of the field...upper bits need to be left alone.
5070 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5071 __ ld(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5072 __ Daddu(a4, a4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5073 __ sd(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5076 __ bind(&normal_sequence);
5077 int last_index = GetSequenceIndexFromFastElementsKind(
5078 TERMINAL_FAST_ELEMENTS_KIND);
5079 for (int i = 0; i <= last_index; ++i) {
5080 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5081 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5082 __ TailCallStub(&stub, eq, a3, Operand(kind));
5085 // If we reached this point there is a problem.
5086 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5094 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5095 int to_index = GetSequenceIndexFromFastElementsKind(
5096 TERMINAL_FAST_ELEMENTS_KIND);
5097 for (int i = 0; i <= to_index; ++i) {
5098 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5099 T stub(isolate, kind);
5101 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5102 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5109 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5110 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5112 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5114 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5119 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5121 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5122 for (int i = 0; i < 2; i++) {
5123 // For internal arrays we only need a few things.
5124 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5126 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5128 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5134 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5135 MacroAssembler* masm,
5136 AllocationSiteOverrideMode mode) {
5137 if (argument_count() == ANY) {
5138 Label not_zero_case, not_one_case;
5140 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5141 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5143 __ bind(¬_zero_case);
5144 __ Branch(¬_one_case, gt, a0, Operand(1));
5145 CreateArrayDispatchOneArgument(masm, mode);
5147 __ bind(¬_one_case);
5148 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5149 } else if (argument_count() == NONE) {
5150 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5151 } else if (argument_count() == ONE) {
5152 CreateArrayDispatchOneArgument(masm, mode);
5153 } else if (argument_count() == MORE_THAN_ONE) {
5154 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5161 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5162 // ----------- S t a t e -------------
5163 // -- a0 : argc (only if argument_count() == ANY)
5164 // -- a1 : constructor
5165 // -- a2 : AllocationSite or undefined
5166 // -- a3 : original constructor
5167 // -- sp[0] : last argument
5168 // -----------------------------------
5170 if (FLAG_debug_code) {
5171 // The array construct code is only set for the global and natives
5172 // builtin Array functions which always have maps.
5174 // Initial map for the builtin Array function should be a map.
5175 __ ld(a4, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5176 // Will both indicate a NULL and a Smi.
5178 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5179 at, Operand(zero_reg));
5180 __ GetObjectType(a4, a4, a5);
5181 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5182 a5, Operand(MAP_TYPE));
5184 // We should either have undefined in a2 or a valid AllocationSite
5185 __ AssertUndefinedOrAllocationSite(a2, a4);
5189 __ Branch(&subclassing, ne, a1, Operand(a3));
5192 // Get the elements kind and case on that.
5193 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5194 __ Branch(&no_info, eq, a2, Operand(at));
5196 __ ld(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5198 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5199 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5200 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5203 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5206 __ bind(&subclassing);
5211 switch (argument_count()) {
5214 __ li(at, Operand(2));
5215 __ addu(a0, a0, at);
5218 __ li(a0, Operand(2));
5221 __ li(a0, Operand(3));
5225 __ JumpToExternalReference(
5226 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5230 void InternalArrayConstructorStub::GenerateCase(
5231 MacroAssembler* masm, ElementsKind kind) {
5233 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5234 __ TailCallStub(&stub0, lo, a0, Operand(1));
5236 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5237 __ TailCallStub(&stubN, hi, a0, Operand(1));
5239 if (IsFastPackedElementsKind(kind)) {
5240 // We might need to create a holey array
5241 // look at the first argument.
5242 __ ld(at, MemOperand(sp, 0));
5244 InternalArraySingleArgumentConstructorStub
5245 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5246 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5249 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5250 __ TailCallStub(&stub1);
5254 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5255 // ----------- S t a t e -------------
5257 // -- a1 : constructor
5258 // -- sp[0] : return address
5259 // -- sp[4] : last argument
5260 // -----------------------------------
5262 if (FLAG_debug_code) {
5263 // The array construct code is only set for the global and natives
5264 // builtin Array functions which always have maps.
5266 // Initial map for the builtin Array function should be a map.
5267 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5268 // Will both indicate a NULL and a Smi.
5270 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5271 at, Operand(zero_reg));
5272 __ GetObjectType(a3, a3, a4);
5273 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5274 a4, Operand(MAP_TYPE));
5277 // Figure out the right elements kind.
5278 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5280 // Load the map's "bit field 2" into a3. We only need the first byte,
5281 // but the following bit field extraction takes care of that anyway.
5282 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5283 // Retrieve elements_kind from bit field 2.
5284 __ DecodeField<Map::ElementsKindBits>(a3);
5286 if (FLAG_debug_code) {
5288 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5290 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5291 a3, Operand(FAST_HOLEY_ELEMENTS));
5295 Label fast_elements_case;
5296 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5297 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5299 __ bind(&fast_elements_case);
5300 GenerateCase(masm, FAST_ELEMENTS);
5304 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5305 Register context_reg = cp;
5306 Register slot_reg = a2;
5307 Register name_reg = a3;
5308 Register result_reg = v0;
5311 // Go up context chain to the script context.
5312 for (int i = 0; i < depth(); ++i) {
5313 __ lw(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5314 context_reg = result_reg;
5317 // Load the PropertyCell value at the specified slot.
5318 __ dsll(at, slot_reg, kPointerSizeLog2);
5319 __ Daddu(at, at, Operand(context_reg));
5320 __ Daddu(at, at, Context::SlotOffset(0));
5321 __ ld(result_reg, MemOperand(at));
5322 __ ld(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5324 // Check that value is not the_hole.
5325 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5326 __ Branch(&slow_case, eq, result_reg, Operand(at));
5329 // Fallback to the runtime.
5330 __ bind(&slow_case);
5331 __ SmiTag(slot_reg);
5332 __ Push(slot_reg, name_reg);
5333 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 2, 1);
5337 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5338 Register context_reg = cp;
5339 Register slot_reg = a2;
5340 Register name_reg = a3;
5341 Register value_reg = a0;
5342 Register cell_reg = a4;
5343 Register cell_details_reg = a5;
5344 Label fast_heapobject_case, fast_smi_case, slow_case;
5346 if (FLAG_debug_code) {
5347 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5348 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5349 __ AssertName(name_reg);
5352 // Go up context chain to the script context.
5353 for (int i = 0; i < depth(); ++i) {
5354 __ ld(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5355 context_reg = cell_reg;
5358 // Load the PropertyCell at the specified slot.
5359 __ dsll(at, slot_reg, kPointerSizeLog2);
5360 __ Daddu(at, at, Operand(context_reg));
5361 __ Daddu(at, at, Context::SlotOffset(0));
5362 __ ld(cell_reg, MemOperand(at));
5364 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5365 __ ld(cell_details_reg,
5366 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5367 __ SmiUntag(cell_details_reg);
5368 __ And(cell_details_reg, cell_details_reg,
5369 PropertyDetails::PropertyCellTypeField::kMask |
5370 PropertyDetails::KindField::kMask);
5372 // Check if PropertyCell holds mutable data.
5373 Label not_mutable_data;
5374 __ Branch(¬_mutable_data, ne, cell_details_reg,
5375 Operand(PropertyDetails::PropertyCellTypeField::encode(
5376 PropertyCellType::kMutable) |
5377 PropertyDetails::KindField::encode(kData)));
5378 __ JumpIfSmi(value_reg, &fast_smi_case);
5379 __ bind(&fast_heapobject_case);
5380 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5381 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5382 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5383 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5384 // RecordWriteField clobbers the value register, so we need to reload.
5385 __ Ret(USE_DELAY_SLOT);
5386 __ ld(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5387 __ bind(¬_mutable_data);
5389 // Check if PropertyCell value matches the new value (relevant for Constant,
5390 // ConstantType and Undefined cells).
5391 Label not_same_value;
5392 __ ld(at, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5393 __ Branch(¬_same_value, ne, value_reg, Operand(at));
5394 if (FLAG_debug_code) {
5396 // This can only be true for Constant, ConstantType and Undefined cells,
5397 // because we never store the_hole via this stub.
5398 __ Branch(&done, eq, cell_details_reg,
5399 Operand(PropertyDetails::PropertyCellTypeField::encode(
5400 PropertyCellType::kConstant) |
5401 PropertyDetails::KindField::encode(kData)));
5402 __ Branch(&done, eq, cell_details_reg,
5403 Operand(PropertyDetails::PropertyCellTypeField::encode(
5404 PropertyCellType::kConstantType) |
5405 PropertyDetails::KindField::encode(kData)));
5406 __ Check(eq, kUnexpectedValue, cell_details_reg,
5407 Operand(PropertyDetails::PropertyCellTypeField::encode(
5408 PropertyCellType::kUndefined) |
5409 PropertyDetails::KindField::encode(kData)));
5413 __ bind(¬_same_value);
5415 // Check if PropertyCell contains data with constant type.
5416 __ Branch(&slow_case, ne, cell_details_reg,
5417 Operand(PropertyDetails::PropertyCellTypeField::encode(
5418 PropertyCellType::kConstantType) |
5419 PropertyDetails::KindField::encode(kData)));
5421 // Now either both old and new values must be SMIs or both must be heap
5422 // objects with same map.
5423 Label value_is_heap_object;
5424 Register cell_value_reg = cell_details_reg;
5425 __ ld(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5426 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5427 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5428 // Old and new values are SMIs, no need for a write barrier here.
5429 __ bind(&fast_smi_case);
5430 __ Ret(USE_DELAY_SLOT);
5431 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5432 __ bind(&value_is_heap_object);
5433 __ JumpIfSmi(cell_value_reg, &slow_case);
5434 Register cell_value_map_reg = cell_value_reg;
5435 __ ld(cell_value_map_reg,
5436 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5437 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5438 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5440 // Fallback to the runtime.
5441 __ bind(&slow_case);
5442 __ SmiTag(slot_reg);
5443 __ Push(slot_reg, name_reg, value_reg);
5444 __ TailCallRuntime(is_strict(language_mode())
5445 ? Runtime::kStoreGlobalViaContext_Strict
5446 : Runtime::kStoreGlobalViaContext_Sloppy,
5451 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5452 int64_t offset = (ref0.address() - ref1.address());
5453 DCHECK(static_cast<int>(offset) == offset);
5454 return static_cast<int>(offset);
5458 // Calls an API function. Allocates HandleScope, extracts returned value
5459 // from handle and propagates exceptions. Restores context. stack_space
5460 // - space to be unwound on exit (includes the call JS arguments space and
5461 // the additional space allocated for the fast call).
5462 static void CallApiFunctionAndReturn(
5463 MacroAssembler* masm, Register function_address,
5464 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5465 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5466 Isolate* isolate = masm->isolate();
5467 ExternalReference next_address =
5468 ExternalReference::handle_scope_next_address(isolate);
5469 const int kNextOffset = 0;
5470 const int kLimitOffset = AddressOffset(
5471 ExternalReference::handle_scope_limit_address(isolate), next_address);
5472 const int kLevelOffset = AddressOffset(
5473 ExternalReference::handle_scope_level_address(isolate), next_address);
5475 DCHECK(function_address.is(a1) || function_address.is(a2));
5477 Label profiler_disabled;
5478 Label end_profiler_check;
5479 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5480 __ lb(t9, MemOperand(t9, 0));
5481 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5483 // Additional parameter is the address of the actual callback.
5484 __ li(t9, Operand(thunk_ref));
5485 __ jmp(&end_profiler_check);
5487 __ bind(&profiler_disabled);
5488 __ mov(t9, function_address);
5489 __ bind(&end_profiler_check);
5491 // Allocate HandleScope in callee-save registers.
5492 __ li(s3, Operand(next_address));
5493 __ ld(s0, MemOperand(s3, kNextOffset));
5494 __ ld(s1, MemOperand(s3, kLimitOffset));
5495 __ lw(s2, MemOperand(s3, kLevelOffset));
5496 __ Addu(s2, s2, Operand(1));
5497 __ sw(s2, MemOperand(s3, kLevelOffset));
5499 if (FLAG_log_timer_events) {
5500 FrameScope frame(masm, StackFrame::MANUAL);
5501 __ PushSafepointRegisters();
5502 __ PrepareCallCFunction(1, a0);
5503 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5504 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5506 __ PopSafepointRegisters();
5509 // Native call returns to the DirectCEntry stub which redirects to the
5510 // return address pushed on stack (could have moved after GC).
5511 // DirectCEntry stub itself is generated early and never moves.
5512 DirectCEntryStub stub(isolate);
5513 stub.GenerateCall(masm, t9);
5515 if (FLAG_log_timer_events) {
5516 FrameScope frame(masm, StackFrame::MANUAL);
5517 __ PushSafepointRegisters();
5518 __ PrepareCallCFunction(1, a0);
5519 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5520 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5522 __ PopSafepointRegisters();
5525 Label promote_scheduled_exception;
5526 Label delete_allocated_handles;
5527 Label leave_exit_frame;
5528 Label return_value_loaded;
5530 // Load value from ReturnValue.
5531 __ ld(v0, return_value_operand);
5532 __ bind(&return_value_loaded);
5534 // No more valid handles (the result handle was the last one). Restore
5535 // previous handle scope.
5536 __ sd(s0, MemOperand(s3, kNextOffset));
5537 if (__ emit_debug_code()) {
5538 __ lw(a1, MemOperand(s3, kLevelOffset));
5539 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5541 __ Subu(s2, s2, Operand(1));
5542 __ sw(s2, MemOperand(s3, kLevelOffset));
5543 __ ld(at, MemOperand(s3, kLimitOffset));
5544 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5546 // Leave the API exit frame.
5547 __ bind(&leave_exit_frame);
5549 bool restore_context = context_restore_operand != NULL;
5550 if (restore_context) {
5551 __ ld(cp, *context_restore_operand);
5553 if (stack_space_offset != kInvalidStackOffset) {
5554 DCHECK(kCArgsSlotsSize == 0);
5555 __ ld(s0, MemOperand(sp, stack_space_offset));
5557 __ li(s0, Operand(stack_space));
5559 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5560 stack_space_offset != kInvalidStackOffset);
5562 // Check if the function scheduled an exception.
5563 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
5564 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5565 __ ld(a5, MemOperand(at));
5566 __ Branch(&promote_scheduled_exception, ne, a4, Operand(a5));
5570 // Re-throw by promoting a scheduled exception.
5571 __ bind(&promote_scheduled_exception);
5572 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5574 // HandleScope limit has changed. Delete allocated extensions.
5575 __ bind(&delete_allocated_handles);
5576 __ sd(s1, MemOperand(s3, kLimitOffset));
5579 __ PrepareCallCFunction(1, s1);
5580 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5581 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5584 __ jmp(&leave_exit_frame);
5588 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5589 const ParameterCount& argc,
5590 bool return_first_arg,
5591 bool call_data_undefined) {
5592 // ----------- S t a t e -------------
5594 // -- a4 : call_data
5596 // -- a1 : api_function_address
5597 // -- a3 : number of arguments if argc is a register
5600 // -- sp[0] : last argument
5602 // -- sp[(argc - 1)* 4] : first argument
5603 // -- sp[argc * 4] : receiver
5604 // -----------------------------------
5606 Register callee = a0;
5607 Register call_data = a4;
5608 Register holder = a2;
5609 Register api_function_address = a1;
5610 Register context = cp;
5612 typedef FunctionCallbackArguments FCA;
5614 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5615 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5616 STATIC_ASSERT(FCA::kDataIndex == 4);
5617 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5618 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5619 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5620 STATIC_ASSERT(FCA::kHolderIndex == 0);
5621 STATIC_ASSERT(FCA::kArgsLength == 7);
5623 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5625 // Save context, callee and call data.
5626 __ Push(context, callee, call_data);
5627 // Load context from callee.
5628 __ ld(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5630 Register scratch = call_data;
5631 if (!call_data_undefined) {
5632 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5634 // Push return value and default return value.
5635 __ Push(scratch, scratch);
5636 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5637 // Push isolate and holder.
5638 __ Push(scratch, holder);
5640 // Prepare arguments.
5641 __ mov(scratch, sp);
5643 // Allocate the v8::Arguments structure in the arguments' space since
5644 // it's not controlled by GC.
5645 const int kApiStackSpace = 4;
5647 FrameScope frame_scope(masm, StackFrame::MANUAL);
5648 __ EnterExitFrame(false, kApiStackSpace);
5650 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5651 // a0 = FunctionCallbackInfo&
5652 // Arguments is after the return address.
5653 __ Daddu(a0, sp, Operand(1 * kPointerSize));
5654 // FunctionCallbackInfo::implicit_args_
5655 __ sd(scratch, MemOperand(a0, 0 * kPointerSize));
5656 if (argc.is_immediate()) {
5657 // FunctionCallbackInfo::values_
5658 __ Daddu(at, scratch,
5659 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5660 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5661 // FunctionCallbackInfo::length_ = argc
5662 __ li(at, Operand(argc.immediate()));
5663 __ sd(at, MemOperand(a0, 2 * kPointerSize));
5664 // FunctionCallbackInfo::is_construct_call_ = 0
5665 __ sd(zero_reg, MemOperand(a0, 3 * kPointerSize));
5667 // FunctionCallbackInfo::values_
5668 __ dsll(at, argc.reg(), kPointerSizeLog2);
5669 __ Daddu(at, at, scratch);
5670 __ Daddu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5671 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5672 // FunctionCallbackInfo::length_ = argc
5673 __ sd(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5674 // FunctionCallbackInfo::is_construct_call_
5675 __ Daddu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5676 __ dsll(at, argc.reg(), kPointerSizeLog2);
5677 __ sd(at, MemOperand(a0, 3 * kPointerSize));
5680 ExternalReference thunk_ref =
5681 ExternalReference::invoke_function_callback(masm->isolate());
5683 AllowExternalCallThatCantCauseGC scope(masm);
5684 MemOperand context_restore_operand(
5685 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5686 // Stores return the first js argument.
5687 int return_value_offset = 0;
5688 if (return_first_arg) {
5689 return_value_offset = 2 + FCA::kArgsLength;
5691 return_value_offset = 2 + FCA::kReturnValueOffset;
5693 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5694 int stack_space = 0;
5695 int32_t stack_space_offset = 4 * kPointerSize;
5696 if (argc.is_immediate()) {
5697 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5698 stack_space_offset = kInvalidStackOffset;
5700 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5701 stack_space_offset, return_value_operand,
5702 &context_restore_operand);
5706 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5707 bool call_data_undefined = this->call_data_undefined();
5708 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5709 call_data_undefined);
5713 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5714 bool is_store = this->is_store();
5715 int argc = this->argc();
5716 bool call_data_undefined = this->call_data_undefined();
5717 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5718 call_data_undefined);
5722 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5723 // ----------- S t a t e -------------
5725 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5727 // -- a2 : api_function_address
5728 // -----------------------------------
5730 Register api_function_address = ApiGetterDescriptor::function_address();
5731 DCHECK(api_function_address.is(a2));
5733 __ mov(a0, sp); // a0 = Handle<Name>
5734 __ Daddu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5736 const int kApiStackSpace = 1;
5737 FrameScope frame_scope(masm, StackFrame::MANUAL);
5738 __ EnterExitFrame(false, kApiStackSpace);
5740 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5741 // a1 (internal::Object** args_) as the data.
5742 __ sd(a1, MemOperand(sp, 1 * kPointerSize));
5743 __ Daddu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5745 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5747 ExternalReference thunk_ref =
5748 ExternalReference::invoke_accessor_getter_callback(isolate());
5749 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5750 kStackUnwindSpace, kInvalidStackOffset,
5751 MemOperand(fp, 6 * kPointerSize), NULL);
5757 } // namespace internal
5760 #endif // V8_TARGET_ARCH_MIPS64