1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #if V8_TARGET_ARCH_MIPS64
7 #include "src/bootstrapper.h"
8 #include "src/code-stubs.h"
9 #include "src/codegen.h"
10 #include "src/ic/handler-compiler.h"
11 #include "src/ic/ic.h"
12 #include "src/ic/stub-cache.h"
13 #include "src/isolate.h"
14 #include "src/mips64/code-stubs-mips64.h"
15 #include "src/regexp/jsregexp.h"
16 #include "src/regexp/regexp-macro-assembler.h"
17 #include "src/runtime/runtime.h"
23 static void InitializeArrayConstructorDescriptor(
24 Isolate* isolate, CodeStubDescriptor* descriptor,
25 int constant_stack_parameter_count) {
26 Address deopt_handler = Runtime::FunctionForId(
27 Runtime::kArrayConstructor)->entry;
29 if (constant_stack_parameter_count == 0) {
30 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
31 JS_FUNCTION_STUB_MODE);
33 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
34 JS_FUNCTION_STUB_MODE);
39 static void InitializeInternalArrayConstructorDescriptor(
40 Isolate* isolate, CodeStubDescriptor* descriptor,
41 int constant_stack_parameter_count) {
42 Address deopt_handler = Runtime::FunctionForId(
43 Runtime::kInternalArrayConstructor)->entry;
45 if (constant_stack_parameter_count == 0) {
46 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
47 JS_FUNCTION_STUB_MODE);
49 descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count,
50 JS_FUNCTION_STUB_MODE);
55 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
56 CodeStubDescriptor* descriptor) {
57 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
61 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
62 CodeStubDescriptor* descriptor) {
63 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
67 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
68 CodeStubDescriptor* descriptor) {
69 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
73 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
74 CodeStubDescriptor* descriptor) {
75 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
79 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
80 CodeStubDescriptor* descriptor) {
81 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
85 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
86 CodeStubDescriptor* descriptor) {
87 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
91 #define __ ACCESS_MASM(masm)
94 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
95 Condition cc, Strength strength);
96 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
102 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
107 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
108 ExternalReference miss) {
109 // Update the static counter each time a new code stub is generated.
110 isolate()->counters()->code_stubs()->Increment();
112 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
113 int param_count = descriptor.GetRegisterParameterCount();
115 // Call the runtime system in a fresh internal frame.
116 FrameScope scope(masm, StackFrame::INTERNAL);
117 DCHECK((param_count == 0) ||
118 a0.is(descriptor.GetRegisterParameter(param_count - 1)));
119 // Push arguments, adjust sp.
120 __ Dsubu(sp, sp, Operand(param_count * kPointerSize));
121 for (int i = 0; i < param_count; ++i) {
122 // Store argument to stack.
123 __ sd(descriptor.GetRegisterParameter(i),
124 MemOperand(sp, (param_count - 1 - i) * kPointerSize));
126 __ CallExternalReference(miss, param_count);
133 void DoubleToIStub::Generate(MacroAssembler* masm) {
134 Label out_of_range, only_low, negate, done;
135 Register input_reg = source();
136 Register result_reg = destination();
138 int double_offset = offset();
139 // Account for saved regs if input is sp.
140 if (input_reg.is(sp)) double_offset += 3 * kPointerSize;
143 GetRegisterThatIsNotOneOf(input_reg, result_reg);
145 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
147 GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2);
148 DoubleRegister double_scratch = kLithiumScratchDouble;
150 __ Push(scratch, scratch2, scratch3);
151 if (!skip_fastpath()) {
152 // Load double input.
153 __ ldc1(double_scratch, MemOperand(input_reg, double_offset));
155 // Clear cumulative exception flags and save the FCSR.
156 __ cfc1(scratch2, FCSR);
157 __ ctc1(zero_reg, FCSR);
159 // Try a conversion to a signed integer.
160 __ Trunc_w_d(double_scratch, double_scratch);
161 // Move the converted value into the result register.
162 __ mfc1(scratch3, double_scratch);
164 // Retrieve and restore the FCSR.
165 __ cfc1(scratch, FCSR);
166 __ ctc1(scratch2, FCSR);
168 // Check for overflow and NaNs.
171 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask
172 | kFCSRInvalidOpFlagMask);
173 // If we had no exceptions then set result_reg and we are done.
175 __ Branch(&error, ne, scratch, Operand(zero_reg));
176 __ Move(result_reg, scratch3);
181 // Load the double value and perform a manual truncation.
182 Register input_high = scratch2;
183 Register input_low = scratch3;
185 __ lw(input_low, MemOperand(input_reg, double_offset));
186 __ lw(input_high, MemOperand(input_reg, double_offset + kIntSize));
188 Label normal_exponent, restore_sign;
189 // Extract the biased exponent in result.
192 HeapNumber::kExponentShift,
193 HeapNumber::kExponentBits);
195 // Check for Infinity and NaNs, which should return 0.
196 __ Subu(scratch, result_reg, HeapNumber::kExponentMask);
197 __ Movz(result_reg, zero_reg, scratch);
198 __ Branch(&done, eq, scratch, Operand(zero_reg));
200 // Express exponent as delta to (number of mantissa bits + 31).
203 Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31));
205 // If the delta is strictly positive, all bits would be shifted away,
206 // which means that we can return 0.
207 __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg));
208 __ mov(result_reg, zero_reg);
211 __ bind(&normal_exponent);
212 const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1;
214 __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits));
217 Register sign = result_reg;
219 __ And(sign, input_high, Operand(HeapNumber::kSignMask));
221 // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need
222 // to check for this specific case.
223 Label high_shift_needed, high_shift_done;
224 __ Branch(&high_shift_needed, lt, scratch, Operand(32));
225 __ mov(input_high, zero_reg);
226 __ Branch(&high_shift_done);
227 __ bind(&high_shift_needed);
229 // Set the implicit 1 before the mantissa part in input_high.
232 Operand(1 << HeapNumber::kMantissaBitsInTopWord));
233 // Shift the mantissa bits to the correct position.
234 // We don't need to clear non-mantissa bits as they will be shifted away.
235 // If they weren't, it would mean that the answer is in the 32bit range.
236 __ sllv(input_high, input_high, scratch);
238 __ bind(&high_shift_done);
240 // Replace the shifted bits with bits from the lower mantissa word.
241 Label pos_shift, shift_done;
243 __ subu(scratch, at, scratch);
244 __ Branch(&pos_shift, ge, scratch, Operand(zero_reg));
247 __ Subu(scratch, zero_reg, scratch);
248 __ sllv(input_low, input_low, scratch);
249 __ Branch(&shift_done);
252 __ srlv(input_low, input_low, scratch);
254 __ bind(&shift_done);
255 __ Or(input_high, input_high, Operand(input_low));
256 // Restore sign if necessary.
257 __ mov(scratch, sign);
260 __ Subu(result_reg, zero_reg, input_high);
261 __ Movz(result_reg, input_high, scratch);
265 __ Pop(scratch, scratch2, scratch3);
270 // Handle the case where the lhs and rhs are the same object.
271 // Equality is almost reflexive (everything but NaN), so this is a test
272 // for "identity and not NaN".
273 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
274 Condition cc, Strength strength) {
276 Label heap_number, return_equal;
277 Register exp_mask_reg = t1;
279 __ Branch(¬_identical, ne, a0, Operand(a1));
281 __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask));
283 // Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
284 // so we do the second best thing - test it ourselves.
285 // They are both equal and they are not both Smis so both of them are not
286 // Smis. If it's not a heap number, then return equal.
287 __ GetObjectType(a0, t0, t0);
288 if (cc == less || cc == greater) {
289 // Call runtime on identical JSObjects.
290 __ Branch(slow, greater, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
291 // Call runtime on identical symbols since we need to throw a TypeError.
292 __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE));
293 // Call runtime on identical SIMD values since we must throw a TypeError.
294 __ Branch(slow, eq, t0, Operand(SIMD128_VALUE_TYPE));
295 if (is_strong(strength)) {
296 // Call the runtime on anything that is converted in the semantics, since
297 // we need to throw a TypeError. Smis have already been ruled out.
298 __ Branch(&return_equal, eq, t0, Operand(HEAP_NUMBER_TYPE));
299 __ And(t0, t0, Operand(kIsNotStringMask));
300 __ Branch(slow, ne, t0, Operand(zero_reg));
303 __ Branch(&heap_number, eq, t0, Operand(HEAP_NUMBER_TYPE));
304 // Comparing JS objects with <=, >= is complicated.
306 __ Branch(slow, greater, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
307 // Call runtime on identical symbols since we need to throw a TypeError.
308 __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE));
309 // Call runtime on identical SIMD values since we must throw a TypeError.
310 __ Branch(slow, eq, t0, Operand(SIMD128_VALUE_TYPE));
311 if (is_strong(strength)) {
312 // Call the runtime on anything that is converted in the semantics,
313 // since we need to throw a TypeError. Smis and heap numbers have
314 // already been ruled out.
315 __ And(t0, t0, Operand(kIsNotStringMask));
316 __ Branch(slow, ne, t0, Operand(zero_reg));
318 // Normally here we fall through to return_equal, but undefined is
319 // special: (undefined == undefined) == true, but
320 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
321 if (cc == less_equal || cc == greater_equal) {
322 __ Branch(&return_equal, ne, t0, Operand(ODDBALL_TYPE));
323 __ LoadRoot(a6, Heap::kUndefinedValueRootIndex);
324 __ Branch(&return_equal, ne, a0, Operand(a6));
325 DCHECK(is_int16(GREATER) && is_int16(LESS));
326 __ Ret(USE_DELAY_SLOT);
328 // undefined <= undefined should fail.
329 __ li(v0, Operand(GREATER));
331 // undefined >= undefined should fail.
332 __ li(v0, Operand(LESS));
338 __ bind(&return_equal);
339 DCHECK(is_int16(GREATER) && is_int16(LESS));
340 __ Ret(USE_DELAY_SLOT);
342 __ li(v0, Operand(GREATER)); // Things aren't less than themselves.
343 } else if (cc == greater) {
344 __ li(v0, Operand(LESS)); // Things aren't greater than themselves.
346 __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves.
348 // For less and greater we don't have to check for NaN since the result of
349 // x < x is false regardless. For the others here is some code to check
351 if (cc != lt && cc != gt) {
352 __ bind(&heap_number);
353 // It is a heap number, so return non-equal if it's NaN and equal if it's
356 // The representation of NaN values has all exponent bits (52..62) set,
357 // and not all mantissa bits (0..51) clear.
358 // Read top bits of double representation (second word of value).
359 __ lwu(a6, FieldMemOperand(a0, HeapNumber::kExponentOffset));
360 // Test that exponent bits are all set.
361 __ And(a7, a6, Operand(exp_mask_reg));
362 // If all bits not set (ne cond), then not a NaN, objects are equal.
363 __ Branch(&return_equal, ne, a7, Operand(exp_mask_reg));
365 // Shift out flag and all exponent bits, retaining only mantissa.
366 __ sll(a6, a6, HeapNumber::kNonMantissaBitsInTopWord);
367 // Or with all low-bits of mantissa.
368 __ lwu(a7, FieldMemOperand(a0, HeapNumber::kMantissaOffset));
369 __ Or(v0, a7, Operand(a6));
370 // For equal we already have the right value in v0: Return zero (equal)
371 // if all bits in mantissa are zero (it's an Infinity) and non-zero if
372 // not (it's a NaN). For <= and >= we need to load v0 with the failing
373 // value if it's a NaN.
375 // All-zero means Infinity means equal.
376 __ Ret(eq, v0, Operand(zero_reg));
377 DCHECK(is_int16(GREATER) && is_int16(LESS));
378 __ Ret(USE_DELAY_SLOT);
380 __ li(v0, Operand(GREATER)); // NaN <= NaN should fail.
382 __ li(v0, Operand(LESS)); // NaN >= NaN should fail.
386 // No fall through here.
388 __ bind(¬_identical);
392 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
395 Label* both_loaded_as_doubles,
398 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
399 (lhs.is(a1) && rhs.is(a0)));
402 __ JumpIfSmi(lhs, &lhs_is_smi);
404 // Check whether the non-smi is a heap number.
405 __ GetObjectType(lhs, t0, t0);
407 // If lhs was not a number and rhs was a Smi then strict equality cannot
408 // succeed. Return non-equal (lhs is already not zero).
409 __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE));
412 // Smi compared non-strictly with a non-Smi non-heap-number. Call
414 __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE));
416 // Rhs is a smi, lhs is a number.
417 // Convert smi rhs to double.
418 __ SmiUntag(at, rhs);
420 __ cvt_d_w(f14, f14);
421 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
423 // We now have both loaded as doubles.
424 __ jmp(both_loaded_as_doubles);
426 __ bind(&lhs_is_smi);
427 // Lhs is a Smi. Check whether the non-smi is a heap number.
428 __ GetObjectType(rhs, t0, t0);
430 // If lhs was not a number and rhs was a Smi then strict equality cannot
431 // succeed. Return non-equal.
432 __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE));
433 __ li(v0, Operand(1));
435 // Smi compared non-strictly with a non-Smi non-heap-number. Call
437 __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE));
440 // Lhs is a smi, rhs is a number.
441 // Convert smi lhs to double.
442 __ SmiUntag(at, lhs);
444 __ cvt_d_w(f12, f12);
445 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
446 // Fall through to both_loaded_as_doubles.
450 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
453 // If either operand is a JS object or an oddball value, then they are
454 // not equal since their pointers are different.
455 // There is no test for undetectability in strict equality.
456 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
457 Label first_non_object;
458 // Get the type of the first operand into a2 and compare it with
459 // FIRST_SPEC_OBJECT_TYPE.
460 __ GetObjectType(lhs, a2, a2);
461 __ Branch(&first_non_object, less, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
464 Label return_not_equal;
465 __ bind(&return_not_equal);
466 __ Ret(USE_DELAY_SLOT);
467 __ li(v0, Operand(1));
469 __ bind(&first_non_object);
470 // Check for oddballs: true, false, null, undefined.
471 __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE));
473 __ GetObjectType(rhs, a3, a3);
474 __ Branch(&return_not_equal, greater, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
476 // Check for oddballs: true, false, null, undefined.
477 __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE));
479 // Now that we have the types we might as well check for
480 // internalized-internalized.
481 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
482 __ Or(a2, a2, Operand(a3));
483 __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask));
484 __ Branch(&return_not_equal, eq, at, Operand(zero_reg));
488 static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm,
491 Label* both_loaded_as_doubles,
492 Label* not_heap_numbers,
494 __ GetObjectType(lhs, a3, a2);
495 __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE));
496 __ ld(a2, FieldMemOperand(rhs, HeapObject::kMapOffset));
497 // If first was a heap number & second wasn't, go to slow case.
498 __ Branch(slow, ne, a3, Operand(a2));
500 // Both are heap numbers. Load them up then jump to the code we have
502 __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset));
503 __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset));
505 __ jmp(both_loaded_as_doubles);
509 // Fast negative check for internalized-to-internalized equality.
510 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
513 Label* possible_strings,
514 Label* not_both_strings) {
515 DCHECK((lhs.is(a0) && rhs.is(a1)) ||
516 (lhs.is(a1) && rhs.is(a0)));
518 // a2 is object type of rhs.
520 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
521 __ And(at, a2, Operand(kIsNotStringMask));
522 __ Branch(&object_test, ne, at, Operand(zero_reg));
523 __ And(at, a2, Operand(kIsNotInternalizedMask));
524 __ Branch(possible_strings, ne, at, Operand(zero_reg));
525 __ GetObjectType(rhs, a3, a3);
526 __ Branch(not_both_strings, ge, a3, Operand(FIRST_NONSTRING_TYPE));
527 __ And(at, a3, Operand(kIsNotInternalizedMask));
528 __ Branch(possible_strings, ne, at, Operand(zero_reg));
530 // Both are internalized strings. We already checked they weren't the same
531 // pointer so they are not equal.
532 __ Ret(USE_DELAY_SLOT);
533 __ li(v0, Operand(1)); // Non-zero indicates not equal.
535 __ bind(&object_test);
536 __ Branch(not_both_strings, lt, a2, Operand(FIRST_SPEC_OBJECT_TYPE));
537 __ GetObjectType(rhs, a2, a3);
538 __ Branch(not_both_strings, lt, a3, Operand(FIRST_SPEC_OBJECT_TYPE));
540 // If both objects are undetectable, they are equal. Otherwise, they
541 // are not equal, since they are different objects and an object is not
542 // equal to undefined.
543 __ ld(a3, FieldMemOperand(lhs, HeapObject::kMapOffset));
544 __ lbu(a2, FieldMemOperand(a2, Map::kBitFieldOffset));
545 __ lbu(a3, FieldMemOperand(a3, Map::kBitFieldOffset));
547 __ And(a0, a0, Operand(1 << Map::kIsUndetectable));
548 __ Ret(USE_DELAY_SLOT);
549 __ xori(v0, a0, 1 << Map::kIsUndetectable);
553 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
555 CompareICState::State expected,
558 if (expected == CompareICState::SMI) {
559 __ JumpIfNotSmi(input, fail);
560 } else if (expected == CompareICState::NUMBER) {
561 __ JumpIfSmi(input, &ok);
562 __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
565 // We could be strict about internalized/string here, but as long as
566 // hydrogen doesn't care, the stub doesn't have to care either.
571 // On entry a1 and a2 are the values to be compared.
572 // On exit a0 is 0, positive or negative to indicate the result of
574 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
577 Condition cc = GetCondition();
580 CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss);
581 CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss);
583 Label slow; // Call builtin.
584 Label not_smis, both_loaded_as_doubles;
586 Label not_two_smis, smi_done;
588 __ JumpIfNotSmi(a2, ¬_two_smis);
592 __ Ret(USE_DELAY_SLOT);
593 __ dsubu(v0, a1, a0);
594 __ bind(¬_two_smis);
596 // NOTICE! This code is only reached after a smi-fast-case check, so
597 // it is certain that at least one operand isn't a smi.
599 // Handle the case where the objects are identical. Either returns the answer
600 // or goes to slow. Only falls through if the objects were not identical.
601 EmitIdenticalObjectComparison(masm, &slow, cc, strength());
603 // If either is a Smi (we know that not both are), then they can only
604 // be strictly equal if the other is a HeapNumber.
605 STATIC_ASSERT(kSmiTag == 0);
606 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
607 __ And(a6, lhs, Operand(rhs));
608 __ JumpIfNotSmi(a6, ¬_smis, a4);
609 // One operand is a smi. EmitSmiNonsmiComparison generates code that can:
610 // 1) Return the answer.
612 // 3) Fall through to both_loaded_as_doubles.
613 // 4) Jump to rhs_not_nan.
614 // In cases 3 and 4 we have found out we were dealing with a number-number
615 // comparison and the numbers have been loaded into f12 and f14 as doubles,
616 // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU.
617 EmitSmiNonsmiComparison(masm, lhs, rhs,
618 &both_loaded_as_doubles, &slow, strict());
620 __ bind(&both_loaded_as_doubles);
621 // f12, f14 are the double representations of the left hand side
622 // and the right hand side if we have FPU. Otherwise a2, a3 represent
623 // left hand side and a0, a1 represent right hand side.
626 __ li(a4, Operand(LESS));
627 __ li(a5, Operand(GREATER));
628 __ li(a6, Operand(EQUAL));
630 // Check if either rhs or lhs is NaN.
631 __ BranchF(NULL, &nan, eq, f12, f14);
633 // Check if LESS condition is satisfied. If true, move conditionally
635 if (kArchVariant != kMips64r6) {
636 __ c(OLT, D, f12, f14);
638 // Use previous check to store conditionally to v0 oposite condition
639 // (GREATER). If rhs is equal to lhs, this will be corrected in next
642 // Check if EQUAL condition is satisfied. If true, move conditionally
644 __ c(EQ, D, f12, f14);
648 __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14);
649 __ mov(v0, a4); // Return LESS as result.
651 __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14);
652 __ mov(v0, a6); // Return EQUAL as result.
654 __ mov(v0, a5); // Return GREATER as result.
660 // NaN comparisons always fail.
661 // Load whatever we need in v0 to make the comparison fail.
662 DCHECK(is_int16(GREATER) && is_int16(LESS));
663 __ Ret(USE_DELAY_SLOT);
664 if (cc == lt || cc == le) {
665 __ li(v0, Operand(GREATER));
667 __ li(v0, Operand(LESS));
672 // At this point we know we are dealing with two different objects,
673 // and neither of them is a Smi. The objects are in lhs_ and rhs_.
675 // This returns non-equal for some object types, or falls through if it
677 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
680 Label check_for_internalized_strings;
681 Label flat_string_check;
682 // Check for heap-number-heap-number comparison. Can jump to slow case,
683 // or load both doubles and jump to the code that handles
684 // that case. If the inputs are not doubles then jumps to
685 // check_for_internalized_strings.
686 // In this case a2 will contain the type of lhs_.
687 EmitCheckForTwoHeapNumbers(masm,
690 &both_loaded_as_doubles,
691 &check_for_internalized_strings,
694 __ bind(&check_for_internalized_strings);
695 if (cc == eq && !strict()) {
696 // Returns an answer for two internalized strings or two
697 // detectable objects.
698 // Otherwise jumps to string case or not both strings case.
699 // Assumes that a2 is the type of lhs_ on entry.
700 EmitCheckForInternalizedStringsOrObjects(
701 masm, lhs, rhs, &flat_string_check, &slow);
704 // Check for both being sequential one-byte strings,
705 // and inline if that is the case.
706 __ bind(&flat_string_check);
708 __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow);
710 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
713 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, a4);
715 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, a4,
718 // Never falls through to here.
721 // Prepare for call to builtin. Push object pointers, a0 (lhs) first,
724 // Figure out which native to call and setup the arguments.
726 __ TailCallRuntime(strict() ? Runtime::kStrictEquals : Runtime::kEquals, 2,
729 int ncr; // NaN compare result.
730 if (cc == lt || cc == le) {
733 DCHECK(cc == gt || cc == ge); // Remaining cases.
736 __ li(a0, Operand(Smi::FromInt(ncr)));
739 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
740 // tagged as a small integer.
742 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3,
751 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
754 __ PushSafepointRegisters();
759 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
762 __ PopSafepointRegisters();
767 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
768 // We don't allow a GC during a store buffer overflow so there is no need to
769 // store the registers in any particular way, but we do have to store and
771 __ MultiPush(kJSCallerSaved | ra.bit());
772 if (save_doubles()) {
773 __ MultiPushFPU(kCallerSavedFPU);
775 const int argument_count = 1;
776 const int fp_argument_count = 0;
777 const Register scratch = a1;
779 AllowExternalCallThatCantCauseGC scope(masm);
780 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
781 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
783 ExternalReference::store_buffer_overflow_function(isolate()),
785 if (save_doubles()) {
786 __ MultiPopFPU(kCallerSavedFPU);
789 __ MultiPop(kJSCallerSaved | ra.bit());
794 void MathPowStub::Generate(MacroAssembler* masm) {
795 const Register base = a1;
796 const Register exponent = MathPowTaggedDescriptor::exponent();
797 DCHECK(exponent.is(a2));
798 const Register heapnumbermap = a5;
799 const Register heapnumber = v0;
800 const DoubleRegister double_base = f2;
801 const DoubleRegister double_exponent = f4;
802 const DoubleRegister double_result = f0;
803 const DoubleRegister double_scratch = f6;
804 const FPURegister single_scratch = f8;
805 const Register scratch = t1;
806 const Register scratch2 = a7;
808 Label call_runtime, done, int_exponent;
809 if (exponent_type() == ON_STACK) {
810 Label base_is_smi, unpack_exponent;
811 // The exponent and base are supplied as arguments on the stack.
812 // This can only happen if the stub is called from non-optimized code.
813 // Load input parameters from stack to double registers.
814 __ ld(base, MemOperand(sp, 1 * kPointerSize));
815 __ ld(exponent, MemOperand(sp, 0 * kPointerSize));
817 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
819 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
820 __ ld(scratch, FieldMemOperand(base, JSObject::kMapOffset));
821 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
823 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
824 __ jmp(&unpack_exponent);
826 __ bind(&base_is_smi);
827 __ mtc1(scratch, single_scratch);
828 __ cvt_d_w(double_base, single_scratch);
829 __ bind(&unpack_exponent);
831 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
833 __ ld(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
834 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
835 __ ldc1(double_exponent,
836 FieldMemOperand(exponent, HeapNumber::kValueOffset));
837 } else if (exponent_type() == TAGGED) {
838 // Base is already in double_base.
839 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
841 __ ldc1(double_exponent,
842 FieldMemOperand(exponent, HeapNumber::kValueOffset));
845 if (exponent_type() != INTEGER) {
846 Label int_exponent_convert;
847 // Detect integer exponents stored as double.
848 __ EmitFPUTruncate(kRoundToMinusInf,
854 kCheckForInexactConversion);
855 // scratch2 == 0 means there was no conversion error.
856 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
858 if (exponent_type() == ON_STACK) {
859 // Detect square root case. Crankshaft detects constant +/-0.5 at
860 // compile time and uses DoMathPowHalf instead. We then skip this check
861 // for non-constant cases of +/-0.5 as these hardly occur.
865 __ Move(double_scratch, 0.5);
866 __ BranchF(USE_DELAY_SLOT,
872 // double_scratch can be overwritten in the delay slot.
873 // Calculates square root of base. Check for the special case of
874 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
875 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
876 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
877 __ neg_d(double_result, double_scratch);
879 // Add +0 to convert -0 to +0.
880 __ add_d(double_scratch, double_base, kDoubleRegZero);
881 __ sqrt_d(double_result, double_scratch);
884 __ bind(¬_plus_half);
885 __ Move(double_scratch, -0.5);
886 __ BranchF(USE_DELAY_SLOT,
892 // double_scratch can be overwritten in the delay slot.
893 // Calculates square root of base. Check for the special case of
894 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
895 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
896 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
897 __ Move(double_result, kDoubleRegZero);
899 // Add +0 to convert -0 to +0.
900 __ add_d(double_scratch, double_base, kDoubleRegZero);
901 __ Move(double_result, 1.);
902 __ sqrt_d(double_scratch, double_scratch);
903 __ div_d(double_result, double_result, double_scratch);
909 AllowExternalCallThatCantCauseGC scope(masm);
910 __ PrepareCallCFunction(0, 2, scratch2);
911 __ MovToFloatParameters(double_base, double_exponent);
913 ExternalReference::power_double_double_function(isolate()),
917 __ MovFromFloatResult(double_result);
920 __ bind(&int_exponent_convert);
923 // Calculate power with integer exponent.
924 __ bind(&int_exponent);
926 // Get two copies of exponent in the registers scratch and exponent.
927 if (exponent_type() == INTEGER) {
928 __ mov(scratch, exponent);
930 // Exponent has previously been stored into scratch as untagged integer.
931 __ mov(exponent, scratch);
934 __ mov_d(double_scratch, double_base); // Back up base.
935 __ Move(double_result, 1.0);
937 // Get absolute value of exponent.
938 Label positive_exponent;
939 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
940 __ Dsubu(scratch, zero_reg, scratch);
941 __ bind(&positive_exponent);
943 Label while_true, no_carry, loop_end;
944 __ bind(&while_true);
946 __ And(scratch2, scratch, 1);
948 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
949 __ mul_d(double_result, double_result, double_scratch);
952 __ dsra(scratch, scratch, 1);
954 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
955 __ mul_d(double_scratch, double_scratch, double_scratch);
957 __ Branch(&while_true);
961 __ Branch(&done, ge, exponent, Operand(zero_reg));
962 __ Move(double_scratch, 1.0);
963 __ div_d(double_result, double_scratch, double_result);
964 // Test whether result is zero. Bail out to check for subnormal result.
965 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
966 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
968 // double_exponent may not contain the exponent value if the input was a
969 // smi. We set it with exponent value before bailing out.
970 __ mtc1(exponent, single_scratch);
971 __ cvt_d_w(double_exponent, single_scratch);
973 // Returning or bailing out.
974 Counters* counters = isolate()->counters();
975 if (exponent_type() == ON_STACK) {
976 // The arguments are still on the stack.
977 __ bind(&call_runtime);
978 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
980 // The stub is called from non-optimized code, which expects the result
981 // as heap number in exponent.
983 __ AllocateHeapNumber(
984 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
985 __ sdc1(double_result,
986 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
987 DCHECK(heapnumber.is(v0));
988 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
993 AllowExternalCallThatCantCauseGC scope(masm);
994 __ PrepareCallCFunction(0, 2, scratch);
995 __ MovToFloatParameters(double_base, double_exponent);
997 ExternalReference::power_double_double_function(isolate()),
1001 __ MovFromFloatResult(double_result);
1004 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1010 bool CEntryStub::NeedsImmovableCode() {
1015 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1016 CEntryStub::GenerateAheadOfTime(isolate);
1017 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1018 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1019 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1020 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1021 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1022 BinaryOpICStub::GenerateAheadOfTime(isolate);
1023 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1024 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1025 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1026 StoreFastElementStub::GenerateAheadOfTime(isolate);
1027 TypeofStub::GenerateAheadOfTime(isolate);
1031 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1032 StoreRegistersStateStub stub(isolate);
1037 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1038 RestoreRegistersStateStub stub(isolate);
1043 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1044 // Generate if not already in cache.
1045 SaveFPRegsMode mode = kSaveFPRegs;
1046 CEntryStub(isolate, 1, mode).GetCode();
1047 StoreBufferOverflowStub(isolate, mode).GetCode();
1048 isolate->set_fp_stubs_generated(true);
1052 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1053 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1058 void CEntryStub::Generate(MacroAssembler* masm) {
1059 // Called from JavaScript; parameters are on stack as if calling JS function
1060 // a0: number of arguments including receiver
1061 // a1: pointer to builtin function
1062 // fp: frame pointer (restored after C call)
1063 // sp: stack pointer (restored as callee's sp after C call)
1064 // cp: current context (C callee-saved)
1066 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1068 // Compute the argv pointer in a callee-saved register.
1069 __ dsll(s1, a0, kPointerSizeLog2);
1070 __ Daddu(s1, sp, s1);
1071 __ Dsubu(s1, s1, kPointerSize);
1073 // Enter the exit frame that transitions from JavaScript to C++.
1074 FrameScope scope(masm, StackFrame::MANUAL);
1075 __ EnterExitFrame(save_doubles());
1077 // s0: number of arguments including receiver (C callee-saved)
1078 // s1: pointer to first argument (C callee-saved)
1079 // s2: pointer to builtin function (C callee-saved)
1081 // Prepare arguments for C routine.
1085 // a1 = argv (set in the delay slot after find_ra below).
1087 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1088 // also need to reserve the 4 argument slots on the stack.
1090 __ AssertStackIsAligned();
1092 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1094 // To let the GC traverse the return address of the exit frames, we need to
1095 // know where the return address is. The CEntryStub is unmovable, so
1096 // we can store the address on the stack to be able to find it again and
1097 // we never have to restore it, because it will not change.
1098 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1099 // This branch-and-link sequence is needed to find the current PC on mips,
1100 // saved to the ra register.
1101 // Use masm-> here instead of the double-underscore macro since extra
1102 // coverage code can interfere with the proper calculation of ra.
1104 masm->bal(&find_ra); // bal exposes branch delay slot.
1106 masm->bind(&find_ra);
1108 // Adjust the value in ra to point to the correct return location, 2nd
1109 // instruction past the real call into C code (the jalr(t9)), and push it.
1110 // This is the return address of the exit frame.
1111 const int kNumInstructionsToJump = 5;
1112 masm->Daddu(ra, ra, kNumInstructionsToJump * kInt32Size);
1113 masm->sd(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1114 // Stack space reservation moved to the branch delay slot below.
1115 // Stack is still aligned.
1117 // Call the C routine.
1118 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1120 // Set up sp in the delay slot.
1121 masm->daddiu(sp, sp, -kCArgsSlotsSize);
1122 // Make sure the stored 'ra' points to this position.
1123 DCHECK_EQ(kNumInstructionsToJump,
1124 masm->InstructionsGeneratedSince(&find_ra));
1127 // Check result for exception sentinel.
1128 Label exception_returned;
1129 __ LoadRoot(a4, Heap::kExceptionRootIndex);
1130 __ Branch(&exception_returned, eq, a4, Operand(v0));
1132 // Check that there is no pending exception, otherwise we
1133 // should have returned the exception sentinel.
1134 if (FLAG_debug_code) {
1136 ExternalReference pending_exception_address(
1137 Isolate::kPendingExceptionAddress, isolate());
1138 __ li(a2, Operand(pending_exception_address));
1139 __ ld(a2, MemOperand(a2));
1140 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
1141 // Cannot use check here as it attempts to generate call into runtime.
1142 __ Branch(&okay, eq, a4, Operand(a2));
1143 __ stop("Unexpected pending exception");
1147 // Exit C frame and return.
1149 // sp: stack pointer
1150 // fp: frame pointer
1151 // s0: still holds argc (callee-saved).
1152 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1154 // Handling of exception.
1155 __ bind(&exception_returned);
1157 ExternalReference pending_handler_context_address(
1158 Isolate::kPendingHandlerContextAddress, isolate());
1159 ExternalReference pending_handler_code_address(
1160 Isolate::kPendingHandlerCodeAddress, isolate());
1161 ExternalReference pending_handler_offset_address(
1162 Isolate::kPendingHandlerOffsetAddress, isolate());
1163 ExternalReference pending_handler_fp_address(
1164 Isolate::kPendingHandlerFPAddress, isolate());
1165 ExternalReference pending_handler_sp_address(
1166 Isolate::kPendingHandlerSPAddress, isolate());
1168 // Ask the runtime for help to determine the handler. This will set v0 to
1169 // contain the current pending exception, don't clobber it.
1170 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1173 FrameScope scope(masm, StackFrame::MANUAL);
1174 __ PrepareCallCFunction(3, 0, a0);
1175 __ mov(a0, zero_reg);
1176 __ mov(a1, zero_reg);
1177 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1178 __ CallCFunction(find_handler, 3);
1181 // Retrieve the handler context, SP and FP.
1182 __ li(cp, Operand(pending_handler_context_address));
1183 __ ld(cp, MemOperand(cp));
1184 __ li(sp, Operand(pending_handler_sp_address));
1185 __ ld(sp, MemOperand(sp));
1186 __ li(fp, Operand(pending_handler_fp_address));
1187 __ ld(fp, MemOperand(fp));
1189 // If the handler is a JS frame, restore the context to the frame. Note that
1190 // the context will be set to (cp == 0) for non-JS frames.
1192 __ Branch(&zero, eq, cp, Operand(zero_reg));
1193 __ sd(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1196 // Compute the handler entry address and jump to it.
1197 __ li(a1, Operand(pending_handler_code_address));
1198 __ ld(a1, MemOperand(a1));
1199 __ li(a2, Operand(pending_handler_offset_address));
1200 __ ld(a2, MemOperand(a2));
1201 __ Daddu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1202 __ Daddu(t9, a1, a2);
1207 void JSEntryStub::Generate(MacroAssembler* masm) {
1208 Label invoke, handler_entry, exit;
1209 Isolate* isolate = masm->isolate();
1211 // TODO(plind): unify the ABI description here.
1213 // a0: entry address
1217 // a4 (a4): on mips64
1220 // 0 arg slots on mips64 (4 args slots on mips)
1221 // args -- in a4/a4 on mips64, on stack on mips
1223 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1225 // Save callee saved registers on the stack.
1226 __ MultiPush(kCalleeSaved | ra.bit());
1228 // Save callee-saved FPU registers.
1229 __ MultiPushFPU(kCalleeSavedFPU);
1230 // Set up the reserved register for 0.0.
1231 __ Move(kDoubleRegZero, 0.0);
1233 // Load argv in s0 register.
1234 if (kMipsAbi == kN64) {
1235 __ mov(s0, a4); // 5th parameter in mips64 a4 (a4) register.
1236 } else { // Abi O32.
1237 // 5th parameter on stack for O32 abi.
1238 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1239 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1240 __ ld(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1243 __ InitializeRootRegister();
1245 // We build an EntryFrame.
1246 __ li(a7, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1247 int marker = type();
1248 __ li(a6, Operand(Smi::FromInt(marker)));
1249 __ li(a5, Operand(Smi::FromInt(marker)));
1250 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate);
1251 __ li(a4, Operand(c_entry_fp));
1252 __ ld(a4, MemOperand(a4));
1253 __ Push(a7, a6, a5, a4);
1254 // Set up frame pointer for the frame to be pushed.
1255 __ daddiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1258 // a0: entry_address
1260 // a2: receiver_pointer
1266 // function slot | entry frame
1268 // bad fp (0xff...f) |
1269 // callee saved registers + ra
1270 // [ O32: 4 args slots]
1273 // If this is the outermost JS call, set js_entry_sp value.
1274 Label non_outermost_js;
1275 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1276 __ li(a5, Operand(ExternalReference(js_entry_sp)));
1277 __ ld(a6, MemOperand(a5));
1278 __ Branch(&non_outermost_js, ne, a6, Operand(zero_reg));
1279 __ sd(fp, MemOperand(a5));
1280 __ li(a4, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1283 __ nop(); // Branch delay slot nop.
1284 __ bind(&non_outermost_js);
1285 __ li(a4, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1289 // Jump to a faked try block that does the invoke, with a faked catch
1290 // block that sets the pending exception.
1292 __ bind(&handler_entry);
1293 handler_offset_ = handler_entry.pos();
1294 // Caught exception: Store result (exception) in the pending exception
1295 // field in the JSEnv and return a failure sentinel. Coming in here the
1296 // fp will be invalid because the PushStackHandler below sets it to 0 to
1297 // signal the existence of the JSEntry frame.
1298 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1300 __ sd(v0, MemOperand(a4)); // We come back from 'invoke'. result is in v0.
1301 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1302 __ b(&exit); // b exposes branch delay slot.
1303 __ nop(); // Branch delay slot nop.
1305 // Invoke: Link this frame into the handler chain.
1307 __ PushStackHandler();
1308 // If an exception not caught by another handler occurs, this handler
1309 // returns control to the code after the bal(&invoke) above, which
1310 // restores all kCalleeSaved registers (including cp and fp) to their
1311 // saved values before returning a failure to C.
1313 // Clear any pending exceptions.
1314 __ LoadRoot(a5, Heap::kTheHoleValueRootIndex);
1315 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1317 __ sd(a5, MemOperand(a4));
1319 // Invoke the function by calling through JS entry trampoline builtin.
1320 // Notice that we cannot store a reference to the trampoline code directly in
1321 // this stub, because runtime stubs are not traversed when doing GC.
1324 // a0: entry_address
1326 // a2: receiver_pointer
1333 // callee saved registers + ra
1334 // [ O32: 4 args slots]
1337 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1338 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1340 __ li(a4, Operand(construct_entry));
1342 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1343 __ li(a4, Operand(entry));
1345 __ ld(t9, MemOperand(a4)); // Deref address.
1346 // Call JSEntryTrampoline.
1347 __ daddiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1350 // Unlink this frame from the handler chain.
1351 __ PopStackHandler();
1353 __ bind(&exit); // v0 holds result
1354 // Check if the current stack frame is marked as the outermost JS frame.
1355 Label non_outermost_js_2;
1357 __ Branch(&non_outermost_js_2,
1360 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1361 __ li(a5, Operand(ExternalReference(js_entry_sp)));
1362 __ sd(zero_reg, MemOperand(a5));
1363 __ bind(&non_outermost_js_2);
1365 // Restore the top frame descriptors from the stack.
1367 __ li(a4, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1369 __ sd(a5, MemOperand(a4));
1371 // Reset the stack to the callee saved registers.
1372 __ daddiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1374 // Restore callee-saved fpu registers.
1375 __ MultiPopFPU(kCalleeSavedFPU);
1377 // Restore callee saved registers from the stack.
1378 __ MultiPop(kCalleeSaved | ra.bit());
1384 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1385 // Return address is in ra.
1388 Register receiver = LoadDescriptor::ReceiverRegister();
1389 Register index = LoadDescriptor::NameRegister();
1390 Register scratch = a5;
1391 Register result = v0;
1392 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1393 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1395 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1396 &miss, // When not a string.
1397 &miss, // When not a number.
1398 &miss, // When index out of range.
1399 STRING_INDEX_IS_ARRAY_INDEX,
1400 RECEIVER_IS_STRING);
1401 char_at_generator.GenerateFast(masm);
1404 StubRuntimeCallHelper call_helper;
1405 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1408 PropertyAccessCompiler::TailCallBuiltin(
1409 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1413 void InstanceOfStub::Generate(MacroAssembler* masm) {
1414 Register const object = a1; // Object (lhs).
1415 Register const function = a0; // Function (rhs).
1416 Register const object_map = a2; // Map of {object}.
1417 Register const function_map = a3; // Map of {function}.
1418 Register const function_prototype = a4; // Prototype of {function}.
1419 Register const scratch = a5;
1421 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1422 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1424 // Check if {object} is a smi.
1425 Label object_is_smi;
1426 __ JumpIfSmi(object, &object_is_smi);
1428 // Lookup the {function} and the {object} map in the global instanceof cache.
1429 // Note: This is safe because we clear the global instanceof cache whenever
1430 // we change the prototype of any object.
1431 Label fast_case, slow_case;
1432 __ ld(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1433 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1434 __ Branch(&fast_case, ne, function, Operand(at));
1435 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1436 __ Branch(&fast_case, ne, object_map, Operand(at));
1437 __ Ret(USE_DELAY_SLOT);
1438 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1440 // If {object} is a smi we can safely return false if {function} is a JS
1441 // function, otherwise we have to miss to the runtime and throw an exception.
1442 __ bind(&object_is_smi);
1443 __ JumpIfSmi(function, &slow_case);
1444 __ GetObjectType(function, function_map, scratch);
1445 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1446 __ Ret(USE_DELAY_SLOT);
1447 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
1449 // Fast-case: The {function} must be a valid JSFunction.
1450 __ bind(&fast_case);
1451 __ JumpIfSmi(function, &slow_case);
1452 __ GetObjectType(function, function_map, scratch);
1453 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1455 // Ensure that {function} has an instance prototype.
1456 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1457 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1458 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1460 // Ensure that {function} is not bound.
1461 Register const shared_info = scratch;
1463 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1465 FieldMemOperand(shared_info, SharedFunctionInfo::kBoundByteOffset));
1466 __ And(at, scratch, Operand(1 << SharedFunctionInfo::kBoundBitWithinByte));
1467 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1469 // Get the "prototype" (or initial map) of the {function}.
1470 __ ld(function_prototype,
1471 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1472 __ AssertNotSmi(function_prototype);
1474 // Resolve the prototype if the {function} has an initial map. Afterwards the
1475 // {function_prototype} will be either the JSReceiver prototype object or the
1476 // hole value, which means that no instances of the {function} were created so
1477 // far and hence we should return false.
1478 Label function_prototype_valid;
1479 __ GetObjectType(function_prototype, scratch, scratch);
1480 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1481 __ ld(function_prototype,
1482 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1483 __ bind(&function_prototype_valid);
1484 __ AssertNotSmi(function_prototype);
1486 // Update the global instanceof cache with the current {object} map and
1487 // {function}. The cached answer will be set when it is known below.
1488 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1489 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1491 // Loop through the prototype chain looking for the {function} prototype.
1492 // Assume true, and change to false if not found.
1493 Register const object_prototype = object_map;
1494 Register const null = scratch;
1496 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1497 __ LoadRoot(null, Heap::kNullValueRootIndex);
1499 __ ld(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1500 __ Branch(&done, eq, object_prototype, Operand(function_prototype));
1501 __ Branch(USE_DELAY_SLOT, &loop, ne, object_prototype, Operand(null));
1502 __ ld(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1503 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1505 __ Ret(USE_DELAY_SLOT);
1506 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1508 // Slow-case: Call the runtime function.
1509 __ bind(&slow_case);
1510 __ Push(object, function);
1511 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1515 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1517 Register receiver = LoadDescriptor::ReceiverRegister();
1518 // Ensure that the vector and slot registers won't be clobbered before
1519 // calling the miss handler.
1520 DCHECK(!AreAliased(a4, a5, LoadWithVectorDescriptor::VectorRegister(),
1521 LoadWithVectorDescriptor::SlotRegister()));
1523 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, a4,
1526 PropertyAccessCompiler::TailCallBuiltin(
1527 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1531 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1532 // The displacement is the offset of the last parameter (if any)
1533 // relative to the frame pointer.
1534 const int kDisplacement =
1535 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1536 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1537 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1539 // Check that the key is a smiGenerateReadElement.
1541 __ JumpIfNotSmi(a1, &slow);
1543 // Check if the calling frame is an arguments adaptor frame.
1545 __ ld(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1546 __ ld(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1550 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1552 // Check index (a1) against formal parameters count limit passed in
1553 // through register a0. Use unsigned comparison to get negative
1555 __ Branch(&slow, hs, a1, Operand(a0));
1557 // Read the argument from the stack and return it.
1558 __ dsubu(a3, a0, a1);
1559 __ SmiScale(a7, a3, kPointerSizeLog2);
1560 __ Daddu(a3, fp, Operand(a7));
1561 __ Ret(USE_DELAY_SLOT);
1562 __ ld(v0, MemOperand(a3, kDisplacement));
1564 // Arguments adaptor case: Check index (a1) against actual arguments
1565 // limit found in the arguments adaptor frame. Use unsigned
1566 // comparison to get negative check for free.
1568 __ ld(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1569 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1571 // Read the argument from the adaptor frame and return it.
1572 __ dsubu(a3, a0, a1);
1573 __ SmiScale(a7, a3, kPointerSizeLog2);
1574 __ Daddu(a3, a2, Operand(a7));
1575 __ Ret(USE_DELAY_SLOT);
1576 __ ld(v0, MemOperand(a3, kDisplacement));
1578 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1579 // by calling the runtime system.
1582 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1586 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1587 // sp[0] : number of parameters
1588 // sp[4] : receiver displacement
1591 // Check if the calling frame is an arguments adaptor frame.
1593 __ ld(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1594 __ ld(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1598 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1600 // Patch the arguments.length and the parameters pointer in the current frame.
1601 __ ld(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1602 __ sd(a2, MemOperand(sp, 0 * kPointerSize));
1603 __ SmiScale(a7, a2, kPointerSizeLog2);
1604 __ Daddu(a3, a3, Operand(a7));
1605 __ daddiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1606 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1609 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1613 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1615 // sp[0] : number of parameters (tagged)
1616 // sp[4] : address of receiver argument
1618 // Registers used over whole function:
1619 // a6 : allocated object (tagged)
1620 // t1 : mapped parameter count (tagged)
1622 __ ld(a1, MemOperand(sp, 0 * kPointerSize));
1623 // a1 = parameter count (tagged)
1625 // Check if the calling frame is an arguments adaptor frame.
1627 Label adaptor_frame, try_allocate;
1628 __ ld(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1629 __ ld(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1630 __ Branch(&adaptor_frame,
1633 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1635 // No adaptor, parameter count = argument count.
1637 __ Branch(&try_allocate);
1639 // We have an adaptor frame. Patch the parameters pointer.
1640 __ bind(&adaptor_frame);
1641 __ ld(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1642 __ SmiScale(t2, a2, kPointerSizeLog2);
1643 __ Daddu(a3, a3, Operand(t2));
1644 __ Daddu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1645 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1647 // a1 = parameter count (tagged)
1648 // a2 = argument count (tagged)
1649 // Compute the mapped parameter count = min(a1, a2) in a1.
1651 __ Branch(&skip_min, lt, a1, Operand(a2));
1655 __ bind(&try_allocate);
1657 // Compute the sizes of backing store, parameter map, and arguments object.
1658 // 1. Parameter map, has 2 extra words containing context and backing store.
1659 const int kParameterMapHeaderSize =
1660 FixedArray::kHeaderSize + 2 * kPointerSize;
1661 // If there are no mapped parameters, we do not need the parameter_map.
1662 Label param_map_size;
1663 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1664 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1665 __ mov(t1, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1666 __ SmiScale(t1, a1, kPointerSizeLog2);
1667 __ daddiu(t1, t1, kParameterMapHeaderSize);
1668 __ bind(¶m_map_size);
1670 // 2. Backing store.
1671 __ SmiScale(t2, a2, kPointerSizeLog2);
1672 __ Daddu(t1, t1, Operand(t2));
1673 __ Daddu(t1, t1, Operand(FixedArray::kHeaderSize));
1675 // 3. Arguments object.
1676 __ Daddu(t1, t1, Operand(Heap::kSloppyArgumentsObjectSize));
1678 // Do the allocation of all three objects in one go.
1679 __ Allocate(t1, v0, a3, a4, &runtime, TAG_OBJECT);
1681 // v0 = address of new object(s) (tagged)
1682 // a2 = argument count (smi-tagged)
1683 // Get the arguments boilerplate from the current native context into a4.
1684 const int kNormalOffset =
1685 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1686 const int kAliasedOffset =
1687 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1689 __ ld(a4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1690 __ ld(a4, FieldMemOperand(a4, GlobalObject::kNativeContextOffset));
1691 Label skip2_ne, skip2_eq;
1692 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1693 __ ld(a4, MemOperand(a4, kNormalOffset));
1696 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1697 __ ld(a4, MemOperand(a4, kAliasedOffset));
1700 // v0 = address of new object (tagged)
1701 // a1 = mapped parameter count (tagged)
1702 // a2 = argument count (smi-tagged)
1703 // a4 = address of arguments map (tagged)
1704 __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset));
1705 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1706 __ sd(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1707 __ sd(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1709 // Set up the callee in-object property.
1710 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1711 __ ld(a3, MemOperand(sp, 2 * kPointerSize));
1712 __ AssertNotSmi(a3);
1713 const int kCalleeOffset = JSObject::kHeaderSize +
1714 Heap::kArgumentsCalleeIndex * kPointerSize;
1715 __ sd(a3, FieldMemOperand(v0, kCalleeOffset));
1717 // Use the length (smi tagged) and set that as an in-object property too.
1718 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1719 const int kLengthOffset = JSObject::kHeaderSize +
1720 Heap::kArgumentsLengthIndex * kPointerSize;
1721 __ sd(a2, FieldMemOperand(v0, kLengthOffset));
1723 // Set up the elements pointer in the allocated arguments object.
1724 // If we allocated a parameter map, a4 will point there, otherwise
1725 // it will point to the backing store.
1726 __ Daddu(a4, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1727 __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset));
1729 // v0 = address of new object (tagged)
1730 // a1 = mapped parameter count (tagged)
1731 // a2 = argument count (tagged)
1732 // a4 = address of parameter map or backing store (tagged)
1733 // Initialize parameter map. If there are no mapped arguments, we're done.
1734 Label skip_parameter_map;
1736 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1737 // Move backing store address to a3, because it is
1738 // expected there when filling in the unmapped arguments.
1742 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1744 __ LoadRoot(a6, Heap::kSloppyArgumentsElementsMapRootIndex);
1745 __ sd(a6, FieldMemOperand(a4, FixedArray::kMapOffset));
1746 __ Daddu(a6, a1, Operand(Smi::FromInt(2)));
1747 __ sd(a6, FieldMemOperand(a4, FixedArray::kLengthOffset));
1748 __ sd(cp, FieldMemOperand(a4, FixedArray::kHeaderSize + 0 * kPointerSize));
1749 __ SmiScale(t2, a1, kPointerSizeLog2);
1750 __ Daddu(a6, a4, Operand(t2));
1751 __ Daddu(a6, a6, Operand(kParameterMapHeaderSize));
1752 __ sd(a6, FieldMemOperand(a4, FixedArray::kHeaderSize + 1 * kPointerSize));
1754 // Copy the parameter slots and the holes in the arguments.
1755 // We need to fill in mapped_parameter_count slots. They index the context,
1756 // where parameters are stored in reverse order, at
1757 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1758 // The mapped parameter thus need to get indices
1759 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1760 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1761 // We loop from right to left.
1762 Label parameters_loop, parameters_test;
1764 __ ld(t1, MemOperand(sp, 0 * kPointerSize));
1765 __ Daddu(t1, t1, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1766 __ Dsubu(t1, t1, Operand(a1));
1767 __ LoadRoot(a7, Heap::kTheHoleValueRootIndex);
1768 __ SmiScale(t2, a6, kPointerSizeLog2);
1769 __ Daddu(a3, a4, Operand(t2));
1770 __ Daddu(a3, a3, Operand(kParameterMapHeaderSize));
1772 // a6 = loop variable (tagged)
1773 // a1 = mapping index (tagged)
1774 // a3 = address of backing store (tagged)
1775 // a4 = address of parameter map (tagged)
1776 // a5 = temporary scratch (a.o., for address calculation)
1777 // a7 = the hole value
1778 __ jmp(¶meters_test);
1780 __ bind(¶meters_loop);
1782 __ Dsubu(a6, a6, Operand(Smi::FromInt(1)));
1783 __ SmiScale(a5, a6, kPointerSizeLog2);
1784 __ Daddu(a5, a5, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1785 __ Daddu(t2, a4, a5);
1786 __ sd(t1, MemOperand(t2));
1787 __ Dsubu(a5, a5, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1788 __ Daddu(t2, a3, a5);
1789 __ sd(a7, MemOperand(t2));
1790 __ Daddu(t1, t1, Operand(Smi::FromInt(1)));
1791 __ bind(¶meters_test);
1792 __ Branch(¶meters_loop, ne, a6, Operand(Smi::FromInt(0)));
1794 __ bind(&skip_parameter_map);
1795 // a2 = argument count (tagged)
1796 // a3 = address of backing store (tagged)
1798 // Copy arguments header and remaining slots (if there are any).
1799 __ LoadRoot(a5, Heap::kFixedArrayMapRootIndex);
1800 __ sd(a5, FieldMemOperand(a3, FixedArray::kMapOffset));
1801 __ sd(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1803 Label arguments_loop, arguments_test;
1805 __ ld(a4, MemOperand(sp, 1 * kPointerSize));
1806 __ SmiScale(t2, t1, kPointerSizeLog2);
1807 __ Dsubu(a4, a4, Operand(t2));
1808 __ jmp(&arguments_test);
1810 __ bind(&arguments_loop);
1811 __ Dsubu(a4, a4, Operand(kPointerSize));
1812 __ ld(a6, MemOperand(a4, 0));
1813 __ SmiScale(t2, t1, kPointerSizeLog2);
1814 __ Daddu(a5, a3, Operand(t2));
1815 __ sd(a6, FieldMemOperand(a5, FixedArray::kHeaderSize));
1816 __ Daddu(t1, t1, Operand(Smi::FromInt(1)));
1818 __ bind(&arguments_test);
1819 __ Branch(&arguments_loop, lt, t1, Operand(a2));
1821 // Return and remove the on-stack parameters.
1824 // Do the runtime call to allocate the arguments object.
1825 // a2 = argument count (tagged)
1827 __ sd(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1828 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1832 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1833 // Return address is in ra.
1836 Register receiver = LoadDescriptor::ReceiverRegister();
1837 Register key = LoadDescriptor::NameRegister();
1839 // Check that the key is an array index, that is Uint32.
1840 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1841 __ Branch(&slow, ne, t0, Operand(zero_reg));
1843 // Everything is fine, call runtime.
1844 __ Push(receiver, key); // Receiver, key.
1846 // Perform tail call to the entry.
1847 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1850 PropertyAccessCompiler::TailCallBuiltin(
1851 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1855 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1856 // sp[0] : number of parameters
1857 // sp[4] : receiver displacement
1859 // Check if the calling frame is an arguments adaptor frame.
1860 Label adaptor_frame, try_allocate, runtime;
1861 __ ld(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1862 __ ld(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1863 __ Branch(&adaptor_frame,
1866 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1868 // Get the length from the frame.
1869 __ ld(a1, MemOperand(sp, 0));
1870 __ Branch(&try_allocate);
1872 // Patch the arguments.length and the parameters pointer.
1873 __ bind(&adaptor_frame);
1874 __ ld(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1875 __ sd(a1, MemOperand(sp, 0));
1876 __ SmiScale(at, a1, kPointerSizeLog2);
1878 __ Daddu(a3, a2, Operand(at));
1880 __ Daddu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1881 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1883 // Try the new space allocation. Start out with computing the size
1884 // of the arguments object and the elements array in words.
1885 Label add_arguments_object;
1886 __ bind(&try_allocate);
1887 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1890 __ Daddu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1891 __ bind(&add_arguments_object);
1892 __ Daddu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1894 // Do the allocation of both objects in one go.
1895 __ Allocate(a1, v0, a2, a3, &runtime,
1896 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1898 // Get the arguments boilerplate from the current native context.
1899 __ ld(a4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1900 __ ld(a4, FieldMemOperand(a4, GlobalObject::kNativeContextOffset));
1901 __ ld(a4, MemOperand(a4, Context::SlotOffset(
1902 Context::STRICT_ARGUMENTS_MAP_INDEX)));
1904 __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset));
1905 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1906 __ sd(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1907 __ sd(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1909 // Get the length (smi tagged) and set that as an in-object property too.
1910 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1911 __ ld(a1, MemOperand(sp, 0 * kPointerSize));
1913 __ sd(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
1914 Heap::kArgumentsLengthIndex * kPointerSize));
1917 __ Branch(&done, eq, a1, Operand(zero_reg));
1919 // Get the parameters pointer from the stack.
1920 __ ld(a2, MemOperand(sp, 1 * kPointerSize));
1922 // Set up the elements pointer in the allocated arguments object and
1923 // initialize the header in the elements fixed array.
1924 __ Daddu(a4, v0, Operand(Heap::kStrictArgumentsObjectSize));
1925 __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset));
1926 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
1927 __ sd(a3, FieldMemOperand(a4, FixedArray::kMapOffset));
1928 __ sd(a1, FieldMemOperand(a4, FixedArray::kLengthOffset));
1929 // Untag the length for the loop.
1933 // Copy the fixed array slots.
1935 // Set up a4 to point to the first array slot.
1936 __ Daddu(a4, a4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1938 // Pre-decrement a2 with kPointerSize on each iteration.
1939 // Pre-decrement in order to skip receiver.
1940 __ Daddu(a2, a2, Operand(-kPointerSize));
1941 __ ld(a3, MemOperand(a2));
1942 // Post-increment a4 with kPointerSize on each iteration.
1943 __ sd(a3, MemOperand(a4));
1944 __ Daddu(a4, a4, Operand(kPointerSize));
1945 __ Dsubu(a1, a1, Operand(1));
1946 __ Branch(&loop, ne, a1, Operand(zero_reg));
1948 // Return and remove the on-stack parameters.
1952 // Do the runtime call to allocate the arguments object.
1954 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1958 void RegExpExecStub::Generate(MacroAssembler* masm) {
1959 // Just jump directly to runtime if native RegExp is not selected at compile
1960 // time or if regexp entry in generated code is turned off runtime switch or
1962 #ifdef V8_INTERPRETED_REGEXP
1963 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1964 #else // V8_INTERPRETED_REGEXP
1966 // Stack frame on entry.
1967 // sp[0]: last_match_info (expected JSArray)
1968 // sp[4]: previous index
1969 // sp[8]: subject string
1970 // sp[12]: JSRegExp object
1972 const int kLastMatchInfoOffset = 0 * kPointerSize;
1973 const int kPreviousIndexOffset = 1 * kPointerSize;
1974 const int kSubjectOffset = 2 * kPointerSize;
1975 const int kJSRegExpOffset = 3 * kPointerSize;
1978 // Allocation of registers for this function. These are in callee save
1979 // registers and will be preserved by the call to the native RegExp code, as
1980 // this code is called using the normal C calling convention. When calling
1981 // directly from generated code the native RegExp code will not do a GC and
1982 // therefore the content of these registers are safe to use after the call.
1983 // MIPS - using s0..s2, since we are not using CEntry Stub.
1984 Register subject = s0;
1985 Register regexp_data = s1;
1986 Register last_match_info_elements = s2;
1988 // Ensure that a RegExp stack is allocated.
1989 ExternalReference address_of_regexp_stack_memory_address =
1990 ExternalReference::address_of_regexp_stack_memory_address(
1992 ExternalReference address_of_regexp_stack_memory_size =
1993 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1994 __ li(a0, Operand(address_of_regexp_stack_memory_size));
1995 __ ld(a0, MemOperand(a0, 0));
1996 __ Branch(&runtime, eq, a0, Operand(zero_reg));
1998 // Check that the first argument is a JSRegExp object.
1999 __ ld(a0, MemOperand(sp, kJSRegExpOffset));
2000 STATIC_ASSERT(kSmiTag == 0);
2001 __ JumpIfSmi(a0, &runtime);
2002 __ GetObjectType(a0, a1, a1);
2003 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2005 // Check that the RegExp has been compiled (data contains a fixed array).
2006 __ ld(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2007 if (FLAG_debug_code) {
2008 __ SmiTst(regexp_data, a4);
2010 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2013 __ GetObjectType(regexp_data, a0, a0);
2015 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2017 Operand(FIXED_ARRAY_TYPE));
2020 // regexp_data: RegExp data (FixedArray)
2021 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2022 __ ld(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2023 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2025 // regexp_data: RegExp data (FixedArray)
2026 // Check that the number of captures fit in the static offsets vector buffer.
2028 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2029 // Check (number_of_captures + 1) * 2 <= offsets vector size
2030 // Or number_of_captures * 2 <= offsets vector size - 2
2031 // Or number_of_captures <= offsets vector size / 2 - 1
2032 // Multiplying by 2 comes for free since a2 is smi-tagged.
2033 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2034 int temp = Isolate::kJSRegexpStaticOffsetsVectorSize / 2 - 1;
2035 __ Branch(&runtime, hi, a2, Operand(Smi::FromInt(temp)));
2037 // Reset offset for possibly sliced string.
2038 __ mov(t0, zero_reg);
2039 __ ld(subject, MemOperand(sp, kSubjectOffset));
2040 __ JumpIfSmi(subject, &runtime);
2041 __ mov(a3, subject); // Make a copy of the original subject string.
2042 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2043 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2044 // subject: subject string
2045 // a3: subject string
2046 // a0: subject string instance type
2047 // regexp_data: RegExp data (FixedArray)
2048 // Handle subject string according to its encoding and representation:
2049 // (1) Sequential string? If yes, go to (5).
2050 // (2) Anything but sequential or cons? If yes, go to (6).
2051 // (3) Cons string. If the string is flat, replace subject with first string.
2052 // Otherwise bailout.
2053 // (4) Is subject external? If yes, go to (7).
2054 // (5) Sequential string. Load regexp code according to encoding.
2058 // Deferred code at the end of the stub:
2059 // (6) Not a long external string? If yes, go to (8).
2060 // (7) External string. Make it, offset-wise, look like a sequential string.
2062 // (8) Short external string or not a string? If yes, bail out to runtime.
2063 // (9) Sliced string. Replace subject with parent. Go to (4).
2065 Label check_underlying; // (4)
2066 Label seq_string; // (5)
2067 Label not_seq_nor_cons; // (6)
2068 Label external_string; // (7)
2069 Label not_long_external; // (8)
2071 // (1) Sequential string? If yes, go to (5).
2074 Operand(kIsNotStringMask |
2075 kStringRepresentationMask |
2076 kShortExternalStringMask));
2077 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2078 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2080 // (2) Anything but sequential or cons? If yes, go to (6).
2081 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2082 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2083 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2084 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2086 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2088 // (3) Cons string. Check that it's flat.
2089 // Replace subject with first string and reload instance type.
2090 __ ld(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2091 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2092 __ Branch(&runtime, ne, a0, Operand(a1));
2093 __ ld(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2095 // (4) Is subject external? If yes, go to (7).
2096 __ bind(&check_underlying);
2097 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2098 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2099 STATIC_ASSERT(kSeqStringTag == 0);
2100 __ And(at, a0, Operand(kStringRepresentationMask));
2101 // The underlying external string is never a short external string.
2102 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2103 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2104 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2106 // (5) Sequential string. Load regexp code according to encoding.
2107 __ bind(&seq_string);
2108 // subject: sequential subject string (or look-alike, external string)
2109 // a3: original subject string
2110 // Load previous index and check range before a3 is overwritten. We have to
2111 // use a3 instead of subject here because subject might have been only made
2112 // to look like a sequential string when it actually is an external string.
2113 __ ld(a1, MemOperand(sp, kPreviousIndexOffset));
2114 __ JumpIfNotSmi(a1, &runtime);
2115 __ ld(a3, FieldMemOperand(a3, String::kLengthOffset));
2116 __ Branch(&runtime, ls, a3, Operand(a1));
2119 STATIC_ASSERT(kStringEncodingMask == 4);
2120 STATIC_ASSERT(kOneByteStringTag == 4);
2121 STATIC_ASSERT(kTwoByteStringTag == 0);
2122 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one_byte.
2123 __ ld(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2124 __ dsra(a3, a0, 2); // a3 is 1 for one_byte, 0 for UC16 (used below).
2125 __ ld(a5, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2126 __ Movz(t9, a5, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2128 // (E) Carry on. String handling is done.
2129 // t9: irregexp code
2130 // Check that the irregexp code has been generated for the actual string
2131 // encoding. If it has, the field contains a code object otherwise it contains
2132 // a smi (code flushing support).
2133 __ JumpIfSmi(t9, &runtime);
2135 // a1: previous index
2136 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2138 // subject: Subject string
2139 // regexp_data: RegExp data (FixedArray)
2140 // All checks done. Now push arguments for native regexp code.
2141 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2144 // Isolates: note we add an additional parameter here (isolate pointer).
2145 const int kRegExpExecuteArguments = 9;
2146 const int kParameterRegisters = (kMipsAbi == kN64) ? 8 : 4;
2147 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2149 // Stack pointer now points to cell where return address is to be written.
2150 // Arguments are before that on the stack or in registers, meaning we
2151 // treat the return address as argument 5. Thus every argument after that
2152 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2153 // allocating space for the c argument slots, we don't need to calculate
2154 // that into the argument positions on the stack. This is how the stack will
2155 // look (sp meaning the value of sp at this moment):
2157 // [sp + 1] - Argument 9
2158 // [sp + 0] - saved ra
2160 // [sp + 5] - Argument 9
2161 // [sp + 4] - Argument 8
2162 // [sp + 3] - Argument 7
2163 // [sp + 2] - Argument 6
2164 // [sp + 1] - Argument 5
2165 // [sp + 0] - saved ra
2167 if (kMipsAbi == kN64) {
2168 // Argument 9: Pass current isolate address.
2169 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2170 __ sd(a0, MemOperand(sp, 1 * kPointerSize));
2172 // Argument 8: Indicate that this is a direct call from JavaScript.
2173 __ li(a7, Operand(1));
2175 // Argument 7: Start (high end) of backtracking stack memory area.
2176 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2177 __ ld(a0, MemOperand(a0, 0));
2178 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2179 __ ld(a2, MemOperand(a2, 0));
2180 __ daddu(a6, a0, a2);
2182 // Argument 6: Set the number of capture registers to zero to force global
2183 // regexps to behave as non-global. This does not affect non-global regexps.
2184 __ mov(a5, zero_reg);
2186 // Argument 5: static offsets vector buffer.
2188 ExternalReference::address_of_static_offsets_vector(isolate())));
2190 DCHECK(kMipsAbi == kO32);
2192 // Argument 9: Pass current isolate address.
2193 // CFunctionArgumentOperand handles MIPS stack argument slots.
2194 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2195 __ sd(a0, MemOperand(sp, 5 * kPointerSize));
2197 // Argument 8: Indicate that this is a direct call from JavaScript.
2198 __ li(a0, Operand(1));
2199 __ sd(a0, MemOperand(sp, 4 * kPointerSize));
2201 // Argument 7: Start (high end) of backtracking stack memory area.
2202 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2203 __ ld(a0, MemOperand(a0, 0));
2204 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2205 __ ld(a2, MemOperand(a2, 0));
2206 __ daddu(a0, a0, a2);
2207 __ sd(a0, MemOperand(sp, 3 * kPointerSize));
2209 // Argument 6: Set the number of capture registers to zero to force global
2210 // regexps to behave as non-global. This does not affect non-global regexps.
2211 __ mov(a0, zero_reg);
2212 __ sd(a0, MemOperand(sp, 2 * kPointerSize));
2214 // Argument 5: static offsets vector buffer.
2216 ExternalReference::address_of_static_offsets_vector(isolate())));
2217 __ sd(a0, MemOperand(sp, 1 * kPointerSize));
2220 // For arguments 4 and 3 get string length, calculate start of string data
2221 // and calculate the shift of the index (0 for one_byte and 1 for two byte).
2222 __ Daddu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2223 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2224 // Load the length from the original subject string from the previous stack
2225 // frame. Therefore we have to use fp, which points exactly to two pointer
2226 // sizes below the previous sp. (Because creating a new stack frame pushes
2227 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2228 __ ld(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2229 // If slice offset is not 0, load the length from the original sliced string.
2230 // Argument 4, a3: End of string data
2231 // Argument 3, a2: Start of string data
2232 // Prepare start and end index of the input.
2233 __ dsllv(t1, t0, a3);
2234 __ daddu(t0, t2, t1);
2235 __ dsllv(t1, a1, a3);
2236 __ daddu(a2, t0, t1);
2238 __ ld(t2, FieldMemOperand(subject, String::kLengthOffset));
2241 __ dsllv(t1, t2, a3);
2242 __ daddu(a3, t0, t1);
2243 // Argument 2 (a1): Previous index.
2246 // Argument 1 (a0): Subject string.
2247 __ mov(a0, subject);
2249 // Locate the code entry and call it.
2250 __ Daddu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2251 DirectCEntryStub stub(isolate());
2252 stub.GenerateCall(masm, t9);
2254 __ LeaveExitFrame(false, no_reg, true);
2257 // subject: subject string (callee saved)
2258 // regexp_data: RegExp data (callee saved)
2259 // last_match_info_elements: Last match info elements (callee saved)
2260 // Check the result.
2262 __ Branch(&success, eq, v0, Operand(1));
2263 // We expect exactly one result since we force the called regexp to behave
2266 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2267 // If not exception it can only be retry. Handle that in the runtime system.
2268 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2269 // Result must now be exception. If there is no pending exception already a
2270 // stack overflow (on the backtrack stack) was detected in RegExp code but
2271 // haven't created the exception yet. Handle that in the runtime system.
2272 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2273 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2274 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2276 __ ld(v0, MemOperand(a2, 0));
2277 __ Branch(&runtime, eq, v0, Operand(a1));
2279 // For exception, throw the exception again.
2280 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2283 // For failure and exception return null.
2284 __ li(v0, Operand(isolate()->factory()->null_value()));
2287 // Process the result from the native regexp code.
2290 __ lw(a1, UntagSmiFieldMemOperand(
2291 regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2292 // Calculate number of capture registers (number_of_captures + 1) * 2.
2293 __ Daddu(a1, a1, Operand(1));
2294 __ dsll(a1, a1, 1); // Multiply by 2.
2296 __ ld(a0, MemOperand(sp, kLastMatchInfoOffset));
2297 __ JumpIfSmi(a0, &runtime);
2298 __ GetObjectType(a0, a2, a2);
2299 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2300 // Check that the JSArray is in fast case.
2301 __ ld(last_match_info_elements,
2302 FieldMemOperand(a0, JSArray::kElementsOffset));
2303 __ ld(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2304 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2305 __ Branch(&runtime, ne, a0, Operand(at));
2306 // Check that the last match info has space for the capture registers and the
2307 // additional information.
2309 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2310 __ Daddu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2312 __ SmiUntag(at, a0);
2313 __ Branch(&runtime, gt, a2, Operand(at));
2315 // a1: number of capture registers
2316 // subject: subject string
2317 // Store the capture count.
2318 __ SmiTag(a2, a1); // To smi.
2319 __ sd(a2, FieldMemOperand(last_match_info_elements,
2320 RegExpImpl::kLastCaptureCountOffset));
2321 // Store last subject and last input.
2323 FieldMemOperand(last_match_info_elements,
2324 RegExpImpl::kLastSubjectOffset));
2325 __ mov(a2, subject);
2326 __ RecordWriteField(last_match_info_elements,
2327 RegExpImpl::kLastSubjectOffset,
2332 __ mov(subject, a2);
2334 FieldMemOperand(last_match_info_elements,
2335 RegExpImpl::kLastInputOffset));
2336 __ RecordWriteField(last_match_info_elements,
2337 RegExpImpl::kLastInputOffset,
2343 // Get the static offsets vector filled by the native regexp code.
2344 ExternalReference address_of_static_offsets_vector =
2345 ExternalReference::address_of_static_offsets_vector(isolate());
2346 __ li(a2, Operand(address_of_static_offsets_vector));
2348 // a1: number of capture registers
2349 // a2: offsets vector
2350 Label next_capture, done;
2351 // Capture register counter starts from number of capture registers and
2352 // counts down until wrapping after zero.
2354 last_match_info_elements,
2355 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2356 __ bind(&next_capture);
2357 __ Dsubu(a1, a1, Operand(1));
2358 __ Branch(&done, lt, a1, Operand(zero_reg));
2359 // Read the value from the static offsets vector buffer.
2360 __ lw(a3, MemOperand(a2, 0));
2361 __ daddiu(a2, a2, kIntSize);
2362 // Store the smi value in the last match info.
2364 __ sd(a3, MemOperand(a0, 0));
2365 __ Branch(&next_capture, USE_DELAY_SLOT);
2366 __ daddiu(a0, a0, kPointerSize); // In branch delay slot.
2370 // Return last match info.
2371 __ ld(v0, MemOperand(sp, kLastMatchInfoOffset));
2374 // Do the runtime call to execute the regexp.
2376 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2378 // Deferred code for string handling.
2379 // (6) Not a long external string? If yes, go to (8).
2380 __ bind(¬_seq_nor_cons);
2382 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2384 // (7) External string. Make it, offset-wise, look like a sequential string.
2385 __ bind(&external_string);
2386 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2387 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2388 if (FLAG_debug_code) {
2389 // Assert that we do not have a cons or slice (indirect strings) here.
2390 // Sequential strings have already been ruled out.
2391 __ And(at, a0, Operand(kIsIndirectStringMask));
2393 kExternalStringExpectedButNotFound,
2398 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2399 // Move the pointer so that offset-wise, it looks like a sequential string.
2400 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2403 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2404 __ jmp(&seq_string); // Go to (5).
2406 // (8) Short external string or not a string? If yes, bail out to runtime.
2407 __ bind(¬_long_external);
2408 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2409 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2410 __ Branch(&runtime, ne, at, Operand(zero_reg));
2412 // (9) Sliced string. Replace subject with parent. Go to (4).
2413 // Load offset into t0 and replace subject string with parent.
2414 __ ld(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2416 __ ld(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2417 __ jmp(&check_underlying); // Go to (4).
2418 #endif // V8_INTERPRETED_REGEXP
2422 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2424 // a0 : number of arguments to the construct function
2425 // a2 : feedback vector
2426 // a3 : slot in feedback vector (Smi)
2427 // a1 : the function to call
2428 // a4 : original constructor (for IsSuperConstructorCall)
2429 FrameScope scope(masm, StackFrame::INTERNAL);
2430 const RegList kSavedRegs = 1 << 4 | // a0
2434 BoolToInt(is_super) << 8; // a4
2437 // Number-of-arguments register must be smi-tagged to call out.
2439 __ MultiPush(kSavedRegs);
2443 __ MultiPop(kSavedRegs);
2448 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2449 // Cache the called function in a feedback vector slot. Cache states
2450 // are uninitialized, monomorphic (indicated by a JSFunction), and
2452 // a0 : number of arguments to the construct function
2453 // a1 : the function to call
2454 // a2 : feedback vector
2455 // a3 : slot in feedback vector (Smi)
2456 // a4 : original constructor (for IsSuperConstructorCall)
2457 Label initialize, done, miss, megamorphic, not_array_function;
2459 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2460 masm->isolate()->heap()->megamorphic_symbol());
2461 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2462 masm->isolate()->heap()->uninitialized_symbol());
2464 // Load the cache state into a5.
2465 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2466 __ Daddu(a5, a2, Operand(a5));
2467 __ ld(a5, FieldMemOperand(a5, FixedArray::kHeaderSize));
2469 // A monomorphic cache hit or an already megamorphic state: invoke the
2470 // function without changing the state.
2471 // We don't know if a5 is a WeakCell or a Symbol, but it's harmless to read at
2472 // this position in a symbol (see static asserts in type-feedback-vector.h).
2473 Label check_allocation_site;
2474 Register feedback_map = a6;
2475 Register weak_value = t0;
2476 __ ld(weak_value, FieldMemOperand(a5, WeakCell::kValueOffset));
2477 __ Branch(&done, eq, a1, Operand(weak_value));
2478 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2479 __ Branch(&done, eq, a5, Operand(at));
2480 __ ld(feedback_map, FieldMemOperand(a5, HeapObject::kMapOffset));
2481 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2482 __ Branch(&check_allocation_site, ne, feedback_map, Operand(at));
2484 // If the weak cell is cleared, we have a new chance to become monomorphic.
2485 __ JumpIfSmi(weak_value, &initialize);
2486 __ jmp(&megamorphic);
2488 __ bind(&check_allocation_site);
2489 // If we came here, we need to see if we are the array function.
2490 // If we didn't have a matching function, and we didn't find the megamorph
2491 // sentinel, then we have in the slot either some other function or an
2493 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2494 __ Branch(&miss, ne, feedback_map, Operand(at));
2496 // Make sure the function is the Array() function
2497 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a5);
2498 __ Branch(&megamorphic, ne, a1, Operand(a5));
2503 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2505 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2506 __ Branch(&initialize, eq, a5, Operand(at));
2507 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2508 // write-barrier is needed.
2509 __ bind(&megamorphic);
2510 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2511 __ Daddu(a5, a2, Operand(a5));
2512 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2513 __ sd(at, FieldMemOperand(a5, FixedArray::kHeaderSize));
2516 // An uninitialized cache is patched with the function.
2517 __ bind(&initialize);
2518 // Make sure the function is the Array() function.
2519 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a5);
2520 __ Branch(¬_array_function, ne, a1, Operand(a5));
2522 // The target function is the Array constructor,
2523 // Create an AllocationSite if we don't already have it, store it in the
2525 CreateAllocationSiteStub create_stub(masm->isolate());
2526 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2529 __ bind(¬_array_function);
2531 CreateWeakCellStub weak_cell_stub(masm->isolate());
2532 CallStubInRecordCallTarget(masm, &weak_cell_stub, is_super);
2537 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2538 __ ld(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2540 // Do not transform the receiver for strict mode functions.
2541 int32_t strict_mode_function_mask =
2542 1 << SharedFunctionInfo::kStrictModeBitWithinByte ;
2543 // Do not transform the receiver for native (Compilerhints already in a3).
2544 int32_t native_mask = 1 << SharedFunctionInfo::kNativeBitWithinByte;
2546 __ lbu(a4, FieldMemOperand(a3, SharedFunctionInfo::kStrictModeByteOffset));
2547 __ And(at, a4, Operand(strict_mode_function_mask));
2548 __ Branch(cont, ne, at, Operand(zero_reg));
2549 __ lbu(a4, FieldMemOperand(a3, SharedFunctionInfo::kNativeByteOffset));
2550 __ And(at, a4, Operand(native_mask));
2551 __ Branch(cont, ne, at, Operand(zero_reg));
2555 static void EmitSlowCase(MacroAssembler* masm, int argc) {
2556 __ li(a0, Operand(argc));
2557 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2561 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2562 // Wrap the receiver and patch it back onto the stack.
2563 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2566 ToObjectStub stub(masm->isolate());
2570 __ Branch(USE_DELAY_SLOT, cont);
2571 __ sd(v0, MemOperand(sp, argc * kPointerSize));
2575 static void CallFunctionNoFeedback(MacroAssembler* masm,
2576 int argc, bool needs_checks,
2577 bool call_as_method) {
2578 // a1 : the function to call
2579 Label slow, wrap, cont;
2582 // Check that the function is really a JavaScript function.
2583 // a1: pushed function (to be verified)
2584 __ JumpIfSmi(a1, &slow);
2586 // Goto slow case if we do not have a function.
2587 __ GetObjectType(a1, a4, a4);
2588 __ Branch(&slow, ne, a4, Operand(JS_FUNCTION_TYPE));
2591 // Fast-case: Invoke the function now.
2592 // a1: pushed function
2593 ParameterCount actual(argc);
2595 if (call_as_method) {
2597 EmitContinueIfStrictOrNative(masm, &cont);
2600 // Compute the receiver in sloppy mode.
2601 __ ld(a3, MemOperand(sp, argc * kPointerSize));
2604 __ JumpIfSmi(a3, &wrap);
2605 __ GetObjectType(a3, a4, a4);
2606 __ Branch(&wrap, lt, a4, Operand(FIRST_SPEC_OBJECT_TYPE));
2613 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2616 // Slow-case: Non-function called.
2618 EmitSlowCase(masm, argc);
2621 if (call_as_method) {
2623 // Wrap the receiver and patch it back onto the stack.
2624 EmitWrapCase(masm, argc, &cont);
2629 void CallFunctionStub::Generate(MacroAssembler* masm) {
2630 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2634 void CallConstructStub::Generate(MacroAssembler* masm) {
2635 // a0 : number of arguments
2636 // a1 : the function to call
2637 // a2 : feedback vector
2638 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2639 // a4 : original constructor (for IsSuperConstructorCall)
2640 Label slow, non_function_call;
2641 // Check that the function is not a smi.
2642 __ JumpIfSmi(a1, &non_function_call);
2643 // Check that the function is a JSFunction.
2644 __ GetObjectType(a1, a5, a5);
2645 __ Branch(&slow, ne, a5, Operand(JS_FUNCTION_TYPE));
2647 if (RecordCallTarget()) {
2648 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2650 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2651 __ Daddu(a5, a2, at);
2652 Label feedback_register_initialized;
2653 // Put the AllocationSite from the feedback vector into a2, or undefined.
2654 __ ld(a2, FieldMemOperand(a5, FixedArray::kHeaderSize));
2655 __ ld(a5, FieldMemOperand(a2, AllocationSite::kMapOffset));
2656 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2657 __ Branch(&feedback_register_initialized, eq, a5, Operand(at));
2658 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2659 __ bind(&feedback_register_initialized);
2661 __ AssertUndefinedOrAllocationSite(a2, a5);
2664 // Pass function as original constructor.
2665 if (IsSuperConstructorCall()) {
2671 // Jump to the function-specific construct stub.
2672 Register jmp_reg = a4;
2673 __ ld(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2674 __ ld(jmp_reg, FieldMemOperand(jmp_reg,
2675 SharedFunctionInfo::kConstructStubOffset));
2676 __ Daddu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2679 // a0: number of arguments
2680 // a1: called object
2684 __ Branch(&non_function_call, ne, a5, Operand(JS_FUNCTION_PROXY_TYPE));
2685 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies.
2686 __ ld(a1, FieldMemOperand(a1, JSFunctionProxy::kConstructTrapOffset));
2687 __ Jump(isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
2689 __ bind(&non_function_call);
2691 // Determine the delegate for the target (if any).
2692 FrameScope scope(masm, StackFrame::INTERNAL);
2695 __ CallRuntime(Runtime::kGetConstructorDelegate, 1);
2700 // The delegate is always a regular function.
2701 __ AssertFunction(a1);
2702 __ Jump(masm->isolate()->builtins()->CallFunction(),
2703 RelocInfo::CODE_TARGET);
2708 // StringCharCodeAtGenerator.
2709 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2710 DCHECK(!a4.is(index_));
2711 DCHECK(!a4.is(result_));
2712 DCHECK(!a4.is(object_));
2714 // If the receiver is a smi trigger the non-string case.
2715 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2716 __ JumpIfSmi(object_, receiver_not_string_);
2718 // Fetch the instance type of the receiver into result register.
2719 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2720 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2721 // If the receiver is not a string trigger the non-string case.
2722 __ And(a4, result_, Operand(kIsNotStringMask));
2723 __ Branch(receiver_not_string_, ne, a4, Operand(zero_reg));
2726 // If the index is non-smi trigger the non-smi case.
2727 __ JumpIfNotSmi(index_, &index_not_smi_);
2729 __ bind(&got_smi_index_);
2731 // Check for index out of range.
2732 __ ld(a4, FieldMemOperand(object_, String::kLengthOffset));
2733 __ Branch(index_out_of_range_, ls, a4, Operand(index_));
2735 __ SmiUntag(index_);
2737 StringCharLoadGenerator::Generate(masm,
2748 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2749 __ ld(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2750 __ ld(vector, FieldMemOperand(vector,
2751 JSFunction::kSharedFunctionInfoOffset));
2752 __ ld(vector, FieldMemOperand(vector,
2753 SharedFunctionInfo::kFeedbackVectorOffset));
2757 void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) {
2761 // a4 - allocation site (loaded from vector[slot])
2762 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2763 __ Branch(miss, ne, a1, Operand(at));
2765 __ li(a0, Operand(arg_count()));
2767 // Increment the call count for monomorphic function calls.
2768 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2769 __ Daddu(a3, a2, Operand(t0));
2770 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2771 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2772 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2776 ArrayConstructorStub stub(masm->isolate(), arg_count());
2777 __ TailCallStub(&stub);
2781 void CallICStub::Generate(MacroAssembler* masm) {
2783 // a3 - slot id (Smi)
2785 const int with_types_offset =
2786 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2787 const int generic_offset =
2788 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2789 Label extra_checks_or_miss, slow_start;
2790 Label slow, wrap, cont;
2791 Label have_js_function;
2792 int argc = arg_count();
2793 ParameterCount actual(argc);
2795 // The checks. First, does r1 match the recorded monomorphic target?
2796 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
2797 __ Daddu(a4, a2, Operand(a4));
2798 __ ld(a4, FieldMemOperand(a4, FixedArray::kHeaderSize));
2800 // We don't know that we have a weak cell. We might have a private symbol
2801 // or an AllocationSite, but the memory is safe to examine.
2802 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2804 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2805 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2806 // computed, meaning that it can't appear to be a pointer. If the low bit is
2807 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2809 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2810 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2811 WeakCell::kValueOffset &&
2812 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2814 __ ld(a5, FieldMemOperand(a4, WeakCell::kValueOffset));
2815 __ Branch(&extra_checks_or_miss, ne, a1, Operand(a5));
2817 // The compare above could have been a SMI/SMI comparison. Guard against this
2818 // convincing us that we have a monomorphic JSFunction.
2819 __ JumpIfSmi(a1, &extra_checks_or_miss);
2821 // Increment the call count for monomorphic function calls.
2822 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2823 __ Daddu(a3, a2, Operand(t0));
2824 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2825 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2826 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2828 __ bind(&have_js_function);
2829 if (CallAsMethod()) {
2830 EmitContinueIfStrictOrNative(masm, &cont);
2831 // Compute the receiver in sloppy mode.
2832 __ ld(a3, MemOperand(sp, argc * kPointerSize));
2834 __ JumpIfSmi(a3, &wrap);
2835 __ GetObjectType(a3, a4, a4);
2836 __ Branch(&wrap, lt, a4, Operand(FIRST_SPEC_OBJECT_TYPE));
2841 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2844 EmitSlowCase(masm, argc);
2846 if (CallAsMethod()) {
2848 EmitWrapCase(masm, argc, &cont);
2851 __ bind(&extra_checks_or_miss);
2852 Label uninitialized, miss, not_allocation_site;
2854 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2855 __ Branch(&slow_start, eq, a4, Operand(at));
2857 // Verify that a4 contains an AllocationSite
2858 __ ld(a5, FieldMemOperand(a4, HeapObject::kMapOffset));
2859 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2860 __ Branch(¬_allocation_site, ne, a5, Operand(at));
2862 HandleArrayCase(masm, &miss);
2864 __ bind(¬_allocation_site);
2866 // The following cases attempt to handle MISS cases without going to the
2868 if (FLAG_trace_ic) {
2872 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2873 __ Branch(&uninitialized, eq, a4, Operand(at));
2875 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2876 // to handle it here. More complex cases are dealt with in the runtime.
2877 __ AssertNotSmi(a4);
2878 __ GetObjectType(a4, a5, a5);
2879 __ Branch(&miss, ne, a5, Operand(JS_FUNCTION_TYPE));
2880 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
2881 __ Daddu(a4, a2, Operand(a4));
2882 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2883 __ sd(at, FieldMemOperand(a4, FixedArray::kHeaderSize));
2884 // We have to update statistics for runtime profiling.
2885 __ ld(a4, FieldMemOperand(a2, with_types_offset));
2886 __ Dsubu(a4, a4, Operand(Smi::FromInt(1)));
2887 __ sd(a4, FieldMemOperand(a2, with_types_offset));
2888 __ ld(a4, FieldMemOperand(a2, generic_offset));
2889 __ Daddu(a4, a4, Operand(Smi::FromInt(1)));
2890 __ Branch(USE_DELAY_SLOT, &slow_start);
2891 __ sd(a4, FieldMemOperand(a2, generic_offset)); // In delay slot.
2893 __ bind(&uninitialized);
2895 // We are going monomorphic, provided we actually have a JSFunction.
2896 __ JumpIfSmi(a1, &miss);
2898 // Goto miss case if we do not have a function.
2899 __ GetObjectType(a1, a4, a4);
2900 __ Branch(&miss, ne, a4, Operand(JS_FUNCTION_TYPE));
2902 // Make sure the function is not the Array() function, which requires special
2903 // behavior on MISS.
2904 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a4);
2905 __ Branch(&miss, eq, a1, Operand(a4));
2908 __ ld(a4, FieldMemOperand(a2, with_types_offset));
2909 __ Daddu(a4, a4, Operand(Smi::FromInt(1)));
2910 __ sd(a4, FieldMemOperand(a2, with_types_offset));
2912 // Initialize the call counter.
2913 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2914 __ Daddu(at, a2, Operand(at));
2915 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2916 __ sd(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2918 // Store the function. Use a stub since we need a frame for allocation.
2923 FrameScope scope(masm, StackFrame::INTERNAL);
2924 CreateWeakCellStub create_stub(masm->isolate());
2926 __ CallStub(&create_stub);
2930 __ Branch(&have_js_function);
2932 // We are here because tracing is on or we encountered a MISS case we can't
2938 __ bind(&slow_start);
2939 // Check that the function is really a JavaScript function.
2940 // a1: pushed function (to be verified)
2941 __ JumpIfSmi(a1, &slow);
2943 // Goto slow case if we do not have a function.
2944 __ GetObjectType(a1, a4, a4);
2945 __ Branch(&slow, ne, a4, Operand(JS_FUNCTION_TYPE));
2946 __ Branch(&have_js_function);
2950 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2951 FrameScope scope(masm, StackFrame::INTERNAL);
2953 // Push the receiver and the function and feedback info.
2954 __ Push(a1, a2, a3);
2957 __ CallRuntime(Runtime::kCallIC_Miss, 3);
2959 // Move result to a1 and exit the internal frame.
2964 void StringCharCodeAtGenerator::GenerateSlow(
2965 MacroAssembler* masm, EmbedMode embed_mode,
2966 const RuntimeCallHelper& call_helper) {
2967 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2969 // Index is not a smi.
2970 __ bind(&index_not_smi_);
2971 // If index is a heap number, try converting it to an integer.
2974 Heap::kHeapNumberMapRootIndex,
2977 call_helper.BeforeCall(masm);
2978 // Consumed by runtime conversion function:
2979 if (embed_mode == PART_OF_IC_HANDLER) {
2980 __ Push(LoadWithVectorDescriptor::VectorRegister(),
2981 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
2983 __ Push(object_, index_);
2985 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2986 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2988 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2989 // NumberToSmi discards numbers that are not exact integers.
2990 __ CallRuntime(Runtime::kNumberToSmi, 1);
2993 // Save the conversion result before the pop instructions below
2994 // have a chance to overwrite it.
2996 __ Move(index_, v0);
2997 if (embed_mode == PART_OF_IC_HANDLER) {
2998 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
2999 LoadWithVectorDescriptor::SlotRegister(), object_);
3003 // Reload the instance type.
3004 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3005 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3006 call_helper.AfterCall(masm);
3007 // If index is still not a smi, it must be out of range.
3008 __ JumpIfNotSmi(index_, index_out_of_range_);
3009 // Otherwise, return to the fast path.
3010 __ Branch(&got_smi_index_);
3012 // Call runtime. We get here when the receiver is a string and the
3013 // index is a number, but the code of getting the actual character
3014 // is too complex (e.g., when the string needs to be flattened).
3015 __ bind(&call_runtime_);
3016 call_helper.BeforeCall(masm);
3018 __ Push(object_, index_);
3019 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3021 __ Move(result_, v0);
3023 call_helper.AfterCall(masm);
3026 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3030 // -------------------------------------------------------------------------
3031 // StringCharFromCodeGenerator
3033 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3034 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3035 __ JumpIfNotSmi(code_, &slow_case_);
3036 __ Branch(&slow_case_, hi, code_,
3037 Operand(Smi::FromInt(String::kMaxOneByteCharCode)));
3039 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3040 // At this point code register contains smi tagged one_byte char code.
3041 __ SmiScale(at, code_, kPointerSizeLog2);
3042 __ Daddu(result_, result_, at);
3043 __ ld(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3044 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3045 __ Branch(&slow_case_, eq, result_, Operand(at));
3050 void StringCharFromCodeGenerator::GenerateSlow(
3051 MacroAssembler* masm,
3052 const RuntimeCallHelper& call_helper) {
3053 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3055 __ bind(&slow_case_);
3056 call_helper.BeforeCall(masm);
3058 __ CallRuntime(Runtime::kCharFromCode, 1);
3059 __ Move(result_, v0);
3061 call_helper.AfterCall(masm);
3064 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3068 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3071 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3076 String::Encoding encoding) {
3077 if (FLAG_debug_code) {
3078 // Check that destination is word aligned.
3079 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3081 kDestinationOfCopyNotAligned,
3086 // Assumes word reads and writes are little endian.
3087 // Nothing to do for zero characters.
3090 if (encoding == String::TWO_BYTE_ENCODING) {
3091 __ Daddu(count, count, count);
3094 Register limit = count; // Read until dest equals this.
3095 __ Daddu(limit, dest, Operand(count));
3097 Label loop_entry, loop;
3098 // Copy bytes from src to dest until dest hits limit.
3099 __ Branch(&loop_entry);
3101 __ lbu(scratch, MemOperand(src));
3102 __ daddiu(src, src, 1);
3103 __ sb(scratch, MemOperand(dest));
3104 __ daddiu(dest, dest, 1);
3105 __ bind(&loop_entry);
3106 __ Branch(&loop, lt, dest, Operand(limit));
3112 void SubStringStub::Generate(MacroAssembler* masm) {
3114 // Stack frame on entry.
3115 // ra: return address
3120 // This stub is called from the native-call %_SubString(...), so
3121 // nothing can be assumed about the arguments. It is tested that:
3122 // "string" is a sequential string,
3123 // both "from" and "to" are smis, and
3124 // 0 <= from <= to <= string.length.
3125 // If any of these assumptions fail, we call the runtime system.
3127 const int kToOffset = 0 * kPointerSize;
3128 const int kFromOffset = 1 * kPointerSize;
3129 const int kStringOffset = 2 * kPointerSize;
3131 __ ld(a2, MemOperand(sp, kToOffset));
3132 __ ld(a3, MemOperand(sp, kFromOffset));
3134 STATIC_ASSERT(kSmiTag == 0);
3136 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3137 // safe in this case.
3138 __ JumpIfNotSmi(a2, &runtime);
3139 __ JumpIfNotSmi(a3, &runtime);
3140 // Both a2 and a3 are untagged integers.
3142 __ SmiUntag(a2, a2);
3143 __ SmiUntag(a3, a3);
3144 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3146 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3147 __ Dsubu(a2, a2, a3);
3149 // Make sure first argument is a string.
3150 __ ld(v0, MemOperand(sp, kStringOffset));
3151 __ JumpIfSmi(v0, &runtime);
3152 __ ld(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3153 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3154 __ And(a4, a1, Operand(kIsNotStringMask));
3156 __ Branch(&runtime, ne, a4, Operand(zero_reg));
3159 __ Branch(&single_char, eq, a2, Operand(1));
3161 // Short-cut for the case of trivial substring.
3163 // v0: original string
3164 // a2: result string length
3165 __ ld(a4, FieldMemOperand(v0, String::kLengthOffset));
3167 // Return original string.
3168 __ Branch(&return_v0, eq, a2, Operand(a4));
3169 // Longer than original string's length or negative: unsafe arguments.
3170 __ Branch(&runtime, hi, a2, Operand(a4));
3171 // Shorter than original string's length: an actual substring.
3173 // Deal with different string types: update the index if necessary
3174 // and put the underlying string into a5.
3175 // v0: original string
3176 // a1: instance type
3178 // a3: from index (untagged)
3179 Label underlying_unpacked, sliced_string, seq_or_external_string;
3180 // If the string is not indirect, it can only be sequential or external.
3181 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3182 STATIC_ASSERT(kIsIndirectStringMask != 0);
3183 __ And(a4, a1, Operand(kIsIndirectStringMask));
3184 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, a4, Operand(zero_reg));
3185 // a4 is used as a scratch register and can be overwritten in either case.
3186 __ And(a4, a1, Operand(kSlicedNotConsMask));
3187 __ Branch(&sliced_string, ne, a4, Operand(zero_reg));
3188 // Cons string. Check whether it is flat, then fetch first part.
3189 __ ld(a5, FieldMemOperand(v0, ConsString::kSecondOffset));
3190 __ LoadRoot(a4, Heap::kempty_stringRootIndex);
3191 __ Branch(&runtime, ne, a5, Operand(a4));
3192 __ ld(a5, FieldMemOperand(v0, ConsString::kFirstOffset));
3193 // Update instance type.
3194 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
3195 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3196 __ jmp(&underlying_unpacked);
3198 __ bind(&sliced_string);
3199 // Sliced string. Fetch parent and correct start index by offset.
3200 __ ld(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
3201 __ ld(a4, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3202 __ SmiUntag(a4); // Add offset to index.
3203 __ Daddu(a3, a3, a4);
3204 // Update instance type.
3205 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
3206 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3207 __ jmp(&underlying_unpacked);
3209 __ bind(&seq_or_external_string);
3210 // Sequential or external string. Just move string to the expected register.
3213 __ bind(&underlying_unpacked);
3215 if (FLAG_string_slices) {
3217 // a5: underlying subject string
3218 // a1: instance type of underlying subject string
3220 // a3: adjusted start index (untagged)
3221 // Short slice. Copy instead of slicing.
3222 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3223 // Allocate new sliced string. At this point we do not reload the instance
3224 // type including the string encoding because we simply rely on the info
3225 // provided by the original string. It does not matter if the original
3226 // string's encoding is wrong because we always have to recheck encoding of
3227 // the newly created string's parent anyways due to externalized strings.
3228 Label two_byte_slice, set_slice_header;
3229 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3230 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3231 __ And(a4, a1, Operand(kStringEncodingMask));
3232 __ Branch(&two_byte_slice, eq, a4, Operand(zero_reg));
3233 __ AllocateOneByteSlicedString(v0, a2, a6, a7, &runtime);
3234 __ jmp(&set_slice_header);
3235 __ bind(&two_byte_slice);
3236 __ AllocateTwoByteSlicedString(v0, a2, a6, a7, &runtime);
3237 __ bind(&set_slice_header);
3239 __ sd(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
3240 __ sd(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3243 __ bind(©_routine);
3246 // a5: underlying subject string
3247 // a1: instance type of underlying subject string
3249 // a3: adjusted start index (untagged)
3250 Label two_byte_sequential, sequential_string, allocate_result;
3251 STATIC_ASSERT(kExternalStringTag != 0);
3252 STATIC_ASSERT(kSeqStringTag == 0);
3253 __ And(a4, a1, Operand(kExternalStringTag));
3254 __ Branch(&sequential_string, eq, a4, Operand(zero_reg));
3256 // Handle external string.
3257 // Rule out short external strings.
3258 STATIC_ASSERT(kShortExternalStringTag != 0);
3259 __ And(a4, a1, Operand(kShortExternalStringTag));
3260 __ Branch(&runtime, ne, a4, Operand(zero_reg));
3261 __ ld(a5, FieldMemOperand(a5, ExternalString::kResourceDataOffset));
3262 // a5 already points to the first character of underlying string.
3263 __ jmp(&allocate_result);
3265 __ bind(&sequential_string);
3266 // Locate first character of underlying subject string.
3267 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3268 __ Daddu(a5, a5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3270 __ bind(&allocate_result);
3271 // Sequential acii string. Allocate the result.
3272 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3273 __ And(a4, a1, Operand(kStringEncodingMask));
3274 __ Branch(&two_byte_sequential, eq, a4, Operand(zero_reg));
3276 // Allocate and copy the resulting one_byte string.
3277 __ AllocateOneByteString(v0, a2, a4, a6, a7, &runtime);
3279 // Locate first character of substring to copy.
3280 __ Daddu(a5, a5, a3);
3282 // Locate first character of result.
3283 __ Daddu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3285 // v0: result string
3286 // a1: first character of result string
3287 // a2: result string length
3288 // a5: first character of substring to copy
3289 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3290 StringHelper::GenerateCopyCharacters(
3291 masm, a1, a5, a2, a3, String::ONE_BYTE_ENCODING);
3294 // Allocate and copy the resulting two-byte string.
3295 __ bind(&two_byte_sequential);
3296 __ AllocateTwoByteString(v0, a2, a4, a6, a7, &runtime);
3298 // Locate first character of substring to copy.
3299 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3301 __ Daddu(a5, a5, a4);
3302 // Locate first character of result.
3303 __ Daddu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3305 // v0: result string.
3306 // a1: first character of result.
3307 // a2: result length.
3308 // a5: first character of substring to copy.
3309 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3310 StringHelper::GenerateCopyCharacters(
3311 masm, a1, a5, a2, a3, String::TWO_BYTE_ENCODING);
3313 __ bind(&return_v0);
3314 Counters* counters = isolate()->counters();
3315 __ IncrementCounter(counters->sub_string_native(), 1, a3, a4);
3318 // Just jump to runtime to create the sub string.
3320 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3322 __ bind(&single_char);
3323 // v0: original string
3324 // a1: instance type
3326 // a3: from index (untagged)
3328 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3329 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3330 generator.GenerateFast(masm);
3332 generator.SkipSlow(masm, &runtime);
3336 void ToNumberStub::Generate(MacroAssembler* masm) {
3337 // The ToNumber stub takes one argument in a0.
3339 __ JumpIfNotSmi(a0, ¬_smi);
3340 __ Ret(USE_DELAY_SLOT);
3344 Label not_heap_number;
3345 __ ld(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3346 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3348 // a1: instance type.
3349 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3350 __ Ret(USE_DELAY_SLOT);
3352 __ bind(¬_heap_number);
3354 Label not_string, slow_string;
3355 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3356 // Check if string has a cached array index.
3357 __ ld(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3358 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3359 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3360 __ IndexFromHash(a2, a0);
3361 __ Ret(USE_DELAY_SLOT);
3363 __ bind(&slow_string);
3364 __ push(a0); // Push argument.
3365 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3366 __ bind(¬_string);
3369 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3370 __ Ret(USE_DELAY_SLOT);
3371 __ ld(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3372 __ bind(¬_oddball);
3374 __ push(a0); // Push argument.
3375 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3379 void ToStringStub::Generate(MacroAssembler* masm) {
3380 // The ToString stub takes on argument in a0.
3382 __ JumpIfSmi(a0, &is_number);
3385 __ GetObjectType(a0, a1, a1);
3387 // a1: receiver instance type
3388 __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
3389 __ Ret(USE_DELAY_SLOT);
3391 __ bind(¬_string);
3393 Label not_heap_number;
3394 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3395 __ bind(&is_number);
3396 NumberToStringStub stub(isolate());
3397 __ TailCallStub(&stub);
3398 __ bind(¬_heap_number);
3401 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3402 __ Ret(USE_DELAY_SLOT);
3403 __ ld(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
3404 __ bind(¬_oddball);
3406 __ push(a0); // Push argument.
3407 __ TailCallRuntime(Runtime::kToString, 1, 1);
3411 void StringHelper::GenerateFlatOneByteStringEquals(
3412 MacroAssembler* masm, Register left, Register right, Register scratch1,
3413 Register scratch2, Register scratch3) {
3414 Register length = scratch1;
3417 Label strings_not_equal, check_zero_length;
3418 __ ld(length, FieldMemOperand(left, String::kLengthOffset));
3419 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
3420 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3421 __ bind(&strings_not_equal);
3422 // Can not put li in delayslot, it has multi instructions.
3423 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3426 // Check if the length is zero.
3427 Label compare_chars;
3428 __ bind(&check_zero_length);
3429 STATIC_ASSERT(kSmiTag == 0);
3430 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3431 DCHECK(is_int16((intptr_t)Smi::FromInt(EQUAL)));
3432 __ Ret(USE_DELAY_SLOT);
3433 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3435 // Compare characters.
3436 __ bind(&compare_chars);
3438 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3439 v0, &strings_not_equal);
3441 // Characters are equal.
3442 __ Ret(USE_DELAY_SLOT);
3443 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3447 void StringHelper::GenerateCompareFlatOneByteStrings(
3448 MacroAssembler* masm, Register left, Register right, Register scratch1,
3449 Register scratch2, Register scratch3, Register scratch4) {
3450 Label result_not_equal, compare_lengths;
3451 // Find minimum length and length difference.
3452 __ ld(scratch1, FieldMemOperand(left, String::kLengthOffset));
3453 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
3454 __ Dsubu(scratch3, scratch1, Operand(scratch2));
3455 Register length_delta = scratch3;
3456 __ slt(scratch4, scratch2, scratch1);
3457 __ Movn(scratch1, scratch2, scratch4);
3458 Register min_length = scratch1;
3459 STATIC_ASSERT(kSmiTag == 0);
3460 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3463 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3464 scratch4, v0, &result_not_equal);
3466 // Compare lengths - strings up to min-length are equal.
3467 __ bind(&compare_lengths);
3468 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3469 // Use length_delta as result if it's zero.
3470 __ mov(scratch2, length_delta);
3471 __ mov(scratch4, zero_reg);
3472 __ mov(v0, zero_reg);
3474 __ bind(&result_not_equal);
3475 // Conditionally update the result based either on length_delta or
3476 // the last comparion performed in the loop above.
3478 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3479 __ li(v0, Operand(Smi::FromInt(GREATER)));
3480 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3481 __ li(v0, Operand(Smi::FromInt(LESS)));
3487 void StringHelper::GenerateOneByteCharsCompareLoop(
3488 MacroAssembler* masm, Register left, Register right, Register length,
3489 Register scratch1, Register scratch2, Register scratch3,
3490 Label* chars_not_equal) {
3491 // Change index to run from -length to -1 by adding length to string
3492 // start. This means that loop ends when index reaches zero, which
3493 // doesn't need an additional compare.
3494 __ SmiUntag(length);
3495 __ Daddu(scratch1, length,
3496 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3497 __ Daddu(left, left, Operand(scratch1));
3498 __ Daddu(right, right, Operand(scratch1));
3499 __ Dsubu(length, zero_reg, length);
3500 Register index = length; // index = -length;
3506 __ Daddu(scratch3, left, index);
3507 __ lbu(scratch1, MemOperand(scratch3));
3508 __ Daddu(scratch3, right, index);
3509 __ lbu(scratch2, MemOperand(scratch3));
3510 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3511 __ Daddu(index, index, 1);
3512 __ Branch(&loop, ne, index, Operand(zero_reg));
3516 void StringCompareStub::Generate(MacroAssembler* masm) {
3517 // ----------- S t a t e -------------
3520 // -- ra : return address
3521 // -----------------------------------
3522 __ AssertString(a1);
3523 __ AssertString(a0);
3526 __ Branch(¬_same, ne, a0, Operand(a1));
3527 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3528 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a1,
3534 // Check that both objects are sequential one-byte strings.
3536 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3538 // Compare flat ASCII strings natively.
3539 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2,
3541 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1);
3545 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3549 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3550 // ----------- S t a t e -------------
3553 // -- ra : return address
3554 // -----------------------------------
3556 // Load a2 with the allocation site. We stick an undefined dummy value here
3557 // and replace it with the real allocation site later when we instantiate this
3558 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3559 __ li(a2, handle(isolate()->heap()->undefined_value()));
3561 // Make sure that we actually patched the allocation site.
3562 if (FLAG_debug_code) {
3563 __ And(at, a2, Operand(kSmiTagMask));
3564 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3565 __ ld(a4, FieldMemOperand(a2, HeapObject::kMapOffset));
3566 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3567 __ Assert(eq, kExpectedAllocationSite, a4, Operand(at));
3570 // Tail call into the stub that handles binary operations with allocation
3572 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3573 __ TailCallStub(&stub);
3577 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3578 DCHECK(state() == CompareICState::SMI);
3581 __ JumpIfNotSmi(a2, &miss);
3583 if (GetCondition() == eq) {
3584 // For equality we do not care about the sign of the result.
3585 __ Ret(USE_DELAY_SLOT);
3586 __ Dsubu(v0, a0, a1);
3588 // Untag before subtracting to avoid handling overflow.
3591 __ Ret(USE_DELAY_SLOT);
3592 __ Dsubu(v0, a1, a0);
3600 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3601 DCHECK(state() == CompareICState::NUMBER);
3604 Label unordered, maybe_undefined1, maybe_undefined2;
3607 if (left() == CompareICState::SMI) {
3608 __ JumpIfNotSmi(a1, &miss);
3610 if (right() == CompareICState::SMI) {
3611 __ JumpIfNotSmi(a0, &miss);
3614 // Inlining the double comparison and falling back to the general compare
3615 // stub if NaN is involved.
3616 // Load left and right operand.
3617 Label done, left, left_smi, right_smi;
3618 __ JumpIfSmi(a0, &right_smi);
3619 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3621 __ Dsubu(a2, a0, Operand(kHeapObjectTag));
3622 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3624 __ bind(&right_smi);
3625 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3626 FPURegister single_scratch = f6;
3627 __ mtc1(a2, single_scratch);
3628 __ cvt_d_w(f2, single_scratch);
3631 __ JumpIfSmi(a1, &left_smi);
3632 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3634 __ Dsubu(a2, a1, Operand(kHeapObjectTag));
3635 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3638 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3639 single_scratch = f8;
3640 __ mtc1(a2, single_scratch);
3641 __ cvt_d_w(f0, single_scratch);
3645 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3646 Label fpu_eq, fpu_lt;
3647 // Test if equal, and also handle the unordered/NaN case.
3648 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3650 // Test if less (unordered case is already handled).
3651 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3653 // Otherwise it's greater, so just fall thru, and return.
3654 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3655 __ Ret(USE_DELAY_SLOT);
3656 __ li(v0, Operand(GREATER));
3659 __ Ret(USE_DELAY_SLOT);
3660 __ li(v0, Operand(EQUAL));
3663 __ Ret(USE_DELAY_SLOT);
3664 __ li(v0, Operand(LESS));
3666 __ bind(&unordered);
3667 __ bind(&generic_stub);
3668 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3669 CompareICState::GENERIC, CompareICState::GENERIC);
3670 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3672 __ bind(&maybe_undefined1);
3673 if (Token::IsOrderedRelationalCompareOp(op())) {
3674 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3675 __ Branch(&miss, ne, a0, Operand(at));
3676 __ JumpIfSmi(a1, &unordered);
3677 __ GetObjectType(a1, a2, a2);
3678 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3682 __ bind(&maybe_undefined2);
3683 if (Token::IsOrderedRelationalCompareOp(op())) {
3684 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3685 __ Branch(&unordered, eq, a1, Operand(at));
3693 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3694 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3697 // Registers containing left and right operands respectively.
3699 Register right = a0;
3703 // Check that both operands are heap objects.
3704 __ JumpIfEitherSmi(left, right, &miss);
3706 // Check that both operands are internalized strings.
3707 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3708 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3709 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3710 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3711 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3712 __ Or(tmp1, tmp1, Operand(tmp2));
3713 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3714 __ Branch(&miss, ne, at, Operand(zero_reg));
3716 // Make sure a0 is non-zero. At this point input operands are
3717 // guaranteed to be non-zero.
3718 DCHECK(right.is(a0));
3719 STATIC_ASSERT(EQUAL == 0);
3720 STATIC_ASSERT(kSmiTag == 0);
3722 // Internalized strings are compared by identity.
3723 __ Ret(ne, left, Operand(right));
3724 DCHECK(is_int16(EQUAL));
3725 __ Ret(USE_DELAY_SLOT);
3726 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3733 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3734 DCHECK(state() == CompareICState::UNIQUE_NAME);
3735 DCHECK(GetCondition() == eq);
3738 // Registers containing left and right operands respectively.
3740 Register right = a0;
3744 // Check that both operands are heap objects.
3745 __ JumpIfEitherSmi(left, right, &miss);
3747 // Check that both operands are unique names. This leaves the instance
3748 // types loaded in tmp1 and tmp2.
3749 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3750 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3751 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3752 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3754 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3755 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3760 // Unique names are compared by identity.
3762 __ Branch(&done, ne, left, Operand(right));
3763 // Make sure a0 is non-zero. At this point input operands are
3764 // guaranteed to be non-zero.
3765 DCHECK(right.is(a0));
3766 STATIC_ASSERT(EQUAL == 0);
3767 STATIC_ASSERT(kSmiTag == 0);
3768 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3777 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3778 DCHECK(state() == CompareICState::STRING);
3781 bool equality = Token::IsEqualityOp(op());
3783 // Registers containing left and right operands respectively.
3785 Register right = a0;
3792 // Check that both operands are heap objects.
3793 __ JumpIfEitherSmi(left, right, &miss);
3795 // Check that both operands are strings. This leaves the instance
3796 // types loaded in tmp1 and tmp2.
3797 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3798 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3799 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3800 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3801 STATIC_ASSERT(kNotStringTag != 0);
3802 __ Or(tmp3, tmp1, tmp2);
3803 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3804 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3806 // Fast check for identical strings.
3807 Label left_ne_right;
3808 STATIC_ASSERT(EQUAL == 0);
3809 STATIC_ASSERT(kSmiTag == 0);
3810 __ Branch(&left_ne_right, ne, left, Operand(right));
3811 __ Ret(USE_DELAY_SLOT);
3812 __ mov(v0, zero_reg); // In the delay slot.
3813 __ bind(&left_ne_right);
3815 // Handle not identical strings.
3817 // Check that both strings are internalized strings. If they are, we're done
3818 // because we already know they are not identical. We know they are both
3821 DCHECK(GetCondition() == eq);
3822 STATIC_ASSERT(kInternalizedTag == 0);
3823 __ Or(tmp3, tmp1, Operand(tmp2));
3824 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3826 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3827 // Make sure a0 is non-zero. At this point input operands are
3828 // guaranteed to be non-zero.
3829 DCHECK(right.is(a0));
3830 __ Ret(USE_DELAY_SLOT);
3831 __ mov(v0, a0); // In the delay slot.
3832 __ bind(&is_symbol);
3835 // Check that both strings are sequential one_byte.
3837 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3840 // Compare flat one_byte strings. Returns when done.
3842 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3845 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3849 // Handle more complex cases in runtime.
3851 __ Push(left, right);
3853 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3855 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3863 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3864 DCHECK(state() == CompareICState::OBJECT);
3866 __ And(a2, a1, Operand(a0));
3867 __ JumpIfSmi(a2, &miss);
3869 __ GetObjectType(a0, a2, a2);
3870 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3871 __ GetObjectType(a1, a2, a2);
3872 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3874 DCHECK(GetCondition() == eq);
3875 __ Ret(USE_DELAY_SLOT);
3876 __ dsubu(v0, a0, a1);
3883 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3885 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3887 __ JumpIfSmi(a2, &miss);
3888 __ GetWeakValue(a4, cell);
3889 __ ld(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3890 __ ld(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3891 __ Branch(&miss, ne, a2, Operand(a4));
3892 __ Branch(&miss, ne, a3, Operand(a4));
3894 __ Ret(USE_DELAY_SLOT);
3895 __ dsubu(v0, a0, a1);
3902 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3904 // Call the runtime system in a fresh internal frame.
3905 FrameScope scope(masm, StackFrame::INTERNAL);
3907 __ Push(ra, a1, a0);
3908 __ li(a4, Operand(Smi::FromInt(op())));
3909 __ daddiu(sp, sp, -kPointerSize);
3910 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3912 __ sd(a4, MemOperand(sp)); // In the delay slot.
3913 // Compute the entry point of the rewritten stub.
3914 __ Daddu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3915 // Restore registers.
3922 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3923 // Make place for arguments to fit C calling convention. Most of the callers
3924 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3925 // so they handle stack restoring and we don't have to do that here.
3926 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3927 // kCArgsSlotsSize stack space after the call.
3928 __ daddiu(sp, sp, -kCArgsSlotsSize);
3929 // Place the return address on the stack, making the call
3930 // GC safe. The RegExp backend also relies on this.
3931 __ sd(ra, MemOperand(sp, kCArgsSlotsSize));
3932 __ Call(t9); // Call the C++ function.
3933 __ ld(t9, MemOperand(sp, kCArgsSlotsSize));
3935 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3936 // In case of an error the return address may point to a memory area
3937 // filled with kZapValue by the GC.
3938 // Dereference the address and check for this.
3939 __ Uld(a4, MemOperand(t9));
3940 __ Assert(ne, kReceivedInvalidReturnAddress, a4,
3941 Operand(reinterpret_cast<uint64_t>(kZapValue)));
3947 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3950 reinterpret_cast<intptr_t>(GetCode().location());
3951 __ Move(t9, target);
3952 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
3957 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3961 Register properties,
3963 Register scratch0) {
3964 DCHECK(name->IsUniqueName());
3965 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3966 // not equal to the name and kProbes-th slot is not used (its name is the
3967 // undefined value), it guarantees the hash table doesn't contain the
3968 // property. It's true even if some slots represent deleted properties
3969 // (their names are the hole value).
3970 for (int i = 0; i < kInlinedProbes; i++) {
3971 // scratch0 points to properties hash.
3972 // Compute the masked index: (hash + i + i * i) & mask.
3973 Register index = scratch0;
3974 // Capacity is smi 2^n.
3975 __ SmiLoadUntag(index, FieldMemOperand(properties, kCapacityOffset));
3976 __ Dsubu(index, index, Operand(1));
3977 __ And(index, index,
3978 Operand(name->Hash() + NameDictionary::GetProbeOffset(i)));
3980 // Scale the index by multiplying by the entry size.
3981 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
3982 __ dsll(at, index, 1);
3983 __ Daddu(index, index, at); // index *= 3.
3985 Register entity_name = scratch0;
3986 // Having undefined at this place means the name is not contained.
3987 STATIC_ASSERT(kSmiTagSize == 1);
3988 Register tmp = properties;
3990 __ dsll(scratch0, index, kPointerSizeLog2);
3991 __ Daddu(tmp, properties, scratch0);
3992 __ ld(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
3994 DCHECK(!tmp.is(entity_name));
3995 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
3996 __ Branch(done, eq, entity_name, Operand(tmp));
3998 // Load the hole ready for use below:
3999 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4001 // Stop if found the property.
4002 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4005 __ Branch(&good, eq, entity_name, Operand(tmp));
4007 // Check if the entry name is not a unique name.
4008 __ ld(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4010 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4011 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4014 // Restore the properties.
4016 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4019 const int spill_mask =
4020 (ra.bit() | a6.bit() | a5.bit() | a4.bit() | a3.bit() |
4021 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4023 __ MultiPush(spill_mask);
4024 __ ld(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4025 __ li(a1, Operand(Handle<Name>(name)));
4026 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4029 __ MultiPop(spill_mask);
4031 __ Branch(done, eq, at, Operand(zero_reg));
4032 __ Branch(miss, ne, at, Operand(zero_reg));
4036 // Probe the name dictionary in the |elements| register. Jump to the
4037 // |done| label if a property with the given name is found. Jump to
4038 // the |miss| label otherwise.
4039 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4040 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4046 Register scratch2) {
4047 DCHECK(!elements.is(scratch1));
4048 DCHECK(!elements.is(scratch2));
4049 DCHECK(!name.is(scratch1));
4050 DCHECK(!name.is(scratch2));
4052 __ AssertName(name);
4054 // Compute the capacity mask.
4055 __ ld(scratch1, FieldMemOperand(elements, kCapacityOffset));
4056 __ SmiUntag(scratch1);
4057 __ Dsubu(scratch1, scratch1, Operand(1));
4059 // Generate an unrolled loop that performs a few probes before
4060 // giving up. Measurements done on Gmail indicate that 2 probes
4061 // cover ~93% of loads from dictionaries.
4062 for (int i = 0; i < kInlinedProbes; i++) {
4063 // Compute the masked index: (hash + i + i * i) & mask.
4064 __ lwu(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4066 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4067 // the hash in a separate instruction. The value hash + i + i * i is right
4068 // shifted in the following and instruction.
4069 DCHECK(NameDictionary::GetProbeOffset(i) <
4070 1 << (32 - Name::kHashFieldOffset));
4071 __ Daddu(scratch2, scratch2, Operand(
4072 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4074 __ dsrl(scratch2, scratch2, Name::kHashShift);
4075 __ And(scratch2, scratch1, scratch2);
4077 // Scale the index by multiplying by the entry size.
4078 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4079 // scratch2 = scratch2 * 3.
4081 __ dsll(at, scratch2, 1);
4082 __ Daddu(scratch2, scratch2, at);
4084 // Check if the key is identical to the name.
4085 __ dsll(at, scratch2, kPointerSizeLog2);
4086 __ Daddu(scratch2, elements, at);
4087 __ ld(at, FieldMemOperand(scratch2, kElementsStartOffset));
4088 __ Branch(done, eq, name, Operand(at));
4091 const int spill_mask =
4092 (ra.bit() | a6.bit() | a5.bit() | a4.bit() |
4093 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4094 ~(scratch1.bit() | scratch2.bit());
4096 __ MultiPush(spill_mask);
4098 DCHECK(!elements.is(a1));
4100 __ Move(a0, elements);
4102 __ Move(a0, elements);
4105 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4107 __ mov(scratch2, a2);
4109 __ MultiPop(spill_mask);
4111 __ Branch(done, ne, at, Operand(zero_reg));
4112 __ Branch(miss, eq, at, Operand(zero_reg));
4116 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4117 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4118 // we cannot call anything that could cause a GC from this stub.
4120 // result: NameDictionary to probe
4122 // dictionary: NameDictionary to probe.
4123 // index: will hold an index of entry if lookup is successful.
4124 // might alias with result_.
4126 // result_ is zero if lookup failed, non zero otherwise.
4128 Register result = v0;
4129 Register dictionary = a0;
4131 Register index = a2;
4134 Register undefined = a5;
4135 Register entry_key = a6;
4137 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4139 __ ld(mask, FieldMemOperand(dictionary, kCapacityOffset));
4141 __ Dsubu(mask, mask, Operand(1));
4143 __ lwu(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4145 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4147 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4148 // Compute the masked index: (hash + i + i * i) & mask.
4149 // Capacity is smi 2^n.
4151 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4152 // the hash in a separate instruction. The value hash + i + i * i is right
4153 // shifted in the following and instruction.
4154 DCHECK(NameDictionary::GetProbeOffset(i) <
4155 1 << (32 - Name::kHashFieldOffset));
4156 __ Daddu(index, hash, Operand(
4157 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4159 __ mov(index, hash);
4161 __ dsrl(index, index, Name::kHashShift);
4162 __ And(index, mask, index);
4164 // Scale the index by multiplying by the entry size.
4165 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4168 __ dsll(index, index, 1);
4169 __ Daddu(index, index, at);
4172 STATIC_ASSERT(kSmiTagSize == 1);
4173 __ dsll(index, index, kPointerSizeLog2);
4174 __ Daddu(index, index, dictionary);
4175 __ ld(entry_key, FieldMemOperand(index, kElementsStartOffset));
4177 // Having undefined at this place means the name is not contained.
4178 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4180 // Stop if found the property.
4181 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4183 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4184 // Check if the entry name is not a unique name.
4185 __ ld(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4187 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4188 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4192 __ bind(&maybe_in_dictionary);
4193 // If we are doing negative lookup then probing failure should be
4194 // treated as a lookup success. For positive lookup probing failure
4195 // should be treated as lookup failure.
4196 if (mode() == POSITIVE_LOOKUP) {
4197 __ Ret(USE_DELAY_SLOT);
4198 __ mov(result, zero_reg);
4201 __ bind(&in_dictionary);
4202 __ Ret(USE_DELAY_SLOT);
4205 __ bind(¬_in_dictionary);
4206 __ Ret(USE_DELAY_SLOT);
4207 __ mov(result, zero_reg);
4211 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4213 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4215 // Hydrogen code stubs need stub2 at snapshot time.
4216 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4221 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4222 // the value has just been written into the object, now this stub makes sure
4223 // we keep the GC informed. The word in the object where the value has been
4224 // written is in the address register.
4225 void RecordWriteStub::Generate(MacroAssembler* masm) {
4226 Label skip_to_incremental_noncompacting;
4227 Label skip_to_incremental_compacting;
4229 // The first two branch+nop instructions are generated with labels so as to
4230 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4231 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4232 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4233 // incremental heap marking.
4234 // See RecordWriteStub::Patch for details.
4235 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4237 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4240 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4241 __ RememberedSetHelper(object(),
4244 save_fp_regs_mode(),
4245 MacroAssembler::kReturnAtEnd);
4249 __ bind(&skip_to_incremental_noncompacting);
4250 GenerateIncremental(masm, INCREMENTAL);
4252 __ bind(&skip_to_incremental_compacting);
4253 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4255 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4256 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4258 PatchBranchIntoNop(masm, 0);
4259 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4263 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4266 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4267 Label dont_need_remembered_set;
4269 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
4270 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4272 &dont_need_remembered_set);
4274 __ CheckPageFlag(regs_.object(),
4276 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4278 &dont_need_remembered_set);
4280 // First notify the incremental marker if necessary, then update the
4282 CheckNeedsToInformIncrementalMarker(
4283 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4284 InformIncrementalMarker(masm);
4285 regs_.Restore(masm);
4286 __ RememberedSetHelper(object(),
4289 save_fp_regs_mode(),
4290 MacroAssembler::kReturnAtEnd);
4292 __ bind(&dont_need_remembered_set);
4295 CheckNeedsToInformIncrementalMarker(
4296 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4297 InformIncrementalMarker(masm);
4298 regs_.Restore(masm);
4303 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4304 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4305 int argument_count = 3;
4306 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4308 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4309 DCHECK(!address.is(regs_.object()));
4310 DCHECK(!address.is(a0));
4311 __ Move(address, regs_.address());
4312 __ Move(a0, regs_.object());
4313 __ Move(a1, address);
4314 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4316 AllowExternalCallThatCantCauseGC scope(masm);
4318 ExternalReference::incremental_marking_record_write_function(isolate()),
4320 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4324 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4325 MacroAssembler* masm,
4326 OnNoNeedToInformIncrementalMarker on_no_need,
4329 Label need_incremental;
4330 Label need_incremental_pop_scratch;
4332 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4333 __ ld(regs_.scratch1(),
4334 MemOperand(regs_.scratch0(),
4335 MemoryChunk::kWriteBarrierCounterOffset));
4336 __ Dsubu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4337 __ sd(regs_.scratch1(),
4338 MemOperand(regs_.scratch0(),
4339 MemoryChunk::kWriteBarrierCounterOffset));
4340 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4342 // Let's look at the color of the object: If it is not black we don't have
4343 // to inform the incremental marker.
4344 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4346 regs_.Restore(masm);
4347 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4348 __ RememberedSetHelper(object(),
4351 save_fp_regs_mode(),
4352 MacroAssembler::kReturnAtEnd);
4359 // Get the value from the slot.
4360 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
4362 if (mode == INCREMENTAL_COMPACTION) {
4363 Label ensure_not_white;
4365 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4366 regs_.scratch1(), // Scratch.
4367 MemoryChunk::kEvacuationCandidateMask,
4371 __ CheckPageFlag(regs_.object(),
4372 regs_.scratch1(), // Scratch.
4373 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4377 __ bind(&ensure_not_white);
4380 // We need extra registers for this, so we push the object and the address
4381 // register temporarily.
4382 __ Push(regs_.object(), regs_.address());
4383 __ EnsureNotWhite(regs_.scratch0(), // The value.
4384 regs_.scratch1(), // Scratch.
4385 regs_.object(), // Scratch.
4386 regs_.address(), // Scratch.
4387 &need_incremental_pop_scratch);
4388 __ Pop(regs_.object(), regs_.address());
4390 regs_.Restore(masm);
4391 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4392 __ RememberedSetHelper(object(),
4395 save_fp_regs_mode(),
4396 MacroAssembler::kReturnAtEnd);
4401 __ bind(&need_incremental_pop_scratch);
4402 __ Pop(regs_.object(), regs_.address());
4404 __ bind(&need_incremental);
4406 // Fall through when we need to inform the incremental marker.
4410 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4411 // ----------- S t a t e -------------
4412 // -- a0 : element value to store
4413 // -- a3 : element index as smi
4414 // -- sp[0] : array literal index in function as smi
4415 // -- sp[4] : array literal
4416 // clobbers a1, a2, a4
4417 // -----------------------------------
4420 Label double_elements;
4422 Label slow_elements;
4423 Label fast_elements;
4425 // Get array literal index, array literal and its map.
4426 __ ld(a4, MemOperand(sp, 0 * kPointerSize));
4427 __ ld(a1, MemOperand(sp, 1 * kPointerSize));
4428 __ ld(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4430 __ CheckFastElements(a2, a5, &double_elements);
4431 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4432 __ JumpIfSmi(a0, &smi_element);
4433 __ CheckFastSmiElements(a2, a5, &fast_elements);
4435 // Store into the array literal requires a elements transition. Call into
4437 __ bind(&slow_elements);
4439 __ Push(a1, a3, a0);
4440 __ ld(a5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4441 __ ld(a5, FieldMemOperand(a5, JSFunction::kLiteralsOffset));
4443 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4445 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4446 __ bind(&fast_elements);
4447 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4448 __ SmiScale(a6, a3, kPointerSizeLog2);
4449 __ Daddu(a6, a5, a6);
4450 __ Daddu(a6, a6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4451 __ sd(a0, MemOperand(a6, 0));
4452 // Update the write barrier for the array store.
4453 __ RecordWrite(a5, a6, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4454 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4455 __ Ret(USE_DELAY_SLOT);
4458 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4459 // and value is Smi.
4460 __ bind(&smi_element);
4461 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4462 __ SmiScale(a6, a3, kPointerSizeLog2);
4463 __ Daddu(a6, a5, a6);
4464 __ sd(a0, FieldMemOperand(a6, FixedArray::kHeaderSize));
4465 __ Ret(USE_DELAY_SLOT);
4468 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4469 __ bind(&double_elements);
4470 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4471 __ StoreNumberToDoubleElements(a0, a3, a5, a7, t1, &slow_elements);
4472 __ Ret(USE_DELAY_SLOT);
4477 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4478 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4479 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4480 int parameter_count_offset =
4481 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4482 __ ld(a1, MemOperand(fp, parameter_count_offset));
4483 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4484 __ Daddu(a1, a1, Operand(1));
4486 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4487 __ dsll(a1, a1, kPointerSizeLog2);
4488 __ Ret(USE_DELAY_SLOT);
4489 __ Daddu(sp, sp, a1);
4493 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4494 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4495 LoadICStub stub(isolate(), state());
4496 stub.GenerateForTrampoline(masm);
4500 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4501 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4502 KeyedLoadICStub stub(isolate(), state());
4503 stub.GenerateForTrampoline(masm);
4507 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4508 EmitLoadTypeFeedbackVector(masm, a2);
4509 CallICStub stub(isolate(), state());
4510 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4514 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4517 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4518 GenerateImpl(masm, true);
4522 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4523 Register receiver_map, Register scratch1,
4524 Register scratch2, bool is_polymorphic,
4526 // feedback initially contains the feedback array
4527 Label next_loop, prepare_next;
4528 Label start_polymorphic;
4530 Register cached_map = scratch1;
4533 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4534 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4535 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4536 // found, now call handler.
4537 Register handler = feedback;
4538 __ ld(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4539 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4542 Register length = scratch2;
4543 __ bind(&start_polymorphic);
4544 __ ld(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4545 if (!is_polymorphic) {
4546 // If the IC could be monomorphic we have to make sure we don't go past the
4547 // end of the feedback array.
4548 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4551 Register too_far = length;
4552 Register pointer_reg = feedback;
4554 // +-----+------+------+-----+-----+ ... ----+
4555 // | map | len | wm0 | h0 | wm1 | hN |
4556 // +-----+------+------+-----+-----+ ... ----+
4560 // pointer_reg too_far
4561 // aka feedback scratch2
4562 // also need receiver_map
4563 // use cached_map (scratch1) to look in the weak map values.
4564 __ SmiScale(too_far, length, kPointerSizeLog2);
4565 __ Daddu(too_far, feedback, Operand(too_far));
4566 __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4567 __ Daddu(pointer_reg, feedback,
4568 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4570 __ bind(&next_loop);
4571 __ ld(cached_map, MemOperand(pointer_reg));
4572 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4573 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4574 __ ld(handler, MemOperand(pointer_reg, kPointerSize));
4575 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4578 __ bind(&prepare_next);
4579 __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4580 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4582 // We exhausted our array of map handler pairs.
4587 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4588 Register receiver_map, Register feedback,
4589 Register vector, Register slot,
4590 Register scratch, Label* compare_map,
4591 Label* load_smi_map, Label* try_array) {
4592 __ JumpIfSmi(receiver, load_smi_map);
4593 __ ld(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4594 __ bind(compare_map);
4595 Register cached_map = scratch;
4596 // Move the weak map into the weak_cell register.
4597 __ ld(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4598 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4599 Register handler = feedback;
4600 __ SmiScale(handler, slot, kPointerSizeLog2);
4601 __ Daddu(handler, vector, Operand(handler));
4603 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4604 __ Daddu(t9, handler, Code::kHeaderSize - kHeapObjectTag);
4609 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4610 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4611 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4612 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4613 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4614 Register feedback = a4;
4615 Register receiver_map = a5;
4616 Register scratch1 = a6;
4618 __ SmiScale(feedback, slot, kPointerSizeLog2);
4619 __ Daddu(feedback, vector, Operand(feedback));
4620 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4622 // Try to quickly handle the monomorphic case without knowing for sure
4623 // if we have a weak cell in feedback. We do know it's safe to look
4624 // at WeakCell::kValueOffset.
4625 Label try_array, load_smi_map, compare_map;
4626 Label not_array, miss;
4627 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4628 scratch1, &compare_map, &load_smi_map, &try_array);
4630 // Is it a fixed array?
4631 __ bind(&try_array);
4632 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4633 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4634 __ Branch(¬_array, ne, scratch1, Operand(at));
4635 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss);
4637 __ bind(¬_array);
4638 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4639 __ Branch(&miss, ne, feedback, Operand(at));
4640 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4641 Code::ComputeHandlerFlags(Code::LOAD_IC));
4642 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4643 receiver, name, feedback,
4644 receiver_map, scratch1, a7);
4647 LoadIC::GenerateMiss(masm);
4649 __ bind(&load_smi_map);
4650 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4651 __ Branch(&compare_map);
4655 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4656 GenerateImpl(masm, false);
4660 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4661 GenerateImpl(masm, true);
4665 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4666 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4667 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4668 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4669 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4670 Register feedback = a4;
4671 Register receiver_map = a5;
4672 Register scratch1 = a6;
4674 __ SmiScale(feedback, slot, kPointerSizeLog2);
4675 __ Daddu(feedback, vector, Operand(feedback));
4676 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4678 // Try to quickly handle the monomorphic case without knowing for sure
4679 // if we have a weak cell in feedback. We do know it's safe to look
4680 // at WeakCell::kValueOffset.
4681 Label try_array, load_smi_map, compare_map;
4682 Label not_array, miss;
4683 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4684 scratch1, &compare_map, &load_smi_map, &try_array);
4686 __ bind(&try_array);
4687 // Is it a fixed array?
4688 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4689 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4690 __ Branch(¬_array, ne, scratch1, Operand(at));
4691 // We have a polymorphic element handler.
4692 __ JumpIfNotSmi(key, &miss);
4694 Label polymorphic, try_poly_name;
4695 __ bind(&polymorphic);
4696 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss);
4698 __ bind(¬_array);
4700 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4701 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4702 Handle<Code> megamorphic_stub =
4703 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4704 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4706 __ bind(&try_poly_name);
4707 // We might have a name in feedback, and a fixed array in the next slot.
4708 __ Branch(&miss, ne, key, Operand(feedback));
4709 // If the name comparison succeeded, we know we have a fixed array with
4710 // at least one map/handler pair.
4711 __ SmiScale(feedback, slot, kPointerSizeLog2);
4712 __ Daddu(feedback, vector, Operand(feedback));
4714 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4715 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, false, &miss);
4718 KeyedLoadIC::GenerateMiss(masm);
4720 __ bind(&load_smi_map);
4721 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4722 __ Branch(&compare_map);
4726 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4727 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4728 VectorStoreICStub stub(isolate(), state());
4729 stub.GenerateForTrampoline(masm);
4733 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4734 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4735 VectorKeyedStoreICStub stub(isolate(), state());
4736 stub.GenerateForTrampoline(masm);
4740 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4741 GenerateImpl(masm, false);
4745 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4746 GenerateImpl(masm, true);
4750 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4751 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4752 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4753 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4754 Register slot = VectorStoreICDescriptor::SlotRegister(); // a4
4755 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4756 Register feedback = a5;
4757 Register receiver_map = a6;
4758 Register scratch1 = a7;
4760 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4761 __ Daddu(feedback, vector, Operand(scratch1));
4762 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4764 // Try to quickly handle the monomorphic case without knowing for sure
4765 // if we have a weak cell in feedback. We do know it's safe to look
4766 // at WeakCell::kValueOffset.
4767 Label try_array, load_smi_map, compare_map;
4768 Label not_array, miss;
4769 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4770 scratch1, &compare_map, &load_smi_map, &try_array);
4772 // Is it a fixed array?
4773 __ bind(&try_array);
4774 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4775 __ Branch(¬_array, ne, scratch1, Heap::kFixedArrayMapRootIndex);
4777 Register scratch2 = t0;
4778 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4781 __ bind(¬_array);
4782 __ Branch(&miss, ne, feedback, Heap::kmegamorphic_symbolRootIndex);
4783 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4784 Code::ComputeHandlerFlags(Code::STORE_IC));
4785 masm->isolate()->stub_cache()->GenerateProbe(
4786 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4787 scratch1, scratch2);
4790 StoreIC::GenerateMiss(masm);
4792 __ bind(&load_smi_map);
4793 __ Branch(USE_DELAY_SLOT, &compare_map);
4794 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4798 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4799 GenerateImpl(masm, false);
4803 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4804 GenerateImpl(masm, true);
4808 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4809 Register receiver_map, Register scratch1,
4810 Register scratch2, Label* miss) {
4811 // feedback initially contains the feedback array
4812 Label next_loop, prepare_next;
4813 Label start_polymorphic;
4814 Label transition_call;
4816 Register cached_map = scratch1;
4817 Register too_far = scratch2;
4818 Register pointer_reg = feedback;
4820 __ ld(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4822 // +-----+------+------+-----+-----+-----+ ... ----+
4823 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4824 // +-----+------+------+-----+-----+ ----+ ... ----+
4828 // pointer_reg too_far
4829 // aka feedback scratch2
4830 // also need receiver_map
4831 // use cached_map (scratch1) to look in the weak map values.
4832 __ SmiScale(too_far, too_far, kPointerSizeLog2);
4833 __ Daddu(too_far, feedback, Operand(too_far));
4834 __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4835 __ Daddu(pointer_reg, feedback,
4836 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4838 __ bind(&next_loop);
4839 __ ld(cached_map, MemOperand(pointer_reg));
4840 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4841 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4842 // Is it a transitioning store?
4843 __ ld(too_far, MemOperand(pointer_reg, kPointerSize));
4844 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4845 __ Branch(&transition_call, ne, too_far, Operand(at));
4847 __ ld(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4848 __ Daddu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4851 __ bind(&transition_call);
4852 __ ld(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4853 __ JumpIfSmi(too_far, miss);
4855 __ ld(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4856 // Load the map into the correct register.
4857 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4858 __ Move(feedback, too_far);
4859 __ Daddu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4862 __ bind(&prepare_next);
4863 __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4864 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4866 // We exhausted our array of map handler pairs.
4871 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4872 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4873 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4874 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4875 Register slot = VectorStoreICDescriptor::SlotRegister(); // a4
4876 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4877 Register feedback = a5;
4878 Register receiver_map = a6;
4879 Register scratch1 = a7;
4881 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4882 __ Daddu(feedback, vector, Operand(scratch1));
4883 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4885 // Try to quickly handle the monomorphic case without knowing for sure
4886 // if we have a weak cell in feedback. We do know it's safe to look
4887 // at WeakCell::kValueOffset.
4888 Label try_array, load_smi_map, compare_map;
4889 Label not_array, miss;
4890 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4891 scratch1, &compare_map, &load_smi_map, &try_array);
4893 __ bind(&try_array);
4894 // Is it a fixed array?
4895 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4896 __ Branch(¬_array, ne, scratch1, Heap::kFixedArrayMapRootIndex);
4898 // We have a polymorphic element handler.
4899 Label try_poly_name;
4901 Register scratch2 = t0;
4903 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4906 __ bind(¬_array);
4908 __ Branch(&try_poly_name, ne, feedback, Heap::kmegamorphic_symbolRootIndex);
4909 Handle<Code> megamorphic_stub =
4910 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4911 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4913 __ bind(&try_poly_name);
4914 // We might have a name in feedback, and a fixed array in the next slot.
4915 __ Branch(&miss, ne, key, Operand(feedback));
4916 // If the name comparison succeeded, we know we have a fixed array with
4917 // at least one map/handler pair.
4918 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4919 __ Daddu(feedback, vector, Operand(scratch1));
4921 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4922 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4926 KeyedStoreIC::GenerateMiss(masm);
4928 __ bind(&load_smi_map);
4929 __ Branch(USE_DELAY_SLOT, &compare_map);
4930 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4934 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4935 if (masm->isolate()->function_entry_hook() != NULL) {
4936 ProfileEntryHookStub stub(masm->isolate());
4944 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4945 // The entry hook is a "push ra" instruction, followed by a call.
4946 // Note: on MIPS "push" is 2 instruction
4947 const int32_t kReturnAddressDistanceFromFunctionStart =
4948 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
4950 // This should contain all kJSCallerSaved registers.
4951 const RegList kSavedRegs =
4952 kJSCallerSaved | // Caller saved registers.
4953 s5.bit(); // Saved stack pointer.
4955 // We also save ra, so the count here is one higher than the mask indicates.
4956 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
4958 // Save all caller-save registers as this may be called from anywhere.
4959 __ MultiPush(kSavedRegs | ra.bit());
4961 // Compute the function's address for the first argument.
4962 __ Dsubu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
4964 // The caller's return address is above the saved temporaries.
4965 // Grab that for the second argument to the hook.
4966 __ Daddu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
4968 // Align the stack if necessary.
4969 int frame_alignment = masm->ActivationFrameAlignment();
4970 if (frame_alignment > kPointerSize) {
4972 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4973 __ And(sp, sp, Operand(-frame_alignment));
4976 __ Dsubu(sp, sp, kCArgsSlotsSize);
4977 #if defined(V8_HOST_ARCH_MIPS) || defined(V8_HOST_ARCH_MIPS64)
4978 int64_t entry_hook =
4979 reinterpret_cast<int64_t>(isolate()->function_entry_hook());
4980 __ li(t9, Operand(entry_hook));
4982 // Under the simulator we need to indirect the entry hook through a
4983 // trampoline function at a known address.
4984 // It additionally takes an isolate as a third parameter.
4985 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4987 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4988 __ li(t9, Operand(ExternalReference(&dispatcher,
4989 ExternalReference::BUILTIN_CALL,
4992 // Call C function through t9 to conform ABI for PIC.
4995 // Restore the stack pointer if needed.
4996 if (frame_alignment > kPointerSize) {
4999 __ Daddu(sp, sp, kCArgsSlotsSize);
5002 // Also pop ra to get Ret(0).
5003 __ MultiPop(kSavedRegs | ra.bit());
5009 static void CreateArrayDispatch(MacroAssembler* masm,
5010 AllocationSiteOverrideMode mode) {
5011 if (mode == DISABLE_ALLOCATION_SITES) {
5012 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5013 __ TailCallStub(&stub);
5014 } else if (mode == DONT_OVERRIDE) {
5015 int last_index = GetSequenceIndexFromFastElementsKind(
5016 TERMINAL_FAST_ELEMENTS_KIND);
5017 for (int i = 0; i <= last_index; ++i) {
5018 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5019 T stub(masm->isolate(), kind);
5020 __ TailCallStub(&stub, eq, a3, Operand(kind));
5023 // If we reached this point there is a problem.
5024 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5031 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5032 AllocationSiteOverrideMode mode) {
5033 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5034 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5035 // a0 - number of arguments
5036 // a1 - constructor?
5037 // sp[0] - last argument
5038 Label normal_sequence;
5039 if (mode == DONT_OVERRIDE) {
5040 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5041 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5042 STATIC_ASSERT(FAST_ELEMENTS == 2);
5043 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5044 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5045 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5047 // is the low bit set? If so, we are holey and that is good.
5048 __ And(at, a3, Operand(1));
5049 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5051 // look at the first argument
5052 __ ld(a5, MemOperand(sp, 0));
5053 __ Branch(&normal_sequence, eq, a5, Operand(zero_reg));
5055 if (mode == DISABLE_ALLOCATION_SITES) {
5056 ElementsKind initial = GetInitialFastElementsKind();
5057 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5059 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5061 DISABLE_ALLOCATION_SITES);
5062 __ TailCallStub(&stub_holey);
5064 __ bind(&normal_sequence);
5065 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5067 DISABLE_ALLOCATION_SITES);
5068 __ TailCallStub(&stub);
5069 } else if (mode == DONT_OVERRIDE) {
5070 // We are going to create a holey array, but our kind is non-holey.
5071 // Fix kind and retry (only if we have an allocation site in the slot).
5072 __ Daddu(a3, a3, Operand(1));
5074 if (FLAG_debug_code) {
5075 __ ld(a5, FieldMemOperand(a2, 0));
5076 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5077 __ Assert(eq, kExpectedAllocationSite, a5, Operand(at));
5080 // Save the resulting elements kind in type info. We can't just store a3
5081 // in the AllocationSite::transition_info field because elements kind is
5082 // restricted to a portion of the field...upper bits need to be left alone.
5083 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5084 __ ld(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5085 __ Daddu(a4, a4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5086 __ sd(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5089 __ bind(&normal_sequence);
5090 int last_index = GetSequenceIndexFromFastElementsKind(
5091 TERMINAL_FAST_ELEMENTS_KIND);
5092 for (int i = 0; i <= last_index; ++i) {
5093 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5094 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5095 __ TailCallStub(&stub, eq, a3, Operand(kind));
5098 // If we reached this point there is a problem.
5099 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5107 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5108 int to_index = GetSequenceIndexFromFastElementsKind(
5109 TERMINAL_FAST_ELEMENTS_KIND);
5110 for (int i = 0; i <= to_index; ++i) {
5111 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5112 T stub(isolate, kind);
5114 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5115 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5122 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5123 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5125 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5127 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5132 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5134 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5135 for (int i = 0; i < 2; i++) {
5136 // For internal arrays we only need a few things.
5137 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5139 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5141 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5147 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5148 MacroAssembler* masm,
5149 AllocationSiteOverrideMode mode) {
5150 if (argument_count() == ANY) {
5151 Label not_zero_case, not_one_case;
5153 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5154 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5156 __ bind(¬_zero_case);
5157 __ Branch(¬_one_case, gt, a0, Operand(1));
5158 CreateArrayDispatchOneArgument(masm, mode);
5160 __ bind(¬_one_case);
5161 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5162 } else if (argument_count() == NONE) {
5163 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5164 } else if (argument_count() == ONE) {
5165 CreateArrayDispatchOneArgument(masm, mode);
5166 } else if (argument_count() == MORE_THAN_ONE) {
5167 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5174 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5175 // ----------- S t a t e -------------
5176 // -- a0 : argc (only if argument_count() == ANY)
5177 // -- a1 : constructor
5178 // -- a2 : AllocationSite or undefined
5179 // -- a3 : original constructor
5180 // -- sp[0] : last argument
5181 // -----------------------------------
5183 if (FLAG_debug_code) {
5184 // The array construct code is only set for the global and natives
5185 // builtin Array functions which always have maps.
5187 // Initial map for the builtin Array function should be a map.
5188 __ ld(a4, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5189 // Will both indicate a NULL and a Smi.
5191 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5192 at, Operand(zero_reg));
5193 __ GetObjectType(a4, a4, a5);
5194 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5195 a5, Operand(MAP_TYPE));
5197 // We should either have undefined in a2 or a valid AllocationSite
5198 __ AssertUndefinedOrAllocationSite(a2, a4);
5202 __ Branch(&subclassing, ne, a1, Operand(a3));
5205 // Get the elements kind and case on that.
5206 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5207 __ Branch(&no_info, eq, a2, Operand(at));
5209 __ ld(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5211 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5212 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5213 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5216 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5219 __ bind(&subclassing);
5224 switch (argument_count()) {
5227 __ li(at, Operand(2));
5228 __ addu(a0, a0, at);
5231 __ li(a0, Operand(2));
5234 __ li(a0, Operand(3));
5238 __ JumpToExternalReference(
5239 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5243 void InternalArrayConstructorStub::GenerateCase(
5244 MacroAssembler* masm, ElementsKind kind) {
5246 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5247 __ TailCallStub(&stub0, lo, a0, Operand(1));
5249 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5250 __ TailCallStub(&stubN, hi, a0, Operand(1));
5252 if (IsFastPackedElementsKind(kind)) {
5253 // We might need to create a holey array
5254 // look at the first argument.
5255 __ ld(at, MemOperand(sp, 0));
5257 InternalArraySingleArgumentConstructorStub
5258 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5259 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5262 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5263 __ TailCallStub(&stub1);
5267 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5268 // ----------- S t a t e -------------
5270 // -- a1 : constructor
5271 // -- sp[0] : return address
5272 // -- sp[4] : last argument
5273 // -----------------------------------
5275 if (FLAG_debug_code) {
5276 // The array construct code is only set for the global and natives
5277 // builtin Array functions which always have maps.
5279 // Initial map for the builtin Array function should be a map.
5280 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5281 // Will both indicate a NULL and a Smi.
5283 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5284 at, Operand(zero_reg));
5285 __ GetObjectType(a3, a3, a4);
5286 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5287 a4, Operand(MAP_TYPE));
5290 // Figure out the right elements kind.
5291 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5293 // Load the map's "bit field 2" into a3. We only need the first byte,
5294 // but the following bit field extraction takes care of that anyway.
5295 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5296 // Retrieve elements_kind from bit field 2.
5297 __ DecodeField<Map::ElementsKindBits>(a3);
5299 if (FLAG_debug_code) {
5301 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5303 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5304 a3, Operand(FAST_HOLEY_ELEMENTS));
5308 Label fast_elements_case;
5309 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5310 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5312 __ bind(&fast_elements_case);
5313 GenerateCase(masm, FAST_ELEMENTS);
5317 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5318 Register context_reg = cp;
5319 Register slot_reg = a2;
5320 Register result_reg = v0;
5323 // Go up context chain to the script context.
5324 for (int i = 0; i < depth(); ++i) {
5325 __ ld(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5326 context_reg = result_reg;
5329 // Load the PropertyCell value at the specified slot.
5330 __ dsll(at, slot_reg, kPointerSizeLog2);
5331 __ Daddu(at, at, Operand(context_reg));
5332 __ ld(result_reg, ContextOperand(at, 0));
5333 __ ld(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5335 // Check that value is not the_hole.
5336 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5337 __ Branch(&slow_case, eq, result_reg, Operand(at));
5340 // Fallback to the runtime.
5341 __ bind(&slow_case);
5342 __ SmiTag(slot_reg);
5344 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5348 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5349 Register context_reg = cp;
5350 Register slot_reg = a2;
5351 Register value_reg = a0;
5352 Register cell_reg = a4;
5353 Register cell_value_reg = a5;
5354 Register cell_details_reg = a6;
5355 Label fast_heapobject_case, fast_smi_case, slow_case;
5357 if (FLAG_debug_code) {
5358 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5359 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5362 // Go up context chain to the script context.
5363 for (int i = 0; i < depth(); ++i) {
5364 __ ld(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5365 context_reg = cell_reg;
5368 // Load the PropertyCell at the specified slot.
5369 __ dsll(at, slot_reg, kPointerSizeLog2);
5370 __ Daddu(at, at, Operand(context_reg));
5371 __ ld(cell_reg, ContextOperand(at, 0));
5373 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5374 __ ld(cell_details_reg,
5375 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5376 __ SmiUntag(cell_details_reg);
5377 __ And(cell_details_reg, cell_details_reg,
5378 PropertyDetails::PropertyCellTypeField::kMask |
5379 PropertyDetails::KindField::kMask |
5380 PropertyDetails::kAttributesReadOnlyMask);
5382 // Check if PropertyCell holds mutable data.
5383 Label not_mutable_data;
5384 __ Branch(¬_mutable_data, ne, cell_details_reg,
5385 Operand(PropertyDetails::PropertyCellTypeField::encode(
5386 PropertyCellType::kMutable) |
5387 PropertyDetails::KindField::encode(kData)));
5388 __ JumpIfSmi(value_reg, &fast_smi_case);
5389 __ bind(&fast_heapobject_case);
5390 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5391 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5392 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5393 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5394 // RecordWriteField clobbers the value register, so we need to reload.
5395 __ Ret(USE_DELAY_SLOT);
5396 __ ld(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5397 __ bind(¬_mutable_data);
5399 // Check if PropertyCell value matches the new value (relevant for Constant,
5400 // ConstantType and Undefined cells).
5401 Label not_same_value;
5402 __ ld(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5403 __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg));
5404 // Make sure the PropertyCell is not marked READ_ONLY.
5405 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5406 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5407 if (FLAG_debug_code) {
5409 // This can only be true for Constant, ConstantType and Undefined cells,
5410 // because we never store the_hole via this stub.
5411 __ Branch(&done, eq, cell_details_reg,
5412 Operand(PropertyDetails::PropertyCellTypeField::encode(
5413 PropertyCellType::kConstant) |
5414 PropertyDetails::KindField::encode(kData)));
5415 __ Branch(&done, eq, cell_details_reg,
5416 Operand(PropertyDetails::PropertyCellTypeField::encode(
5417 PropertyCellType::kConstantType) |
5418 PropertyDetails::KindField::encode(kData)));
5419 __ Check(eq, kUnexpectedValue, cell_details_reg,
5420 Operand(PropertyDetails::PropertyCellTypeField::encode(
5421 PropertyCellType::kUndefined) |
5422 PropertyDetails::KindField::encode(kData)));
5426 __ bind(¬_same_value);
5428 // Check if PropertyCell contains data with constant type (and is not
5430 __ Branch(&slow_case, ne, cell_details_reg,
5431 Operand(PropertyDetails::PropertyCellTypeField::encode(
5432 PropertyCellType::kConstantType) |
5433 PropertyDetails::KindField::encode(kData)));
5435 // Now either both old and new values must be SMIs or both must be heap
5436 // objects with same map.
5437 Label value_is_heap_object;
5438 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5439 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5440 // Old and new values are SMIs, no need for a write barrier here.
5441 __ bind(&fast_smi_case);
5442 __ Ret(USE_DELAY_SLOT);
5443 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5444 __ bind(&value_is_heap_object);
5445 __ JumpIfSmi(cell_value_reg, &slow_case);
5446 Register cell_value_map_reg = cell_value_reg;
5447 __ ld(cell_value_map_reg,
5448 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5449 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5450 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5452 // Fallback to the runtime.
5453 __ bind(&slow_case);
5454 __ SmiTag(slot_reg);
5455 __ Push(slot_reg, value_reg);
5456 __ TailCallRuntime(is_strict(language_mode())
5457 ? Runtime::kStoreGlobalViaContext_Strict
5458 : Runtime::kStoreGlobalViaContext_Sloppy,
5463 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5464 int64_t offset = (ref0.address() - ref1.address());
5465 DCHECK(static_cast<int>(offset) == offset);
5466 return static_cast<int>(offset);
5470 // Calls an API function. Allocates HandleScope, extracts returned value
5471 // from handle and propagates exceptions. Restores context. stack_space
5472 // - space to be unwound on exit (includes the call JS arguments space and
5473 // the additional space allocated for the fast call).
5474 static void CallApiFunctionAndReturn(
5475 MacroAssembler* masm, Register function_address,
5476 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5477 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5478 Isolate* isolate = masm->isolate();
5479 ExternalReference next_address =
5480 ExternalReference::handle_scope_next_address(isolate);
5481 const int kNextOffset = 0;
5482 const int kLimitOffset = AddressOffset(
5483 ExternalReference::handle_scope_limit_address(isolate), next_address);
5484 const int kLevelOffset = AddressOffset(
5485 ExternalReference::handle_scope_level_address(isolate), next_address);
5487 DCHECK(function_address.is(a1) || function_address.is(a2));
5489 Label profiler_disabled;
5490 Label end_profiler_check;
5491 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5492 __ lb(t9, MemOperand(t9, 0));
5493 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5495 // Additional parameter is the address of the actual callback.
5496 __ li(t9, Operand(thunk_ref));
5497 __ jmp(&end_profiler_check);
5499 __ bind(&profiler_disabled);
5500 __ mov(t9, function_address);
5501 __ bind(&end_profiler_check);
5503 // Allocate HandleScope in callee-save registers.
5504 __ li(s3, Operand(next_address));
5505 __ ld(s0, MemOperand(s3, kNextOffset));
5506 __ ld(s1, MemOperand(s3, kLimitOffset));
5507 __ lw(s2, MemOperand(s3, kLevelOffset));
5508 __ Addu(s2, s2, Operand(1));
5509 __ sw(s2, MemOperand(s3, kLevelOffset));
5511 if (FLAG_log_timer_events) {
5512 FrameScope frame(masm, StackFrame::MANUAL);
5513 __ PushSafepointRegisters();
5514 __ PrepareCallCFunction(1, a0);
5515 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5516 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5518 __ PopSafepointRegisters();
5521 // Native call returns to the DirectCEntry stub which redirects to the
5522 // return address pushed on stack (could have moved after GC).
5523 // DirectCEntry stub itself is generated early and never moves.
5524 DirectCEntryStub stub(isolate);
5525 stub.GenerateCall(masm, t9);
5527 if (FLAG_log_timer_events) {
5528 FrameScope frame(masm, StackFrame::MANUAL);
5529 __ PushSafepointRegisters();
5530 __ PrepareCallCFunction(1, a0);
5531 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5532 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5534 __ PopSafepointRegisters();
5537 Label promote_scheduled_exception;
5538 Label delete_allocated_handles;
5539 Label leave_exit_frame;
5540 Label return_value_loaded;
5542 // Load value from ReturnValue.
5543 __ ld(v0, return_value_operand);
5544 __ bind(&return_value_loaded);
5546 // No more valid handles (the result handle was the last one). Restore
5547 // previous handle scope.
5548 __ sd(s0, MemOperand(s3, kNextOffset));
5549 if (__ emit_debug_code()) {
5550 __ lw(a1, MemOperand(s3, kLevelOffset));
5551 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5553 __ Subu(s2, s2, Operand(1));
5554 __ sw(s2, MemOperand(s3, kLevelOffset));
5555 __ ld(at, MemOperand(s3, kLimitOffset));
5556 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5558 // Leave the API exit frame.
5559 __ bind(&leave_exit_frame);
5561 bool restore_context = context_restore_operand != NULL;
5562 if (restore_context) {
5563 __ ld(cp, *context_restore_operand);
5565 if (stack_space_offset != kInvalidStackOffset) {
5566 DCHECK(kCArgsSlotsSize == 0);
5567 __ ld(s0, MemOperand(sp, stack_space_offset));
5569 __ li(s0, Operand(stack_space));
5571 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5572 stack_space_offset != kInvalidStackOffset);
5574 // Check if the function scheduled an exception.
5575 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
5576 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5577 __ ld(a5, MemOperand(at));
5578 __ Branch(&promote_scheduled_exception, ne, a4, Operand(a5));
5582 // Re-throw by promoting a scheduled exception.
5583 __ bind(&promote_scheduled_exception);
5584 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5586 // HandleScope limit has changed. Delete allocated extensions.
5587 __ bind(&delete_allocated_handles);
5588 __ sd(s1, MemOperand(s3, kLimitOffset));
5591 __ PrepareCallCFunction(1, s1);
5592 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5593 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5596 __ jmp(&leave_exit_frame);
5600 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5601 const ParameterCount& argc,
5602 bool return_first_arg,
5603 bool call_data_undefined) {
5604 // ----------- S t a t e -------------
5606 // -- a4 : call_data
5608 // -- a1 : api_function_address
5609 // -- a3 : number of arguments if argc is a register
5612 // -- sp[0] : last argument
5614 // -- sp[(argc - 1)* 4] : first argument
5615 // -- sp[argc * 4] : receiver
5616 // -----------------------------------
5618 Register callee = a0;
5619 Register call_data = a4;
5620 Register holder = a2;
5621 Register api_function_address = a1;
5622 Register context = cp;
5624 typedef FunctionCallbackArguments FCA;
5626 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5627 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5628 STATIC_ASSERT(FCA::kDataIndex == 4);
5629 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5630 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5631 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5632 STATIC_ASSERT(FCA::kHolderIndex == 0);
5633 STATIC_ASSERT(FCA::kArgsLength == 7);
5635 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5637 // Save context, callee and call data.
5638 __ Push(context, callee, call_data);
5639 // Load context from callee.
5640 __ ld(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5642 Register scratch = call_data;
5643 if (!call_data_undefined) {
5644 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5646 // Push return value and default return value.
5647 __ Push(scratch, scratch);
5648 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5649 // Push isolate and holder.
5650 __ Push(scratch, holder);
5652 // Prepare arguments.
5653 __ mov(scratch, sp);
5655 // Allocate the v8::Arguments structure in the arguments' space since
5656 // it's not controlled by GC.
5657 const int kApiStackSpace = 4;
5659 FrameScope frame_scope(masm, StackFrame::MANUAL);
5660 __ EnterExitFrame(false, kApiStackSpace);
5662 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5663 // a0 = FunctionCallbackInfo&
5664 // Arguments is after the return address.
5665 __ Daddu(a0, sp, Operand(1 * kPointerSize));
5666 // FunctionCallbackInfo::implicit_args_
5667 __ sd(scratch, MemOperand(a0, 0 * kPointerSize));
5668 if (argc.is_immediate()) {
5669 // FunctionCallbackInfo::values_
5670 __ Daddu(at, scratch,
5671 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5672 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5673 // FunctionCallbackInfo::length_ = argc
5674 __ li(at, Operand(argc.immediate()));
5675 __ sd(at, MemOperand(a0, 2 * kPointerSize));
5676 // FunctionCallbackInfo::is_construct_call_ = 0
5677 __ sd(zero_reg, MemOperand(a0, 3 * kPointerSize));
5679 // FunctionCallbackInfo::values_
5680 __ dsll(at, argc.reg(), kPointerSizeLog2);
5681 __ Daddu(at, at, scratch);
5682 __ Daddu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5683 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5684 // FunctionCallbackInfo::length_ = argc
5685 __ sd(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5686 // FunctionCallbackInfo::is_construct_call_
5687 __ Daddu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5688 __ dsll(at, argc.reg(), kPointerSizeLog2);
5689 __ sd(at, MemOperand(a0, 3 * kPointerSize));
5692 ExternalReference thunk_ref =
5693 ExternalReference::invoke_function_callback(masm->isolate());
5695 AllowExternalCallThatCantCauseGC scope(masm);
5696 MemOperand context_restore_operand(
5697 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5698 // Stores return the first js argument.
5699 int return_value_offset = 0;
5700 if (return_first_arg) {
5701 return_value_offset = 2 + FCA::kArgsLength;
5703 return_value_offset = 2 + FCA::kReturnValueOffset;
5705 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5706 int stack_space = 0;
5707 int32_t stack_space_offset = 4 * kPointerSize;
5708 if (argc.is_immediate()) {
5709 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5710 stack_space_offset = kInvalidStackOffset;
5712 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5713 stack_space_offset, return_value_operand,
5714 &context_restore_operand);
5718 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5719 bool call_data_undefined = this->call_data_undefined();
5720 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5721 call_data_undefined);
5725 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5726 bool is_store = this->is_store();
5727 int argc = this->argc();
5728 bool call_data_undefined = this->call_data_undefined();
5729 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5730 call_data_undefined);
5734 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5735 // ----------- S t a t e -------------
5737 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5739 // -- a2 : api_function_address
5740 // -----------------------------------
5742 Register api_function_address = ApiGetterDescriptor::function_address();
5743 DCHECK(api_function_address.is(a2));
5745 __ mov(a0, sp); // a0 = Handle<Name>
5746 __ Daddu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5748 const int kApiStackSpace = 1;
5749 FrameScope frame_scope(masm, StackFrame::MANUAL);
5750 __ EnterExitFrame(false, kApiStackSpace);
5752 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5753 // a1 (internal::Object** args_) as the data.
5754 __ sd(a1, MemOperand(sp, 1 * kPointerSize));
5755 __ Daddu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5757 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5759 ExternalReference thunk_ref =
5760 ExternalReference::invoke_accessor_getter_callback(isolate());
5761 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5762 kStackUnwindSpace, kInvalidStackOffset,
5763 MemOperand(fp, 6 * kPointerSize), NULL);
5769 } // namespace internal
5772 #endif // V8_TARGET_ARCH_MIPS64