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.
725 if (cc == eq && strict()) {
726 __ TailCallRuntime(Runtime::kStrictEquals, 2, 1);
730 context_index = Context::EQUALS_BUILTIN_INDEX;
732 context_index = is_strong(strength())
733 ? Context::COMPARE_STRONG_BUILTIN_INDEX
734 : Context::COMPARE_BUILTIN_INDEX;
735 int ncr; // NaN compare result.
736 if (cc == lt || cc == le) {
739 DCHECK(cc == gt || cc == ge); // Remaining cases.
742 __ li(a0, Operand(Smi::FromInt(ncr)));
746 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
747 // tagged as a small integer.
748 __ InvokeBuiltin(context_index, JUMP_FUNCTION);
756 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
759 __ PushSafepointRegisters();
764 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
767 __ PopSafepointRegisters();
772 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
773 // We don't allow a GC during a store buffer overflow so there is no need to
774 // store the registers in any particular way, but we do have to store and
776 __ MultiPush(kJSCallerSaved | ra.bit());
777 if (save_doubles()) {
778 __ MultiPushFPU(kCallerSavedFPU);
780 const int argument_count = 1;
781 const int fp_argument_count = 0;
782 const Register scratch = a1;
784 AllowExternalCallThatCantCauseGC scope(masm);
785 __ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
786 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
788 ExternalReference::store_buffer_overflow_function(isolate()),
790 if (save_doubles()) {
791 __ MultiPopFPU(kCallerSavedFPU);
794 __ MultiPop(kJSCallerSaved | ra.bit());
799 void MathPowStub::Generate(MacroAssembler* masm) {
800 const Register base = a1;
801 const Register exponent = MathPowTaggedDescriptor::exponent();
802 DCHECK(exponent.is(a2));
803 const Register heapnumbermap = a5;
804 const Register heapnumber = v0;
805 const DoubleRegister double_base = f2;
806 const DoubleRegister double_exponent = f4;
807 const DoubleRegister double_result = f0;
808 const DoubleRegister double_scratch = f6;
809 const FPURegister single_scratch = f8;
810 const Register scratch = t1;
811 const Register scratch2 = a7;
813 Label call_runtime, done, int_exponent;
814 if (exponent_type() == ON_STACK) {
815 Label base_is_smi, unpack_exponent;
816 // The exponent and base are supplied as arguments on the stack.
817 // This can only happen if the stub is called from non-optimized code.
818 // Load input parameters from stack to double registers.
819 __ ld(base, MemOperand(sp, 1 * kPointerSize));
820 __ ld(exponent, MemOperand(sp, 0 * kPointerSize));
822 __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
824 __ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
825 __ ld(scratch, FieldMemOperand(base, JSObject::kMapOffset));
826 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
828 __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
829 __ jmp(&unpack_exponent);
831 __ bind(&base_is_smi);
832 __ mtc1(scratch, single_scratch);
833 __ cvt_d_w(double_base, single_scratch);
834 __ bind(&unpack_exponent);
836 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
838 __ ld(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
839 __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap));
840 __ ldc1(double_exponent,
841 FieldMemOperand(exponent, HeapNumber::kValueOffset));
842 } else if (exponent_type() == TAGGED) {
843 // Base is already in double_base.
844 __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
846 __ ldc1(double_exponent,
847 FieldMemOperand(exponent, HeapNumber::kValueOffset));
850 if (exponent_type() != INTEGER) {
851 Label int_exponent_convert;
852 // Detect integer exponents stored as double.
853 __ EmitFPUTruncate(kRoundToMinusInf,
859 kCheckForInexactConversion);
860 // scratch2 == 0 means there was no conversion error.
861 __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
863 if (exponent_type() == ON_STACK) {
864 // Detect square root case. Crankshaft detects constant +/-0.5 at
865 // compile time and uses DoMathPowHalf instead. We then skip this check
866 // for non-constant cases of +/-0.5 as these hardly occur.
870 __ Move(double_scratch, 0.5);
871 __ BranchF(USE_DELAY_SLOT,
877 // double_scratch can be overwritten in the delay slot.
878 // Calculates square root of base. Check for the special case of
879 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
880 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
881 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
882 __ neg_d(double_result, double_scratch);
884 // Add +0 to convert -0 to +0.
885 __ add_d(double_scratch, double_base, kDoubleRegZero);
886 __ sqrt_d(double_result, double_scratch);
889 __ bind(¬_plus_half);
890 __ Move(double_scratch, -0.5);
891 __ BranchF(USE_DELAY_SLOT,
897 // double_scratch can be overwritten in the delay slot.
898 // Calculates square root of base. Check for the special case of
899 // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
900 __ Move(double_scratch, static_cast<double>(-V8_INFINITY));
901 __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch);
902 __ Move(double_result, kDoubleRegZero);
904 // Add +0 to convert -0 to +0.
905 __ add_d(double_scratch, double_base, kDoubleRegZero);
906 __ Move(double_result, 1.);
907 __ sqrt_d(double_scratch, double_scratch);
908 __ div_d(double_result, double_result, double_scratch);
914 AllowExternalCallThatCantCauseGC scope(masm);
915 __ PrepareCallCFunction(0, 2, scratch2);
916 __ MovToFloatParameters(double_base, double_exponent);
918 ExternalReference::power_double_double_function(isolate()),
922 __ MovFromFloatResult(double_result);
925 __ bind(&int_exponent_convert);
928 // Calculate power with integer exponent.
929 __ bind(&int_exponent);
931 // Get two copies of exponent in the registers scratch and exponent.
932 if (exponent_type() == INTEGER) {
933 __ mov(scratch, exponent);
935 // Exponent has previously been stored into scratch as untagged integer.
936 __ mov(exponent, scratch);
939 __ mov_d(double_scratch, double_base); // Back up base.
940 __ Move(double_result, 1.0);
942 // Get absolute value of exponent.
943 Label positive_exponent;
944 __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
945 __ Dsubu(scratch, zero_reg, scratch);
946 __ bind(&positive_exponent);
948 Label while_true, no_carry, loop_end;
949 __ bind(&while_true);
951 __ And(scratch2, scratch, 1);
953 __ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
954 __ mul_d(double_result, double_result, double_scratch);
957 __ dsra(scratch, scratch, 1);
959 __ Branch(&loop_end, eq, scratch, Operand(zero_reg));
960 __ mul_d(double_scratch, double_scratch, double_scratch);
962 __ Branch(&while_true);
966 __ Branch(&done, ge, exponent, Operand(zero_reg));
967 __ Move(double_scratch, 1.0);
968 __ div_d(double_result, double_scratch, double_result);
969 // Test whether result is zero. Bail out to check for subnormal result.
970 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
971 __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero);
973 // double_exponent may not contain the exponent value if the input was a
974 // smi. We set it with exponent value before bailing out.
975 __ mtc1(exponent, single_scratch);
976 __ cvt_d_w(double_exponent, single_scratch);
978 // Returning or bailing out.
979 Counters* counters = isolate()->counters();
980 if (exponent_type() == ON_STACK) {
981 // The arguments are still on the stack.
982 __ bind(&call_runtime);
983 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
985 // The stub is called from non-optimized code, which expects the result
986 // as heap number in exponent.
988 __ AllocateHeapNumber(
989 heapnumber, scratch, scratch2, heapnumbermap, &call_runtime);
990 __ sdc1(double_result,
991 FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
992 DCHECK(heapnumber.is(v0));
993 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
998 AllowExternalCallThatCantCauseGC scope(masm);
999 __ PrepareCallCFunction(0, 2, scratch);
1000 __ MovToFloatParameters(double_base, double_exponent);
1002 ExternalReference::power_double_double_function(isolate()),
1006 __ MovFromFloatResult(double_result);
1009 __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
1015 bool CEntryStub::NeedsImmovableCode() {
1020 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
1021 CEntryStub::GenerateAheadOfTime(isolate);
1022 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1023 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1024 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1025 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1026 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1027 BinaryOpICStub::GenerateAheadOfTime(isolate);
1028 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1029 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1030 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1031 StoreFastElementStub::GenerateAheadOfTime(isolate);
1032 TypeofStub::GenerateAheadOfTime(isolate);
1036 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1037 StoreRegistersStateStub stub(isolate);
1042 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1043 RestoreRegistersStateStub stub(isolate);
1048 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1049 // Generate if not already in cache.
1050 SaveFPRegsMode mode = kSaveFPRegs;
1051 CEntryStub(isolate, 1, mode).GetCode();
1052 StoreBufferOverflowStub(isolate, mode).GetCode();
1053 isolate->set_fp_stubs_generated(true);
1057 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1058 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1063 void CEntryStub::Generate(MacroAssembler* masm) {
1064 // Called from JavaScript; parameters are on stack as if calling JS function
1065 // a0: number of arguments including receiver
1066 // a1: pointer to builtin function
1067 // fp: frame pointer (restored after C call)
1068 // sp: stack pointer (restored as callee's sp after C call)
1069 // cp: current context (C callee-saved)
1071 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1073 // Compute the argv pointer in a callee-saved register.
1074 __ dsll(s1, a0, kPointerSizeLog2);
1075 __ Daddu(s1, sp, s1);
1076 __ Dsubu(s1, s1, kPointerSize);
1078 // Enter the exit frame that transitions from JavaScript to C++.
1079 FrameScope scope(masm, StackFrame::MANUAL);
1080 __ EnterExitFrame(save_doubles());
1082 // s0: number of arguments including receiver (C callee-saved)
1083 // s1: pointer to first argument (C callee-saved)
1084 // s2: pointer to builtin function (C callee-saved)
1086 // Prepare arguments for C routine.
1090 // a1 = argv (set in the delay slot after find_ra below).
1092 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We
1093 // also need to reserve the 4 argument slots on the stack.
1095 __ AssertStackIsAligned();
1097 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1099 // To let the GC traverse the return address of the exit frames, we need to
1100 // know where the return address is. The CEntryStub is unmovable, so
1101 // we can store the address on the stack to be able to find it again and
1102 // we never have to restore it, because it will not change.
1103 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
1104 // This branch-and-link sequence is needed to find the current PC on mips,
1105 // saved to the ra register.
1106 // Use masm-> here instead of the double-underscore macro since extra
1107 // coverage code can interfere with the proper calculation of ra.
1109 masm->bal(&find_ra); // bal exposes branch delay slot.
1111 masm->bind(&find_ra);
1113 // Adjust the value in ra to point to the correct return location, 2nd
1114 // instruction past the real call into C code (the jalr(t9)), and push it.
1115 // This is the return address of the exit frame.
1116 const int kNumInstructionsToJump = 5;
1117 masm->Daddu(ra, ra, kNumInstructionsToJump * kInt32Size);
1118 masm->sd(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame.
1119 // Stack space reservation moved to the branch delay slot below.
1120 // Stack is still aligned.
1122 // Call the C routine.
1123 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC.
1125 // Set up sp in the delay slot.
1126 masm->daddiu(sp, sp, -kCArgsSlotsSize);
1127 // Make sure the stored 'ra' points to this position.
1128 DCHECK_EQ(kNumInstructionsToJump,
1129 masm->InstructionsGeneratedSince(&find_ra));
1132 // Check result for exception sentinel.
1133 Label exception_returned;
1134 __ LoadRoot(a4, Heap::kExceptionRootIndex);
1135 __ Branch(&exception_returned, eq, a4, Operand(v0));
1137 // Check that there is no pending exception, otherwise we
1138 // should have returned the exception sentinel.
1139 if (FLAG_debug_code) {
1141 ExternalReference pending_exception_address(
1142 Isolate::kPendingExceptionAddress, isolate());
1143 __ li(a2, Operand(pending_exception_address));
1144 __ ld(a2, MemOperand(a2));
1145 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
1146 // Cannot use check here as it attempts to generate call into runtime.
1147 __ Branch(&okay, eq, a4, Operand(a2));
1148 __ stop("Unexpected pending exception");
1152 // Exit C frame and return.
1154 // sp: stack pointer
1155 // fp: frame pointer
1156 // s0: still holds argc (callee-saved).
1157 __ LeaveExitFrame(save_doubles(), s0, true, EMIT_RETURN);
1159 // Handling of exception.
1160 __ bind(&exception_returned);
1162 ExternalReference pending_handler_context_address(
1163 Isolate::kPendingHandlerContextAddress, isolate());
1164 ExternalReference pending_handler_code_address(
1165 Isolate::kPendingHandlerCodeAddress, isolate());
1166 ExternalReference pending_handler_offset_address(
1167 Isolate::kPendingHandlerOffsetAddress, isolate());
1168 ExternalReference pending_handler_fp_address(
1169 Isolate::kPendingHandlerFPAddress, isolate());
1170 ExternalReference pending_handler_sp_address(
1171 Isolate::kPendingHandlerSPAddress, isolate());
1173 // Ask the runtime for help to determine the handler. This will set v0 to
1174 // contain the current pending exception, don't clobber it.
1175 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1178 FrameScope scope(masm, StackFrame::MANUAL);
1179 __ PrepareCallCFunction(3, 0, a0);
1180 __ mov(a0, zero_reg);
1181 __ mov(a1, zero_reg);
1182 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
1183 __ CallCFunction(find_handler, 3);
1186 // Retrieve the handler context, SP and FP.
1187 __ li(cp, Operand(pending_handler_context_address));
1188 __ ld(cp, MemOperand(cp));
1189 __ li(sp, Operand(pending_handler_sp_address));
1190 __ ld(sp, MemOperand(sp));
1191 __ li(fp, Operand(pending_handler_fp_address));
1192 __ ld(fp, MemOperand(fp));
1194 // If the handler is a JS frame, restore the context to the frame. Note that
1195 // the context will be set to (cp == 0) for non-JS frames.
1197 __ Branch(&zero, eq, cp, Operand(zero_reg));
1198 __ sd(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1201 // Compute the handler entry address and jump to it.
1202 __ li(a1, Operand(pending_handler_code_address));
1203 __ ld(a1, MemOperand(a1));
1204 __ li(a2, Operand(pending_handler_offset_address));
1205 __ ld(a2, MemOperand(a2));
1206 __ Daddu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1207 __ Daddu(t9, a1, a2);
1212 void JSEntryStub::Generate(MacroAssembler* masm) {
1213 Label invoke, handler_entry, exit;
1214 Isolate* isolate = masm->isolate();
1216 // TODO(plind): unify the ABI description here.
1218 // a0: entry address
1222 // a4 (a4): on mips64
1225 // 0 arg slots on mips64 (4 args slots on mips)
1226 // args -- in a4/a4 on mips64, on stack on mips
1228 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1230 // Save callee saved registers on the stack.
1231 __ MultiPush(kCalleeSaved | ra.bit());
1233 // Save callee-saved FPU registers.
1234 __ MultiPushFPU(kCalleeSavedFPU);
1235 // Set up the reserved register for 0.0.
1236 __ Move(kDoubleRegZero, 0.0);
1238 // Load argv in s0 register.
1239 if (kMipsAbi == kN64) {
1240 __ mov(s0, a4); // 5th parameter in mips64 a4 (a4) register.
1241 } else { // Abi O32.
1242 // 5th parameter on stack for O32 abi.
1243 int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
1244 offset_to_argv += kNumCalleeSavedFPU * kDoubleSize;
1245 __ ld(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize));
1248 __ InitializeRootRegister();
1250 // We build an EntryFrame.
1251 __ li(a7, Operand(-1)); // Push a bad frame pointer to fail if it is used.
1252 int marker = type();
1253 __ li(a6, Operand(Smi::FromInt(marker)));
1254 __ li(a5, Operand(Smi::FromInt(marker)));
1255 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate);
1256 __ li(a4, Operand(c_entry_fp));
1257 __ ld(a4, MemOperand(a4));
1258 __ Push(a7, a6, a5, a4);
1259 // Set up frame pointer for the frame to be pushed.
1260 __ daddiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
1263 // a0: entry_address
1265 // a2: receiver_pointer
1271 // function slot | entry frame
1273 // bad fp (0xff...f) |
1274 // callee saved registers + ra
1275 // [ O32: 4 args slots]
1278 // If this is the outermost JS call, set js_entry_sp value.
1279 Label non_outermost_js;
1280 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
1281 __ li(a5, Operand(ExternalReference(js_entry_sp)));
1282 __ ld(a6, MemOperand(a5));
1283 __ Branch(&non_outermost_js, ne, a6, Operand(zero_reg));
1284 __ sd(fp, MemOperand(a5));
1285 __ li(a4, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1288 __ nop(); // Branch delay slot nop.
1289 __ bind(&non_outermost_js);
1290 __ li(a4, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
1294 // Jump to a faked try block that does the invoke, with a faked catch
1295 // block that sets the pending exception.
1297 __ bind(&handler_entry);
1298 handler_offset_ = handler_entry.pos();
1299 // Caught exception: Store result (exception) in the pending exception
1300 // field in the JSEnv and return a failure sentinel. Coming in here the
1301 // fp will be invalid because the PushStackHandler below sets it to 0 to
1302 // signal the existence of the JSEntry frame.
1303 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1305 __ sd(v0, MemOperand(a4)); // We come back from 'invoke'. result is in v0.
1306 __ LoadRoot(v0, Heap::kExceptionRootIndex);
1307 __ b(&exit); // b exposes branch delay slot.
1308 __ nop(); // Branch delay slot nop.
1310 // Invoke: Link this frame into the handler chain.
1312 __ PushStackHandler();
1313 // If an exception not caught by another handler occurs, this handler
1314 // returns control to the code after the bal(&invoke) above, which
1315 // restores all kCalleeSaved registers (including cp and fp) to their
1316 // saved values before returning a failure to C.
1318 // Clear any pending exceptions.
1319 __ LoadRoot(a5, Heap::kTheHoleValueRootIndex);
1320 __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1322 __ sd(a5, MemOperand(a4));
1324 // Invoke the function by calling through JS entry trampoline builtin.
1325 // Notice that we cannot store a reference to the trampoline code directly in
1326 // this stub, because runtime stubs are not traversed when doing GC.
1329 // a0: entry_address
1331 // a2: receiver_pointer
1338 // callee saved registers + ra
1339 // [ O32: 4 args slots]
1342 if (type() == StackFrame::ENTRY_CONSTRUCT) {
1343 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
1345 __ li(a4, Operand(construct_entry));
1347 ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate());
1348 __ li(a4, Operand(entry));
1350 __ ld(t9, MemOperand(a4)); // Deref address.
1351 // Call JSEntryTrampoline.
1352 __ daddiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1355 // Unlink this frame from the handler chain.
1356 __ PopStackHandler();
1358 __ bind(&exit); // v0 holds result
1359 // Check if the current stack frame is marked as the outermost JS frame.
1360 Label non_outermost_js_2;
1362 __ Branch(&non_outermost_js_2,
1365 Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
1366 __ li(a5, Operand(ExternalReference(js_entry_sp)));
1367 __ sd(zero_reg, MemOperand(a5));
1368 __ bind(&non_outermost_js_2);
1370 // Restore the top frame descriptors from the stack.
1372 __ li(a4, Operand(ExternalReference(Isolate::kCEntryFPAddress,
1374 __ sd(a5, MemOperand(a4));
1376 // Reset the stack to the callee saved registers.
1377 __ daddiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
1379 // Restore callee-saved fpu registers.
1380 __ MultiPopFPU(kCalleeSavedFPU);
1382 // Restore callee saved registers from the stack.
1383 __ MultiPop(kCalleeSaved | ra.bit());
1389 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1390 // Return address is in ra.
1393 Register receiver = LoadDescriptor::ReceiverRegister();
1394 Register index = LoadDescriptor::NameRegister();
1395 Register scratch = a5;
1396 Register result = v0;
1397 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1398 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()));
1400 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1401 &miss, // When not a string.
1402 &miss, // When not a number.
1403 &miss, // When index out of range.
1404 STRING_INDEX_IS_ARRAY_INDEX,
1405 RECEIVER_IS_STRING);
1406 char_at_generator.GenerateFast(masm);
1409 StubRuntimeCallHelper call_helper;
1410 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1413 PropertyAccessCompiler::TailCallBuiltin(
1414 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1418 void InstanceOfStub::Generate(MacroAssembler* masm) {
1419 Register const object = a1; // Object (lhs).
1420 Register const function = a0; // Function (rhs).
1421 Register const object_map = a2; // Map of {object}.
1422 Register const function_map = a3; // Map of {function}.
1423 Register const function_prototype = a4; // Prototype of {function}.
1424 Register const scratch = a5;
1426 DCHECK(object.is(InstanceOfDescriptor::LeftRegister()));
1427 DCHECK(function.is(InstanceOfDescriptor::RightRegister()));
1429 // Check if {object} is a smi.
1430 Label object_is_smi;
1431 __ JumpIfSmi(object, &object_is_smi);
1433 // Lookup the {function} and the {object} map in the global instanceof cache.
1434 // Note: This is safe because we clear the global instanceof cache whenever
1435 // we change the prototype of any object.
1436 Label fast_case, slow_case;
1437 __ ld(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
1438 __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex);
1439 __ Branch(&fast_case, ne, function, Operand(at));
1440 __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex);
1441 __ Branch(&fast_case, ne, object_map, Operand(at));
1442 __ Ret(USE_DELAY_SLOT);
1443 __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1445 // If {object} is a smi we can safely return false if {function} is a JS
1446 // function, otherwise we have to miss to the runtime and throw an exception.
1447 __ bind(&object_is_smi);
1448 __ JumpIfSmi(function, &slow_case);
1449 __ GetObjectType(function, function_map, scratch);
1450 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1451 __ Ret(USE_DELAY_SLOT);
1452 __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot.
1454 // Fast-case: The {function} must be a valid JSFunction.
1455 __ bind(&fast_case);
1456 __ JumpIfSmi(function, &slow_case);
1457 __ GetObjectType(function, function_map, scratch);
1458 __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
1460 // Ensure that {function} has an instance prototype.
1461 __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1462 __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
1463 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1465 // Ensure that {function} is not bound.
1466 Register const shared_info = scratch;
1468 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1470 FieldMemOperand(shared_info, SharedFunctionInfo::kBoundByteOffset));
1471 __ And(at, scratch, Operand(1 << SharedFunctionInfo::kBoundBitWithinByte));
1472 __ Branch(&slow_case, ne, at, Operand(zero_reg));
1474 // Get the "prototype" (or initial map) of the {function}.
1475 __ ld(function_prototype,
1476 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
1477 __ AssertNotSmi(function_prototype);
1479 // Resolve the prototype if the {function} has an initial map. Afterwards the
1480 // {function_prototype} will be either the JSReceiver prototype object or the
1481 // hole value, which means that no instances of the {function} were created so
1482 // far and hence we should return false.
1483 Label function_prototype_valid;
1484 __ GetObjectType(function_prototype, scratch, scratch);
1485 __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE));
1486 __ ld(function_prototype,
1487 FieldMemOperand(function_prototype, Map::kPrototypeOffset));
1488 __ bind(&function_prototype_valid);
1489 __ AssertNotSmi(function_prototype);
1491 // Update the global instanceof cache with the current {object} map and
1492 // {function}. The cached answer will be set when it is known below.
1493 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1494 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex);
1496 // Loop through the prototype chain looking for the {function} prototype.
1497 // Assume true, and change to false if not found.
1498 Register const object_prototype = object_map;
1499 Register const null = scratch;
1501 __ LoadRoot(v0, Heap::kTrueValueRootIndex);
1502 __ LoadRoot(null, Heap::kNullValueRootIndex);
1504 __ ld(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
1505 __ Branch(&done, eq, object_prototype, Operand(function_prototype));
1506 __ Branch(USE_DELAY_SLOT, &loop, ne, object_prototype, Operand(null));
1507 __ ld(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
1508 __ LoadRoot(v0, Heap::kFalseValueRootIndex);
1510 __ Ret(USE_DELAY_SLOT);
1511 __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot.
1513 // Slow-case: Call the runtime function.
1514 __ bind(&slow_case);
1515 __ Push(object, function);
1516 __ TailCallRuntime(Runtime::kInstanceOf, 2, 1);
1520 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1522 Register receiver = LoadDescriptor::ReceiverRegister();
1523 // Ensure that the vector and slot registers won't be clobbered before
1524 // calling the miss handler.
1525 DCHECK(!AreAliased(a4, a5, LoadWithVectorDescriptor::VectorRegister(),
1526 LoadWithVectorDescriptor::SlotRegister()));
1528 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, a4,
1531 PropertyAccessCompiler::TailCallBuiltin(
1532 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1536 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1537 // The displacement is the offset of the last parameter (if any)
1538 // relative to the frame pointer.
1539 const int kDisplacement =
1540 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1541 DCHECK(a1.is(ArgumentsAccessReadDescriptor::index()));
1542 DCHECK(a0.is(ArgumentsAccessReadDescriptor::parameter_count()));
1544 // Check that the key is a smiGenerateReadElement.
1546 __ JumpIfNotSmi(a1, &slow);
1548 // Check if the calling frame is an arguments adaptor frame.
1550 __ ld(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1551 __ ld(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1555 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1557 // Check index (a1) against formal parameters count limit passed in
1558 // through register a0. Use unsigned comparison to get negative
1560 __ Branch(&slow, hs, a1, Operand(a0));
1562 // Read the argument from the stack and return it.
1563 __ dsubu(a3, a0, a1);
1564 __ SmiScale(a7, a3, kPointerSizeLog2);
1565 __ Daddu(a3, fp, Operand(a7));
1566 __ Ret(USE_DELAY_SLOT);
1567 __ ld(v0, MemOperand(a3, kDisplacement));
1569 // Arguments adaptor case: Check index (a1) against actual arguments
1570 // limit found in the arguments adaptor frame. Use unsigned
1571 // comparison to get negative check for free.
1573 __ ld(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1574 __ Branch(&slow, Ugreater_equal, a1, Operand(a0));
1576 // Read the argument from the adaptor frame and return it.
1577 __ dsubu(a3, a0, a1);
1578 __ SmiScale(a7, a3, kPointerSizeLog2);
1579 __ Daddu(a3, a2, Operand(a7));
1580 __ Ret(USE_DELAY_SLOT);
1581 __ ld(v0, MemOperand(a3, kDisplacement));
1583 // Slow-case: Handle non-smi or out-of-bounds access to arguments
1584 // by calling the runtime system.
1587 __ TailCallRuntime(Runtime::kArguments, 1, 1);
1591 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1592 // sp[0] : number of parameters
1593 // sp[4] : receiver displacement
1596 // Check if the calling frame is an arguments adaptor frame.
1598 __ ld(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1599 __ ld(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1603 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1605 // Patch the arguments.length and the parameters pointer in the current frame.
1606 __ ld(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1607 __ sd(a2, MemOperand(sp, 0 * kPointerSize));
1608 __ SmiScale(a7, a2, kPointerSizeLog2);
1609 __ Daddu(a3, a3, Operand(a7));
1610 __ daddiu(a3, a3, StandardFrameConstants::kCallerSPOffset);
1611 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1614 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1618 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1620 // sp[0] : number of parameters (tagged)
1621 // sp[4] : address of receiver argument
1623 // Registers used over whole function:
1624 // a6 : allocated object (tagged)
1625 // t1 : mapped parameter count (tagged)
1627 __ ld(a1, MemOperand(sp, 0 * kPointerSize));
1628 // a1 = parameter count (tagged)
1630 // Check if the calling frame is an arguments adaptor frame.
1632 Label adaptor_frame, try_allocate;
1633 __ ld(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1634 __ ld(a2, MemOperand(a3, StandardFrameConstants::kContextOffset));
1635 __ Branch(&adaptor_frame,
1638 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1640 // No adaptor, parameter count = argument count.
1642 __ Branch(&try_allocate);
1644 // We have an adaptor frame. Patch the parameters pointer.
1645 __ bind(&adaptor_frame);
1646 __ ld(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset));
1647 __ SmiScale(t2, a2, kPointerSizeLog2);
1648 __ Daddu(a3, a3, Operand(t2));
1649 __ Daddu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1650 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1652 // a1 = parameter count (tagged)
1653 // a2 = argument count (tagged)
1654 // Compute the mapped parameter count = min(a1, a2) in a1.
1656 __ Branch(&skip_min, lt, a1, Operand(a2));
1660 __ bind(&try_allocate);
1662 // Compute the sizes of backing store, parameter map, and arguments object.
1663 // 1. Parameter map, has 2 extra words containing context and backing store.
1664 const int kParameterMapHeaderSize =
1665 FixedArray::kHeaderSize + 2 * kPointerSize;
1666 // If there are no mapped parameters, we do not need the parameter_map.
1667 Label param_map_size;
1668 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1669 __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg));
1670 __ mov(t1, zero_reg); // In delay slot: param map size = 0 when a1 == 0.
1671 __ SmiScale(t1, a1, kPointerSizeLog2);
1672 __ daddiu(t1, t1, kParameterMapHeaderSize);
1673 __ bind(¶m_map_size);
1675 // 2. Backing store.
1676 __ SmiScale(t2, a2, kPointerSizeLog2);
1677 __ Daddu(t1, t1, Operand(t2));
1678 __ Daddu(t1, t1, Operand(FixedArray::kHeaderSize));
1680 // 3. Arguments object.
1681 __ Daddu(t1, t1, Operand(Heap::kSloppyArgumentsObjectSize));
1683 // Do the allocation of all three objects in one go.
1684 __ Allocate(t1, v0, a3, a4, &runtime, TAG_OBJECT);
1686 // v0 = address of new object(s) (tagged)
1687 // a2 = argument count (smi-tagged)
1688 // Get the arguments boilerplate from the current native context into a4.
1689 const int kNormalOffset =
1690 Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
1691 const int kAliasedOffset =
1692 Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
1694 __ ld(a4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1695 __ ld(a4, FieldMemOperand(a4, GlobalObject::kNativeContextOffset));
1696 Label skip2_ne, skip2_eq;
1697 __ Branch(&skip2_ne, ne, a1, Operand(zero_reg));
1698 __ ld(a4, MemOperand(a4, kNormalOffset));
1701 __ Branch(&skip2_eq, eq, a1, Operand(zero_reg));
1702 __ ld(a4, MemOperand(a4, kAliasedOffset));
1705 // v0 = address of new object (tagged)
1706 // a1 = mapped parameter count (tagged)
1707 // a2 = argument count (smi-tagged)
1708 // a4 = address of arguments map (tagged)
1709 __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset));
1710 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1711 __ sd(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1712 __ sd(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1714 // Set up the callee in-object property.
1715 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1716 __ ld(a3, MemOperand(sp, 2 * kPointerSize));
1717 __ AssertNotSmi(a3);
1718 const int kCalleeOffset = JSObject::kHeaderSize +
1719 Heap::kArgumentsCalleeIndex * kPointerSize;
1720 __ sd(a3, FieldMemOperand(v0, kCalleeOffset));
1722 // Use the length (smi tagged) and set that as an in-object property too.
1723 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1724 const int kLengthOffset = JSObject::kHeaderSize +
1725 Heap::kArgumentsLengthIndex * kPointerSize;
1726 __ sd(a2, FieldMemOperand(v0, kLengthOffset));
1728 // Set up the elements pointer in the allocated arguments object.
1729 // If we allocated a parameter map, a4 will point there, otherwise
1730 // it will point to the backing store.
1731 __ Daddu(a4, v0, Operand(Heap::kSloppyArgumentsObjectSize));
1732 __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset));
1734 // v0 = address of new object (tagged)
1735 // a1 = mapped parameter count (tagged)
1736 // a2 = argument count (tagged)
1737 // a4 = address of parameter map or backing store (tagged)
1738 // Initialize parameter map. If there are no mapped arguments, we're done.
1739 Label skip_parameter_map;
1741 __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0)));
1742 // Move backing store address to a3, because it is
1743 // expected there when filling in the unmapped arguments.
1747 __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0)));
1749 __ LoadRoot(a6, Heap::kSloppyArgumentsElementsMapRootIndex);
1750 __ sd(a6, FieldMemOperand(a4, FixedArray::kMapOffset));
1751 __ Daddu(a6, a1, Operand(Smi::FromInt(2)));
1752 __ sd(a6, FieldMemOperand(a4, FixedArray::kLengthOffset));
1753 __ sd(cp, FieldMemOperand(a4, FixedArray::kHeaderSize + 0 * kPointerSize));
1754 __ SmiScale(t2, a1, kPointerSizeLog2);
1755 __ Daddu(a6, a4, Operand(t2));
1756 __ Daddu(a6, a6, Operand(kParameterMapHeaderSize));
1757 __ sd(a6, FieldMemOperand(a4, FixedArray::kHeaderSize + 1 * kPointerSize));
1759 // Copy the parameter slots and the holes in the arguments.
1760 // We need to fill in mapped_parameter_count slots. They index the context,
1761 // where parameters are stored in reverse order, at
1762 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
1763 // The mapped parameter thus need to get indices
1764 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
1765 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
1766 // We loop from right to left.
1767 Label parameters_loop, parameters_test;
1769 __ ld(t1, MemOperand(sp, 0 * kPointerSize));
1770 __ Daddu(t1, t1, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
1771 __ Dsubu(t1, t1, Operand(a1));
1772 __ LoadRoot(a7, Heap::kTheHoleValueRootIndex);
1773 __ SmiScale(t2, a6, kPointerSizeLog2);
1774 __ Daddu(a3, a4, Operand(t2));
1775 __ Daddu(a3, a3, Operand(kParameterMapHeaderSize));
1777 // a6 = loop variable (tagged)
1778 // a1 = mapping index (tagged)
1779 // a3 = address of backing store (tagged)
1780 // a4 = address of parameter map (tagged)
1781 // a5 = temporary scratch (a.o., for address calculation)
1782 // a7 = the hole value
1783 __ jmp(¶meters_test);
1785 __ bind(¶meters_loop);
1787 __ Dsubu(a6, a6, Operand(Smi::FromInt(1)));
1788 __ SmiScale(a5, a6, kPointerSizeLog2);
1789 __ Daddu(a5, a5, Operand(kParameterMapHeaderSize - kHeapObjectTag));
1790 __ Daddu(t2, a4, a5);
1791 __ sd(t1, MemOperand(t2));
1792 __ Dsubu(a5, a5, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
1793 __ Daddu(t2, a3, a5);
1794 __ sd(a7, MemOperand(t2));
1795 __ Daddu(t1, t1, Operand(Smi::FromInt(1)));
1796 __ bind(¶meters_test);
1797 __ Branch(¶meters_loop, ne, a6, Operand(Smi::FromInt(0)));
1799 __ bind(&skip_parameter_map);
1800 // a2 = argument count (tagged)
1801 // a3 = address of backing store (tagged)
1803 // Copy arguments header and remaining slots (if there are any).
1804 __ LoadRoot(a5, Heap::kFixedArrayMapRootIndex);
1805 __ sd(a5, FieldMemOperand(a3, FixedArray::kMapOffset));
1806 __ sd(a2, FieldMemOperand(a3, FixedArray::kLengthOffset));
1808 Label arguments_loop, arguments_test;
1810 __ ld(a4, MemOperand(sp, 1 * kPointerSize));
1811 __ SmiScale(t2, t1, kPointerSizeLog2);
1812 __ Dsubu(a4, a4, Operand(t2));
1813 __ jmp(&arguments_test);
1815 __ bind(&arguments_loop);
1816 __ Dsubu(a4, a4, Operand(kPointerSize));
1817 __ ld(a6, MemOperand(a4, 0));
1818 __ SmiScale(t2, t1, kPointerSizeLog2);
1819 __ Daddu(a5, a3, Operand(t2));
1820 __ sd(a6, FieldMemOperand(a5, FixedArray::kHeaderSize));
1821 __ Daddu(t1, t1, Operand(Smi::FromInt(1)));
1823 __ bind(&arguments_test);
1824 __ Branch(&arguments_loop, lt, t1, Operand(a2));
1826 // Return and remove the on-stack parameters.
1829 // Do the runtime call to allocate the arguments object.
1830 // a2 = argument count (tagged)
1832 __ sd(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
1833 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1837 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
1838 // Return address is in ra.
1841 Register receiver = LoadDescriptor::ReceiverRegister();
1842 Register key = LoadDescriptor::NameRegister();
1844 // Check that the key is an array index, that is Uint32.
1845 __ And(t0, key, Operand(kSmiTagMask | kSmiSignMask));
1846 __ Branch(&slow, ne, t0, Operand(zero_reg));
1848 // Everything is fine, call runtime.
1849 __ Push(receiver, key); // Receiver, key.
1851 // Perform tail call to the entry.
1852 __ TailCallRuntime(Runtime::kLoadElementWithInterceptor, 2, 1);
1855 PropertyAccessCompiler::TailCallBuiltin(
1856 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1860 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
1861 // sp[0] : number of parameters
1862 // sp[4] : receiver displacement
1864 // Check if the calling frame is an arguments adaptor frame.
1865 Label adaptor_frame, try_allocate, runtime;
1866 __ ld(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1867 __ ld(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
1868 __ Branch(&adaptor_frame,
1871 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1873 // Get the length from the frame.
1874 __ ld(a1, MemOperand(sp, 0));
1875 __ Branch(&try_allocate);
1877 // Patch the arguments.length and the parameters pointer.
1878 __ bind(&adaptor_frame);
1879 __ ld(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
1880 __ sd(a1, MemOperand(sp, 0));
1881 __ SmiScale(at, a1, kPointerSizeLog2);
1883 __ Daddu(a3, a2, Operand(at));
1885 __ Daddu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset));
1886 __ sd(a3, MemOperand(sp, 1 * kPointerSize));
1888 // Try the new space allocation. Start out with computing the size
1889 // of the arguments object and the elements array in words.
1890 Label add_arguments_object;
1891 __ bind(&try_allocate);
1892 __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg));
1895 __ Daddu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize));
1896 __ bind(&add_arguments_object);
1897 __ Daddu(a1, a1, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
1899 // Do the allocation of both objects in one go.
1900 __ Allocate(a1, v0, a2, a3, &runtime,
1901 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
1903 // Get the arguments boilerplate from the current native context.
1904 __ ld(a4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
1905 __ ld(a4, FieldMemOperand(a4, GlobalObject::kNativeContextOffset));
1906 __ ld(a4, MemOperand(a4, Context::SlotOffset(
1907 Context::STRICT_ARGUMENTS_MAP_INDEX)));
1909 __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset));
1910 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex);
1911 __ sd(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset));
1912 __ sd(a3, FieldMemOperand(v0, JSObject::kElementsOffset));
1914 // Get the length (smi tagged) and set that as an in-object property too.
1915 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1916 __ ld(a1, MemOperand(sp, 0 * kPointerSize));
1918 __ sd(a1, FieldMemOperand(v0, JSObject::kHeaderSize +
1919 Heap::kArgumentsLengthIndex * kPointerSize));
1922 __ Branch(&done, eq, a1, Operand(zero_reg));
1924 // Get the parameters pointer from the stack.
1925 __ ld(a2, MemOperand(sp, 1 * kPointerSize));
1927 // Set up the elements pointer in the allocated arguments object and
1928 // initialize the header in the elements fixed array.
1929 __ Daddu(a4, v0, Operand(Heap::kStrictArgumentsObjectSize));
1930 __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset));
1931 __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex);
1932 __ sd(a3, FieldMemOperand(a4, FixedArray::kMapOffset));
1933 __ sd(a1, FieldMemOperand(a4, FixedArray::kLengthOffset));
1934 // Untag the length for the loop.
1938 // Copy the fixed array slots.
1940 // Set up a4 to point to the first array slot.
1941 __ Daddu(a4, a4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1943 // Pre-decrement a2 with kPointerSize on each iteration.
1944 // Pre-decrement in order to skip receiver.
1945 __ Daddu(a2, a2, Operand(-kPointerSize));
1946 __ ld(a3, MemOperand(a2));
1947 // Post-increment a4 with kPointerSize on each iteration.
1948 __ sd(a3, MemOperand(a4));
1949 __ Daddu(a4, a4, Operand(kPointerSize));
1950 __ Dsubu(a1, a1, Operand(1));
1951 __ Branch(&loop, ne, a1, Operand(zero_reg));
1953 // Return and remove the on-stack parameters.
1957 // Do the runtime call to allocate the arguments object.
1959 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
1963 void RegExpExecStub::Generate(MacroAssembler* masm) {
1964 // Just jump directly to runtime if native RegExp is not selected at compile
1965 // time or if regexp entry in generated code is turned off runtime switch or
1967 #ifdef V8_INTERPRETED_REGEXP
1968 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1969 #else // V8_INTERPRETED_REGEXP
1971 // Stack frame on entry.
1972 // sp[0]: last_match_info (expected JSArray)
1973 // sp[4]: previous index
1974 // sp[8]: subject string
1975 // sp[12]: JSRegExp object
1977 const int kLastMatchInfoOffset = 0 * kPointerSize;
1978 const int kPreviousIndexOffset = 1 * kPointerSize;
1979 const int kSubjectOffset = 2 * kPointerSize;
1980 const int kJSRegExpOffset = 3 * kPointerSize;
1983 // Allocation of registers for this function. These are in callee save
1984 // registers and will be preserved by the call to the native RegExp code, as
1985 // this code is called using the normal C calling convention. When calling
1986 // directly from generated code the native RegExp code will not do a GC and
1987 // therefore the content of these registers are safe to use after the call.
1988 // MIPS - using s0..s2, since we are not using CEntry Stub.
1989 Register subject = s0;
1990 Register regexp_data = s1;
1991 Register last_match_info_elements = s2;
1993 // Ensure that a RegExp stack is allocated.
1994 ExternalReference address_of_regexp_stack_memory_address =
1995 ExternalReference::address_of_regexp_stack_memory_address(
1997 ExternalReference address_of_regexp_stack_memory_size =
1998 ExternalReference::address_of_regexp_stack_memory_size(isolate());
1999 __ li(a0, Operand(address_of_regexp_stack_memory_size));
2000 __ ld(a0, MemOperand(a0, 0));
2001 __ Branch(&runtime, eq, a0, Operand(zero_reg));
2003 // Check that the first argument is a JSRegExp object.
2004 __ ld(a0, MemOperand(sp, kJSRegExpOffset));
2005 STATIC_ASSERT(kSmiTag == 0);
2006 __ JumpIfSmi(a0, &runtime);
2007 __ GetObjectType(a0, a1, a1);
2008 __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE));
2010 // Check that the RegExp has been compiled (data contains a fixed array).
2011 __ ld(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset));
2012 if (FLAG_debug_code) {
2013 __ SmiTst(regexp_data, a4);
2015 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2018 __ GetObjectType(regexp_data, a0, a0);
2020 kUnexpectedTypeForRegExpDataFixedArrayExpected,
2022 Operand(FIXED_ARRAY_TYPE));
2025 // regexp_data: RegExp data (FixedArray)
2026 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2027 __ ld(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2028 __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
2030 // regexp_data: RegExp data (FixedArray)
2031 // Check that the number of captures fit in the static offsets vector buffer.
2033 FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2034 // Check (number_of_captures + 1) * 2 <= offsets vector size
2035 // Or number_of_captures * 2 <= offsets vector size - 2
2036 // Or number_of_captures <= offsets vector size / 2 - 1
2037 // Multiplying by 2 comes for free since a2 is smi-tagged.
2038 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2039 int temp = Isolate::kJSRegexpStaticOffsetsVectorSize / 2 - 1;
2040 __ Branch(&runtime, hi, a2, Operand(Smi::FromInt(temp)));
2042 // Reset offset for possibly sliced string.
2043 __ mov(t0, zero_reg);
2044 __ ld(subject, MemOperand(sp, kSubjectOffset));
2045 __ JumpIfSmi(subject, &runtime);
2046 __ mov(a3, subject); // Make a copy of the original subject string.
2047 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2048 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2049 // subject: subject string
2050 // a3: subject string
2051 // a0: subject string instance type
2052 // regexp_data: RegExp data (FixedArray)
2053 // Handle subject string according to its encoding and representation:
2054 // (1) Sequential string? If yes, go to (5).
2055 // (2) Anything but sequential or cons? If yes, go to (6).
2056 // (3) Cons string. If the string is flat, replace subject with first string.
2057 // Otherwise bailout.
2058 // (4) Is subject external? If yes, go to (7).
2059 // (5) Sequential string. Load regexp code according to encoding.
2063 // Deferred code at the end of the stub:
2064 // (6) Not a long external string? If yes, go to (8).
2065 // (7) External string. Make it, offset-wise, look like a sequential string.
2067 // (8) Short external string or not a string? If yes, bail out to runtime.
2068 // (9) Sliced string. Replace subject with parent. Go to (4).
2070 Label check_underlying; // (4)
2071 Label seq_string; // (5)
2072 Label not_seq_nor_cons; // (6)
2073 Label external_string; // (7)
2074 Label not_long_external; // (8)
2076 // (1) Sequential string? If yes, go to (5).
2079 Operand(kIsNotStringMask |
2080 kStringRepresentationMask |
2081 kShortExternalStringMask));
2082 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2083 __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
2085 // (2) Anything but sequential or cons? If yes, go to (6).
2086 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2087 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2088 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2089 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2091 __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
2093 // (3) Cons string. Check that it's flat.
2094 // Replace subject with first string and reload instance type.
2095 __ ld(a0, FieldMemOperand(subject, ConsString::kSecondOffset));
2096 __ LoadRoot(a1, Heap::kempty_stringRootIndex);
2097 __ Branch(&runtime, ne, a0, Operand(a1));
2098 __ ld(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2100 // (4) Is subject external? If yes, go to (7).
2101 __ bind(&check_underlying);
2102 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2103 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2104 STATIC_ASSERT(kSeqStringTag == 0);
2105 __ And(at, a0, Operand(kStringRepresentationMask));
2106 // The underlying external string is never a short external string.
2107 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2108 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2109 __ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
2111 // (5) Sequential string. Load regexp code according to encoding.
2112 __ bind(&seq_string);
2113 // subject: sequential subject string (or look-alike, external string)
2114 // a3: original subject string
2115 // Load previous index and check range before a3 is overwritten. We have to
2116 // use a3 instead of subject here because subject might have been only made
2117 // to look like a sequential string when it actually is an external string.
2118 __ ld(a1, MemOperand(sp, kPreviousIndexOffset));
2119 __ JumpIfNotSmi(a1, &runtime);
2120 __ ld(a3, FieldMemOperand(a3, String::kLengthOffset));
2121 __ Branch(&runtime, ls, a3, Operand(a1));
2124 STATIC_ASSERT(kStringEncodingMask == 4);
2125 STATIC_ASSERT(kOneByteStringTag == 4);
2126 STATIC_ASSERT(kTwoByteStringTag == 0);
2127 __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one_byte.
2128 __ ld(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
2129 __ dsra(a3, a0, 2); // a3 is 1 for one_byte, 0 for UC16 (used below).
2130 __ ld(a5, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
2131 __ Movz(t9, a5, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset.
2133 // (E) Carry on. String handling is done.
2134 // t9: irregexp code
2135 // Check that the irregexp code has been generated for the actual string
2136 // encoding. If it has, the field contains a code object otherwise it contains
2137 // a smi (code flushing support).
2138 __ JumpIfSmi(t9, &runtime);
2140 // a1: previous index
2141 // a3: encoding of subject string (1 if one_byte, 0 if two_byte);
2143 // subject: Subject string
2144 // regexp_data: RegExp data (FixedArray)
2145 // All checks done. Now push arguments for native regexp code.
2146 __ IncrementCounter(isolate()->counters()->regexp_entry_native(),
2149 // Isolates: note we add an additional parameter here (isolate pointer).
2150 const int kRegExpExecuteArguments = 9;
2151 const int kParameterRegisters = (kMipsAbi == kN64) ? 8 : 4;
2152 __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
2154 // Stack pointer now points to cell where return address is to be written.
2155 // Arguments are before that on the stack or in registers, meaning we
2156 // treat the return address as argument 5. Thus every argument after that
2157 // needs to be shifted back by 1. Since DirectCEntryStub will handle
2158 // allocating space for the c argument slots, we don't need to calculate
2159 // that into the argument positions on the stack. This is how the stack will
2160 // look (sp meaning the value of sp at this moment):
2162 // [sp + 1] - Argument 9
2163 // [sp + 0] - saved ra
2165 // [sp + 5] - Argument 9
2166 // [sp + 4] - Argument 8
2167 // [sp + 3] - Argument 7
2168 // [sp + 2] - Argument 6
2169 // [sp + 1] - Argument 5
2170 // [sp + 0] - saved ra
2172 if (kMipsAbi == kN64) {
2173 // Argument 9: Pass current isolate address.
2174 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2175 __ sd(a0, MemOperand(sp, 1 * kPointerSize));
2177 // Argument 8: Indicate that this is a direct call from JavaScript.
2178 __ li(a7, Operand(1));
2180 // Argument 7: Start (high end) of backtracking stack memory area.
2181 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2182 __ ld(a0, MemOperand(a0, 0));
2183 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2184 __ ld(a2, MemOperand(a2, 0));
2185 __ daddu(a6, a0, a2);
2187 // Argument 6: Set the number of capture registers to zero to force global
2188 // regexps to behave as non-global. This does not affect non-global regexps.
2189 __ mov(a5, zero_reg);
2191 // Argument 5: static offsets vector buffer.
2193 ExternalReference::address_of_static_offsets_vector(isolate())));
2195 DCHECK(kMipsAbi == kO32);
2197 // Argument 9: Pass current isolate address.
2198 // CFunctionArgumentOperand handles MIPS stack argument slots.
2199 __ li(a0, Operand(ExternalReference::isolate_address(isolate())));
2200 __ sd(a0, MemOperand(sp, 5 * kPointerSize));
2202 // Argument 8: Indicate that this is a direct call from JavaScript.
2203 __ li(a0, Operand(1));
2204 __ sd(a0, MemOperand(sp, 4 * kPointerSize));
2206 // Argument 7: Start (high end) of backtracking stack memory area.
2207 __ li(a0, Operand(address_of_regexp_stack_memory_address));
2208 __ ld(a0, MemOperand(a0, 0));
2209 __ li(a2, Operand(address_of_regexp_stack_memory_size));
2210 __ ld(a2, MemOperand(a2, 0));
2211 __ daddu(a0, a0, a2);
2212 __ sd(a0, MemOperand(sp, 3 * kPointerSize));
2214 // Argument 6: Set the number of capture registers to zero to force global
2215 // regexps to behave as non-global. This does not affect non-global regexps.
2216 __ mov(a0, zero_reg);
2217 __ sd(a0, MemOperand(sp, 2 * kPointerSize));
2219 // Argument 5: static offsets vector buffer.
2221 ExternalReference::address_of_static_offsets_vector(isolate())));
2222 __ sd(a0, MemOperand(sp, 1 * kPointerSize));
2225 // For arguments 4 and 3 get string length, calculate start of string data
2226 // and calculate the shift of the index (0 for one_byte and 1 for two byte).
2227 __ Daddu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
2228 __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte.
2229 // Load the length from the original subject string from the previous stack
2230 // frame. Therefore we have to use fp, which points exactly to two pointer
2231 // sizes below the previous sp. (Because creating a new stack frame pushes
2232 // the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
2233 __ ld(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2234 // If slice offset is not 0, load the length from the original sliced string.
2235 // Argument 4, a3: End of string data
2236 // Argument 3, a2: Start of string data
2237 // Prepare start and end index of the input.
2238 __ dsllv(t1, t0, a3);
2239 __ daddu(t0, t2, t1);
2240 __ dsllv(t1, a1, a3);
2241 __ daddu(a2, t0, t1);
2243 __ ld(t2, FieldMemOperand(subject, String::kLengthOffset));
2246 __ dsllv(t1, t2, a3);
2247 __ daddu(a3, t0, t1);
2248 // Argument 2 (a1): Previous index.
2251 // Argument 1 (a0): Subject string.
2252 __ mov(a0, subject);
2254 // Locate the code entry and call it.
2255 __ Daddu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag));
2256 DirectCEntryStub stub(isolate());
2257 stub.GenerateCall(masm, t9);
2259 __ LeaveExitFrame(false, no_reg, true);
2262 // subject: subject string (callee saved)
2263 // regexp_data: RegExp data (callee saved)
2264 // last_match_info_elements: Last match info elements (callee saved)
2265 // Check the result.
2267 __ Branch(&success, eq, v0, Operand(1));
2268 // We expect exactly one result since we force the called regexp to behave
2271 __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE));
2272 // If not exception it can only be retry. Handle that in the runtime system.
2273 __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
2274 // Result must now be exception. If there is no pending exception already a
2275 // stack overflow (on the backtrack stack) was detected in RegExp code but
2276 // haven't created the exception yet. Handle that in the runtime system.
2277 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
2278 __ li(a1, Operand(isolate()->factory()->the_hole_value()));
2279 __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2281 __ ld(v0, MemOperand(a2, 0));
2282 __ Branch(&runtime, eq, v0, Operand(a1));
2284 // For exception, throw the exception again.
2285 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2288 // For failure and exception return null.
2289 __ li(v0, Operand(isolate()->factory()->null_value()));
2292 // Process the result from the native regexp code.
2295 __ lw(a1, UntagSmiFieldMemOperand(
2296 regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
2297 // Calculate number of capture registers (number_of_captures + 1) * 2.
2298 __ Daddu(a1, a1, Operand(1));
2299 __ dsll(a1, a1, 1); // Multiply by 2.
2301 __ ld(a0, MemOperand(sp, kLastMatchInfoOffset));
2302 __ JumpIfSmi(a0, &runtime);
2303 __ GetObjectType(a0, a2, a2);
2304 __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE));
2305 // Check that the JSArray is in fast case.
2306 __ ld(last_match_info_elements,
2307 FieldMemOperand(a0, JSArray::kElementsOffset));
2308 __ ld(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2309 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2310 __ Branch(&runtime, ne, a0, Operand(at));
2311 // Check that the last match info has space for the capture registers and the
2312 // additional information.
2314 FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
2315 __ Daddu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead));
2317 __ SmiUntag(at, a0);
2318 __ Branch(&runtime, gt, a2, Operand(at));
2320 // a1: number of capture registers
2321 // subject: subject string
2322 // Store the capture count.
2323 __ SmiTag(a2, a1); // To smi.
2324 __ sd(a2, FieldMemOperand(last_match_info_elements,
2325 RegExpImpl::kLastCaptureCountOffset));
2326 // Store last subject and last input.
2328 FieldMemOperand(last_match_info_elements,
2329 RegExpImpl::kLastSubjectOffset));
2330 __ mov(a2, subject);
2331 __ RecordWriteField(last_match_info_elements,
2332 RegExpImpl::kLastSubjectOffset,
2337 __ mov(subject, a2);
2339 FieldMemOperand(last_match_info_elements,
2340 RegExpImpl::kLastInputOffset));
2341 __ RecordWriteField(last_match_info_elements,
2342 RegExpImpl::kLastInputOffset,
2348 // Get the static offsets vector filled by the native regexp code.
2349 ExternalReference address_of_static_offsets_vector =
2350 ExternalReference::address_of_static_offsets_vector(isolate());
2351 __ li(a2, Operand(address_of_static_offsets_vector));
2353 // a1: number of capture registers
2354 // a2: offsets vector
2355 Label next_capture, done;
2356 // Capture register counter starts from number of capture registers and
2357 // counts down until wrapping after zero.
2359 last_match_info_elements,
2360 Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
2361 __ bind(&next_capture);
2362 __ Dsubu(a1, a1, Operand(1));
2363 __ Branch(&done, lt, a1, Operand(zero_reg));
2364 // Read the value from the static offsets vector buffer.
2365 __ lw(a3, MemOperand(a2, 0));
2366 __ daddiu(a2, a2, kIntSize);
2367 // Store the smi value in the last match info.
2369 __ sd(a3, MemOperand(a0, 0));
2370 __ Branch(&next_capture, USE_DELAY_SLOT);
2371 __ daddiu(a0, a0, kPointerSize); // In branch delay slot.
2375 // Return last match info.
2376 __ ld(v0, MemOperand(sp, kLastMatchInfoOffset));
2379 // Do the runtime call to execute the regexp.
2381 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2383 // Deferred code for string handling.
2384 // (6) Not a long external string? If yes, go to (8).
2385 __ bind(¬_seq_nor_cons);
2387 __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag));
2389 // (7) External string. Make it, offset-wise, look like a sequential string.
2390 __ bind(&external_string);
2391 __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
2392 __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
2393 if (FLAG_debug_code) {
2394 // Assert that we do not have a cons or slice (indirect strings) here.
2395 // Sequential strings have already been ruled out.
2396 __ And(at, a0, Operand(kIsIndirectStringMask));
2398 kExternalStringExpectedButNotFound,
2403 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2404 // Move the pointer so that offset-wise, it looks like a sequential string.
2405 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2408 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2409 __ jmp(&seq_string); // Go to (5).
2411 // (8) Short external string or not a string? If yes, bail out to runtime.
2412 __ bind(¬_long_external);
2413 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
2414 __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
2415 __ Branch(&runtime, ne, at, Operand(zero_reg));
2417 // (9) Sliced string. Replace subject with parent. Go to (4).
2418 // Load offset into t0 and replace subject string with parent.
2419 __ ld(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
2421 __ ld(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2422 __ jmp(&check_underlying); // Go to (4).
2423 #endif // V8_INTERPRETED_REGEXP
2427 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2429 // a0 : number of arguments to the construct function
2430 // a2 : feedback vector
2431 // a3 : slot in feedback vector (Smi)
2432 // a1 : the function to call
2433 // a4 : original constructor (for IsSuperConstructorCall)
2434 FrameScope scope(masm, StackFrame::INTERNAL);
2435 const RegList kSavedRegs = 1 << 4 | // a0
2439 BoolToInt(is_super) << 8; // a4
2442 // Number-of-arguments register must be smi-tagged to call out.
2444 __ MultiPush(kSavedRegs);
2448 __ MultiPop(kSavedRegs);
2453 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) {
2454 // Cache the called function in a feedback vector slot. Cache states
2455 // are uninitialized, monomorphic (indicated by a JSFunction), and
2457 // a0 : number of arguments to the construct function
2458 // a1 : the function to call
2459 // a2 : feedback vector
2460 // a3 : slot in feedback vector (Smi)
2461 // a4 : original constructor (for IsSuperConstructorCall)
2462 Label initialize, done, miss, megamorphic, not_array_function;
2464 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2465 masm->isolate()->heap()->megamorphic_symbol());
2466 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2467 masm->isolate()->heap()->uninitialized_symbol());
2469 // Load the cache state into a5.
2470 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2471 __ Daddu(a5, a2, Operand(a5));
2472 __ ld(a5, FieldMemOperand(a5, FixedArray::kHeaderSize));
2474 // A monomorphic cache hit or an already megamorphic state: invoke the
2475 // function without changing the state.
2476 // We don't know if a5 is a WeakCell or a Symbol, but it's harmless to read at
2477 // this position in a symbol (see static asserts in type-feedback-vector.h).
2478 Label check_allocation_site;
2479 Register feedback_map = a6;
2480 Register weak_value = t0;
2481 __ ld(weak_value, FieldMemOperand(a5, WeakCell::kValueOffset));
2482 __ Branch(&done, eq, a1, Operand(weak_value));
2483 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2484 __ Branch(&done, eq, a5, Operand(at));
2485 __ ld(feedback_map, FieldMemOperand(a5, HeapObject::kMapOffset));
2486 __ LoadRoot(at, Heap::kWeakCellMapRootIndex);
2487 __ Branch(FLAG_pretenuring_call_new ? &miss : &check_allocation_site, ne,
2488 feedback_map, Operand(at));
2490 // If the weak cell is cleared, we have a new chance to become monomorphic.
2491 __ JumpIfSmi(weak_value, &initialize);
2492 __ jmp(&megamorphic);
2494 if (!FLAG_pretenuring_call_new) {
2495 __ bind(&check_allocation_site);
2496 // If we came here, we need to see if we are the array function.
2497 // If we didn't have a matching function, and we didn't find the megamorph
2498 // sentinel, then we have in the slot either some other function or an
2500 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2501 __ Branch(&miss, ne, feedback_map, Operand(at));
2503 // Make sure the function is the Array() function
2504 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a5);
2505 __ Branch(&megamorphic, ne, a1, Operand(a5));
2511 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2513 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2514 __ Branch(&initialize, eq, a5, Operand(at));
2515 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2516 // write-barrier is needed.
2517 __ bind(&megamorphic);
2518 __ dsrl(a5, a3, 32 - kPointerSizeLog2);
2519 __ Daddu(a5, a2, Operand(a5));
2520 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2521 __ sd(at, FieldMemOperand(a5, FixedArray::kHeaderSize));
2524 // An uninitialized cache is patched with the function.
2525 __ bind(&initialize);
2526 if (!FLAG_pretenuring_call_new) {
2527 // Make sure the function is the Array() function.
2528 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a5);
2529 __ Branch(¬_array_function, ne, a1, Operand(a5));
2531 // The target function is the Array constructor,
2532 // Create an AllocationSite if we don't already have it, store it in the
2534 CreateAllocationSiteStub create_stub(masm->isolate());
2535 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2538 __ bind(¬_array_function);
2541 CreateWeakCellStub create_stub(masm->isolate());
2542 CallStubInRecordCallTarget(masm, &create_stub, is_super);
2547 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2548 __ ld(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2550 // Do not transform the receiver for strict mode functions.
2551 int32_t strict_mode_function_mask =
2552 1 << SharedFunctionInfo::kStrictModeBitWithinByte ;
2553 // Do not transform the receiver for native (Compilerhints already in a3).
2554 int32_t native_mask = 1 << SharedFunctionInfo::kNativeBitWithinByte;
2556 __ lbu(a4, FieldMemOperand(a3, SharedFunctionInfo::kStrictModeByteOffset));
2557 __ And(at, a4, Operand(strict_mode_function_mask));
2558 __ Branch(cont, ne, at, Operand(zero_reg));
2559 __ lbu(a4, FieldMemOperand(a3, SharedFunctionInfo::kNativeByteOffset));
2560 __ And(at, a4, Operand(native_mask));
2561 __ Branch(cont, ne, at, Operand(zero_reg));
2565 static void EmitSlowCase(MacroAssembler* masm,
2567 Label* non_function) {
2568 // Check for function proxy.
2569 __ Branch(non_function, ne, a4, Operand(JS_FUNCTION_PROXY_TYPE));
2570 __ push(a1); // put proxy as additional argument
2571 __ li(a0, Operand(argc + 1, RelocInfo::NONE32));
2572 __ mov(a2, zero_reg);
2573 __ GetBuiltinFunction(a1, Context::CALL_FUNCTION_PROXY_BUILTIN_INDEX);
2575 Handle<Code> adaptor =
2576 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2577 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2580 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2581 // of the original receiver from the call site).
2582 __ bind(non_function);
2583 __ sd(a1, MemOperand(sp, argc * kPointerSize));
2584 __ li(a0, Operand(argc)); // Set up the number of arguments.
2585 __ mov(a2, zero_reg);
2586 __ GetBuiltinFunction(a1, Context::CALL_NON_FUNCTION_BUILTIN_INDEX);
2587 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2588 RelocInfo::CODE_TARGET);
2592 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2593 // Wrap the receiver and patch it back onto the stack.
2594 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2597 ToObjectStub stub(masm->isolate());
2601 __ Branch(USE_DELAY_SLOT, cont);
2602 __ sd(v0, MemOperand(sp, argc * kPointerSize));
2606 static void CallFunctionNoFeedback(MacroAssembler* masm,
2607 int argc, bool needs_checks,
2608 bool call_as_method) {
2609 // a1 : the function to call
2610 Label slow, non_function, wrap, cont;
2613 // Check that the function is really a JavaScript function.
2614 // a1: pushed function (to be verified)
2615 __ JumpIfSmi(a1, &non_function);
2617 // Goto slow case if we do not have a function.
2618 __ GetObjectType(a1, a4, a4);
2619 __ Branch(&slow, ne, a4, Operand(JS_FUNCTION_TYPE));
2622 // Fast-case: Invoke the function now.
2623 // a1: pushed function
2624 ParameterCount actual(argc);
2626 if (call_as_method) {
2628 EmitContinueIfStrictOrNative(masm, &cont);
2631 // Compute the receiver in sloppy mode.
2632 __ ld(a3, MemOperand(sp, argc * kPointerSize));
2635 __ JumpIfSmi(a3, &wrap);
2636 __ GetObjectType(a3, a4, a4);
2637 __ Branch(&wrap, lt, a4, Operand(FIRST_SPEC_OBJECT_TYPE));
2644 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2647 // Slow-case: Non-function called.
2649 EmitSlowCase(masm, argc, &non_function);
2652 if (call_as_method) {
2654 // Wrap the receiver and patch it back onto the stack.
2655 EmitWrapCase(masm, argc, &cont);
2660 void CallFunctionStub::Generate(MacroAssembler* masm) {
2661 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2665 void CallConstructStub::Generate(MacroAssembler* masm) {
2666 // a0 : number of arguments
2667 // a1 : the function to call
2668 // a2 : feedback vector
2669 // a3 : slot in feedback vector (Smi, for RecordCallTarget)
2670 // a4 : original constructor (for IsSuperConstructorCall)
2671 Label slow, non_function_call;
2672 // Check that the function is not a smi.
2673 __ JumpIfSmi(a1, &non_function_call);
2674 // Check that the function is a JSFunction.
2675 __ GetObjectType(a1, a5, a5);
2676 __ Branch(&slow, ne, a5, Operand(JS_FUNCTION_TYPE));
2678 if (RecordCallTarget()) {
2679 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
2681 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2682 __ Daddu(a5, a2, at);
2683 if (FLAG_pretenuring_call_new) {
2684 // Put the AllocationSite from the feedback vector into a2.
2685 // By adding kPointerSize we encode that we know the AllocationSite
2686 // entry is at the feedback vector slot given by a3 + 1.
2687 __ ld(a2, FieldMemOperand(a5, FixedArray::kHeaderSize + kPointerSize));
2689 Label feedback_register_initialized;
2690 // Put the AllocationSite from the feedback vector into a2, or undefined.
2691 __ ld(a2, FieldMemOperand(a5, FixedArray::kHeaderSize));
2692 __ ld(a5, FieldMemOperand(a2, AllocationSite::kMapOffset));
2693 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2694 __ Branch(&feedback_register_initialized, eq, a5, Operand(at));
2695 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2696 __ bind(&feedback_register_initialized);
2699 __ AssertUndefinedOrAllocationSite(a2, a5);
2702 // Pass function as original constructor.
2703 if (IsSuperConstructorCall()) {
2709 // Jump to the function-specific construct stub.
2710 Register jmp_reg = a4;
2711 __ ld(jmp_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2712 __ ld(jmp_reg, FieldMemOperand(jmp_reg,
2713 SharedFunctionInfo::kConstructStubOffset));
2714 __ Daddu(at, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
2717 // a0: number of arguments
2718 // a1: called object
2722 __ Branch(&non_function_call, ne, a5, Operand(JS_FUNCTION_PROXY_TYPE));
2723 __ GetBuiltinFunction(
2724 a1, Context::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR_BUILTIN_INDEX);
2727 __ bind(&non_function_call);
2728 __ GetBuiltinFunction(
2729 a1, Context::CALL_NON_FUNCTION_AS_CONSTRUCTOR_BUILTIN_INDEX);
2731 // Set expected number of arguments to zero (not changing r0).
2732 __ li(a2, Operand(0, RelocInfo::NONE32));
2733 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2734 RelocInfo::CODE_TARGET);
2738 // StringCharCodeAtGenerator.
2739 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2740 DCHECK(!a4.is(index_));
2741 DCHECK(!a4.is(result_));
2742 DCHECK(!a4.is(object_));
2744 // If the receiver is a smi trigger the non-string case.
2745 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2746 __ JumpIfSmi(object_, receiver_not_string_);
2748 // Fetch the instance type of the receiver into result register.
2749 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
2750 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
2751 // If the receiver is not a string trigger the non-string case.
2752 __ And(a4, result_, Operand(kIsNotStringMask));
2753 __ Branch(receiver_not_string_, ne, a4, Operand(zero_reg));
2756 // If the index is non-smi trigger the non-smi case.
2757 __ JumpIfNotSmi(index_, &index_not_smi_);
2759 __ bind(&got_smi_index_);
2761 // Check for index out of range.
2762 __ ld(a4, FieldMemOperand(object_, String::kLengthOffset));
2763 __ Branch(index_out_of_range_, ls, a4, Operand(index_));
2765 __ SmiUntag(index_);
2767 StringCharLoadGenerator::Generate(masm,
2778 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
2779 __ ld(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2780 __ ld(vector, FieldMemOperand(vector,
2781 JSFunction::kSharedFunctionInfoOffset));
2782 __ ld(vector, FieldMemOperand(vector,
2783 SharedFunctionInfo::kFeedbackVectorOffset));
2787 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
2793 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, at);
2794 __ Branch(&miss, ne, a1, Operand(at));
2796 __ li(a0, Operand(arg_count()));
2797 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2798 __ Daddu(at, a2, Operand(at));
2799 __ ld(a4, FieldMemOperand(at, FixedArray::kHeaderSize));
2801 // Verify that a4 contains an AllocationSite
2802 __ ld(a5, FieldMemOperand(a4, HeapObject::kMapOffset));
2803 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
2804 __ Branch(&miss, ne, a5, Operand(at));
2806 // Increment the call count for monomorphic function calls.
2807 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2808 __ Daddu(a3, a2, Operand(t0));
2809 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2810 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2811 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2815 ArrayConstructorStub stub(masm->isolate(), arg_count());
2816 __ TailCallStub(&stub);
2821 // The slow case, we need this no matter what to complete a call after a miss.
2822 CallFunctionNoFeedback(masm,
2828 __ stop("Unexpected code address");
2832 void CallICStub::Generate(MacroAssembler* masm) {
2834 // a3 - slot id (Smi)
2836 const int with_types_offset =
2837 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
2838 const int generic_offset =
2839 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
2840 Label extra_checks_or_miss, slow_start;
2841 Label slow, non_function, wrap, cont;
2842 Label have_js_function;
2843 int argc = arg_count();
2844 ParameterCount actual(argc);
2846 // The checks. First, does r1 match the recorded monomorphic target?
2847 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
2848 __ Daddu(a4, a2, Operand(a4));
2849 __ ld(a4, FieldMemOperand(a4, FixedArray::kHeaderSize));
2851 // We don't know that we have a weak cell. We might have a private symbol
2852 // or an AllocationSite, but the memory is safe to examine.
2853 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
2855 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
2856 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
2857 // computed, meaning that it can't appear to be a pointer. If the low bit is
2858 // 0, then hash is computed, but the 0 bit prevents the field from appearing
2860 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2861 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2862 WeakCell::kValueOffset &&
2863 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2865 __ ld(a5, FieldMemOperand(a4, WeakCell::kValueOffset));
2866 __ Branch(&extra_checks_or_miss, ne, a1, Operand(a5));
2868 // The compare above could have been a SMI/SMI comparison. Guard against this
2869 // convincing us that we have a monomorphic JSFunction.
2870 __ JumpIfSmi(a1, &extra_checks_or_miss);
2872 // Increment the call count for monomorphic function calls.
2873 __ dsrl(t0, a3, 32 - kPointerSizeLog2);
2874 __ Daddu(a3, a2, Operand(t0));
2875 __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2876 __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2877 __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize));
2879 __ bind(&have_js_function);
2880 if (CallAsMethod()) {
2881 EmitContinueIfStrictOrNative(masm, &cont);
2882 // Compute the receiver in sloppy mode.
2883 __ ld(a3, MemOperand(sp, argc * kPointerSize));
2885 __ JumpIfSmi(a3, &wrap);
2886 __ GetObjectType(a3, a4, a4);
2887 __ Branch(&wrap, lt, a4, Operand(FIRST_SPEC_OBJECT_TYPE));
2892 __ InvokeFunction(a1, actual, JUMP_FUNCTION, NullCallWrapper());
2895 EmitSlowCase(masm, argc, &non_function);
2897 if (CallAsMethod()) {
2899 EmitWrapCase(masm, argc, &cont);
2902 __ bind(&extra_checks_or_miss);
2903 Label uninitialized, miss;
2905 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2906 __ Branch(&slow_start, eq, a4, Operand(at));
2908 // The following cases attempt to handle MISS cases without going to the
2910 if (FLAG_trace_ic) {
2914 __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex);
2915 __ Branch(&uninitialized, eq, a4, Operand(at));
2917 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2918 // to handle it here. More complex cases are dealt with in the runtime.
2919 __ AssertNotSmi(a4);
2920 __ GetObjectType(a4, a5, a5);
2921 __ Branch(&miss, ne, a5, Operand(JS_FUNCTION_TYPE));
2922 __ dsrl(a4, a3, 32 - kPointerSizeLog2);
2923 __ Daddu(a4, a2, Operand(a4));
2924 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
2925 __ sd(at, FieldMemOperand(a4, FixedArray::kHeaderSize));
2926 // We have to update statistics for runtime profiling.
2927 __ ld(a4, FieldMemOperand(a2, with_types_offset));
2928 __ Dsubu(a4, a4, Operand(Smi::FromInt(1)));
2929 __ sd(a4, FieldMemOperand(a2, with_types_offset));
2930 __ ld(a4, FieldMemOperand(a2, generic_offset));
2931 __ Daddu(a4, a4, Operand(Smi::FromInt(1)));
2932 __ Branch(USE_DELAY_SLOT, &slow_start);
2933 __ sd(a4, FieldMemOperand(a2, generic_offset)); // In delay slot.
2935 __ bind(&uninitialized);
2937 // We are going monomorphic, provided we actually have a JSFunction.
2938 __ JumpIfSmi(a1, &miss);
2940 // Goto miss case if we do not have a function.
2941 __ GetObjectType(a1, a4, a4);
2942 __ Branch(&miss, ne, a4, Operand(JS_FUNCTION_TYPE));
2944 // Make sure the function is not the Array() function, which requires special
2945 // behavior on MISS.
2946 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, a4);
2947 __ Branch(&miss, eq, a1, Operand(a4));
2950 __ ld(a4, FieldMemOperand(a2, with_types_offset));
2951 __ Daddu(a4, a4, Operand(Smi::FromInt(1)));
2952 __ sd(a4, FieldMemOperand(a2, with_types_offset));
2954 // Initialize the call counter.
2955 __ dsrl(at, a3, 32 - kPointerSizeLog2);
2956 __ Daddu(at, a2, Operand(at));
2957 __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2958 __ sd(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize));
2960 // Store the function. Use a stub since we need a frame for allocation.
2965 FrameScope scope(masm, StackFrame::INTERNAL);
2966 CreateWeakCellStub create_stub(masm->isolate());
2968 __ CallStub(&create_stub);
2972 __ Branch(&have_js_function);
2974 // We are here because tracing is on or we encountered a MISS case we can't
2980 __ bind(&slow_start);
2981 // Check that the function is really a JavaScript function.
2982 // r1: pushed function (to be verified)
2983 __ JumpIfSmi(a1, &non_function);
2985 // Goto slow case if we do not have a function.
2986 __ GetObjectType(a1, a4, a4);
2987 __ Branch(&slow, ne, a4, Operand(JS_FUNCTION_TYPE));
2988 __ Branch(&have_js_function);
2992 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2993 FrameScope scope(masm, StackFrame::INTERNAL);
2995 // Push the receiver and the function and feedback info.
2996 __ Push(a1, a2, a3);
2999 Runtime::FunctionId id = GetICState() == DEFAULT
3000 ? Runtime::kCallIC_Miss //
3001 : Runtime::kCallIC_Customization_Miss;
3002 __ CallRuntime(id, 3);
3004 // Move result to a1 and exit the internal frame.
3009 void StringCharCodeAtGenerator::GenerateSlow(
3010 MacroAssembler* masm, EmbedMode embed_mode,
3011 const RuntimeCallHelper& call_helper) {
3012 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3014 // Index is not a smi.
3015 __ bind(&index_not_smi_);
3016 // If index is a heap number, try converting it to an integer.
3019 Heap::kHeapNumberMapRootIndex,
3022 call_helper.BeforeCall(masm);
3023 // Consumed by runtime conversion function:
3024 if (embed_mode == PART_OF_IC_HANDLER) {
3025 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3026 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3028 __ Push(object_, index_);
3030 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3031 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3033 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3034 // NumberToSmi discards numbers that are not exact integers.
3035 __ CallRuntime(Runtime::kNumberToSmi, 1);
3038 // Save the conversion result before the pop instructions below
3039 // have a chance to overwrite it.
3041 __ Move(index_, v0);
3042 if (embed_mode == PART_OF_IC_HANDLER) {
3043 __ Pop(LoadWithVectorDescriptor::VectorRegister(),
3044 LoadWithVectorDescriptor::SlotRegister(), object_);
3048 // Reload the instance type.
3049 __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3050 __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3051 call_helper.AfterCall(masm);
3052 // If index is still not a smi, it must be out of range.
3053 __ JumpIfNotSmi(index_, index_out_of_range_);
3054 // Otherwise, return to the fast path.
3055 __ Branch(&got_smi_index_);
3057 // Call runtime. We get here when the receiver is a string and the
3058 // index is a number, but the code of getting the actual character
3059 // is too complex (e.g., when the string needs to be flattened).
3060 __ bind(&call_runtime_);
3061 call_helper.BeforeCall(masm);
3063 __ Push(object_, index_);
3064 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3066 __ Move(result_, v0);
3068 call_helper.AfterCall(masm);
3071 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3075 // -------------------------------------------------------------------------
3076 // StringCharFromCodeGenerator
3078 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3079 // Fast case of Heap::LookupSingleCharacterStringFromCode.
3080 __ JumpIfNotSmi(code_, &slow_case_);
3081 __ Branch(&slow_case_, hi, code_,
3082 Operand(Smi::FromInt(String::kMaxOneByteCharCode)));
3084 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3085 // At this point code register contains smi tagged one_byte char code.
3086 __ SmiScale(at, code_, kPointerSizeLog2);
3087 __ Daddu(result_, result_, at);
3088 __ ld(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3089 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3090 __ Branch(&slow_case_, eq, result_, Operand(at));
3095 void StringCharFromCodeGenerator::GenerateSlow(
3096 MacroAssembler* masm,
3097 const RuntimeCallHelper& call_helper) {
3098 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3100 __ bind(&slow_case_);
3101 call_helper.BeforeCall(masm);
3103 __ CallRuntime(Runtime::kCharFromCode, 1);
3104 __ Move(result_, v0);
3106 call_helper.AfterCall(masm);
3109 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3113 enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 };
3116 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
3121 String::Encoding encoding) {
3122 if (FLAG_debug_code) {
3123 // Check that destination is word aligned.
3124 __ And(scratch, dest, Operand(kPointerAlignmentMask));
3126 kDestinationOfCopyNotAligned,
3131 // Assumes word reads and writes are little endian.
3132 // Nothing to do for zero characters.
3135 if (encoding == String::TWO_BYTE_ENCODING) {
3136 __ Daddu(count, count, count);
3139 Register limit = count; // Read until dest equals this.
3140 __ Daddu(limit, dest, Operand(count));
3142 Label loop_entry, loop;
3143 // Copy bytes from src to dest until dest hits limit.
3144 __ Branch(&loop_entry);
3146 __ lbu(scratch, MemOperand(src));
3147 __ daddiu(src, src, 1);
3148 __ sb(scratch, MemOperand(dest));
3149 __ daddiu(dest, dest, 1);
3150 __ bind(&loop_entry);
3151 __ Branch(&loop, lt, dest, Operand(limit));
3157 void SubStringStub::Generate(MacroAssembler* masm) {
3159 // Stack frame on entry.
3160 // ra: return address
3165 // This stub is called from the native-call %_SubString(...), so
3166 // nothing can be assumed about the arguments. It is tested that:
3167 // "string" is a sequential string,
3168 // both "from" and "to" are smis, and
3169 // 0 <= from <= to <= string.length.
3170 // If any of these assumptions fail, we call the runtime system.
3172 const int kToOffset = 0 * kPointerSize;
3173 const int kFromOffset = 1 * kPointerSize;
3174 const int kStringOffset = 2 * kPointerSize;
3176 __ ld(a2, MemOperand(sp, kToOffset));
3177 __ ld(a3, MemOperand(sp, kFromOffset));
3179 STATIC_ASSERT(kSmiTag == 0);
3181 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
3182 // safe in this case.
3183 __ JumpIfNotSmi(a2, &runtime);
3184 __ JumpIfNotSmi(a3, &runtime);
3185 // Both a2 and a3 are untagged integers.
3187 __ SmiUntag(a2, a2);
3188 __ SmiUntag(a3, a3);
3189 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
3191 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
3192 __ Dsubu(a2, a2, a3);
3194 // Make sure first argument is a string.
3195 __ ld(v0, MemOperand(sp, kStringOffset));
3196 __ JumpIfSmi(v0, &runtime);
3197 __ ld(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
3198 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3199 __ And(a4, a1, Operand(kIsNotStringMask));
3201 __ Branch(&runtime, ne, a4, Operand(zero_reg));
3204 __ Branch(&single_char, eq, a2, Operand(1));
3206 // Short-cut for the case of trivial substring.
3208 // v0: original string
3209 // a2: result string length
3210 __ ld(a4, FieldMemOperand(v0, String::kLengthOffset));
3212 // Return original string.
3213 __ Branch(&return_v0, eq, a2, Operand(a4));
3214 // Longer than original string's length or negative: unsafe arguments.
3215 __ Branch(&runtime, hi, a2, Operand(a4));
3216 // Shorter than original string's length: an actual substring.
3218 // Deal with different string types: update the index if necessary
3219 // and put the underlying string into a5.
3220 // v0: original string
3221 // a1: instance type
3223 // a3: from index (untagged)
3224 Label underlying_unpacked, sliced_string, seq_or_external_string;
3225 // If the string is not indirect, it can only be sequential or external.
3226 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3227 STATIC_ASSERT(kIsIndirectStringMask != 0);
3228 __ And(a4, a1, Operand(kIsIndirectStringMask));
3229 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, a4, Operand(zero_reg));
3230 // a4 is used as a scratch register and can be overwritten in either case.
3231 __ And(a4, a1, Operand(kSlicedNotConsMask));
3232 __ Branch(&sliced_string, ne, a4, Operand(zero_reg));
3233 // Cons string. Check whether it is flat, then fetch first part.
3234 __ ld(a5, FieldMemOperand(v0, ConsString::kSecondOffset));
3235 __ LoadRoot(a4, Heap::kempty_stringRootIndex);
3236 __ Branch(&runtime, ne, a5, Operand(a4));
3237 __ ld(a5, FieldMemOperand(v0, ConsString::kFirstOffset));
3238 // Update instance type.
3239 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
3240 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3241 __ jmp(&underlying_unpacked);
3243 __ bind(&sliced_string);
3244 // Sliced string. Fetch parent and correct start index by offset.
3245 __ ld(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
3246 __ ld(a4, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3247 __ SmiUntag(a4); // Add offset to index.
3248 __ Daddu(a3, a3, a4);
3249 // Update instance type.
3250 __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
3251 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3252 __ jmp(&underlying_unpacked);
3254 __ bind(&seq_or_external_string);
3255 // Sequential or external string. Just move string to the expected register.
3258 __ bind(&underlying_unpacked);
3260 if (FLAG_string_slices) {
3262 // a5: underlying subject string
3263 // a1: instance type of underlying subject string
3265 // a3: adjusted start index (untagged)
3266 // Short slice. Copy instead of slicing.
3267 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength));
3268 // Allocate new sliced string. At this point we do not reload the instance
3269 // type including the string encoding because we simply rely on the info
3270 // provided by the original string. It does not matter if the original
3271 // string's encoding is wrong because we always have to recheck encoding of
3272 // the newly created string's parent anyways due to externalized strings.
3273 Label two_byte_slice, set_slice_header;
3274 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3275 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3276 __ And(a4, a1, Operand(kStringEncodingMask));
3277 __ Branch(&two_byte_slice, eq, a4, Operand(zero_reg));
3278 __ AllocateOneByteSlicedString(v0, a2, a6, a7, &runtime);
3279 __ jmp(&set_slice_header);
3280 __ bind(&two_byte_slice);
3281 __ AllocateTwoByteSlicedString(v0, a2, a6, a7, &runtime);
3282 __ bind(&set_slice_header);
3284 __ sd(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
3285 __ sd(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
3288 __ bind(©_routine);
3291 // a5: underlying subject string
3292 // a1: instance type of underlying subject string
3294 // a3: adjusted start index (untagged)
3295 Label two_byte_sequential, sequential_string, allocate_result;
3296 STATIC_ASSERT(kExternalStringTag != 0);
3297 STATIC_ASSERT(kSeqStringTag == 0);
3298 __ And(a4, a1, Operand(kExternalStringTag));
3299 __ Branch(&sequential_string, eq, a4, Operand(zero_reg));
3301 // Handle external string.
3302 // Rule out short external strings.
3303 STATIC_ASSERT(kShortExternalStringTag != 0);
3304 __ And(a4, a1, Operand(kShortExternalStringTag));
3305 __ Branch(&runtime, ne, a4, Operand(zero_reg));
3306 __ ld(a5, FieldMemOperand(a5, ExternalString::kResourceDataOffset));
3307 // a5 already points to the first character of underlying string.
3308 __ jmp(&allocate_result);
3310 __ bind(&sequential_string);
3311 // Locate first character of underlying subject string.
3312 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3313 __ Daddu(a5, a5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3315 __ bind(&allocate_result);
3316 // Sequential acii string. Allocate the result.
3317 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3318 __ And(a4, a1, Operand(kStringEncodingMask));
3319 __ Branch(&two_byte_sequential, eq, a4, Operand(zero_reg));
3321 // Allocate and copy the resulting one_byte string.
3322 __ AllocateOneByteString(v0, a2, a4, a6, a7, &runtime);
3324 // Locate first character of substring to copy.
3325 __ Daddu(a5, a5, a3);
3327 // Locate first character of result.
3328 __ Daddu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3330 // v0: result string
3331 // a1: first character of result string
3332 // a2: result string length
3333 // a5: first character of substring to copy
3334 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3335 StringHelper::GenerateCopyCharacters(
3336 masm, a1, a5, a2, a3, String::ONE_BYTE_ENCODING);
3339 // Allocate and copy the resulting two-byte string.
3340 __ bind(&two_byte_sequential);
3341 __ AllocateTwoByteString(v0, a2, a4, a6, a7, &runtime);
3343 // Locate first character of substring to copy.
3344 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3346 __ Daddu(a5, a5, a4);
3347 // Locate first character of result.
3348 __ Daddu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3350 // v0: result string.
3351 // a1: first character of result.
3352 // a2: result length.
3353 // a5: first character of substring to copy.
3354 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3355 StringHelper::GenerateCopyCharacters(
3356 masm, a1, a5, a2, a3, String::TWO_BYTE_ENCODING);
3358 __ bind(&return_v0);
3359 Counters* counters = isolate()->counters();
3360 __ IncrementCounter(counters->sub_string_native(), 1, a3, a4);
3363 // Just jump to runtime to create the sub string.
3365 __ TailCallRuntime(Runtime::kSubString, 3, 1);
3367 __ bind(&single_char);
3368 // v0: original string
3369 // a1: instance type
3371 // a3: from index (untagged)
3373 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
3374 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
3375 generator.GenerateFast(masm);
3377 generator.SkipSlow(masm, &runtime);
3381 void ToNumberStub::Generate(MacroAssembler* masm) {
3382 // The ToNumber stub takes one argument in a0.
3384 __ JumpIfNotSmi(a0, ¬_smi);
3385 __ Ret(USE_DELAY_SLOT);
3389 Label not_heap_number;
3390 __ ld(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
3391 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
3393 // a1: instance type.
3394 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3395 __ Ret(USE_DELAY_SLOT);
3397 __ bind(¬_heap_number);
3399 Label not_string, slow_string;
3400 __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE));
3401 // Check if string has a cached array index.
3402 __ ld(a2, FieldMemOperand(a0, String::kHashFieldOffset));
3403 __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
3404 __ Branch(&slow_string, ne, at, Operand(zero_reg));
3405 __ IndexFromHash(a2, a0);
3406 __ Ret(USE_DELAY_SLOT);
3408 __ bind(&slow_string);
3409 __ push(a0); // Push argument.
3410 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3411 __ bind(¬_string);
3414 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3415 __ Ret(USE_DELAY_SLOT);
3416 __ ld(v0, FieldMemOperand(a0, Oddball::kToNumberOffset));
3417 __ bind(¬_oddball);
3419 __ push(a0); // Push argument.
3420 __ TailCallRuntime(Runtime::kToNumber, 1, 1);
3424 void ToStringStub::Generate(MacroAssembler* masm) {
3425 // The ToString stub takes on argument in a0.
3427 __ JumpIfSmi(a0, &is_number);
3430 __ GetObjectType(a0, a1, a1);
3432 // a1: receiver instance type
3433 __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
3434 __ Ret(USE_DELAY_SLOT);
3436 __ bind(¬_string);
3438 Label not_heap_number;
3439 __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE));
3440 __ bind(&is_number);
3441 NumberToStringStub stub(isolate());
3442 __ TailCallStub(&stub);
3443 __ bind(¬_heap_number);
3446 __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE));
3447 __ Ret(USE_DELAY_SLOT);
3448 __ ld(v0, FieldMemOperand(a0, Oddball::kToStringOffset));
3449 __ bind(¬_oddball);
3451 __ push(a0); // Push argument.
3452 __ TailCallRuntime(Runtime::kToString, 1, 1);
3456 void StringHelper::GenerateFlatOneByteStringEquals(
3457 MacroAssembler* masm, Register left, Register right, Register scratch1,
3458 Register scratch2, Register scratch3) {
3459 Register length = scratch1;
3462 Label strings_not_equal, check_zero_length;
3463 __ ld(length, FieldMemOperand(left, String::kLengthOffset));
3464 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
3465 __ Branch(&check_zero_length, eq, length, Operand(scratch2));
3466 __ bind(&strings_not_equal);
3467 // Can not put li in delayslot, it has multi instructions.
3468 __ li(v0, Operand(Smi::FromInt(NOT_EQUAL)));
3471 // Check if the length is zero.
3472 Label compare_chars;
3473 __ bind(&check_zero_length);
3474 STATIC_ASSERT(kSmiTag == 0);
3475 __ Branch(&compare_chars, ne, length, Operand(zero_reg));
3476 DCHECK(is_int16((intptr_t)Smi::FromInt(EQUAL)));
3477 __ Ret(USE_DELAY_SLOT);
3478 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3480 // Compare characters.
3481 __ bind(&compare_chars);
3483 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3,
3484 v0, &strings_not_equal);
3486 // Characters are equal.
3487 __ Ret(USE_DELAY_SLOT);
3488 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3492 void StringHelper::GenerateCompareFlatOneByteStrings(
3493 MacroAssembler* masm, Register left, Register right, Register scratch1,
3494 Register scratch2, Register scratch3, Register scratch4) {
3495 Label result_not_equal, compare_lengths;
3496 // Find minimum length and length difference.
3497 __ ld(scratch1, FieldMemOperand(left, String::kLengthOffset));
3498 __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset));
3499 __ Dsubu(scratch3, scratch1, Operand(scratch2));
3500 Register length_delta = scratch3;
3501 __ slt(scratch4, scratch2, scratch1);
3502 __ Movn(scratch1, scratch2, scratch4);
3503 Register min_length = scratch1;
3504 STATIC_ASSERT(kSmiTag == 0);
3505 __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg));
3508 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3509 scratch4, v0, &result_not_equal);
3511 // Compare lengths - strings up to min-length are equal.
3512 __ bind(&compare_lengths);
3513 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
3514 // Use length_delta as result if it's zero.
3515 __ mov(scratch2, length_delta);
3516 __ mov(scratch4, zero_reg);
3517 __ mov(v0, zero_reg);
3519 __ bind(&result_not_equal);
3520 // Conditionally update the result based either on length_delta or
3521 // the last comparion performed in the loop above.
3523 __ Branch(&ret, eq, scratch2, Operand(scratch4));
3524 __ li(v0, Operand(Smi::FromInt(GREATER)));
3525 __ Branch(&ret, gt, scratch2, Operand(scratch4));
3526 __ li(v0, Operand(Smi::FromInt(LESS)));
3532 void StringHelper::GenerateOneByteCharsCompareLoop(
3533 MacroAssembler* masm, Register left, Register right, Register length,
3534 Register scratch1, Register scratch2, Register scratch3,
3535 Label* chars_not_equal) {
3536 // Change index to run from -length to -1 by adding length to string
3537 // start. This means that loop ends when index reaches zero, which
3538 // doesn't need an additional compare.
3539 __ SmiUntag(length);
3540 __ Daddu(scratch1, length,
3541 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3542 __ Daddu(left, left, Operand(scratch1));
3543 __ Daddu(right, right, Operand(scratch1));
3544 __ Dsubu(length, zero_reg, length);
3545 Register index = length; // index = -length;
3551 __ Daddu(scratch3, left, index);
3552 __ lbu(scratch1, MemOperand(scratch3));
3553 __ Daddu(scratch3, right, index);
3554 __ lbu(scratch2, MemOperand(scratch3));
3555 __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2));
3556 __ Daddu(index, index, 1);
3557 __ Branch(&loop, ne, index, Operand(zero_reg));
3561 void StringCompareStub::Generate(MacroAssembler* masm) {
3564 Counters* counters = isolate()->counters();
3566 // Stack frame on entry.
3567 // sp[0]: right string
3568 // sp[4]: left string
3569 __ ld(a1, MemOperand(sp, 1 * kPointerSize)); // Left.
3570 __ ld(a0, MemOperand(sp, 0 * kPointerSize)); // Right.
3573 __ Branch(¬_same, ne, a0, Operand(a1));
3574 STATIC_ASSERT(EQUAL == 0);
3575 STATIC_ASSERT(kSmiTag == 0);
3576 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3577 __ IncrementCounter(counters->string_compare_native(), 1, a1, a2);
3582 // Check that both objects are sequential one_byte strings.
3583 __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime);
3585 // Compare flat one_byte strings natively. Remove arguments from stack first.
3586 __ IncrementCounter(counters->string_compare_native(), 1, a2, a3);
3587 __ Daddu(sp, sp, Operand(2 * kPointerSize));
3588 StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, a4, a5);
3591 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3595 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3596 // ----------- S t a t e -------------
3599 // -- ra : return address
3600 // -----------------------------------
3602 // Load a2 with the allocation site. We stick an undefined dummy value here
3603 // and replace it with the real allocation site later when we instantiate this
3604 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3605 __ li(a2, handle(isolate()->heap()->undefined_value()));
3607 // Make sure that we actually patched the allocation site.
3608 if (FLAG_debug_code) {
3609 __ And(at, a2, Operand(kSmiTagMask));
3610 __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg));
3611 __ ld(a4, FieldMemOperand(a2, HeapObject::kMapOffset));
3612 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
3613 __ Assert(eq, kExpectedAllocationSite, a4, Operand(at));
3616 // Tail call into the stub that handles binary operations with allocation
3618 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3619 __ TailCallStub(&stub);
3623 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3624 DCHECK(state() == CompareICState::SMI);
3627 __ JumpIfNotSmi(a2, &miss);
3629 if (GetCondition() == eq) {
3630 // For equality we do not care about the sign of the result.
3631 __ Ret(USE_DELAY_SLOT);
3632 __ Dsubu(v0, a0, a1);
3634 // Untag before subtracting to avoid handling overflow.
3637 __ Ret(USE_DELAY_SLOT);
3638 __ Dsubu(v0, a1, a0);
3646 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3647 DCHECK(state() == CompareICState::NUMBER);
3650 Label unordered, maybe_undefined1, maybe_undefined2;
3653 if (left() == CompareICState::SMI) {
3654 __ JumpIfNotSmi(a1, &miss);
3656 if (right() == CompareICState::SMI) {
3657 __ JumpIfNotSmi(a0, &miss);
3660 // Inlining the double comparison and falling back to the general compare
3661 // stub if NaN is involved.
3662 // Load left and right operand.
3663 Label done, left, left_smi, right_smi;
3664 __ JumpIfSmi(a0, &right_smi);
3665 __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
3667 __ Dsubu(a2, a0, Operand(kHeapObjectTag));
3668 __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset));
3670 __ bind(&right_smi);
3671 __ SmiUntag(a2, a0); // Can't clobber a0 yet.
3672 FPURegister single_scratch = f6;
3673 __ mtc1(a2, single_scratch);
3674 __ cvt_d_w(f2, single_scratch);
3677 __ JumpIfSmi(a1, &left_smi);
3678 __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
3680 __ Dsubu(a2, a1, Operand(kHeapObjectTag));
3681 __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset));
3684 __ SmiUntag(a2, a1); // Can't clobber a1 yet.
3685 single_scratch = f8;
3686 __ mtc1(a2, single_scratch);
3687 __ cvt_d_w(f0, single_scratch);
3691 // Return a result of -1, 0, or 1, or use CompareStub for NaNs.
3692 Label fpu_eq, fpu_lt;
3693 // Test if equal, and also handle the unordered/NaN case.
3694 __ BranchF(&fpu_eq, &unordered, eq, f0, f2);
3696 // Test if less (unordered case is already handled).
3697 __ BranchF(&fpu_lt, NULL, lt, f0, f2);
3699 // Otherwise it's greater, so just fall thru, and return.
3700 DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS));
3701 __ Ret(USE_DELAY_SLOT);
3702 __ li(v0, Operand(GREATER));
3705 __ Ret(USE_DELAY_SLOT);
3706 __ li(v0, Operand(EQUAL));
3709 __ Ret(USE_DELAY_SLOT);
3710 __ li(v0, Operand(LESS));
3712 __ bind(&unordered);
3713 __ bind(&generic_stub);
3714 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3715 CompareICState::GENERIC, CompareICState::GENERIC);
3716 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3718 __ bind(&maybe_undefined1);
3719 if (Token::IsOrderedRelationalCompareOp(op())) {
3720 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3721 __ Branch(&miss, ne, a0, Operand(at));
3722 __ JumpIfSmi(a1, &unordered);
3723 __ GetObjectType(a1, a2, a2);
3724 __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE));
3728 __ bind(&maybe_undefined2);
3729 if (Token::IsOrderedRelationalCompareOp(op())) {
3730 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
3731 __ Branch(&unordered, eq, a1, Operand(at));
3739 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3740 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3743 // Registers containing left and right operands respectively.
3745 Register right = a0;
3749 // Check that both operands are heap objects.
3750 __ JumpIfEitherSmi(left, right, &miss);
3752 // Check that both operands are internalized strings.
3753 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3754 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3755 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3756 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3757 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3758 __ Or(tmp1, tmp1, Operand(tmp2));
3759 __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3760 __ Branch(&miss, ne, at, Operand(zero_reg));
3762 // Make sure a0 is non-zero. At this point input operands are
3763 // guaranteed to be non-zero.
3764 DCHECK(right.is(a0));
3765 STATIC_ASSERT(EQUAL == 0);
3766 STATIC_ASSERT(kSmiTag == 0);
3768 // Internalized strings are compared by identity.
3769 __ Ret(ne, left, Operand(right));
3770 DCHECK(is_int16(EQUAL));
3771 __ Ret(USE_DELAY_SLOT);
3772 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3779 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3780 DCHECK(state() == CompareICState::UNIQUE_NAME);
3781 DCHECK(GetCondition() == eq);
3784 // Registers containing left and right operands respectively.
3786 Register right = a0;
3790 // Check that both operands are heap objects.
3791 __ JumpIfEitherSmi(left, right, &miss);
3793 // Check that both operands are unique names. This leaves the instance
3794 // types loaded in tmp1 and tmp2.
3795 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3796 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3797 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3798 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3800 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss);
3801 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss);
3806 // Unique names are compared by identity.
3808 __ Branch(&done, ne, left, Operand(right));
3809 // Make sure a0 is non-zero. At this point input operands are
3810 // guaranteed to be non-zero.
3811 DCHECK(right.is(a0));
3812 STATIC_ASSERT(EQUAL == 0);
3813 STATIC_ASSERT(kSmiTag == 0);
3814 __ li(v0, Operand(Smi::FromInt(EQUAL)));
3823 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3824 DCHECK(state() == CompareICState::STRING);
3827 bool equality = Token::IsEqualityOp(op());
3829 // Registers containing left and right operands respectively.
3831 Register right = a0;
3838 // Check that both operands are heap objects.
3839 __ JumpIfEitherSmi(left, right, &miss);
3841 // Check that both operands are strings. This leaves the instance
3842 // types loaded in tmp1 and tmp2.
3843 __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
3844 __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3845 __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
3846 __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
3847 STATIC_ASSERT(kNotStringTag != 0);
3848 __ Or(tmp3, tmp1, tmp2);
3849 __ And(tmp5, tmp3, Operand(kIsNotStringMask));
3850 __ Branch(&miss, ne, tmp5, Operand(zero_reg));
3852 // Fast check for identical strings.
3853 Label left_ne_right;
3854 STATIC_ASSERT(EQUAL == 0);
3855 STATIC_ASSERT(kSmiTag == 0);
3856 __ Branch(&left_ne_right, ne, left, Operand(right));
3857 __ Ret(USE_DELAY_SLOT);
3858 __ mov(v0, zero_reg); // In the delay slot.
3859 __ bind(&left_ne_right);
3861 // Handle not identical strings.
3863 // Check that both strings are internalized strings. If they are, we're done
3864 // because we already know they are not identical. We know they are both
3867 DCHECK(GetCondition() == eq);
3868 STATIC_ASSERT(kInternalizedTag == 0);
3869 __ Or(tmp3, tmp1, Operand(tmp2));
3870 __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask));
3872 __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg));
3873 // Make sure a0 is non-zero. At this point input operands are
3874 // guaranteed to be non-zero.
3875 DCHECK(right.is(a0));
3876 __ Ret(USE_DELAY_SLOT);
3877 __ mov(v0, a0); // In the delay slot.
3878 __ bind(&is_symbol);
3881 // Check that both strings are sequential one_byte.
3883 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4,
3886 // Compare flat one_byte strings. Returns when done.
3888 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2,
3891 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3895 // Handle more complex cases in runtime.
3897 __ Push(left, right);
3899 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3901 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
3909 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3910 DCHECK(state() == CompareICState::OBJECT);
3912 __ And(a2, a1, Operand(a0));
3913 __ JumpIfSmi(a2, &miss);
3915 __ GetObjectType(a0, a2, a2);
3916 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3917 __ GetObjectType(a1, a2, a2);
3918 __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE));
3920 DCHECK(GetCondition() == eq);
3921 __ Ret(USE_DELAY_SLOT);
3922 __ dsubu(v0, a0, a1);
3929 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3931 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3933 __ JumpIfSmi(a2, &miss);
3934 __ GetWeakValue(a4, cell);
3935 __ ld(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
3936 __ ld(a3, FieldMemOperand(a1, HeapObject::kMapOffset));
3937 __ Branch(&miss, ne, a2, Operand(a4));
3938 __ Branch(&miss, ne, a3, Operand(a4));
3940 __ Ret(USE_DELAY_SLOT);
3941 __ dsubu(v0, a0, a1);
3948 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3950 // Call the runtime system in a fresh internal frame.
3951 FrameScope scope(masm, StackFrame::INTERNAL);
3953 __ Push(ra, a1, a0);
3954 __ li(a4, Operand(Smi::FromInt(op())));
3955 __ daddiu(sp, sp, -kPointerSize);
3956 __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs,
3958 __ sd(a4, MemOperand(sp)); // In the delay slot.
3959 // Compute the entry point of the rewritten stub.
3960 __ Daddu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
3961 // Restore registers.
3968 void DirectCEntryStub::Generate(MacroAssembler* masm) {
3969 // Make place for arguments to fit C calling convention. Most of the callers
3970 // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame
3971 // so they handle stack restoring and we don't have to do that here.
3972 // Any caller of DirectCEntryStub::GenerateCall must take care of dropping
3973 // kCArgsSlotsSize stack space after the call.
3974 __ daddiu(sp, sp, -kCArgsSlotsSize);
3975 // Place the return address on the stack, making the call
3976 // GC safe. The RegExp backend also relies on this.
3977 __ sd(ra, MemOperand(sp, kCArgsSlotsSize));
3978 __ Call(t9); // Call the C++ function.
3979 __ ld(t9, MemOperand(sp, kCArgsSlotsSize));
3981 if (FLAG_debug_code && FLAG_enable_slow_asserts) {
3982 // In case of an error the return address may point to a memory area
3983 // filled with kZapValue by the GC.
3984 // Dereference the address and check for this.
3985 __ Uld(a4, MemOperand(t9));
3986 __ Assert(ne, kReceivedInvalidReturnAddress, a4,
3987 Operand(reinterpret_cast<uint64_t>(kZapValue)));
3993 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
3996 reinterpret_cast<intptr_t>(GetCode().location());
3997 __ Move(t9, target);
3998 __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE);
4003 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4007 Register properties,
4009 Register scratch0) {
4010 DCHECK(name->IsUniqueName());
4011 // If names of slots in range from 1 to kProbes - 1 for the hash value are
4012 // not equal to the name and kProbes-th slot is not used (its name is the
4013 // undefined value), it guarantees the hash table doesn't contain the
4014 // property. It's true even if some slots represent deleted properties
4015 // (their names are the hole value).
4016 for (int i = 0; i < kInlinedProbes; i++) {
4017 // scratch0 points to properties hash.
4018 // Compute the masked index: (hash + i + i * i) & mask.
4019 Register index = scratch0;
4020 // Capacity is smi 2^n.
4021 __ SmiLoadUntag(index, FieldMemOperand(properties, kCapacityOffset));
4022 __ Dsubu(index, index, Operand(1));
4023 __ And(index, index,
4024 Operand(name->Hash() + NameDictionary::GetProbeOffset(i)));
4026 // Scale the index by multiplying by the entry size.
4027 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4028 __ dsll(at, index, 1);
4029 __ Daddu(index, index, at); // index *= 3.
4031 Register entity_name = scratch0;
4032 // Having undefined at this place means the name is not contained.
4033 STATIC_ASSERT(kSmiTagSize == 1);
4034 Register tmp = properties;
4036 __ dsll(scratch0, index, kPointerSizeLog2);
4037 __ Daddu(tmp, properties, scratch0);
4038 __ ld(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
4040 DCHECK(!tmp.is(entity_name));
4041 __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
4042 __ Branch(done, eq, entity_name, Operand(tmp));
4044 // Load the hole ready for use below:
4045 __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
4047 // Stop if found the property.
4048 __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name)));
4051 __ Branch(&good, eq, entity_name, Operand(tmp));
4053 // Check if the entry name is not a unique name.
4054 __ ld(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
4056 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
4057 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
4060 // Restore the properties.
4062 FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4065 const int spill_mask =
4066 (ra.bit() | a6.bit() | a5.bit() | a4.bit() | a3.bit() |
4067 a2.bit() | a1.bit() | a0.bit() | v0.bit());
4069 __ MultiPush(spill_mask);
4070 __ ld(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
4071 __ li(a1, Operand(Handle<Name>(name)));
4072 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
4075 __ MultiPop(spill_mask);
4077 __ Branch(done, eq, at, Operand(zero_reg));
4078 __ Branch(miss, ne, at, Operand(zero_reg));
4082 // Probe the name dictionary in the |elements| register. Jump to the
4083 // |done| label if a property with the given name is found. Jump to
4084 // the |miss| label otherwise.
4085 // If lookup was successful |scratch2| will be equal to elements + 4 * index.
4086 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
4092 Register scratch2) {
4093 DCHECK(!elements.is(scratch1));
4094 DCHECK(!elements.is(scratch2));
4095 DCHECK(!name.is(scratch1));
4096 DCHECK(!name.is(scratch2));
4098 __ AssertName(name);
4100 // Compute the capacity mask.
4101 __ ld(scratch1, FieldMemOperand(elements, kCapacityOffset));
4102 __ SmiUntag(scratch1);
4103 __ Dsubu(scratch1, scratch1, Operand(1));
4105 // Generate an unrolled loop that performs a few probes before
4106 // giving up. Measurements done on Gmail indicate that 2 probes
4107 // cover ~93% of loads from dictionaries.
4108 for (int i = 0; i < kInlinedProbes; i++) {
4109 // Compute the masked index: (hash + i + i * i) & mask.
4110 __ lwu(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4112 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4113 // the hash in a separate instruction. The value hash + i + i * i is right
4114 // shifted in the following and instruction.
4115 DCHECK(NameDictionary::GetProbeOffset(i) <
4116 1 << (32 - Name::kHashFieldOffset));
4117 __ Daddu(scratch2, scratch2, Operand(
4118 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4120 __ dsrl(scratch2, scratch2, Name::kHashShift);
4121 __ And(scratch2, scratch1, scratch2);
4123 // Scale the index by multiplying by the entry size.
4124 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4125 // scratch2 = scratch2 * 3.
4127 __ dsll(at, scratch2, 1);
4128 __ Daddu(scratch2, scratch2, at);
4130 // Check if the key is identical to the name.
4131 __ dsll(at, scratch2, kPointerSizeLog2);
4132 __ Daddu(scratch2, elements, at);
4133 __ ld(at, FieldMemOperand(scratch2, kElementsStartOffset));
4134 __ Branch(done, eq, name, Operand(at));
4137 const int spill_mask =
4138 (ra.bit() | a6.bit() | a5.bit() | a4.bit() |
4139 a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) &
4140 ~(scratch1.bit() | scratch2.bit());
4142 __ MultiPush(spill_mask);
4144 DCHECK(!elements.is(a1));
4146 __ Move(a0, elements);
4148 __ Move(a0, elements);
4151 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4153 __ mov(scratch2, a2);
4155 __ MultiPop(spill_mask);
4157 __ Branch(done, ne, at, Operand(zero_reg));
4158 __ Branch(miss, eq, at, Operand(zero_reg));
4162 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
4163 // This stub overrides SometimesSetsUpAFrame() to return false. That means
4164 // we cannot call anything that could cause a GC from this stub.
4166 // result: NameDictionary to probe
4168 // dictionary: NameDictionary to probe.
4169 // index: will hold an index of entry if lookup is successful.
4170 // might alias with result_.
4172 // result_ is zero if lookup failed, non zero otherwise.
4174 Register result = v0;
4175 Register dictionary = a0;
4177 Register index = a2;
4180 Register undefined = a5;
4181 Register entry_key = a6;
4183 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
4185 __ ld(mask, FieldMemOperand(dictionary, kCapacityOffset));
4187 __ Dsubu(mask, mask, Operand(1));
4189 __ lwu(hash, FieldMemOperand(key, Name::kHashFieldOffset));
4191 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
4193 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
4194 // Compute the masked index: (hash + i + i * i) & mask.
4195 // Capacity is smi 2^n.
4197 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4198 // the hash in a separate instruction. The value hash + i + i * i is right
4199 // shifted in the following and instruction.
4200 DCHECK(NameDictionary::GetProbeOffset(i) <
4201 1 << (32 - Name::kHashFieldOffset));
4202 __ Daddu(index, hash, Operand(
4203 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4205 __ mov(index, hash);
4207 __ dsrl(index, index, Name::kHashShift);
4208 __ And(index, mask, index);
4210 // Scale the index by multiplying by the entry size.
4211 STATIC_ASSERT(NameDictionary::kEntrySize == 3);
4214 __ dsll(index, index, 1);
4215 __ Daddu(index, index, at);
4218 STATIC_ASSERT(kSmiTagSize == 1);
4219 __ dsll(index, index, kPointerSizeLog2);
4220 __ Daddu(index, index, dictionary);
4221 __ ld(entry_key, FieldMemOperand(index, kElementsStartOffset));
4223 // Having undefined at this place means the name is not contained.
4224 __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined));
4226 // Stop if found the property.
4227 __ Branch(&in_dictionary, eq, entry_key, Operand(key));
4229 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
4230 // Check if the entry name is not a unique name.
4231 __ ld(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
4233 FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
4234 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
4238 __ bind(&maybe_in_dictionary);
4239 // If we are doing negative lookup then probing failure should be
4240 // treated as a lookup success. For positive lookup probing failure
4241 // should be treated as lookup failure.
4242 if (mode() == POSITIVE_LOOKUP) {
4243 __ Ret(USE_DELAY_SLOT);
4244 __ mov(result, zero_reg);
4247 __ bind(&in_dictionary);
4248 __ Ret(USE_DELAY_SLOT);
4251 __ bind(¬_in_dictionary);
4252 __ Ret(USE_DELAY_SLOT);
4253 __ mov(result, zero_reg);
4257 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
4259 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
4261 // Hydrogen code stubs need stub2 at snapshot time.
4262 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
4267 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
4268 // the value has just been written into the object, now this stub makes sure
4269 // we keep the GC informed. The word in the object where the value has been
4270 // written is in the address register.
4271 void RecordWriteStub::Generate(MacroAssembler* masm) {
4272 Label skip_to_incremental_noncompacting;
4273 Label skip_to_incremental_compacting;
4275 // The first two branch+nop instructions are generated with labels so as to
4276 // get the offset fixed up correctly by the bind(Label*) call. We patch it
4277 // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this
4278 // position) and the "beq zero_reg, zero_reg, ..." when we start and stop
4279 // incremental heap marking.
4280 // See RecordWriteStub::Patch for details.
4281 __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting);
4283 __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting);
4286 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4287 __ RememberedSetHelper(object(),
4290 save_fp_regs_mode(),
4291 MacroAssembler::kReturnAtEnd);
4295 __ bind(&skip_to_incremental_noncompacting);
4296 GenerateIncremental(masm, INCREMENTAL);
4298 __ bind(&skip_to_incremental_compacting);
4299 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4301 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
4302 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
4304 PatchBranchIntoNop(masm, 0);
4305 PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize);
4309 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4312 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4313 Label dont_need_remembered_set;
4315 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
4316 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
4318 &dont_need_remembered_set);
4320 __ CheckPageFlag(regs_.object(),
4322 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4324 &dont_need_remembered_set);
4326 // First notify the incremental marker if necessary, then update the
4328 CheckNeedsToInformIncrementalMarker(
4329 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4330 InformIncrementalMarker(masm);
4331 regs_.Restore(masm);
4332 __ RememberedSetHelper(object(),
4335 save_fp_regs_mode(),
4336 MacroAssembler::kReturnAtEnd);
4338 __ bind(&dont_need_remembered_set);
4341 CheckNeedsToInformIncrementalMarker(
4342 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4343 InformIncrementalMarker(masm);
4344 regs_.Restore(masm);
4349 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4350 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4351 int argument_count = 3;
4352 __ PrepareCallCFunction(argument_count, regs_.scratch0());
4354 a0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
4355 DCHECK(!address.is(regs_.object()));
4356 DCHECK(!address.is(a0));
4357 __ Move(address, regs_.address());
4358 __ Move(a0, regs_.object());
4359 __ Move(a1, address);
4360 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
4362 AllowExternalCallThatCantCauseGC scope(masm);
4364 ExternalReference::incremental_marking_record_write_function(isolate()),
4366 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4370 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4371 MacroAssembler* masm,
4372 OnNoNeedToInformIncrementalMarker on_no_need,
4375 Label need_incremental;
4376 Label need_incremental_pop_scratch;
4378 __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
4379 __ ld(regs_.scratch1(),
4380 MemOperand(regs_.scratch0(),
4381 MemoryChunk::kWriteBarrierCounterOffset));
4382 __ Dsubu(regs_.scratch1(), regs_.scratch1(), Operand(1));
4383 __ sd(regs_.scratch1(),
4384 MemOperand(regs_.scratch0(),
4385 MemoryChunk::kWriteBarrierCounterOffset));
4386 __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg));
4388 // Let's look at the color of the object: If it is not black we don't have
4389 // to inform the incremental marker.
4390 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4392 regs_.Restore(masm);
4393 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4394 __ RememberedSetHelper(object(),
4397 save_fp_regs_mode(),
4398 MacroAssembler::kReturnAtEnd);
4405 // Get the value from the slot.
4406 __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0));
4408 if (mode == INCREMENTAL_COMPACTION) {
4409 Label ensure_not_white;
4411 __ CheckPageFlag(regs_.scratch0(), // Contains value.
4412 regs_.scratch1(), // Scratch.
4413 MemoryChunk::kEvacuationCandidateMask,
4417 __ CheckPageFlag(regs_.object(),
4418 regs_.scratch1(), // Scratch.
4419 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4423 __ bind(&ensure_not_white);
4426 // We need extra registers for this, so we push the object and the address
4427 // register temporarily.
4428 __ Push(regs_.object(), regs_.address());
4429 __ EnsureNotWhite(regs_.scratch0(), // The value.
4430 regs_.scratch1(), // Scratch.
4431 regs_.object(), // Scratch.
4432 regs_.address(), // Scratch.
4433 &need_incremental_pop_scratch);
4434 __ Pop(regs_.object(), regs_.address());
4436 regs_.Restore(masm);
4437 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4438 __ RememberedSetHelper(object(),
4441 save_fp_regs_mode(),
4442 MacroAssembler::kReturnAtEnd);
4447 __ bind(&need_incremental_pop_scratch);
4448 __ Pop(regs_.object(), regs_.address());
4450 __ bind(&need_incremental);
4452 // Fall through when we need to inform the incremental marker.
4456 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4457 // ----------- S t a t e -------------
4458 // -- a0 : element value to store
4459 // -- a3 : element index as smi
4460 // -- sp[0] : array literal index in function as smi
4461 // -- sp[4] : array literal
4462 // clobbers a1, a2, a4
4463 // -----------------------------------
4466 Label double_elements;
4468 Label slow_elements;
4469 Label fast_elements;
4471 // Get array literal index, array literal and its map.
4472 __ ld(a4, MemOperand(sp, 0 * kPointerSize));
4473 __ ld(a1, MemOperand(sp, 1 * kPointerSize));
4474 __ ld(a2, FieldMemOperand(a1, JSObject::kMapOffset));
4476 __ CheckFastElements(a2, a5, &double_elements);
4477 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4478 __ JumpIfSmi(a0, &smi_element);
4479 __ CheckFastSmiElements(a2, a5, &fast_elements);
4481 // Store into the array literal requires a elements transition. Call into
4483 __ bind(&slow_elements);
4485 __ Push(a1, a3, a0);
4486 __ ld(a5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4487 __ ld(a5, FieldMemOperand(a5, JSFunction::kLiteralsOffset));
4489 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4491 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4492 __ bind(&fast_elements);
4493 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4494 __ SmiScale(a6, a3, kPointerSizeLog2);
4495 __ Daddu(a6, a5, a6);
4496 __ Daddu(a6, a6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4497 __ sd(a0, MemOperand(a6, 0));
4498 // Update the write barrier for the array store.
4499 __ RecordWrite(a5, a6, a0, kRAHasNotBeenSaved, kDontSaveFPRegs,
4500 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4501 __ Ret(USE_DELAY_SLOT);
4504 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4505 // and value is Smi.
4506 __ bind(&smi_element);
4507 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4508 __ SmiScale(a6, a3, kPointerSizeLog2);
4509 __ Daddu(a6, a5, a6);
4510 __ sd(a0, FieldMemOperand(a6, FixedArray::kHeaderSize));
4511 __ Ret(USE_DELAY_SLOT);
4514 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4515 __ bind(&double_elements);
4516 __ ld(a5, FieldMemOperand(a1, JSObject::kElementsOffset));
4517 __ StoreNumberToDoubleElements(a0, a3, a5, a7, t1, &slow_elements);
4518 __ Ret(USE_DELAY_SLOT);
4523 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4524 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4525 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4526 int parameter_count_offset =
4527 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4528 __ ld(a1, MemOperand(fp, parameter_count_offset));
4529 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4530 __ Daddu(a1, a1, Operand(1));
4532 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4533 __ dsll(a1, a1, kPointerSizeLog2);
4534 __ Ret(USE_DELAY_SLOT);
4535 __ Daddu(sp, sp, a1);
4539 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4540 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4541 LoadICStub stub(isolate(), state());
4542 stub.GenerateForTrampoline(masm);
4546 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4547 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4548 KeyedLoadICStub stub(isolate(), state());
4549 stub.GenerateForTrampoline(masm);
4553 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4554 EmitLoadTypeFeedbackVector(masm, a2);
4555 CallICStub stub(isolate(), state());
4556 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4560 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4561 EmitLoadTypeFeedbackVector(masm, a2);
4562 CallIC_ArrayStub stub(isolate(), state());
4563 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4567 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4570 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4571 GenerateImpl(masm, true);
4575 static void HandleArrayCases(MacroAssembler* masm, Register feedback,
4576 Register receiver_map, Register scratch1,
4577 Register scratch2, bool is_polymorphic,
4579 // feedback initially contains the feedback array
4580 Label next_loop, prepare_next;
4581 Label start_polymorphic;
4583 Register cached_map = scratch1;
4586 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4587 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4588 __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map));
4589 // found, now call handler.
4590 Register handler = feedback;
4591 __ ld(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4592 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4595 Register length = scratch2;
4596 __ bind(&start_polymorphic);
4597 __ ld(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4598 if (!is_polymorphic) {
4599 // If the IC could be monomorphic we have to make sure we don't go past the
4600 // end of the feedback array.
4601 __ Branch(miss, eq, length, Operand(Smi::FromInt(2)));
4604 Register too_far = length;
4605 Register pointer_reg = feedback;
4607 // +-----+------+------+-----+-----+ ... ----+
4608 // | map | len | wm0 | h0 | wm1 | hN |
4609 // +-----+------+------+-----+-----+ ... ----+
4613 // pointer_reg too_far
4614 // aka feedback scratch2
4615 // also need receiver_map
4616 // use cached_map (scratch1) to look in the weak map values.
4617 __ SmiScale(too_far, length, kPointerSizeLog2);
4618 __ Daddu(too_far, feedback, Operand(too_far));
4619 __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4620 __ Daddu(pointer_reg, feedback,
4621 Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag));
4623 __ bind(&next_loop);
4624 __ ld(cached_map, MemOperand(pointer_reg));
4625 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4626 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4627 __ ld(handler, MemOperand(pointer_reg, kPointerSize));
4628 __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag));
4631 __ bind(&prepare_next);
4632 __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 2));
4633 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4635 // We exhausted our array of map handler pairs.
4640 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4641 Register receiver_map, Register feedback,
4642 Register vector, Register slot,
4643 Register scratch, Label* compare_map,
4644 Label* load_smi_map, Label* try_array) {
4645 __ JumpIfSmi(receiver, load_smi_map);
4646 __ ld(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4647 __ bind(compare_map);
4648 Register cached_map = scratch;
4649 // Move the weak map into the weak_cell register.
4650 __ ld(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4651 __ Branch(try_array, ne, cached_map, Operand(receiver_map));
4652 Register handler = feedback;
4653 __ SmiScale(handler, slot, kPointerSizeLog2);
4654 __ Daddu(handler, vector, Operand(handler));
4656 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4657 __ Daddu(t9, handler, Code::kHeaderSize - kHeapObjectTag);
4662 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4663 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4664 Register name = LoadWithVectorDescriptor::NameRegister(); // a2
4665 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4666 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4667 Register feedback = a4;
4668 Register receiver_map = a5;
4669 Register scratch1 = a6;
4671 __ SmiScale(feedback, slot, kPointerSizeLog2);
4672 __ Daddu(feedback, vector, Operand(feedback));
4673 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4675 // Try to quickly handle the monomorphic case without knowing for sure
4676 // if we have a weak cell in feedback. We do know it's safe to look
4677 // at WeakCell::kValueOffset.
4678 Label try_array, load_smi_map, compare_map;
4679 Label not_array, miss;
4680 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4681 scratch1, &compare_map, &load_smi_map, &try_array);
4683 // Is it a fixed array?
4684 __ bind(&try_array);
4685 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4686 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4687 __ Branch(¬_array, ne, scratch1, Operand(at));
4688 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss);
4690 __ bind(¬_array);
4691 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4692 __ Branch(&miss, ne, feedback, Operand(at));
4693 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4694 Code::ComputeHandlerFlags(Code::LOAD_IC));
4695 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4696 receiver, name, feedback,
4697 receiver_map, scratch1, a7);
4700 LoadIC::GenerateMiss(masm);
4702 __ bind(&load_smi_map);
4703 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4704 __ Branch(&compare_map);
4708 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4709 GenerateImpl(masm, false);
4713 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4714 GenerateImpl(masm, true);
4718 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4719 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1
4720 Register key = LoadWithVectorDescriptor::NameRegister(); // a2
4721 Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3
4722 Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0
4723 Register feedback = a4;
4724 Register receiver_map = a5;
4725 Register scratch1 = a6;
4727 __ SmiScale(feedback, slot, kPointerSizeLog2);
4728 __ Daddu(feedback, vector, Operand(feedback));
4729 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4731 // Try to quickly handle the monomorphic case without knowing for sure
4732 // if we have a weak cell in feedback. We do know it's safe to look
4733 // at WeakCell::kValueOffset.
4734 Label try_array, load_smi_map, compare_map;
4735 Label not_array, miss;
4736 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4737 scratch1, &compare_map, &load_smi_map, &try_array);
4739 __ bind(&try_array);
4740 // Is it a fixed array?
4741 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4742 __ LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4743 __ Branch(¬_array, ne, scratch1, Operand(at));
4744 // We have a polymorphic element handler.
4745 __ JumpIfNotSmi(key, &miss);
4747 Label polymorphic, try_poly_name;
4748 __ bind(&polymorphic);
4749 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss);
4751 __ bind(¬_array);
4753 __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex);
4754 __ Branch(&try_poly_name, ne, feedback, Operand(at));
4755 Handle<Code> megamorphic_stub =
4756 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4757 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4759 __ bind(&try_poly_name);
4760 // We might have a name in feedback, and a fixed array in the next slot.
4761 __ Branch(&miss, ne, key, Operand(feedback));
4762 // If the name comparison succeeded, we know we have a fixed array with
4763 // at least one map/handler pair.
4764 __ SmiScale(feedback, slot, kPointerSizeLog2);
4765 __ Daddu(feedback, vector, Operand(feedback));
4767 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4768 HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, false, &miss);
4771 KeyedLoadIC::GenerateMiss(masm);
4773 __ bind(&load_smi_map);
4774 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4775 __ Branch(&compare_map);
4779 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4780 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4781 VectorStoreICStub stub(isolate(), state());
4782 stub.GenerateForTrampoline(masm);
4786 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4787 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4788 VectorKeyedStoreICStub stub(isolate(), state());
4789 stub.GenerateForTrampoline(masm);
4793 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4794 GenerateImpl(masm, false);
4798 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4799 GenerateImpl(masm, true);
4803 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4804 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4805 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4806 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4807 Register slot = VectorStoreICDescriptor::SlotRegister(); // a4
4808 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4809 Register feedback = a5;
4810 Register receiver_map = a6;
4811 Register scratch1 = a7;
4813 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4814 __ Daddu(feedback, vector, Operand(scratch1));
4815 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4817 // Try to quickly handle the monomorphic case without knowing for sure
4818 // if we have a weak cell in feedback. We do know it's safe to look
4819 // at WeakCell::kValueOffset.
4820 Label try_array, load_smi_map, compare_map;
4821 Label not_array, miss;
4822 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4823 scratch1, &compare_map, &load_smi_map, &try_array);
4825 // Is it a fixed array?
4826 __ bind(&try_array);
4827 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4828 __ Branch(¬_array, ne, scratch1, Heap::kFixedArrayMapRootIndex);
4830 Register scratch2 = t0;
4831 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true,
4834 __ bind(¬_array);
4835 __ Branch(&miss, ne, feedback, Heap::kmegamorphic_symbolRootIndex);
4836 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4837 Code::ComputeHandlerFlags(Code::STORE_IC));
4838 masm->isolate()->stub_cache()->GenerateProbe(
4839 masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map,
4840 scratch1, scratch2);
4843 StoreIC::GenerateMiss(masm);
4845 __ bind(&load_smi_map);
4846 __ Branch(USE_DELAY_SLOT, &compare_map);
4847 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4851 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4852 GenerateImpl(masm, false);
4856 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4857 GenerateImpl(masm, true);
4861 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback,
4862 Register receiver_map, Register scratch1,
4863 Register scratch2, Label* miss) {
4864 // feedback initially contains the feedback array
4865 Label next_loop, prepare_next;
4866 Label start_polymorphic;
4867 Label transition_call;
4869 Register cached_map = scratch1;
4870 Register too_far = scratch2;
4871 Register pointer_reg = feedback;
4873 __ ld(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4875 // +-----+------+------+-----+-----+-----+ ... ----+
4876 // | map | len | wm0 | wt0 | h0 | wm1 | hN |
4877 // +-----+------+------+-----+-----+ ----+ ... ----+
4881 // pointer_reg too_far
4882 // aka feedback scratch2
4883 // also need receiver_map
4884 // use cached_map (scratch1) to look in the weak map values.
4885 __ SmiScale(too_far, too_far, kPointerSizeLog2);
4886 __ Daddu(too_far, feedback, Operand(too_far));
4887 __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4888 __ Daddu(pointer_reg, feedback,
4889 Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag));
4891 __ bind(&next_loop);
4892 __ ld(cached_map, MemOperand(pointer_reg));
4893 __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4894 __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map));
4895 // Is it a transitioning store?
4896 __ ld(too_far, MemOperand(pointer_reg, kPointerSize));
4897 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4898 __ Branch(&transition_call, ne, too_far, Operand(at));
4900 __ ld(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2));
4901 __ Daddu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
4904 __ bind(&transition_call);
4905 __ ld(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset));
4906 __ JumpIfSmi(too_far, miss);
4908 __ ld(receiver_map, MemOperand(pointer_reg, kPointerSize * 2));
4909 // Load the map into the correct register.
4910 DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister()));
4911 __ Move(feedback, too_far);
4912 __ Daddu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag));
4915 __ bind(&prepare_next);
4916 __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 3));
4917 __ Branch(&next_loop, lt, pointer_reg, Operand(too_far));
4919 // We exhausted our array of map handler pairs.
4924 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4925 Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1
4926 Register key = VectorStoreICDescriptor::NameRegister(); // a2
4927 Register vector = VectorStoreICDescriptor::VectorRegister(); // a3
4928 Register slot = VectorStoreICDescriptor::SlotRegister(); // a4
4929 DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0
4930 Register feedback = a5;
4931 Register receiver_map = a6;
4932 Register scratch1 = a7;
4934 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4935 __ Daddu(feedback, vector, Operand(scratch1));
4936 __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4938 // Try to quickly handle the monomorphic case without knowing for sure
4939 // if we have a weak cell in feedback. We do know it's safe to look
4940 // at WeakCell::kValueOffset.
4941 Label try_array, load_smi_map, compare_map;
4942 Label not_array, miss;
4943 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4944 scratch1, &compare_map, &load_smi_map, &try_array);
4946 __ bind(&try_array);
4947 // Is it a fixed array?
4948 __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4949 __ Branch(¬_array, ne, scratch1, Heap::kFixedArrayMapRootIndex);
4951 // We have a polymorphic element handler.
4952 Label try_poly_name;
4954 Register scratch2 = t0;
4956 HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2,
4959 __ bind(¬_array);
4961 __ Branch(&try_poly_name, ne, feedback, Heap::kmegamorphic_symbolRootIndex);
4962 Handle<Code> megamorphic_stub =
4963 KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4964 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4966 __ bind(&try_poly_name);
4967 // We might have a name in feedback, and a fixed array in the next slot.
4968 __ Branch(&miss, ne, key, Operand(feedback));
4969 // If the name comparison succeeded, we know we have a fixed array with
4970 // at least one map/handler pair.
4971 __ SmiScale(scratch1, slot, kPointerSizeLog2);
4972 __ Daddu(feedback, vector, Operand(scratch1));
4974 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4975 HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false,
4979 KeyedStoreIC::GenerateMiss(masm);
4981 __ bind(&load_smi_map);
4982 __ Branch(USE_DELAY_SLOT, &compare_map);
4983 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot.
4987 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4988 if (masm->isolate()->function_entry_hook() != NULL) {
4989 ProfileEntryHookStub stub(masm->isolate());
4997 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4998 // The entry hook is a "push ra" instruction, followed by a call.
4999 // Note: on MIPS "push" is 2 instruction
5000 const int32_t kReturnAddressDistanceFromFunctionStart =
5001 Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize);
5003 // This should contain all kJSCallerSaved registers.
5004 const RegList kSavedRegs =
5005 kJSCallerSaved | // Caller saved registers.
5006 s5.bit(); // Saved stack pointer.
5008 // We also save ra, so the count here is one higher than the mask indicates.
5009 const int32_t kNumSavedRegs = kNumJSCallerSaved + 2;
5011 // Save all caller-save registers as this may be called from anywhere.
5012 __ MultiPush(kSavedRegs | ra.bit());
5014 // Compute the function's address for the first argument.
5015 __ Dsubu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart));
5017 // The caller's return address is above the saved temporaries.
5018 // Grab that for the second argument to the hook.
5019 __ Daddu(a1, sp, Operand(kNumSavedRegs * kPointerSize));
5021 // Align the stack if necessary.
5022 int frame_alignment = masm->ActivationFrameAlignment();
5023 if (frame_alignment > kPointerSize) {
5025 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5026 __ And(sp, sp, Operand(-frame_alignment));
5029 __ Dsubu(sp, sp, kCArgsSlotsSize);
5030 #if defined(V8_HOST_ARCH_MIPS) || defined(V8_HOST_ARCH_MIPS64)
5031 int64_t entry_hook =
5032 reinterpret_cast<int64_t>(isolate()->function_entry_hook());
5033 __ li(t9, Operand(entry_hook));
5035 // Under the simulator we need to indirect the entry hook through a
5036 // trampoline function at a known address.
5037 // It additionally takes an isolate as a third parameter.
5038 __ li(a2, Operand(ExternalReference::isolate_address(isolate())));
5040 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
5041 __ li(t9, Operand(ExternalReference(&dispatcher,
5042 ExternalReference::BUILTIN_CALL,
5045 // Call C function through t9 to conform ABI for PIC.
5048 // Restore the stack pointer if needed.
5049 if (frame_alignment > kPointerSize) {
5052 __ Daddu(sp, sp, kCArgsSlotsSize);
5055 // Also pop ra to get Ret(0).
5056 __ MultiPop(kSavedRegs | ra.bit());
5062 static void CreateArrayDispatch(MacroAssembler* masm,
5063 AllocationSiteOverrideMode mode) {
5064 if (mode == DISABLE_ALLOCATION_SITES) {
5065 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5066 __ TailCallStub(&stub);
5067 } else if (mode == DONT_OVERRIDE) {
5068 int last_index = GetSequenceIndexFromFastElementsKind(
5069 TERMINAL_FAST_ELEMENTS_KIND);
5070 for (int i = 0; i <= last_index; ++i) {
5071 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5072 T stub(masm->isolate(), kind);
5073 __ TailCallStub(&stub, eq, a3, Operand(kind));
5076 // If we reached this point there is a problem.
5077 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5084 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5085 AllocationSiteOverrideMode mode) {
5086 // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5087 // a3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5088 // a0 - number of arguments
5089 // a1 - constructor?
5090 // sp[0] - last argument
5091 Label normal_sequence;
5092 if (mode == DONT_OVERRIDE) {
5093 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5094 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5095 STATIC_ASSERT(FAST_ELEMENTS == 2);
5096 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5097 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5098 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5100 // is the low bit set? If so, we are holey and that is good.
5101 __ And(at, a3, Operand(1));
5102 __ Branch(&normal_sequence, ne, at, Operand(zero_reg));
5104 // look at the first argument
5105 __ ld(a5, MemOperand(sp, 0));
5106 __ Branch(&normal_sequence, eq, a5, Operand(zero_reg));
5108 if (mode == DISABLE_ALLOCATION_SITES) {
5109 ElementsKind initial = GetInitialFastElementsKind();
5110 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5112 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5114 DISABLE_ALLOCATION_SITES);
5115 __ TailCallStub(&stub_holey);
5117 __ bind(&normal_sequence);
5118 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5120 DISABLE_ALLOCATION_SITES);
5121 __ TailCallStub(&stub);
5122 } else if (mode == DONT_OVERRIDE) {
5123 // We are going to create a holey array, but our kind is non-holey.
5124 // Fix kind and retry (only if we have an allocation site in the slot).
5125 __ Daddu(a3, a3, Operand(1));
5127 if (FLAG_debug_code) {
5128 __ ld(a5, FieldMemOperand(a2, 0));
5129 __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex);
5130 __ Assert(eq, kExpectedAllocationSite, a5, Operand(at));
5133 // Save the resulting elements kind in type info. We can't just store a3
5134 // in the AllocationSite::transition_info field because elements kind is
5135 // restricted to a portion of the field...upper bits need to be left alone.
5136 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5137 __ ld(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5138 __ Daddu(a4, a4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley)));
5139 __ sd(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5142 __ bind(&normal_sequence);
5143 int last_index = GetSequenceIndexFromFastElementsKind(
5144 TERMINAL_FAST_ELEMENTS_KIND);
5145 for (int i = 0; i <= last_index; ++i) {
5146 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5147 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
5148 __ TailCallStub(&stub, eq, a3, Operand(kind));
5151 // If we reached this point there is a problem.
5152 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5160 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5161 int to_index = GetSequenceIndexFromFastElementsKind(
5162 TERMINAL_FAST_ELEMENTS_KIND);
5163 for (int i = 0; i <= to_index; ++i) {
5164 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5165 T stub(isolate, kind);
5167 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5168 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5175 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5176 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5178 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5180 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5185 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5187 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5188 for (int i = 0; i < 2; i++) {
5189 // For internal arrays we only need a few things.
5190 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5192 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5194 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5200 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5201 MacroAssembler* masm,
5202 AllocationSiteOverrideMode mode) {
5203 if (argument_count() == ANY) {
5204 Label not_zero_case, not_one_case;
5206 __ Branch(¬_zero_case, ne, at, Operand(zero_reg));
5207 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5209 __ bind(¬_zero_case);
5210 __ Branch(¬_one_case, gt, a0, Operand(1));
5211 CreateArrayDispatchOneArgument(masm, mode);
5213 __ bind(¬_one_case);
5214 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5215 } else if (argument_count() == NONE) {
5216 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5217 } else if (argument_count() == ONE) {
5218 CreateArrayDispatchOneArgument(masm, mode);
5219 } else if (argument_count() == MORE_THAN_ONE) {
5220 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5227 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5228 // ----------- S t a t e -------------
5229 // -- a0 : argc (only if argument_count() == ANY)
5230 // -- a1 : constructor
5231 // -- a2 : AllocationSite or undefined
5232 // -- a3 : original constructor
5233 // -- sp[0] : last argument
5234 // -----------------------------------
5236 if (FLAG_debug_code) {
5237 // The array construct code is only set for the global and natives
5238 // builtin Array functions which always have maps.
5240 // Initial map for the builtin Array function should be a map.
5241 __ ld(a4, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5242 // Will both indicate a NULL and a Smi.
5244 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5245 at, Operand(zero_reg));
5246 __ GetObjectType(a4, a4, a5);
5247 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5248 a5, Operand(MAP_TYPE));
5250 // We should either have undefined in a2 or a valid AllocationSite
5251 __ AssertUndefinedOrAllocationSite(a2, a4);
5255 __ Branch(&subclassing, ne, a1, Operand(a3));
5258 // Get the elements kind and case on that.
5259 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
5260 __ Branch(&no_info, eq, a2, Operand(at));
5262 __ ld(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset));
5264 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5265 __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask));
5266 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5269 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5272 __ bind(&subclassing);
5277 switch (argument_count()) {
5280 __ li(at, Operand(2));
5281 __ addu(a0, a0, at);
5284 __ li(a0, Operand(2));
5287 __ li(a0, Operand(3));
5291 __ JumpToExternalReference(
5292 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5296 void InternalArrayConstructorStub::GenerateCase(
5297 MacroAssembler* masm, ElementsKind kind) {
5299 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5300 __ TailCallStub(&stub0, lo, a0, Operand(1));
5302 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5303 __ TailCallStub(&stubN, hi, a0, Operand(1));
5305 if (IsFastPackedElementsKind(kind)) {
5306 // We might need to create a holey array
5307 // look at the first argument.
5308 __ ld(at, MemOperand(sp, 0));
5310 InternalArraySingleArgumentConstructorStub
5311 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5312 __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg));
5315 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5316 __ TailCallStub(&stub1);
5320 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5321 // ----------- S t a t e -------------
5323 // -- a1 : constructor
5324 // -- sp[0] : return address
5325 // -- sp[4] : last argument
5326 // -----------------------------------
5328 if (FLAG_debug_code) {
5329 // The array construct code is only set for the global and natives
5330 // builtin Array functions which always have maps.
5332 // Initial map for the builtin Array function should be a map.
5333 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5334 // Will both indicate a NULL and a Smi.
5336 __ Assert(ne, kUnexpectedInitialMapForArrayFunction,
5337 at, Operand(zero_reg));
5338 __ GetObjectType(a3, a3, a4);
5339 __ Assert(eq, kUnexpectedInitialMapForArrayFunction,
5340 a4, Operand(MAP_TYPE));
5343 // Figure out the right elements kind.
5344 __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
5346 // Load the map's "bit field 2" into a3. We only need the first byte,
5347 // but the following bit field extraction takes care of that anyway.
5348 __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset));
5349 // Retrieve elements_kind from bit field 2.
5350 __ DecodeField<Map::ElementsKindBits>(a3);
5352 if (FLAG_debug_code) {
5354 __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS));
5356 eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray,
5357 a3, Operand(FAST_HOLEY_ELEMENTS));
5361 Label fast_elements_case;
5362 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS));
5363 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5365 __ bind(&fast_elements_case);
5366 GenerateCase(masm, FAST_ELEMENTS);
5370 void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) {
5371 Register context_reg = cp;
5372 Register slot_reg = a2;
5373 Register result_reg = v0;
5376 // Go up context chain to the script context.
5377 for (int i = 0; i < depth(); ++i) {
5378 __ ld(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5379 context_reg = result_reg;
5382 // Load the PropertyCell value at the specified slot.
5383 __ dsll(at, slot_reg, kPointerSizeLog2);
5384 __ Daddu(at, at, Operand(context_reg));
5385 __ ld(result_reg, ContextOperand(at, 0));
5386 __ ld(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset));
5388 // Check that value is not the_hole.
5389 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5390 __ Branch(&slow_case, eq, result_reg, Operand(at));
5393 // Fallback to the runtime.
5394 __ bind(&slow_case);
5395 __ SmiTag(slot_reg);
5397 __ TailCallRuntime(Runtime::kLoadGlobalViaContext, 1, 1);
5401 void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) {
5402 Register context_reg = cp;
5403 Register slot_reg = a2;
5404 Register value_reg = a0;
5405 Register cell_reg = a4;
5406 Register cell_value_reg = a5;
5407 Register cell_details_reg = a6;
5408 Label fast_heapobject_case, fast_smi_case, slow_case;
5410 if (FLAG_debug_code) {
5411 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
5412 __ Check(ne, kUnexpectedValue, value_reg, Operand(at));
5415 // Go up context chain to the script context.
5416 for (int i = 0; i < depth(); ++i) {
5417 __ ld(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX));
5418 context_reg = cell_reg;
5421 // Load the PropertyCell at the specified slot.
5422 __ dsll(at, slot_reg, kPointerSizeLog2);
5423 __ Daddu(at, at, Operand(context_reg));
5424 __ ld(cell_reg, ContextOperand(at, 0));
5426 // Load PropertyDetails for the cell (actually only the cell_type and kind).
5427 __ ld(cell_details_reg,
5428 FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset));
5429 __ SmiUntag(cell_details_reg);
5430 __ And(cell_details_reg, cell_details_reg,
5431 PropertyDetails::PropertyCellTypeField::kMask |
5432 PropertyDetails::KindField::kMask |
5433 PropertyDetails::kAttributesReadOnlyMask);
5435 // Check if PropertyCell holds mutable data.
5436 Label not_mutable_data;
5437 __ Branch(¬_mutable_data, ne, cell_details_reg,
5438 Operand(PropertyDetails::PropertyCellTypeField::encode(
5439 PropertyCellType::kMutable) |
5440 PropertyDetails::KindField::encode(kData)));
5441 __ JumpIfSmi(value_reg, &fast_smi_case);
5442 __ bind(&fast_heapobject_case);
5443 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5444 __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg,
5445 cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs,
5446 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
5447 // RecordWriteField clobbers the value register, so we need to reload.
5448 __ Ret(USE_DELAY_SLOT);
5449 __ ld(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5450 __ bind(¬_mutable_data);
5452 // Check if PropertyCell value matches the new value (relevant for Constant,
5453 // ConstantType and Undefined cells).
5454 Label not_same_value;
5455 __ ld(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5456 __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg));
5457 // Make sure the PropertyCell is not marked READ_ONLY.
5458 __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask);
5459 __ Branch(&slow_case, ne, at, Operand(zero_reg));
5460 if (FLAG_debug_code) {
5462 // This can only be true for Constant, ConstantType and Undefined cells,
5463 // because we never store the_hole via this stub.
5464 __ Branch(&done, eq, cell_details_reg,
5465 Operand(PropertyDetails::PropertyCellTypeField::encode(
5466 PropertyCellType::kConstant) |
5467 PropertyDetails::KindField::encode(kData)));
5468 __ Branch(&done, eq, cell_details_reg,
5469 Operand(PropertyDetails::PropertyCellTypeField::encode(
5470 PropertyCellType::kConstantType) |
5471 PropertyDetails::KindField::encode(kData)));
5472 __ Check(eq, kUnexpectedValue, cell_details_reg,
5473 Operand(PropertyDetails::PropertyCellTypeField::encode(
5474 PropertyCellType::kUndefined) |
5475 PropertyDetails::KindField::encode(kData)));
5479 __ bind(¬_same_value);
5481 // Check if PropertyCell contains data with constant type (and is not
5483 __ Branch(&slow_case, ne, cell_details_reg,
5484 Operand(PropertyDetails::PropertyCellTypeField::encode(
5485 PropertyCellType::kConstantType) |
5486 PropertyDetails::KindField::encode(kData)));
5488 // Now either both old and new values must be SMIs or both must be heap
5489 // objects with same map.
5490 Label value_is_heap_object;
5491 __ JumpIfNotSmi(value_reg, &value_is_heap_object);
5492 __ JumpIfNotSmi(cell_value_reg, &slow_case);
5493 // Old and new values are SMIs, no need for a write barrier here.
5494 __ bind(&fast_smi_case);
5495 __ Ret(USE_DELAY_SLOT);
5496 __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset));
5497 __ bind(&value_is_heap_object);
5498 __ JumpIfSmi(cell_value_reg, &slow_case);
5499 Register cell_value_map_reg = cell_value_reg;
5500 __ ld(cell_value_map_reg,
5501 FieldMemOperand(cell_value_reg, HeapObject::kMapOffset));
5502 __ Branch(&fast_heapobject_case, eq, cell_value_map_reg,
5503 FieldMemOperand(value_reg, HeapObject::kMapOffset));
5505 // Fallback to the runtime.
5506 __ bind(&slow_case);
5507 __ SmiTag(slot_reg);
5508 __ Push(slot_reg, value_reg);
5509 __ TailCallRuntime(is_strict(language_mode())
5510 ? Runtime::kStoreGlobalViaContext_Strict
5511 : Runtime::kStoreGlobalViaContext_Sloppy,
5516 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5517 int64_t offset = (ref0.address() - ref1.address());
5518 DCHECK(static_cast<int>(offset) == offset);
5519 return static_cast<int>(offset);
5523 // Calls an API function. Allocates HandleScope, extracts returned value
5524 // from handle and propagates exceptions. Restores context. stack_space
5525 // - space to be unwound on exit (includes the call JS arguments space and
5526 // the additional space allocated for the fast call).
5527 static void CallApiFunctionAndReturn(
5528 MacroAssembler* masm, Register function_address,
5529 ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset,
5530 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5531 Isolate* isolate = masm->isolate();
5532 ExternalReference next_address =
5533 ExternalReference::handle_scope_next_address(isolate);
5534 const int kNextOffset = 0;
5535 const int kLimitOffset = AddressOffset(
5536 ExternalReference::handle_scope_limit_address(isolate), next_address);
5537 const int kLevelOffset = AddressOffset(
5538 ExternalReference::handle_scope_level_address(isolate), next_address);
5540 DCHECK(function_address.is(a1) || function_address.is(a2));
5542 Label profiler_disabled;
5543 Label end_profiler_check;
5544 __ li(t9, Operand(ExternalReference::is_profiling_address(isolate)));
5545 __ lb(t9, MemOperand(t9, 0));
5546 __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg));
5548 // Additional parameter is the address of the actual callback.
5549 __ li(t9, Operand(thunk_ref));
5550 __ jmp(&end_profiler_check);
5552 __ bind(&profiler_disabled);
5553 __ mov(t9, function_address);
5554 __ bind(&end_profiler_check);
5556 // Allocate HandleScope in callee-save registers.
5557 __ li(s3, Operand(next_address));
5558 __ ld(s0, MemOperand(s3, kNextOffset));
5559 __ ld(s1, MemOperand(s3, kLimitOffset));
5560 __ lw(s2, MemOperand(s3, kLevelOffset));
5561 __ Addu(s2, s2, Operand(1));
5562 __ sw(s2, MemOperand(s3, kLevelOffset));
5564 if (FLAG_log_timer_events) {
5565 FrameScope frame(masm, StackFrame::MANUAL);
5566 __ PushSafepointRegisters();
5567 __ PrepareCallCFunction(1, a0);
5568 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5569 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5571 __ PopSafepointRegisters();
5574 // Native call returns to the DirectCEntry stub which redirects to the
5575 // return address pushed on stack (could have moved after GC).
5576 // DirectCEntry stub itself is generated early and never moves.
5577 DirectCEntryStub stub(isolate);
5578 stub.GenerateCall(masm, t9);
5580 if (FLAG_log_timer_events) {
5581 FrameScope frame(masm, StackFrame::MANUAL);
5582 __ PushSafepointRegisters();
5583 __ PrepareCallCFunction(1, a0);
5584 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5585 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5587 __ PopSafepointRegisters();
5590 Label promote_scheduled_exception;
5591 Label delete_allocated_handles;
5592 Label leave_exit_frame;
5593 Label return_value_loaded;
5595 // Load value from ReturnValue.
5596 __ ld(v0, return_value_operand);
5597 __ bind(&return_value_loaded);
5599 // No more valid handles (the result handle was the last one). Restore
5600 // previous handle scope.
5601 __ sd(s0, MemOperand(s3, kNextOffset));
5602 if (__ emit_debug_code()) {
5603 __ lw(a1, MemOperand(s3, kLevelOffset));
5604 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2));
5606 __ Subu(s2, s2, Operand(1));
5607 __ sw(s2, MemOperand(s3, kLevelOffset));
5608 __ ld(at, MemOperand(s3, kLimitOffset));
5609 __ Branch(&delete_allocated_handles, ne, s1, Operand(at));
5611 // Leave the API exit frame.
5612 __ bind(&leave_exit_frame);
5614 bool restore_context = context_restore_operand != NULL;
5615 if (restore_context) {
5616 __ ld(cp, *context_restore_operand);
5618 if (stack_space_offset != kInvalidStackOffset) {
5619 DCHECK(kCArgsSlotsSize == 0);
5620 __ ld(s0, MemOperand(sp, stack_space_offset));
5622 __ li(s0, Operand(stack_space));
5624 __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN,
5625 stack_space_offset != kInvalidStackOffset);
5627 // Check if the function scheduled an exception.
5628 __ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
5629 __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate)));
5630 __ ld(a5, MemOperand(at));
5631 __ Branch(&promote_scheduled_exception, ne, a4, Operand(a5));
5635 // Re-throw by promoting a scheduled exception.
5636 __ bind(&promote_scheduled_exception);
5637 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5639 // HandleScope limit has changed. Delete allocated extensions.
5640 __ bind(&delete_allocated_handles);
5641 __ sd(s1, MemOperand(s3, kLimitOffset));
5644 __ PrepareCallCFunction(1, s1);
5645 __ li(a0, Operand(ExternalReference::isolate_address(isolate)));
5646 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5649 __ jmp(&leave_exit_frame);
5653 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5654 const ParameterCount& argc,
5655 bool return_first_arg,
5656 bool call_data_undefined) {
5657 // ----------- S t a t e -------------
5659 // -- a4 : call_data
5661 // -- a1 : api_function_address
5662 // -- a3 : number of arguments if argc is a register
5665 // -- sp[0] : last argument
5667 // -- sp[(argc - 1)* 4] : first argument
5668 // -- sp[argc * 4] : receiver
5669 // -----------------------------------
5671 Register callee = a0;
5672 Register call_data = a4;
5673 Register holder = a2;
5674 Register api_function_address = a1;
5675 Register context = cp;
5677 typedef FunctionCallbackArguments FCA;
5679 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5680 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5681 STATIC_ASSERT(FCA::kDataIndex == 4);
5682 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5683 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5684 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5685 STATIC_ASSERT(FCA::kHolderIndex == 0);
5686 STATIC_ASSERT(FCA::kArgsLength == 7);
5688 DCHECK(argc.is_immediate() || a3.is(argc.reg()));
5690 // Save context, callee and call data.
5691 __ Push(context, callee, call_data);
5692 // Load context from callee.
5693 __ ld(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5695 Register scratch = call_data;
5696 if (!call_data_undefined) {
5697 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5699 // Push return value and default return value.
5700 __ Push(scratch, scratch);
5701 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
5702 // Push isolate and holder.
5703 __ Push(scratch, holder);
5705 // Prepare arguments.
5706 __ mov(scratch, sp);
5708 // Allocate the v8::Arguments structure in the arguments' space since
5709 // it's not controlled by GC.
5710 const int kApiStackSpace = 4;
5712 FrameScope frame_scope(masm, StackFrame::MANUAL);
5713 __ EnterExitFrame(false, kApiStackSpace);
5715 DCHECK(!api_function_address.is(a0) && !scratch.is(a0));
5716 // a0 = FunctionCallbackInfo&
5717 // Arguments is after the return address.
5718 __ Daddu(a0, sp, Operand(1 * kPointerSize));
5719 // FunctionCallbackInfo::implicit_args_
5720 __ sd(scratch, MemOperand(a0, 0 * kPointerSize));
5721 if (argc.is_immediate()) {
5722 // FunctionCallbackInfo::values_
5723 __ Daddu(at, scratch,
5724 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5725 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5726 // FunctionCallbackInfo::length_ = argc
5727 __ li(at, Operand(argc.immediate()));
5728 __ sd(at, MemOperand(a0, 2 * kPointerSize));
5729 // FunctionCallbackInfo::is_construct_call_ = 0
5730 __ sd(zero_reg, MemOperand(a0, 3 * kPointerSize));
5732 // FunctionCallbackInfo::values_
5733 __ dsll(at, argc.reg(), kPointerSizeLog2);
5734 __ Daddu(at, at, scratch);
5735 __ Daddu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
5736 __ sd(at, MemOperand(a0, 1 * kPointerSize));
5737 // FunctionCallbackInfo::length_ = argc
5738 __ sd(argc.reg(), MemOperand(a0, 2 * kPointerSize));
5739 // FunctionCallbackInfo::is_construct_call_
5740 __ Daddu(argc.reg(), argc.reg(), Operand(FCA::kArgsLength + 1));
5741 __ dsll(at, argc.reg(), kPointerSizeLog2);
5742 __ sd(at, MemOperand(a0, 3 * kPointerSize));
5745 ExternalReference thunk_ref =
5746 ExternalReference::invoke_function_callback(masm->isolate());
5748 AllowExternalCallThatCantCauseGC scope(masm);
5749 MemOperand context_restore_operand(
5750 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5751 // Stores return the first js argument.
5752 int return_value_offset = 0;
5753 if (return_first_arg) {
5754 return_value_offset = 2 + FCA::kArgsLength;
5756 return_value_offset = 2 + FCA::kReturnValueOffset;
5758 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5759 int stack_space = 0;
5760 int32_t stack_space_offset = 4 * kPointerSize;
5761 if (argc.is_immediate()) {
5762 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5763 stack_space_offset = kInvalidStackOffset;
5765 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5766 stack_space_offset, return_value_operand,
5767 &context_restore_operand);
5771 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5772 bool call_data_undefined = this->call_data_undefined();
5773 CallApiFunctionStubHelper(masm, ParameterCount(a3), false,
5774 call_data_undefined);
5778 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5779 bool is_store = this->is_store();
5780 int argc = this->argc();
5781 bool call_data_undefined = this->call_data_undefined();
5782 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5783 call_data_undefined);
5787 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5788 // ----------- S t a t e -------------
5790 // -- sp[4 - kArgsLength*4] : PropertyCallbackArguments object
5792 // -- a2 : api_function_address
5793 // -----------------------------------
5795 Register api_function_address = ApiGetterDescriptor::function_address();
5796 DCHECK(api_function_address.is(a2));
5798 __ mov(a0, sp); // a0 = Handle<Name>
5799 __ Daddu(a1, a0, Operand(1 * kPointerSize)); // a1 = PCA
5801 const int kApiStackSpace = 1;
5802 FrameScope frame_scope(masm, StackFrame::MANUAL);
5803 __ EnterExitFrame(false, kApiStackSpace);
5805 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5806 // a1 (internal::Object** args_) as the data.
5807 __ sd(a1, MemOperand(sp, 1 * kPointerSize));
5808 __ Daddu(a1, sp, Operand(1 * kPointerSize)); // a1 = AccessorInfo&
5810 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5812 ExternalReference thunk_ref =
5813 ExternalReference::invoke_accessor_getter_callback(isolate());
5814 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5815 kStackUnwindSpace, kInvalidStackOffset,
5816 MemOperand(fp, 6 * kPointerSize), NULL);
5822 } // namespace internal
5825 #endif // V8_TARGET_ARCH_MIPS64