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 #include <limits.h> // For LONG_MIN, LONG_MAX.
7 #if V8_TARGET_ARCH_MIPS
9 #include "src/base/bits.h"
10 #include "src/base/division-by-constant.h"
11 #include "src/bootstrapper.h"
12 #include "src/codegen.h"
13 #include "src/cpu-profiler.h"
14 #include "src/debug/debug.h"
15 #include "src/runtime/runtime.h"
20 MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size)
21 : Assembler(arg_isolate, buffer, size),
22 generating_stub_(false),
24 has_double_zero_reg_set_(false) {
25 if (isolate() != NULL) {
26 code_object_ = Handle<Object>(isolate()->heap()->undefined_value(),
32 void MacroAssembler::Load(Register dst,
33 const MemOperand& src,
35 DCHECK(!r.IsDouble());
38 } else if (r.IsUInteger8()) {
40 } else if (r.IsInteger16()) {
42 } else if (r.IsUInteger16()) {
50 void MacroAssembler::Store(Register src,
51 const MemOperand& dst,
53 DCHECK(!r.IsDouble());
54 if (r.IsInteger8() || r.IsUInteger8()) {
56 } else if (r.IsInteger16() || r.IsUInteger16()) {
59 if (r.IsHeapObject()) {
61 } else if (r.IsSmi()) {
69 void MacroAssembler::LoadRoot(Register destination,
70 Heap::RootListIndex index) {
71 lw(destination, MemOperand(s6, index << kPointerSizeLog2));
75 void MacroAssembler::LoadRoot(Register destination,
76 Heap::RootListIndex index,
78 Register src1, const Operand& src2) {
79 Branch(2, NegateCondition(cond), src1, src2);
80 lw(destination, MemOperand(s6, index << kPointerSizeLog2));
84 void MacroAssembler::StoreRoot(Register source,
85 Heap::RootListIndex index) {
86 DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
87 sw(source, MemOperand(s6, index << kPointerSizeLog2));
91 void MacroAssembler::StoreRoot(Register source,
92 Heap::RootListIndex index,
94 Register src1, const Operand& src2) {
95 DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
96 Branch(2, NegateCondition(cond), src1, src2);
97 sw(source, MemOperand(s6, index << kPointerSizeLog2));
101 // Push and pop all registers that can hold pointers.
102 void MacroAssembler::PushSafepointRegisters() {
103 // Safepoints expect a block of kNumSafepointRegisters values on the
104 // stack, so adjust the stack for unsaved registers.
105 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
106 DCHECK(num_unsaved >= 0);
107 if (num_unsaved > 0) {
108 Subu(sp, sp, Operand(num_unsaved * kPointerSize));
110 MultiPush(kSafepointSavedRegisters);
114 void MacroAssembler::PopSafepointRegisters() {
115 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
116 MultiPop(kSafepointSavedRegisters);
117 if (num_unsaved > 0) {
118 Addu(sp, sp, Operand(num_unsaved * kPointerSize));
123 void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) {
124 sw(src, SafepointRegisterSlot(dst));
128 void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) {
129 lw(dst, SafepointRegisterSlot(src));
133 int MacroAssembler::SafepointRegisterStackIndex(int reg_code) {
134 // The registers are pushed starting with the highest encoding,
135 // which means that lowest encodings are closest to the stack pointer.
136 return kSafepointRegisterStackIndexMap[reg_code];
140 MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) {
141 return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize);
145 MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) {
146 UNIMPLEMENTED_MIPS();
147 // General purpose registers are pushed last on the stack.
148 int doubles_size = FPURegister::NumAllocatableRegisters() * kDoubleSize;
149 int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize;
150 return MemOperand(sp, doubles_size + register_offset);
154 void MacroAssembler::InNewSpace(Register object,
158 DCHECK(cc == eq || cc == ne);
159 And(scratch, object, Operand(ExternalReference::new_space_mask(isolate())));
160 Branch(branch, cc, scratch,
161 Operand(ExternalReference::new_space_start(isolate())));
165 // Clobbers object, dst, value, and ra, if (ra_status == kRAHasBeenSaved)
166 // The register 'object' contains a heap object pointer. The heap object
167 // tag is shifted away.
168 void MacroAssembler::RecordWriteField(
174 SaveFPRegsMode save_fp,
175 RememberedSetAction remembered_set_action,
177 PointersToHereCheck pointers_to_here_check_for_value) {
178 DCHECK(!AreAliased(value, dst, t8, object));
179 // First, check if a write barrier is even needed. The tests below
180 // catch stores of Smis.
183 // Skip barrier if writing a smi.
184 if (smi_check == INLINE_SMI_CHECK) {
185 JumpIfSmi(value, &done);
188 // Although the object register is tagged, the offset is relative to the start
189 // of the object, so so offset must be a multiple of kPointerSize.
190 DCHECK(IsAligned(offset, kPointerSize));
192 Addu(dst, object, Operand(offset - kHeapObjectTag));
193 if (emit_debug_code()) {
195 And(t8, dst, Operand((1 << kPointerSizeLog2) - 1));
196 Branch(&ok, eq, t8, Operand(zero_reg));
197 stop("Unaligned cell in write barrier");
206 remembered_set_action,
208 pointers_to_here_check_for_value);
212 // Clobber clobbered input registers when running with the debug-code flag
213 // turned on to provoke errors.
214 if (emit_debug_code()) {
215 li(value, Operand(bit_cast<int32_t>(kZapValue + 4)));
216 li(dst, Operand(bit_cast<int32_t>(kZapValue + 8)));
221 // Clobbers object, dst, map, and ra, if (ra_status == kRAHasBeenSaved)
222 void MacroAssembler::RecordWriteForMap(Register object,
226 SaveFPRegsMode fp_mode) {
227 if (emit_debug_code()) {
229 lw(dst, FieldMemOperand(map, HeapObject::kMapOffset));
231 kWrongAddressOrValuePassedToRecordWrite,
233 Operand(isolate()->factory()->meta_map()));
236 if (!FLAG_incremental_marking) {
240 if (emit_debug_code()) {
241 lw(at, FieldMemOperand(object, HeapObject::kMapOffset));
243 kWrongAddressOrValuePassedToRecordWrite,
250 // A single check of the map's pages interesting flag suffices, since it is
251 // only set during incremental collection, and then it's also guaranteed that
252 // the from object's page's interesting flag is also set. This optimization
253 // relies on the fact that maps can never be in new space.
255 map, // Used as scratch.
256 MemoryChunk::kPointersToHereAreInterestingMask,
260 Addu(dst, object, Operand(HeapObject::kMapOffset - kHeapObjectTag));
261 if (emit_debug_code()) {
263 And(at, dst, Operand((1 << kPointerSizeLog2) - 1));
264 Branch(&ok, eq, at, Operand(zero_reg));
265 stop("Unaligned cell in write barrier");
269 // Record the actual write.
270 if (ra_status == kRAHasNotBeenSaved) {
273 RecordWriteStub stub(isolate(), object, map, dst, OMIT_REMEMBERED_SET,
276 if (ra_status == kRAHasNotBeenSaved) {
282 // Count number of write barriers in generated code.
283 isolate()->counters()->write_barriers_static()->Increment();
284 IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, at, dst);
286 // Clobber clobbered registers when running with the debug-code flag
287 // turned on to provoke errors.
288 if (emit_debug_code()) {
289 li(dst, Operand(bit_cast<int32_t>(kZapValue + 12)));
290 li(map, Operand(bit_cast<int32_t>(kZapValue + 16)));
295 // Clobbers object, address, value, and ra, if (ra_status == kRAHasBeenSaved)
296 // The register 'object' contains a heap object pointer. The heap object
297 // tag is shifted away.
298 void MacroAssembler::RecordWrite(
303 SaveFPRegsMode fp_mode,
304 RememberedSetAction remembered_set_action,
306 PointersToHereCheck pointers_to_here_check_for_value) {
307 DCHECK(!AreAliased(object, address, value, t8));
308 DCHECK(!AreAliased(object, address, value, t9));
310 if (emit_debug_code()) {
311 lw(at, MemOperand(address));
313 eq, kWrongAddressOrValuePassedToRecordWrite, at, Operand(value));
316 if (remembered_set_action == OMIT_REMEMBERED_SET &&
317 !FLAG_incremental_marking) {
321 // First, check if a write barrier is even needed. The tests below
322 // catch stores of smis and stores into the young generation.
325 if (smi_check == INLINE_SMI_CHECK) {
326 DCHECK_EQ(0, kSmiTag);
327 JumpIfSmi(value, &done);
330 if (pointers_to_here_check_for_value != kPointersToHereAreAlwaysInteresting) {
332 value, // Used as scratch.
333 MemoryChunk::kPointersToHereAreInterestingMask,
337 CheckPageFlag(object,
338 value, // Used as scratch.
339 MemoryChunk::kPointersFromHereAreInterestingMask,
343 // Record the actual write.
344 if (ra_status == kRAHasNotBeenSaved) {
347 RecordWriteStub stub(isolate(), object, value, address, remembered_set_action,
350 if (ra_status == kRAHasNotBeenSaved) {
356 // Count number of write barriers in generated code.
357 isolate()->counters()->write_barriers_static()->Increment();
358 IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, at,
361 // Clobber clobbered registers when running with the debug-code flag
362 // turned on to provoke errors.
363 if (emit_debug_code()) {
364 li(address, Operand(bit_cast<int32_t>(kZapValue + 12)));
365 li(value, Operand(bit_cast<int32_t>(kZapValue + 16)));
370 void MacroAssembler::RememberedSetHelper(Register object, // For debug tests.
373 SaveFPRegsMode fp_mode,
374 RememberedSetFinalAction and_then) {
376 if (emit_debug_code()) {
378 JumpIfNotInNewSpace(object, scratch, &ok);
379 stop("Remembered set pointer is in new space");
382 // Load store buffer top.
383 ExternalReference store_buffer =
384 ExternalReference::store_buffer_top(isolate());
385 li(t8, Operand(store_buffer));
386 lw(scratch, MemOperand(t8));
387 // Store pointer to buffer and increment buffer top.
388 sw(address, MemOperand(scratch));
389 Addu(scratch, scratch, kPointerSize);
390 // Write back new top of buffer.
391 sw(scratch, MemOperand(t8));
392 // Call stub on end of buffer.
393 // Check for end of buffer.
394 And(t8, scratch, Operand(StoreBuffer::kStoreBufferOverflowBit));
395 if (and_then == kFallThroughAtEnd) {
396 Branch(&done, eq, t8, Operand(zero_reg));
398 DCHECK(and_then == kReturnAtEnd);
399 Ret(eq, t8, Operand(zero_reg));
402 StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode);
403 CallStub(&store_buffer_overflow);
406 if (and_then == kReturnAtEnd) {
412 // -----------------------------------------------------------------------------
413 // Allocation support.
416 void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
421 DCHECK(!holder_reg.is(scratch));
422 DCHECK(!holder_reg.is(at));
423 DCHECK(!scratch.is(at));
425 // Load current lexical context from the stack frame.
426 lw(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset));
427 // In debug mode, make sure the lexical context is set.
429 Check(ne, kWeShouldNotHaveAnEmptyLexicalContext,
430 scratch, Operand(zero_reg));
433 // Load the native context of the current context.
435 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize;
436 lw(scratch, FieldMemOperand(scratch, offset));
437 lw(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
439 // Check the context is a native context.
440 if (emit_debug_code()) {
441 push(holder_reg); // Temporarily save holder on the stack.
442 // Read the first word and compare to the native_context_map.
443 lw(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset));
444 LoadRoot(at, Heap::kNativeContextMapRootIndex);
445 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext,
446 holder_reg, Operand(at));
447 pop(holder_reg); // Restore holder.
450 // Check if both contexts are the same.
451 lw(at, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
452 Branch(&same_contexts, eq, scratch, Operand(at));
454 // Check the context is a native context.
455 if (emit_debug_code()) {
456 push(holder_reg); // Temporarily save holder on the stack.
457 mov(holder_reg, at); // Move at to its holding place.
458 LoadRoot(at, Heap::kNullValueRootIndex);
459 Check(ne, kJSGlobalProxyContextShouldNotBeNull,
460 holder_reg, Operand(at));
462 lw(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset));
463 LoadRoot(at, Heap::kNativeContextMapRootIndex);
464 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext,
465 holder_reg, Operand(at));
466 // Restore at is not needed. at is reloaded below.
467 pop(holder_reg); // Restore holder.
468 // Restore at to holder's context.
469 lw(at, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
472 // Check that the security token in the calling global object is
473 // compatible with the security token in the receiving global
475 int token_offset = Context::kHeaderSize +
476 Context::SECURITY_TOKEN_INDEX * kPointerSize;
478 lw(scratch, FieldMemOperand(scratch, token_offset));
479 lw(at, FieldMemOperand(at, token_offset));
480 Branch(miss, ne, scratch, Operand(at));
482 bind(&same_contexts);
486 // Compute the hash code from the untagged key. This must be kept in sync with
487 // ComputeIntegerHash in utils.h and KeyedLoadGenericStub in
488 // code-stub-hydrogen.cc
489 void MacroAssembler::GetNumberHash(Register reg0, Register scratch) {
490 // First of all we assign the hash seed to scratch.
491 LoadRoot(scratch, Heap::kHashSeedRootIndex);
494 // Xor original key with a seed.
495 xor_(reg0, reg0, scratch);
497 // Compute the hash code from the untagged key. This must be kept in sync
498 // with ComputeIntegerHash in utils.h.
500 // hash = ~hash + (hash << 15);
501 nor(scratch, reg0, zero_reg);
503 addu(reg0, scratch, at);
505 // hash = hash ^ (hash >> 12);
507 xor_(reg0, reg0, at);
509 // hash = hash + (hash << 2);
511 addu(reg0, reg0, at);
513 // hash = hash ^ (hash >> 4);
515 xor_(reg0, reg0, at);
517 // hash = hash * 2057;
518 sll(scratch, reg0, 11);
520 addu(reg0, reg0, at);
521 addu(reg0, reg0, scratch);
523 // hash = hash ^ (hash >> 16);
525 xor_(reg0, reg0, at);
526 And(reg0, reg0, Operand(0x3fffffff));
530 void MacroAssembler::LoadFromNumberDictionary(Label* miss,
539 // elements - holds the slow-case elements of the receiver on entry.
540 // Unchanged unless 'result' is the same register.
542 // key - holds the smi key on entry.
543 // Unchanged unless 'result' is the same register.
546 // result - holds the result on exit if the load succeeded.
547 // Allowed to be the same as 'key' or 'result'.
548 // Unchanged on bailout so 'key' or 'result' can be used
549 // in further computation.
551 // Scratch registers:
553 // reg0 - holds the untagged key on entry and holds the hash once computed.
555 // reg1 - Used to hold the capacity mask of the dictionary.
557 // reg2 - Used for the index into the dictionary.
558 // at - Temporary (avoid MacroAssembler instructions also using 'at').
561 GetNumberHash(reg0, reg1);
563 // Compute the capacity mask.
564 lw(reg1, FieldMemOperand(elements, SeededNumberDictionary::kCapacityOffset));
565 sra(reg1, reg1, kSmiTagSize);
566 Subu(reg1, reg1, Operand(1));
568 // Generate an unrolled loop that performs a few probes before giving up.
569 for (int i = 0; i < kNumberDictionaryProbes; i++) {
570 // Use reg2 for index calculations and keep the hash intact in reg0.
572 // Compute the masked index: (hash + i + i * i) & mask.
574 Addu(reg2, reg2, Operand(SeededNumberDictionary::GetProbeOffset(i)));
576 and_(reg2, reg2, reg1);
578 // Scale the index by multiplying by the element size.
579 DCHECK(SeededNumberDictionary::kEntrySize == 3);
580 sll(at, reg2, 1); // 2x.
581 addu(reg2, reg2, at); // reg2 = reg2 * 3.
583 // Check if the key is identical to the name.
584 sll(at, reg2, kPointerSizeLog2);
585 addu(reg2, elements, at);
587 lw(at, FieldMemOperand(reg2, SeededNumberDictionary::kElementsStartOffset));
588 if (i != kNumberDictionaryProbes - 1) {
589 Branch(&done, eq, key, Operand(at));
591 Branch(miss, ne, key, Operand(at));
596 // Check that the value is a field property.
597 // reg2: elements + (index * kPointerSize).
598 const int kDetailsOffset =
599 SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize;
600 lw(reg1, FieldMemOperand(reg2, kDetailsOffset));
602 And(at, reg1, Operand(Smi::FromInt(PropertyDetails::TypeField::kMask)));
603 Branch(miss, ne, at, Operand(zero_reg));
605 // Get the value at the masked, scaled index and return.
606 const int kValueOffset =
607 SeededNumberDictionary::kElementsStartOffset + kPointerSize;
608 lw(result, FieldMemOperand(reg2, kValueOffset));
612 // ---------------------------------------------------------------------------
613 // Instruction macros.
615 void MacroAssembler::Addu(Register rd, Register rs, const Operand& rt) {
617 addu(rd, rs, rt.rm());
619 if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
620 addiu(rd, rs, rt.imm32_);
622 // li handles the relocation.
631 void MacroAssembler::Subu(Register rd, Register rs, const Operand& rt) {
633 subu(rd, rs, rt.rm());
635 if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
636 addiu(rd, rs, -rt.imm32_); // No subiu instr, use addiu(x, y, -imm).
638 // li handles the relocation.
647 void MacroAssembler::Mul(Register rd, Register rs, const Operand& rt) {
649 if (IsMipsArchVariant(kLoongson)) {
653 mul(rd, rs, rt.rm());
656 // li handles the relocation.
659 if (IsMipsArchVariant(kLoongson)) {
669 void MacroAssembler::Mul(Register rd_hi, Register rd_lo,
670 Register rs, const Operand& rt) {
672 if (!IsMipsArchVariant(kMips32r6)) {
678 DCHECK(!rd_hi.is(rs));
679 DCHECK(!rd_hi.is(rt.rm()) && !rd_lo.is(rt.rm()));
680 muh(rd_hi, rs, rt.rm());
681 mul(rd_lo, rs, rt.rm());
683 DCHECK(!rd_hi.is(rt.rm()) && !rd_lo.is(rt.rm()));
684 mul(rd_lo, rs, rt.rm());
685 muh(rd_hi, rs, rt.rm());
689 // li handles the relocation.
692 if (!IsMipsArchVariant(kMips32r6)) {
698 DCHECK(!rd_hi.is(rs));
699 DCHECK(!rd_hi.is(at) && !rd_lo.is(at));
703 DCHECK(!rd_hi.is(at) && !rd_lo.is(at));
712 void MacroAssembler::Mulh(Register rd, Register rs, const Operand& rt) {
714 if (!IsMipsArchVariant(kMips32r6)) {
718 muh(rd, rs, rt.rm());
721 // li handles the relocation.
724 if (!IsMipsArchVariant(kMips32r6)) {
734 void MacroAssembler::Mult(Register rs, const Operand& rt) {
738 // li handles the relocation.
746 void MacroAssembler::Mulhu(Register rd, Register rs, const Operand& rt) {
748 if (!IsMipsArchVariant(kMips32r6)) {
752 muhu(rd, rs, rt.rm());
755 // li handles the relocation.
758 if (!IsMipsArchVariant(kMips32r6)) {
768 void MacroAssembler::Multu(Register rs, const Operand& rt) {
772 // li handles the relocation.
780 void MacroAssembler::Div(Register rs, const Operand& rt) {
784 // li handles the relocation.
792 void MacroAssembler::Div(Register rem, Register res,
793 Register rs, const Operand& rt) {
795 if (!IsMipsArchVariant(kMips32r6)) {
800 div(res, rs, rt.rm());
801 mod(rem, rs, rt.rm());
804 // li handles the relocation.
807 if (!IsMipsArchVariant(kMips32r6)) {
819 void MacroAssembler::Div(Register res, Register rs, const Operand& rt) {
821 if (!IsMipsArchVariant(kMips32r6)) {
825 div(res, rs, rt.rm());
828 // li handles the relocation.
831 if (!IsMipsArchVariant(kMips32r6)) {
841 void MacroAssembler::Mod(Register rd, Register rs, const Operand& rt) {
843 if (!IsMipsArchVariant(kMips32r6)) {
847 mod(rd, rs, rt.rm());
850 // li handles the relocation.
853 if (!IsMipsArchVariant(kMips32r6)) {
863 void MacroAssembler::Modu(Register rd, Register rs, const Operand& rt) {
865 if (!IsMipsArchVariant(kMips32r6)) {
869 modu(rd, rs, rt.rm());
872 // li handles the relocation.
875 if (!IsMipsArchVariant(kMips32r6)) {
885 void MacroAssembler::Divu(Register rs, const Operand& rt) {
889 // li handles the relocation.
897 void MacroAssembler::Divu(Register res, Register rs, const Operand& rt) {
899 if (!IsMipsArchVariant(kMips32r6)) {
903 divu(res, rs, rt.rm());
906 // li handles the relocation.
909 if (!IsMipsArchVariant(kMips32r6)) {
919 void MacroAssembler::And(Register rd, Register rs, const Operand& rt) {
921 and_(rd, rs, rt.rm());
923 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
924 andi(rd, rs, rt.imm32_);
926 // li handles the relocation.
935 void MacroAssembler::Or(Register rd, Register rs, const Operand& rt) {
937 or_(rd, rs, rt.rm());
939 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
940 ori(rd, rs, rt.imm32_);
942 // li handles the relocation.
951 void MacroAssembler::Xor(Register rd, Register rs, const Operand& rt) {
953 xor_(rd, rs, rt.rm());
955 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
956 xori(rd, rs, rt.imm32_);
958 // li handles the relocation.
967 void MacroAssembler::Nor(Register rd, Register rs, const Operand& rt) {
969 nor(rd, rs, rt.rm());
971 // li handles the relocation.
979 void MacroAssembler::Neg(Register rs, const Operand& rt) {
982 DCHECK(!at.is(rt.rm()));
984 xor_(rs, rt.rm(), at);
988 void MacroAssembler::Slt(Register rd, Register rs, const Operand& rt) {
990 slt(rd, rs, rt.rm());
992 if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
993 slti(rd, rs, rt.imm32_);
995 // li handles the relocation.
1004 void MacroAssembler::Sltu(Register rd, Register rs, const Operand& rt) {
1006 sltu(rd, rs, rt.rm());
1008 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
1009 sltiu(rd, rs, rt.imm32_);
1011 // li handles the relocation.
1020 void MacroAssembler::Ror(Register rd, Register rs, const Operand& rt) {
1021 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1023 rotrv(rd, rs, rt.rm());
1025 rotr(rd, rs, rt.imm32_);
1029 subu(at, zero_reg, rt.rm());
1031 srlv(rd, rs, rt.rm());
1034 if (rt.imm32_ == 0) {
1037 srl(at, rs, rt.imm32_);
1038 sll(rd, rs, (0x20 - rt.imm32_) & 0x1f);
1046 void MacroAssembler::Pref(int32_t hint, const MemOperand& rs) {
1047 if (IsMipsArchVariant(kLoongson)) {
1055 // ------------Pseudo-instructions-------------
1057 void MacroAssembler::Ulw(Register rd, const MemOperand& rs) {
1059 lwl(rd, MemOperand(rs.rm(), rs.offset() + 3));
1063 void MacroAssembler::Usw(Register rd, const MemOperand& rs) {
1065 swl(rd, MemOperand(rs.rm(), rs.offset() + 3));
1069 void MacroAssembler::li(Register dst, Handle<Object> value, LiFlags mode) {
1070 AllowDeferredHandleDereference smi_check;
1071 if (value->IsSmi()) {
1072 li(dst, Operand(value), mode);
1074 DCHECK(value->IsHeapObject());
1075 if (isolate()->heap()->InNewSpace(*value)) {
1076 Handle<Cell> cell = isolate()->factory()->NewCell(value);
1077 li(dst, Operand(cell));
1078 lw(dst, FieldMemOperand(dst, Cell::kValueOffset));
1080 li(dst, Operand(value));
1086 void MacroAssembler::li(Register rd, Operand j, LiFlags mode) {
1087 DCHECK(!j.is_reg());
1088 BlockTrampolinePoolScope block_trampoline_pool(this);
1089 if (!MustUseReg(j.rmode_) && mode == OPTIMIZE_SIZE) {
1090 // Normal load of an immediate value which does not need Relocation Info.
1091 if (is_int16(j.imm32_)) {
1092 addiu(rd, zero_reg, j.imm32_);
1093 } else if (!(j.imm32_ & kHiMask)) {
1094 ori(rd, zero_reg, j.imm32_);
1095 } else if (!(j.imm32_ & kImm16Mask)) {
1096 lui(rd, (j.imm32_ >> kLuiShift) & kImm16Mask);
1098 lui(rd, (j.imm32_ >> kLuiShift) & kImm16Mask);
1099 ori(rd, rd, (j.imm32_ & kImm16Mask));
1102 if (MustUseReg(j.rmode_)) {
1103 RecordRelocInfo(j.rmode_, j.imm32_);
1105 // We always need the same number of instructions as we may need to patch
1106 // this code to load another value which may need 2 instructions to load.
1107 lui(rd, (j.imm32_ >> kLuiShift) & kImm16Mask);
1108 ori(rd, rd, (j.imm32_ & kImm16Mask));
1113 void MacroAssembler::MultiPush(RegList regs) {
1114 int16_t num_to_push = NumberOfBitsSet(regs);
1115 int16_t stack_offset = num_to_push * kPointerSize;
1117 Subu(sp, sp, Operand(stack_offset));
1118 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1119 if ((regs & (1 << i)) != 0) {
1120 stack_offset -= kPointerSize;
1121 sw(ToRegister(i), MemOperand(sp, stack_offset));
1127 void MacroAssembler::MultiPushReversed(RegList regs) {
1128 int16_t num_to_push = NumberOfBitsSet(regs);
1129 int16_t stack_offset = num_to_push * kPointerSize;
1131 Subu(sp, sp, Operand(stack_offset));
1132 for (int16_t i = 0; i < kNumRegisters; i++) {
1133 if ((regs & (1 << i)) != 0) {
1134 stack_offset -= kPointerSize;
1135 sw(ToRegister(i), MemOperand(sp, stack_offset));
1141 void MacroAssembler::MultiPop(RegList regs) {
1142 int16_t stack_offset = 0;
1144 for (int16_t i = 0; i < kNumRegisters; i++) {
1145 if ((regs & (1 << i)) != 0) {
1146 lw(ToRegister(i), MemOperand(sp, stack_offset));
1147 stack_offset += kPointerSize;
1150 addiu(sp, sp, stack_offset);
1154 void MacroAssembler::MultiPopReversed(RegList regs) {
1155 int16_t stack_offset = 0;
1157 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1158 if ((regs & (1 << i)) != 0) {
1159 lw(ToRegister(i), MemOperand(sp, stack_offset));
1160 stack_offset += kPointerSize;
1163 addiu(sp, sp, stack_offset);
1167 void MacroAssembler::MultiPushFPU(RegList regs) {
1168 int16_t num_to_push = NumberOfBitsSet(regs);
1169 int16_t stack_offset = num_to_push * kDoubleSize;
1171 Subu(sp, sp, Operand(stack_offset));
1172 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1173 if ((regs & (1 << i)) != 0) {
1174 stack_offset -= kDoubleSize;
1175 sdc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1181 void MacroAssembler::MultiPushReversedFPU(RegList regs) {
1182 int16_t num_to_push = NumberOfBitsSet(regs);
1183 int16_t stack_offset = num_to_push * kDoubleSize;
1185 Subu(sp, sp, Operand(stack_offset));
1186 for (int16_t i = 0; i < kNumRegisters; i++) {
1187 if ((regs & (1 << i)) != 0) {
1188 stack_offset -= kDoubleSize;
1189 sdc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1195 void MacroAssembler::MultiPopFPU(RegList regs) {
1196 int16_t stack_offset = 0;
1198 for (int16_t i = 0; i < kNumRegisters; i++) {
1199 if ((regs & (1 << i)) != 0) {
1200 ldc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1201 stack_offset += kDoubleSize;
1204 addiu(sp, sp, stack_offset);
1208 void MacroAssembler::MultiPopReversedFPU(RegList regs) {
1209 int16_t stack_offset = 0;
1211 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1212 if ((regs & (1 << i)) != 0) {
1213 ldc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1214 stack_offset += kDoubleSize;
1217 addiu(sp, sp, stack_offset);
1221 void MacroAssembler::FlushICache(Register address, unsigned instructions) {
1222 RegList saved_regs = kJSCallerSaved | ra.bit();
1223 MultiPush(saved_regs);
1224 AllowExternalCallThatCantCauseGC scope(this);
1226 // Save to a0 in case address == t0.
1228 PrepareCallCFunction(2, t0);
1230 li(a1, instructions * kInstrSize);
1231 CallCFunction(ExternalReference::flush_icache_function(isolate()), 2);
1232 MultiPop(saved_regs);
1236 void MacroAssembler::Ext(Register rt,
1241 DCHECK(pos + size < 33);
1243 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1244 ext_(rt, rs, pos, size);
1246 // Move rs to rt and shift it left then right to get the
1247 // desired bitfield on the right side and zeroes on the left.
1248 int shift_left = 32 - (pos + size);
1249 sll(rt, rs, shift_left); // Acts as a move if shift_left == 0.
1251 int shift_right = 32 - size;
1252 if (shift_right > 0) {
1253 srl(rt, rt, shift_right);
1259 void MacroAssembler::Ins(Register rt,
1264 DCHECK(pos + size <= 32);
1267 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1268 ins_(rt, rs, pos, size);
1270 DCHECK(!rt.is(t8) && !rs.is(t8));
1271 Subu(at, zero_reg, Operand(1));
1272 srl(at, at, 32 - size);
1276 nor(at, at, zero_reg);
1283 void MacroAssembler::Cvt_d_uw(FPURegister fd,
1285 FPURegister scratch) {
1286 // Move the data from fs to t8.
1288 Cvt_d_uw(fd, t8, scratch);
1292 void MacroAssembler::Cvt_d_uw(FPURegister fd,
1294 FPURegister scratch) {
1295 // Convert rs to a FP value in fd (and fd + 1).
1296 // We do this by converting rs minus the MSB to avoid sign conversion,
1297 // then adding 2^31 to the result (if needed).
1299 DCHECK(!fd.is(scratch));
1303 // Save rs's MSB to t9.
1307 // Move the result to fd.
1310 // Convert fd to a real FP value.
1313 Label conversion_done;
1315 // If rs's MSB was 0, it's done.
1316 // Otherwise we need to add that to the FP register.
1317 Branch(&conversion_done, eq, t9, Operand(zero_reg));
1319 // Load 2^31 into f20 as its float representation.
1321 mtc1(zero_reg, scratch);
1324 add_d(fd, fd, scratch);
1326 bind(&conversion_done);
1330 void MacroAssembler::Trunc_uw_d(FPURegister fd,
1332 FPURegister scratch) {
1333 Trunc_uw_d(fs, t8, scratch);
1338 void MacroAssembler::Trunc_w_d(FPURegister fd, FPURegister fs) {
1339 if (IsMipsArchVariant(kLoongson) && fd.is(fs)) {
1349 void MacroAssembler::Round_w_d(FPURegister fd, FPURegister fs) {
1350 if (IsMipsArchVariant(kLoongson) && fd.is(fs)) {
1360 void MacroAssembler::Floor_w_d(FPURegister fd, FPURegister fs) {
1361 if (IsMipsArchVariant(kLoongson) && fd.is(fs)) {
1371 void MacroAssembler::Ceil_w_d(FPURegister fd, FPURegister fs) {
1372 if (IsMipsArchVariant(kLoongson) && fd.is(fs)) {
1382 void MacroAssembler::Trunc_uw_d(FPURegister fd,
1384 FPURegister scratch) {
1385 DCHECK(!fd.is(scratch));
1388 // Load 2^31 into scratch as its float representation.
1390 mtc1(zero_reg, scratch);
1392 // Test if scratch > fd.
1393 // If fd < 2^31 we can convert it normally.
1394 Label simple_convert;
1395 BranchF(&simple_convert, NULL, lt, fd, scratch);
1397 // First we subtract 2^31 from fd, then trunc it to rs
1398 // and add 2^31 to rs.
1399 sub_d(scratch, fd, scratch);
1400 trunc_w_d(scratch, scratch);
1402 Or(rs, rs, 1 << 31);
1406 // Simple conversion.
1407 bind(&simple_convert);
1408 trunc_w_d(scratch, fd);
1415 void MacroAssembler::Mthc1(Register rt, FPURegister fs) {
1419 mtc1(rt, fs.high());
1424 void MacroAssembler::Mfhc1(Register rt, FPURegister fs) {
1428 mfc1(rt, fs.high());
1433 void MacroAssembler::BranchFCommon(SecondaryField sizeField, Label* target,
1434 Label* nan, Condition cond, FPURegister cmp1,
1435 FPURegister cmp2, BranchDelaySlot bd) {
1437 BlockTrampolinePoolScope block_trampoline_pool(this);
1443 if (IsMipsArchVariant(kMips32r6)) {
1444 sizeField = sizeField == D ? L : W;
1446 DCHECK(nan || target);
1447 // Check for unordered (NaN) cases.
1450 nan->is_bound() ? is_near(nan) : is_trampoline_emitted();
1451 if (!IsMipsArchVariant(kMips32r6)) {
1454 c(UN, D, cmp1, cmp2);
1460 c(UN, D, cmp1, cmp2);
1462 if (bd == PROTECT) {
1467 // Use kDoubleCompareReg for comparison result. It has to be unavailable
1468 // to lithium register allocator.
1469 DCHECK(!cmp1.is(kDoubleCompareReg) && !cmp2.is(kDoubleCompareReg));
1472 cmp(UN, L, kDoubleCompareReg, cmp1, cmp2);
1473 bc1eqz(&skip, kDoubleCompareReg);
1478 cmp(UN, L, kDoubleCompareReg, cmp1, cmp2);
1479 bc1nez(nan, kDoubleCompareReg);
1480 if (bd == PROTECT) {
1489 target->is_bound() ? is_near(target) : is_trampoline_emitted();
1492 Condition neg_cond = NegateFpuCondition(cond);
1493 BranchShortF(sizeField, &skip, neg_cond, cmp1, cmp2, bd);
1497 BranchShortF(sizeField, target, cond, cmp1, cmp2, bd);
1503 void MacroAssembler::BranchShortF(SecondaryField sizeField, Label* target,
1504 Condition cc, FPURegister cmp1,
1505 FPURegister cmp2, BranchDelaySlot bd) {
1506 if (!IsMipsArchVariant(kMips32r6)) {
1507 BlockTrampolinePoolScope block_trampoline_pool(this);
1509 // Here NaN cases were either handled by this function or are assumed to
1510 // have been handled by the caller.
1513 c(OLT, sizeField, cmp1, cmp2);
1517 c(ULT, sizeField, cmp1, cmp2);
1521 c(ULE, sizeField, cmp1, cmp2);
1525 c(OLE, sizeField, cmp1, cmp2);
1529 c(ULT, sizeField, cmp1, cmp2);
1533 c(OLT, sizeField, cmp1, cmp2);
1537 c(OLE, sizeField, cmp1, cmp2);
1541 c(ULE, sizeField, cmp1, cmp2);
1545 c(EQ, sizeField, cmp1, cmp2);
1549 c(UEQ, sizeField, cmp1, cmp2);
1552 case ne: // Unordered or not equal.
1553 c(EQ, sizeField, cmp1, cmp2);
1557 c(UEQ, sizeField, cmp1, cmp2);
1565 BlockTrampolinePoolScope block_trampoline_pool(this);
1567 // Here NaN cases were either handled by this function or are assumed to
1568 // have been handled by the caller.
1569 // Unsigned conditions are treated as their signed counterpart.
1570 // Use kDoubleCompareReg for comparison result, it is
1571 // valid in fp64 (FR = 1) mode which is implied for mips32r6.
1572 DCHECK(!cmp1.is(kDoubleCompareReg) && !cmp2.is(kDoubleCompareReg));
1575 cmp(OLT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1576 bc1nez(target, kDoubleCompareReg);
1579 cmp(ULT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1580 bc1nez(target, kDoubleCompareReg);
1583 cmp(ULE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1584 bc1eqz(target, kDoubleCompareReg);
1587 cmp(OLE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1588 bc1eqz(target, kDoubleCompareReg);
1591 cmp(ULT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1592 bc1eqz(target, kDoubleCompareReg);
1595 cmp(OLT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1596 bc1eqz(target, kDoubleCompareReg);
1599 cmp(OLE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1600 bc1nez(target, kDoubleCompareReg);
1603 cmp(ULE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1604 bc1nez(target, kDoubleCompareReg);
1607 cmp(EQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1608 bc1nez(target, kDoubleCompareReg);
1611 cmp(UEQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1612 bc1nez(target, kDoubleCompareReg);
1615 cmp(EQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1616 bc1eqz(target, kDoubleCompareReg);
1619 cmp(UEQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1620 bc1eqz(target, kDoubleCompareReg);
1627 if (bd == PROTECT) {
1633 void MacroAssembler::FmoveLow(FPURegister dst, Register src_low) {
1635 DCHECK(!src_low.is(at));
1645 void MacroAssembler::Move(FPURegister dst, float imm) {
1646 li(at, Operand(bit_cast<int32_t>(imm)));
1651 void MacroAssembler::Move(FPURegister dst, double imm) {
1652 static const DoubleRepresentation minus_zero(-0.0);
1653 static const DoubleRepresentation zero(0.0);
1654 DoubleRepresentation value_rep(imm);
1655 // Handle special values first.
1656 if (value_rep == zero && has_double_zero_reg_set_) {
1657 mov_d(dst, kDoubleRegZero);
1658 } else if (value_rep == minus_zero && has_double_zero_reg_set_) {
1659 neg_d(dst, kDoubleRegZero);
1662 DoubleAsTwoUInt32(imm, &lo, &hi);
1663 // Move the low part of the double into the lower of the corresponding FPU
1664 // register of FPU register pair.
1666 li(at, Operand(lo));
1669 mtc1(zero_reg, dst);
1671 // Move the high part of the double into the higher of the corresponding FPU
1672 // register of FPU register pair.
1674 li(at, Operand(hi));
1677 Mthc1(zero_reg, dst);
1679 if (dst.is(kDoubleRegZero)) has_double_zero_reg_set_ = true;
1684 void MacroAssembler::Movz(Register rd, Register rs, Register rt) {
1685 if (IsMipsArchVariant(kLoongson) || IsMipsArchVariant(kMips32r6)) {
1687 Branch(&done, ne, rt, Operand(zero_reg));
1696 void MacroAssembler::Movn(Register rd, Register rs, Register rt) {
1697 if (IsMipsArchVariant(kLoongson) || IsMipsArchVariant(kMips32r6)) {
1699 Branch(&done, eq, rt, Operand(zero_reg));
1708 void MacroAssembler::Movt(Register rd, Register rs, uint16_t cc) {
1709 if (IsMipsArchVariant(kLoongson)) {
1710 // Tests an FP condition code and then conditionally move rs to rd.
1711 // We do not currently use any FPU cc bit other than bit 0.
1713 DCHECK(!(rs.is(t8) || rd.is(t8)));
1715 Register scratch = t8;
1716 // For testing purposes we need to fetch content of the FCSR register and
1717 // than test its cc (floating point condition code) bit (for cc = 0, it is
1718 // 24. bit of the FCSR).
1719 cfc1(scratch, FCSR);
1720 // For the MIPS I, II and III architectures, the contents of scratch is
1721 // UNPREDICTABLE for the instruction immediately following CFC1.
1723 srl(scratch, scratch, 16);
1724 andi(scratch, scratch, 0x0080);
1725 Branch(&done, eq, scratch, Operand(zero_reg));
1734 void MacroAssembler::Movf(Register rd, Register rs, uint16_t cc) {
1735 if (IsMipsArchVariant(kLoongson)) {
1736 // Tests an FP condition code and then conditionally move rs to rd.
1737 // We do not currently use any FPU cc bit other than bit 0.
1739 DCHECK(!(rs.is(t8) || rd.is(t8)));
1741 Register scratch = t8;
1742 // For testing purposes we need to fetch content of the FCSR register and
1743 // than test its cc (floating point condition code) bit (for cc = 0, it is
1744 // 24. bit of the FCSR).
1745 cfc1(scratch, FCSR);
1746 // For the MIPS I, II and III architectures, the contents of scratch is
1747 // UNPREDICTABLE for the instruction immediately following CFC1.
1749 srl(scratch, scratch, 16);
1750 andi(scratch, scratch, 0x0080);
1751 Branch(&done, ne, scratch, Operand(zero_reg));
1760 void MacroAssembler::Clz(Register rd, Register rs) {
1761 if (IsMipsArchVariant(kLoongson)) {
1762 DCHECK(!(rd.is(t8) || rd.is(t9)) && !(rs.is(t8) || rs.is(t9)));
1764 Register scratch = t9;
1770 and_(scratch, at, mask);
1771 Branch(&end, ne, scratch, Operand(zero_reg));
1773 Branch(&loop, ne, mask, Operand(zero_reg), USE_DELAY_SLOT);
1782 void MacroAssembler::EmitFPUTruncate(FPURoundingMode rounding_mode,
1784 DoubleRegister double_input,
1786 DoubleRegister double_scratch,
1787 Register except_flag,
1788 CheckForInexactConversion check_inexact) {
1789 DCHECK(!result.is(scratch));
1790 DCHECK(!double_input.is(double_scratch));
1791 DCHECK(!except_flag.is(scratch));
1795 // Clear the except flag (0 = no exception)
1796 mov(except_flag, zero_reg);
1798 // Test for values that can be exactly represented as a signed 32-bit integer.
1799 cvt_w_d(double_scratch, double_input);
1800 mfc1(result, double_scratch);
1801 cvt_d_w(double_scratch, double_scratch);
1802 BranchF(&done, NULL, eq, double_input, double_scratch);
1804 int32_t except_mask = kFCSRFlagMask; // Assume interested in all exceptions.
1806 if (check_inexact == kDontCheckForInexactConversion) {
1807 // Ignore inexact exceptions.
1808 except_mask &= ~kFCSRInexactFlagMask;
1812 cfc1(scratch, FCSR);
1813 // Disable FPU exceptions.
1814 ctc1(zero_reg, FCSR);
1816 // Do operation based on rounding mode.
1817 switch (rounding_mode) {
1818 case kRoundToNearest:
1819 Round_w_d(double_scratch, double_input);
1822 Trunc_w_d(double_scratch, double_input);
1824 case kRoundToPlusInf:
1825 Ceil_w_d(double_scratch, double_input);
1827 case kRoundToMinusInf:
1828 Floor_w_d(double_scratch, double_input);
1830 } // End of switch-statement.
1833 cfc1(except_flag, FCSR);
1835 ctc1(scratch, FCSR);
1836 // Move the converted value into the result register.
1837 mfc1(result, double_scratch);
1839 // Check for fpu exceptions.
1840 And(except_flag, except_flag, Operand(except_mask));
1846 void MacroAssembler::TryInlineTruncateDoubleToI(Register result,
1847 DoubleRegister double_input,
1849 DoubleRegister single_scratch = kLithiumScratchDouble.low();
1850 Register scratch = at;
1851 Register scratch2 = t9;
1853 // Clear cumulative exception flags and save the FCSR.
1854 cfc1(scratch2, FCSR);
1855 ctc1(zero_reg, FCSR);
1856 // Try a conversion to a signed integer.
1857 trunc_w_d(single_scratch, double_input);
1858 mfc1(result, single_scratch);
1859 // Retrieve and restore the FCSR.
1860 cfc1(scratch, FCSR);
1861 ctc1(scratch2, FCSR);
1862 // Check for overflow and NaNs.
1865 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask | kFCSRInvalidOpFlagMask);
1866 // If we had no exceptions we are done.
1867 Branch(done, eq, scratch, Operand(zero_reg));
1871 void MacroAssembler::TruncateDoubleToI(Register result,
1872 DoubleRegister double_input) {
1875 TryInlineTruncateDoubleToI(result, double_input, &done);
1877 // If we fell through then inline version didn't succeed - call stub instead.
1879 Subu(sp, sp, Operand(kDoubleSize)); // Put input on stack.
1880 sdc1(double_input, MemOperand(sp, 0));
1882 DoubleToIStub stub(isolate(), sp, result, 0, true, true);
1885 Addu(sp, sp, Operand(kDoubleSize));
1892 void MacroAssembler::TruncateHeapNumberToI(Register result, Register object) {
1894 DoubleRegister double_scratch = f12;
1895 DCHECK(!result.is(object));
1897 ldc1(double_scratch,
1898 MemOperand(object, HeapNumber::kValueOffset - kHeapObjectTag));
1899 TryInlineTruncateDoubleToI(result, double_scratch, &done);
1901 // If we fell through then inline version didn't succeed - call stub instead.
1903 DoubleToIStub stub(isolate(),
1906 HeapNumber::kValueOffset - kHeapObjectTag,
1916 void MacroAssembler::TruncateNumberToI(Register object,
1918 Register heap_number_map,
1920 Label* not_number) {
1922 DCHECK(!result.is(object));
1924 UntagAndJumpIfSmi(result, object, &done);
1925 JumpIfNotHeapNumber(object, heap_number_map, scratch, not_number);
1926 TruncateHeapNumberToI(result, object);
1932 void MacroAssembler::GetLeastBitsFromSmi(Register dst,
1934 int num_least_bits) {
1935 Ext(dst, src, kSmiTagSize, num_least_bits);
1939 void MacroAssembler::GetLeastBitsFromInt32(Register dst,
1941 int num_least_bits) {
1942 And(dst, src, Operand((1 << num_least_bits) - 1));
1946 // Emulated condtional branches do not emit a nop in the branch delay slot.
1948 // BRANCH_ARGS_CHECK checks that conditional jump arguments are correct.
1949 #define BRANCH_ARGS_CHECK(cond, rs, rt) DCHECK( \
1950 (cond == cc_always && rs.is(zero_reg) && rt.rm().is(zero_reg)) || \
1951 (cond != cc_always && (!rs.is(zero_reg) || !rt.rm().is(zero_reg))))
1954 void MacroAssembler::Branch(int16_t offset, BranchDelaySlot bdslot) {
1955 BranchShort(offset, bdslot);
1959 void MacroAssembler::Branch(int16_t offset, Condition cond, Register rs,
1961 BranchDelaySlot bdslot) {
1962 BranchShort(offset, cond, rs, rt, bdslot);
1966 void MacroAssembler::Branch(Label* L, BranchDelaySlot bdslot) {
1967 if (L->is_bound()) {
1969 BranchShort(L, bdslot);
1974 if (is_trampoline_emitted()) {
1977 BranchShort(L, bdslot);
1983 void MacroAssembler::Branch(Label* L, Condition cond, Register rs,
1985 BranchDelaySlot bdslot) {
1986 if (L->is_bound()) {
1988 BranchShort(L, cond, rs, rt, bdslot);
1990 if (cond != cc_always) {
1992 Condition neg_cond = NegateCondition(cond);
1993 BranchShort(&skip, neg_cond, rs, rt);
2001 if (is_trampoline_emitted()) {
2002 if (cond != cc_always) {
2004 Condition neg_cond = NegateCondition(cond);
2005 BranchShort(&skip, neg_cond, rs, rt);
2012 BranchShort(L, cond, rs, rt, bdslot);
2018 void MacroAssembler::Branch(Label* L,
2021 Heap::RootListIndex index,
2022 BranchDelaySlot bdslot) {
2023 LoadRoot(at, index);
2024 Branch(L, cond, rs, Operand(at), bdslot);
2028 void MacroAssembler::BranchShort(int16_t offset, BranchDelaySlot bdslot) {
2031 // Emit a nop in the branch delay slot if required.
2032 if (bdslot == PROTECT)
2037 void MacroAssembler::BranchShort(int16_t offset, Condition cond, Register rs,
2039 BranchDelaySlot bdslot) {
2040 BRANCH_ARGS_CHECK(cond, rs, rt);
2041 DCHECK(!rs.is(zero_reg));
2042 Register r2 = no_reg;
2043 Register scratch = at;
2046 // NOTE: 'at' can be clobbered by Branch but it is legal to use it as rs or
2048 BlockTrampolinePoolScope block_trampoline_pool(this);
2055 beq(rs, r2, offset);
2058 bne(rs, r2, offset);
2060 // Signed comparison.
2062 if (r2.is(zero_reg)) {
2065 slt(scratch, r2, rs);
2066 bne(scratch, zero_reg, offset);
2070 if (r2.is(zero_reg)) {
2073 slt(scratch, rs, r2);
2074 beq(scratch, zero_reg, offset);
2078 if (r2.is(zero_reg)) {
2081 slt(scratch, rs, r2);
2082 bne(scratch, zero_reg, offset);
2086 if (r2.is(zero_reg)) {
2089 slt(scratch, r2, rs);
2090 beq(scratch, zero_reg, offset);
2093 // Unsigned comparison.
2095 if (r2.is(zero_reg)) {
2096 bne(rs, zero_reg, offset);
2098 sltu(scratch, r2, rs);
2099 bne(scratch, zero_reg, offset);
2102 case Ugreater_equal:
2103 if (r2.is(zero_reg)) {
2106 sltu(scratch, rs, r2);
2107 beq(scratch, zero_reg, offset);
2111 if (r2.is(zero_reg)) {
2112 // No code needs to be emitted.
2115 sltu(scratch, rs, r2);
2116 bne(scratch, zero_reg, offset);
2120 if (r2.is(zero_reg)) {
2121 beq(rs, zero_reg, offset);
2123 sltu(scratch, r2, rs);
2124 beq(scratch, zero_reg, offset);
2131 // Be careful to always use shifted_branch_offset only just before the
2132 // branch instruction, as the location will be remember for patching the
2134 BlockTrampolinePoolScope block_trampoline_pool(this);
2140 if (rt.imm32_ == 0) {
2141 beq(rs, zero_reg, offset);
2143 // We don't want any other register but scratch clobbered.
2144 DCHECK(!scratch.is(rs));
2147 beq(rs, r2, offset);
2151 if (rt.imm32_ == 0) {
2152 bne(rs, zero_reg, offset);
2154 // We don't want any other register but scratch clobbered.
2155 DCHECK(!scratch.is(rs));
2158 bne(rs, r2, offset);
2161 // Signed comparison.
2163 if (rt.imm32_ == 0) {
2168 slt(scratch, r2, rs);
2169 bne(scratch, zero_reg, offset);
2173 if (rt.imm32_ == 0) {
2175 } else if (is_int16(rt.imm32_)) {
2176 slti(scratch, rs, rt.imm32_);
2177 beq(scratch, zero_reg, offset);
2181 slt(scratch, rs, r2);
2182 beq(scratch, zero_reg, offset);
2186 if (rt.imm32_ == 0) {
2188 } else if (is_int16(rt.imm32_)) {
2189 slti(scratch, rs, rt.imm32_);
2190 bne(scratch, zero_reg, offset);
2194 slt(scratch, rs, r2);
2195 bne(scratch, zero_reg, offset);
2199 if (rt.imm32_ == 0) {
2204 slt(scratch, r2, rs);
2205 beq(scratch, zero_reg, offset);
2208 // Unsigned comparison.
2210 if (rt.imm32_ == 0) {
2211 bne(rs, zero_reg, offset);
2215 sltu(scratch, r2, rs);
2216 bne(scratch, zero_reg, offset);
2219 case Ugreater_equal:
2220 if (rt.imm32_ == 0) {
2222 } else if (is_int16(rt.imm32_)) {
2223 sltiu(scratch, rs, rt.imm32_);
2224 beq(scratch, zero_reg, offset);
2228 sltu(scratch, rs, r2);
2229 beq(scratch, zero_reg, offset);
2233 if (rt.imm32_ == 0) {
2234 // No code needs to be emitted.
2236 } else if (is_int16(rt.imm32_)) {
2237 sltiu(scratch, rs, rt.imm32_);
2238 bne(scratch, zero_reg, offset);
2242 sltu(scratch, rs, r2);
2243 bne(scratch, zero_reg, offset);
2247 if (rt.imm32_ == 0) {
2248 beq(rs, zero_reg, offset);
2252 sltu(scratch, r2, rs);
2253 beq(scratch, zero_reg, offset);
2260 // Emit a nop in the branch delay slot if required.
2261 if (bdslot == PROTECT)
2266 void MacroAssembler::BranchShort(Label* L, BranchDelaySlot bdslot) {
2267 // We use branch_offset as an argument for the branch instructions to be sure
2268 // it is called just before generating the branch instruction, as needed.
2270 b(shifted_branch_offset(L, false));
2272 // Emit a nop in the branch delay slot if required.
2273 if (bdslot == PROTECT)
2278 void MacroAssembler::BranchShort(Label* L, Condition cond, Register rs,
2280 BranchDelaySlot bdslot) {
2281 BRANCH_ARGS_CHECK(cond, rs, rt);
2284 Register r2 = no_reg;
2285 Register scratch = at;
2287 BlockTrampolinePoolScope block_trampoline_pool(this);
2289 // Be careful to always use shifted_branch_offset only just before the
2290 // branch instruction, as the location will be remember for patching the
2294 offset = shifted_branch_offset(L, false);
2298 offset = shifted_branch_offset(L, false);
2299 beq(rs, r2, offset);
2302 offset = shifted_branch_offset(L, false);
2303 bne(rs, r2, offset);
2305 // Signed comparison.
2307 if (r2.is(zero_reg)) {
2308 offset = shifted_branch_offset(L, false);
2311 slt(scratch, r2, rs);
2312 offset = shifted_branch_offset(L, false);
2313 bne(scratch, zero_reg, offset);
2317 if (r2.is(zero_reg)) {
2318 offset = shifted_branch_offset(L, false);
2321 slt(scratch, rs, r2);
2322 offset = shifted_branch_offset(L, false);
2323 beq(scratch, zero_reg, offset);
2327 if (r2.is(zero_reg)) {
2328 offset = shifted_branch_offset(L, false);
2331 slt(scratch, rs, r2);
2332 offset = shifted_branch_offset(L, false);
2333 bne(scratch, zero_reg, offset);
2337 if (r2.is(zero_reg)) {
2338 offset = shifted_branch_offset(L, false);
2341 slt(scratch, r2, rs);
2342 offset = shifted_branch_offset(L, false);
2343 beq(scratch, zero_reg, offset);
2346 // Unsigned comparison.
2348 if (r2.is(zero_reg)) {
2349 offset = shifted_branch_offset(L, false);
2350 bne(rs, zero_reg, offset);
2352 sltu(scratch, r2, rs);
2353 offset = shifted_branch_offset(L, false);
2354 bne(scratch, zero_reg, offset);
2357 case Ugreater_equal:
2358 if (r2.is(zero_reg)) {
2359 offset = shifted_branch_offset(L, false);
2362 sltu(scratch, rs, r2);
2363 offset = shifted_branch_offset(L, false);
2364 beq(scratch, zero_reg, offset);
2368 if (r2.is(zero_reg)) {
2369 // No code needs to be emitted.
2372 sltu(scratch, rs, r2);
2373 offset = shifted_branch_offset(L, false);
2374 bne(scratch, zero_reg, offset);
2378 if (r2.is(zero_reg)) {
2379 offset = shifted_branch_offset(L, false);
2380 beq(rs, zero_reg, offset);
2382 sltu(scratch, r2, rs);
2383 offset = shifted_branch_offset(L, false);
2384 beq(scratch, zero_reg, offset);
2391 // Be careful to always use shifted_branch_offset only just before the
2392 // branch instruction, as the location will be remember for patching the
2394 BlockTrampolinePoolScope block_trampoline_pool(this);
2397 offset = shifted_branch_offset(L, false);
2401 if (rt.imm32_ == 0) {
2402 offset = shifted_branch_offset(L, false);
2403 beq(rs, zero_reg, offset);
2405 DCHECK(!scratch.is(rs));
2408 offset = shifted_branch_offset(L, false);
2409 beq(rs, r2, offset);
2413 if (rt.imm32_ == 0) {
2414 offset = shifted_branch_offset(L, false);
2415 bne(rs, zero_reg, offset);
2417 DCHECK(!scratch.is(rs));
2420 offset = shifted_branch_offset(L, false);
2421 bne(rs, r2, offset);
2424 // Signed comparison.
2426 if (rt.imm32_ == 0) {
2427 offset = shifted_branch_offset(L, false);
2430 DCHECK(!scratch.is(rs));
2433 slt(scratch, r2, rs);
2434 offset = shifted_branch_offset(L, false);
2435 bne(scratch, zero_reg, offset);
2439 if (rt.imm32_ == 0) {
2440 offset = shifted_branch_offset(L, false);
2442 } else if (is_int16(rt.imm32_)) {
2443 slti(scratch, rs, rt.imm32_);
2444 offset = shifted_branch_offset(L, false);
2445 beq(scratch, zero_reg, offset);
2447 DCHECK(!scratch.is(rs));
2450 slt(scratch, rs, r2);
2451 offset = shifted_branch_offset(L, false);
2452 beq(scratch, zero_reg, offset);
2456 if (rt.imm32_ == 0) {
2457 offset = shifted_branch_offset(L, false);
2459 } else if (is_int16(rt.imm32_)) {
2460 slti(scratch, rs, rt.imm32_);
2461 offset = shifted_branch_offset(L, false);
2462 bne(scratch, zero_reg, offset);
2464 DCHECK(!scratch.is(rs));
2467 slt(scratch, rs, r2);
2468 offset = shifted_branch_offset(L, false);
2469 bne(scratch, zero_reg, offset);
2473 if (rt.imm32_ == 0) {
2474 offset = shifted_branch_offset(L, false);
2477 DCHECK(!scratch.is(rs));
2480 slt(scratch, r2, rs);
2481 offset = shifted_branch_offset(L, false);
2482 beq(scratch, zero_reg, offset);
2485 // Unsigned comparison.
2487 if (rt.imm32_ == 0) {
2488 offset = shifted_branch_offset(L, false);
2489 bne(rs, zero_reg, offset);
2491 DCHECK(!scratch.is(rs));
2494 sltu(scratch, r2, rs);
2495 offset = shifted_branch_offset(L, false);
2496 bne(scratch, zero_reg, offset);
2499 case Ugreater_equal:
2500 if (rt.imm32_ == 0) {
2501 offset = shifted_branch_offset(L, false);
2503 } else if (is_int16(rt.imm32_)) {
2504 sltiu(scratch, rs, rt.imm32_);
2505 offset = shifted_branch_offset(L, false);
2506 beq(scratch, zero_reg, offset);
2508 DCHECK(!scratch.is(rs));
2511 sltu(scratch, rs, r2);
2512 offset = shifted_branch_offset(L, false);
2513 beq(scratch, zero_reg, offset);
2517 if (rt.imm32_ == 0) {
2518 // No code needs to be emitted.
2520 } else if (is_int16(rt.imm32_)) {
2521 sltiu(scratch, rs, rt.imm32_);
2522 offset = shifted_branch_offset(L, false);
2523 bne(scratch, zero_reg, offset);
2525 DCHECK(!scratch.is(rs));
2528 sltu(scratch, rs, r2);
2529 offset = shifted_branch_offset(L, false);
2530 bne(scratch, zero_reg, offset);
2534 if (rt.imm32_ == 0) {
2535 offset = shifted_branch_offset(L, false);
2536 beq(rs, zero_reg, offset);
2538 DCHECK(!scratch.is(rs));
2541 sltu(scratch, r2, rs);
2542 offset = shifted_branch_offset(L, false);
2543 beq(scratch, zero_reg, offset);
2550 // Check that offset could actually hold on an int16_t.
2551 DCHECK(is_int16(offset));
2552 // Emit a nop in the branch delay slot if required.
2553 if (bdslot == PROTECT)
2558 void MacroAssembler::BranchAndLink(int16_t offset, BranchDelaySlot bdslot) {
2559 BranchAndLinkShort(offset, bdslot);
2563 void MacroAssembler::BranchAndLink(int16_t offset, Condition cond, Register rs,
2565 BranchDelaySlot bdslot) {
2566 BranchAndLinkShort(offset, cond, rs, rt, bdslot);
2570 void MacroAssembler::BranchAndLink(Label* L, BranchDelaySlot bdslot) {
2571 if (L->is_bound()) {
2573 BranchAndLinkShort(L, bdslot);
2578 if (is_trampoline_emitted()) {
2581 BranchAndLinkShort(L, bdslot);
2587 void MacroAssembler::BranchAndLink(Label* L, Condition cond, Register rs,
2589 BranchDelaySlot bdslot) {
2590 if (L->is_bound()) {
2592 BranchAndLinkShort(L, cond, rs, rt, bdslot);
2595 Condition neg_cond = NegateCondition(cond);
2596 BranchShort(&skip, neg_cond, rs, rt);
2601 if (is_trampoline_emitted()) {
2603 Condition neg_cond = NegateCondition(cond);
2604 BranchShort(&skip, neg_cond, rs, rt);
2608 BranchAndLinkShort(L, cond, rs, rt, bdslot);
2614 // We need to use a bgezal or bltzal, but they can't be used directly with the
2615 // slt instructions. We could use sub or add instead but we would miss overflow
2616 // cases, so we keep slt and add an intermediate third instruction.
2617 void MacroAssembler::BranchAndLinkShort(int16_t offset,
2618 BranchDelaySlot bdslot) {
2621 // Emit a nop in the branch delay slot if required.
2622 if (bdslot == PROTECT)
2627 void MacroAssembler::BranchAndLinkShort(int16_t offset, Condition cond,
2628 Register rs, const Operand& rt,
2629 BranchDelaySlot bdslot) {
2630 BRANCH_ARGS_CHECK(cond, rs, rt);
2631 Register r2 = no_reg;
2632 Register scratch = at;
2636 } else if (cond != cc_always) {
2641 if (!IsMipsArchVariant(kMips32r6)) {
2642 BlockTrampolinePoolScope block_trampoline_pool(this);
2658 // Signed comparison.
2660 slt(scratch, r2, rs);
2661 addiu(scratch, scratch, -1);
2662 bgezal(scratch, offset);
2665 slt(scratch, rs, r2);
2666 addiu(scratch, scratch, -1);
2667 bltzal(scratch, offset);
2670 slt(scratch, rs, r2);
2671 addiu(scratch, scratch, -1);
2672 bgezal(scratch, offset);
2675 slt(scratch, r2, rs);
2676 addiu(scratch, scratch, -1);
2677 bltzal(scratch, offset);
2680 // Unsigned comparison.
2682 sltu(scratch, r2, rs);
2683 addiu(scratch, scratch, -1);
2684 bgezal(scratch, offset);
2686 case Ugreater_equal:
2687 sltu(scratch, rs, r2);
2688 addiu(scratch, scratch, -1);
2689 bltzal(scratch, offset);
2692 sltu(scratch, rs, r2);
2693 addiu(scratch, scratch, -1);
2694 bgezal(scratch, offset);
2697 sltu(scratch, r2, rs);
2698 addiu(scratch, scratch, -1);
2699 bltzal(scratch, offset);
2706 BlockTrampolinePoolScope block_trampoline_pool(this);
2722 // Signed comparison.
2725 slt(scratch, r2, rs);
2726 beq(scratch, zero_reg, 2);
2732 slt(scratch, rs, r2);
2733 bne(scratch, zero_reg, 2);
2739 slt(scratch, rs, r2);
2740 bne(scratch, zero_reg, 2);
2746 slt(scratch, r2, rs);
2747 bne(scratch, zero_reg, 2);
2753 // Unsigned comparison.
2756 sltu(scratch, r2, rs);
2757 beq(scratch, zero_reg, 2);
2761 case Ugreater_equal:
2763 sltu(scratch, rs, r2);
2764 bne(scratch, zero_reg, 2);
2770 sltu(scratch, rs, r2);
2771 bne(scratch, zero_reg, 2);
2777 sltu(scratch, r2, rs);
2778 bne(scratch, zero_reg, 2);
2787 // Emit a nop in the branch delay slot if required.
2788 if (bdslot == PROTECT)
2793 void MacroAssembler::BranchAndLinkShort(Label* L, BranchDelaySlot bdslot) {
2794 bal(shifted_branch_offset(L, false));
2796 // Emit a nop in the branch delay slot if required.
2797 if (bdslot == PROTECT)
2802 void MacroAssembler::BranchAndLinkShort(Label* L, Condition cond, Register rs,
2804 BranchDelaySlot bdslot) {
2805 BRANCH_ARGS_CHECK(cond, rs, rt);
2808 Register r2 = no_reg;
2809 Register scratch = at;
2812 } else if (cond != cc_always) {
2817 if (!IsMipsArchVariant(kMips32r6)) {
2818 BlockTrampolinePoolScope block_trampoline_pool(this);
2821 offset = shifted_branch_offset(L, false);
2827 offset = shifted_branch_offset(L, false);
2833 offset = shifted_branch_offset(L, false);
2837 // Signed comparison.
2839 slt(scratch, r2, rs);
2840 addiu(scratch, scratch, -1);
2841 offset = shifted_branch_offset(L, false);
2842 bgezal(scratch, offset);
2845 slt(scratch, rs, r2);
2846 addiu(scratch, scratch, -1);
2847 offset = shifted_branch_offset(L, false);
2848 bltzal(scratch, offset);
2851 slt(scratch, rs, r2);
2852 addiu(scratch, scratch, -1);
2853 offset = shifted_branch_offset(L, false);
2854 bgezal(scratch, offset);
2857 slt(scratch, r2, rs);
2858 addiu(scratch, scratch, -1);
2859 offset = shifted_branch_offset(L, false);
2860 bltzal(scratch, offset);
2863 // Unsigned comparison.
2865 sltu(scratch, r2, rs);
2866 addiu(scratch, scratch, -1);
2867 offset = shifted_branch_offset(L, false);
2868 bgezal(scratch, offset);
2870 case Ugreater_equal:
2871 sltu(scratch, rs, r2);
2872 addiu(scratch, scratch, -1);
2873 offset = shifted_branch_offset(L, false);
2874 bltzal(scratch, offset);
2877 sltu(scratch, rs, r2);
2878 addiu(scratch, scratch, -1);
2879 offset = shifted_branch_offset(L, false);
2880 bgezal(scratch, offset);
2883 sltu(scratch, r2, rs);
2884 addiu(scratch, scratch, -1);
2885 offset = shifted_branch_offset(L, false);
2886 bltzal(scratch, offset);
2893 BlockTrampolinePoolScope block_trampoline_pool(this);
2896 offset = shifted_branch_offset(L, false);
2902 offset = shifted_branch_offset(L, false);
2908 offset = shifted_branch_offset(L, false);
2912 // Signed comparison.
2915 slt(scratch, r2, rs);
2916 beq(scratch, zero_reg, 2);
2918 offset = shifted_branch_offset(L, false);
2923 slt(scratch, rs, r2);
2924 bne(scratch, zero_reg, 2);
2926 offset = shifted_branch_offset(L, false);
2931 slt(scratch, rs, r2);
2932 bne(scratch, zero_reg, 2);
2934 offset = shifted_branch_offset(L, false);
2939 slt(scratch, r2, rs);
2940 bne(scratch, zero_reg, 2);
2942 offset = shifted_branch_offset(L, false);
2947 // Unsigned comparison.
2950 sltu(scratch, r2, rs);
2951 beq(scratch, zero_reg, 2);
2953 offset = shifted_branch_offset(L, false);
2956 case Ugreater_equal:
2958 sltu(scratch, rs, r2);
2959 bne(scratch, zero_reg, 2);
2961 offset = shifted_branch_offset(L, false);
2966 sltu(scratch, rs, r2);
2967 bne(scratch, zero_reg, 2);
2969 offset = shifted_branch_offset(L, false);
2974 sltu(scratch, r2, rs);
2975 bne(scratch, zero_reg, 2);
2977 offset = shifted_branch_offset(L, false);
2986 // Check that offset could actually hold on an int16_t.
2987 DCHECK(is_int16(offset));
2989 // Emit a nop in the branch delay slot if required.
2990 if (bdslot == PROTECT)
2995 void MacroAssembler::Jump(Register target,
2999 BranchDelaySlot bd) {
3000 BlockTrampolinePoolScope block_trampoline_pool(this);
3001 if (cond == cc_always) {
3004 BRANCH_ARGS_CHECK(cond, rs, rt);
3005 Branch(2, NegateCondition(cond), rs, rt);
3008 // Emit a nop in the branch delay slot if required.
3014 void MacroAssembler::Jump(intptr_t target,
3015 RelocInfo::Mode rmode,
3019 BranchDelaySlot bd) {
3021 if (cond != cc_always) {
3022 Branch(USE_DELAY_SLOT, &skip, NegateCondition(cond), rs, rt);
3024 // The first instruction of 'li' may be placed in the delay slot.
3025 // This is not an issue, t9 is expected to be clobbered anyway.
3026 li(t9, Operand(target, rmode));
3027 Jump(t9, al, zero_reg, Operand(zero_reg), bd);
3032 void MacroAssembler::Jump(Address target,
3033 RelocInfo::Mode rmode,
3037 BranchDelaySlot bd) {
3038 DCHECK(!RelocInfo::IsCodeTarget(rmode));
3039 Jump(reinterpret_cast<intptr_t>(target), rmode, cond, rs, rt, bd);
3043 void MacroAssembler::Jump(Handle<Code> code,
3044 RelocInfo::Mode rmode,
3048 BranchDelaySlot bd) {
3049 DCHECK(RelocInfo::IsCodeTarget(rmode));
3050 AllowDeferredHandleDereference embedding_raw_address;
3051 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond, rs, rt, bd);
3055 int MacroAssembler::CallSize(Register target,
3059 BranchDelaySlot bd) {
3062 if (cond == cc_always) {
3071 return size * kInstrSize;
3075 // Note: To call gcc-compiled C code on mips, you must call thru t9.
3076 void MacroAssembler::Call(Register target,
3080 BranchDelaySlot bd) {
3081 BlockTrampolinePoolScope block_trampoline_pool(this);
3084 if (cond == cc_always) {
3087 BRANCH_ARGS_CHECK(cond, rs, rt);
3088 Branch(2, NegateCondition(cond), rs, rt);
3091 // Emit a nop in the branch delay slot if required.
3095 DCHECK_EQ(CallSize(target, cond, rs, rt, bd),
3096 SizeOfCodeGeneratedSince(&start));
3100 int MacroAssembler::CallSize(Address target,
3101 RelocInfo::Mode rmode,
3105 BranchDelaySlot bd) {
3106 int size = CallSize(t9, cond, rs, rt, bd);
3107 return size + 2 * kInstrSize;
3111 void MacroAssembler::Call(Address target,
3112 RelocInfo::Mode rmode,
3116 BranchDelaySlot bd) {
3117 BlockTrampolinePoolScope block_trampoline_pool(this);
3120 int32_t target_int = reinterpret_cast<int32_t>(target);
3121 // Must record previous source positions before the
3122 // li() generates a new code target.
3123 positions_recorder()->WriteRecordedPositions();
3124 li(t9, Operand(target_int, rmode), CONSTANT_SIZE);
3125 Call(t9, cond, rs, rt, bd);
3126 DCHECK_EQ(CallSize(target, rmode, cond, rs, rt, bd),
3127 SizeOfCodeGeneratedSince(&start));
3131 int MacroAssembler::CallSize(Handle<Code> code,
3132 RelocInfo::Mode rmode,
3133 TypeFeedbackId ast_id,
3137 BranchDelaySlot bd) {
3138 AllowDeferredHandleDereference using_raw_address;
3139 return CallSize(reinterpret_cast<Address>(code.location()),
3140 rmode, cond, rs, rt, bd);
3144 void MacroAssembler::Call(Handle<Code> code,
3145 RelocInfo::Mode rmode,
3146 TypeFeedbackId ast_id,
3150 BranchDelaySlot bd) {
3151 BlockTrampolinePoolScope block_trampoline_pool(this);
3154 DCHECK(RelocInfo::IsCodeTarget(rmode));
3155 if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) {
3156 SetRecordedAstId(ast_id);
3157 rmode = RelocInfo::CODE_TARGET_WITH_ID;
3159 AllowDeferredHandleDereference embedding_raw_address;
3160 Call(reinterpret_cast<Address>(code.location()), rmode, cond, rs, rt, bd);
3161 DCHECK_EQ(CallSize(code, rmode, ast_id, cond, rs, rt, bd),
3162 SizeOfCodeGeneratedSince(&start));
3166 void MacroAssembler::Ret(Condition cond,
3169 BranchDelaySlot bd) {
3170 Jump(ra, cond, rs, rt, bd);
3174 void MacroAssembler::Jr(Label* L, BranchDelaySlot bdslot) {
3175 BlockTrampolinePoolScope block_trampoline_pool(this);
3178 imm32 = jump_address(L);
3179 { BlockGrowBufferScope block_buf_growth(this);
3180 // Buffer growth (and relocation) must be blocked for internal references
3181 // until associated instructions are emitted and available to be patched.
3182 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE_ENCODED);
3183 lui(at, (imm32 & kHiMask) >> kLuiShift);
3184 ori(at, at, (imm32 & kImm16Mask));
3188 // Emit a nop in the branch delay slot if required.
3189 if (bdslot == PROTECT)
3194 void MacroAssembler::Jalr(Label* L, BranchDelaySlot bdslot) {
3195 BlockTrampolinePoolScope block_trampoline_pool(this);
3198 imm32 = jump_address(L);
3199 { BlockGrowBufferScope block_buf_growth(this);
3200 // Buffer growth (and relocation) must be blocked for internal references
3201 // until associated instructions are emitted and available to be patched.
3202 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE_ENCODED);
3203 lui(at, (imm32 & kHiMask) >> kLuiShift);
3204 ori(at, at, (imm32 & kImm16Mask));
3208 // Emit a nop in the branch delay slot if required.
3209 if (bdslot == PROTECT)
3214 void MacroAssembler::DropAndRet(int drop) {
3215 DCHECK(is_int16(drop * kPointerSize));
3216 Ret(USE_DELAY_SLOT);
3217 addiu(sp, sp, drop * kPointerSize);
3220 void MacroAssembler::DropAndRet(int drop,
3223 const Operand& r2) {
3224 // Both Drop and Ret need to be conditional.
3226 if (cond != cc_always) {
3227 Branch(&skip, NegateCondition(cond), r1, r2);
3233 if (cond != cc_always) {
3239 void MacroAssembler::Drop(int count,
3242 const Operand& op) {
3250 Branch(&skip, NegateCondition(cond), reg, op);
3253 Addu(sp, sp, Operand(count * kPointerSize));
3262 void MacroAssembler::Swap(Register reg1,
3265 if (scratch.is(no_reg)) {
3266 Xor(reg1, reg1, Operand(reg2));
3267 Xor(reg2, reg2, Operand(reg1));
3268 Xor(reg1, reg1, Operand(reg2));
3277 void MacroAssembler::Call(Label* target) {
3278 BranchAndLink(target);
3282 void MacroAssembler::Push(Handle<Object> handle) {
3283 li(at, Operand(handle));
3288 void MacroAssembler::DebugBreak() {
3289 PrepareCEntryArgs(0);
3290 PrepareCEntryFunction(
3291 ExternalReference(Runtime::kHandleDebuggerStatement, isolate()));
3292 CEntryStub ces(isolate(), 1);
3293 DCHECK(AllowThisStubCall(&ces));
3294 Call(ces.GetCode(), RelocInfo::DEBUGGER_STATEMENT);
3298 // ---------------------------------------------------------------------------
3299 // Exception handling.
3301 void MacroAssembler::PushStackHandler() {
3302 // Adjust this code if not the case.
3303 STATIC_ASSERT(StackHandlerConstants::kSize == 1 * kPointerSize);
3304 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
3306 // Link the current handler as the next handler.
3307 li(t2, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
3308 lw(t1, MemOperand(t2));
3311 // Set this new handler as the current one.
3312 sw(sp, MemOperand(t2));
3316 void MacroAssembler::PopStackHandler() {
3317 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
3319 Addu(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize));
3320 li(at, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
3321 sw(a1, MemOperand(at));
3325 void MacroAssembler::Allocate(int object_size,
3330 AllocationFlags flags) {
3331 DCHECK(object_size <= Page::kMaxRegularHeapObjectSize);
3332 if (!FLAG_inline_new) {
3333 if (emit_debug_code()) {
3334 // Trash the registers to simulate an allocation failure.
3336 li(scratch1, 0x7191);
3337 li(scratch2, 0x7291);
3343 DCHECK(!result.is(scratch1));
3344 DCHECK(!result.is(scratch2));
3345 DCHECK(!scratch1.is(scratch2));
3346 DCHECK(!scratch1.is(t9));
3347 DCHECK(!scratch2.is(t9));
3348 DCHECK(!result.is(t9));
3350 // Make object size into bytes.
3351 if ((flags & SIZE_IN_WORDS) != 0) {
3352 object_size *= kPointerSize;
3354 DCHECK_EQ(0, object_size & kObjectAlignmentMask);
3356 // Check relative positions of allocation top and limit addresses.
3357 // ARM adds additional checks to make sure the ldm instruction can be
3358 // used. On MIPS we don't have ldm so we don't need additional checks either.
3359 ExternalReference allocation_top =
3360 AllocationUtils::GetAllocationTopReference(isolate(), flags);
3361 ExternalReference allocation_limit =
3362 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
3365 reinterpret_cast<intptr_t>(allocation_top.address());
3367 reinterpret_cast<intptr_t>(allocation_limit.address());
3368 DCHECK((limit - top) == kPointerSize);
3370 // Set up allocation top address and object size registers.
3371 Register topaddr = scratch1;
3372 li(topaddr, Operand(allocation_top));
3374 // This code stores a temporary value in t9.
3375 if ((flags & RESULT_CONTAINS_TOP) == 0) {
3376 // Load allocation top into result and allocation limit into t9.
3377 lw(result, MemOperand(topaddr));
3378 lw(t9, MemOperand(topaddr, kPointerSize));
3380 if (emit_debug_code()) {
3381 // Assert that result actually contains top on entry. t9 is used
3382 // immediately below so this use of t9 does not cause difference with
3383 // respect to register content between debug and release mode.
3384 lw(t9, MemOperand(topaddr));
3385 Check(eq, kUnexpectedAllocationTop, result, Operand(t9));
3387 // Load allocation limit into t9. Result already contains allocation top.
3388 lw(t9, MemOperand(topaddr, limit - top));
3391 if ((flags & DOUBLE_ALIGNMENT) != 0) {
3392 // Align the next allocation. Storing the filler map without checking top is
3393 // safe in new-space because the limit of the heap is aligned there.
3394 DCHECK(kPointerAlignment * 2 == kDoubleAlignment);
3395 And(scratch2, result, Operand(kDoubleAlignmentMask));
3397 Branch(&aligned, eq, scratch2, Operand(zero_reg));
3398 if ((flags & PRETENURE) != 0) {
3399 Branch(gc_required, Ugreater_equal, result, Operand(t9));
3401 li(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
3402 sw(scratch2, MemOperand(result));
3403 Addu(result, result, Operand(kDoubleSize / 2));
3407 // Calculate new top and bail out if new space is exhausted. Use result
3408 // to calculate the new top.
3409 Addu(scratch2, result, Operand(object_size));
3410 Branch(gc_required, Ugreater, scratch2, Operand(t9));
3411 sw(scratch2, MemOperand(topaddr));
3413 // Tag object if requested.
3414 if ((flags & TAG_OBJECT) != 0) {
3415 Addu(result, result, Operand(kHeapObjectTag));
3420 void MacroAssembler::Allocate(Register object_size,
3425 AllocationFlags flags) {
3426 if (!FLAG_inline_new) {
3427 if (emit_debug_code()) {
3428 // Trash the registers to simulate an allocation failure.
3430 li(scratch1, 0x7191);
3431 li(scratch2, 0x7291);
3437 DCHECK(!result.is(scratch1));
3438 DCHECK(!result.is(scratch2));
3439 DCHECK(!scratch1.is(scratch2));
3440 DCHECK(!object_size.is(t9));
3441 DCHECK(!scratch1.is(t9) && !scratch2.is(t9) && !result.is(t9));
3443 // Check relative positions of allocation top and limit addresses.
3444 // ARM adds additional checks to make sure the ldm instruction can be
3445 // used. On MIPS we don't have ldm so we don't need additional checks either.
3446 ExternalReference allocation_top =
3447 AllocationUtils::GetAllocationTopReference(isolate(), flags);
3448 ExternalReference allocation_limit =
3449 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
3451 reinterpret_cast<intptr_t>(allocation_top.address());
3453 reinterpret_cast<intptr_t>(allocation_limit.address());
3454 DCHECK((limit - top) == kPointerSize);
3456 // Set up allocation top address and object size registers.
3457 Register topaddr = scratch1;
3458 li(topaddr, Operand(allocation_top));
3460 // This code stores a temporary value in t9.
3461 if ((flags & RESULT_CONTAINS_TOP) == 0) {
3462 // Load allocation top into result and allocation limit into t9.
3463 lw(result, MemOperand(topaddr));
3464 lw(t9, MemOperand(topaddr, kPointerSize));
3466 if (emit_debug_code()) {
3467 // Assert that result actually contains top on entry. t9 is used
3468 // immediately below so this use of t9 does not cause difference with
3469 // respect to register content between debug and release mode.
3470 lw(t9, MemOperand(topaddr));
3471 Check(eq, kUnexpectedAllocationTop, result, Operand(t9));
3473 // Load allocation limit into t9. Result already contains allocation top.
3474 lw(t9, MemOperand(topaddr, limit - top));
3477 if ((flags & DOUBLE_ALIGNMENT) != 0) {
3478 // Align the next allocation. Storing the filler map without checking top is
3479 // safe in new-space because the limit of the heap is aligned there.
3480 DCHECK(kPointerAlignment * 2 == kDoubleAlignment);
3481 And(scratch2, result, Operand(kDoubleAlignmentMask));
3483 Branch(&aligned, eq, scratch2, Operand(zero_reg));
3484 if ((flags & PRETENURE) != 0) {
3485 Branch(gc_required, Ugreater_equal, result, Operand(t9));
3487 li(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
3488 sw(scratch2, MemOperand(result));
3489 Addu(result, result, Operand(kDoubleSize / 2));
3493 // Calculate new top and bail out if new space is exhausted. Use result
3494 // to calculate the new top. Object size may be in words so a shift is
3495 // required to get the number of bytes.
3496 if ((flags & SIZE_IN_WORDS) != 0) {
3497 sll(scratch2, object_size, kPointerSizeLog2);
3498 Addu(scratch2, result, scratch2);
3500 Addu(scratch2, result, Operand(object_size));
3502 Branch(gc_required, Ugreater, scratch2, Operand(t9));
3504 // Update allocation top. result temporarily holds the new top.
3505 if (emit_debug_code()) {
3506 And(t9, scratch2, Operand(kObjectAlignmentMask));
3507 Check(eq, kUnalignedAllocationInNewSpace, t9, Operand(zero_reg));
3509 sw(scratch2, MemOperand(topaddr));
3511 // Tag object if requested.
3512 if ((flags & TAG_OBJECT) != 0) {
3513 Addu(result, result, Operand(kHeapObjectTag));
3518 void MacroAssembler::AllocateTwoByteString(Register result,
3523 Label* gc_required) {
3524 // Calculate the number of bytes needed for the characters in the string while
3525 // observing object alignment.
3526 DCHECK((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3527 sll(scratch1, length, 1); // Length in bytes, not chars.
3528 addiu(scratch1, scratch1,
3529 kObjectAlignmentMask + SeqTwoByteString::kHeaderSize);
3530 And(scratch1, scratch1, Operand(~kObjectAlignmentMask));
3532 // Allocate two-byte string in new space.
3540 // Set the map, length and hash field.
3541 InitializeNewString(result,
3543 Heap::kStringMapRootIndex,
3549 void MacroAssembler::AllocateOneByteString(Register result, Register length,
3550 Register scratch1, Register scratch2,
3552 Label* gc_required) {
3553 // Calculate the number of bytes needed for the characters in the string
3554 // while observing object alignment.
3555 DCHECK((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3556 DCHECK(kCharSize == 1);
3557 addiu(scratch1, length, kObjectAlignmentMask + SeqOneByteString::kHeaderSize);
3558 And(scratch1, scratch1, Operand(~kObjectAlignmentMask));
3560 // Allocate one-byte string in new space.
3568 // Set the map, length and hash field.
3569 InitializeNewString(result, length, Heap::kOneByteStringMapRootIndex,
3570 scratch1, scratch2);
3574 void MacroAssembler::AllocateTwoByteConsString(Register result,
3578 Label* gc_required) {
3579 Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required,
3581 InitializeNewString(result,
3583 Heap::kConsStringMapRootIndex,
3589 void MacroAssembler::AllocateOneByteConsString(Register result, Register length,
3592 Label* gc_required) {
3593 Allocate(ConsString::kSize,
3600 InitializeNewString(result, length, Heap::kConsOneByteStringMapRootIndex,
3601 scratch1, scratch2);
3605 void MacroAssembler::AllocateTwoByteSlicedString(Register result,
3609 Label* gc_required) {
3610 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
3613 InitializeNewString(result,
3615 Heap::kSlicedStringMapRootIndex,
3621 void MacroAssembler::AllocateOneByteSlicedString(Register result,
3625 Label* gc_required) {
3626 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
3629 InitializeNewString(result, length, Heap::kSlicedOneByteStringMapRootIndex,
3630 scratch1, scratch2);
3634 void MacroAssembler::JumpIfNotUniqueNameInstanceType(Register reg,
3635 Label* not_unique_name) {
3636 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3638 And(at, reg, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3639 Branch(&succeed, eq, at, Operand(zero_reg));
3640 Branch(not_unique_name, ne, reg, Operand(SYMBOL_TYPE));
3646 // Allocates a heap number or jumps to the label if the young space is full and
3647 // a scavenge is needed.
3648 void MacroAssembler::AllocateHeapNumber(Register result,
3651 Register heap_number_map,
3653 TaggingMode tagging_mode,
3655 // Allocate an object in the heap for the heap number and tag it as a heap
3657 Allocate(HeapNumber::kSize, result, scratch1, scratch2, need_gc,
3658 tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS);
3660 Heap::RootListIndex map_index = mode == MUTABLE
3661 ? Heap::kMutableHeapNumberMapRootIndex
3662 : Heap::kHeapNumberMapRootIndex;
3663 AssertIsRoot(heap_number_map, map_index);
3665 // Store heap number map in the allocated object.
3666 if (tagging_mode == TAG_RESULT) {
3667 sw(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset));
3669 sw(heap_number_map, MemOperand(result, HeapObject::kMapOffset));
3674 void MacroAssembler::AllocateHeapNumberWithValue(Register result,
3678 Label* gc_required) {
3679 LoadRoot(t8, Heap::kHeapNumberMapRootIndex);
3680 AllocateHeapNumber(result, scratch1, scratch2, t8, gc_required);
3681 sdc1(value, FieldMemOperand(result, HeapNumber::kValueOffset));
3685 // Copies a fixed number of fields of heap objects from src to dst.
3686 void MacroAssembler::CopyFields(Register dst,
3690 DCHECK((temps & dst.bit()) == 0);
3691 DCHECK((temps & src.bit()) == 0);
3692 // Primitive implementation using only one temporary register.
3694 Register tmp = no_reg;
3695 // Find a temp register in temps list.
3696 for (int i = 0; i < kNumRegisters; i++) {
3697 if ((temps & (1 << i)) != 0) {
3702 DCHECK(!tmp.is(no_reg));
3704 for (int i = 0; i < field_count; i++) {
3705 lw(tmp, FieldMemOperand(src, i * kPointerSize));
3706 sw(tmp, FieldMemOperand(dst, i * kPointerSize));
3711 void MacroAssembler::CopyBytes(Register src,
3715 Label align_loop_1, word_loop, byte_loop, byte_loop_1, done;
3717 // Align src before copying in word size chunks.
3718 Branch(&byte_loop, le, length, Operand(kPointerSize));
3719 bind(&align_loop_1);
3720 And(scratch, src, kPointerSize - 1);
3721 Branch(&word_loop, eq, scratch, Operand(zero_reg));
3722 lbu(scratch, MemOperand(src));
3724 sb(scratch, MemOperand(dst));
3726 Subu(length, length, Operand(1));
3727 Branch(&align_loop_1, ne, length, Operand(zero_reg));
3729 // Copy bytes in word size chunks.
3731 if (emit_debug_code()) {
3732 And(scratch, src, kPointerSize - 1);
3733 Assert(eq, kExpectingAlignmentForCopyBytes,
3734 scratch, Operand(zero_reg));
3736 Branch(&byte_loop, lt, length, Operand(kPointerSize));
3737 lw(scratch, MemOperand(src));
3738 Addu(src, src, kPointerSize);
3740 // TODO(kalmard) check if this can be optimized to use sw in most cases.
3741 // Can't use unaligned access - copy byte by byte.
3742 if (kArchEndian == kLittle) {
3743 sb(scratch, MemOperand(dst, 0));
3744 srl(scratch, scratch, 8);
3745 sb(scratch, MemOperand(dst, 1));
3746 srl(scratch, scratch, 8);
3747 sb(scratch, MemOperand(dst, 2));
3748 srl(scratch, scratch, 8);
3749 sb(scratch, MemOperand(dst, 3));
3751 sb(scratch, MemOperand(dst, 3));
3752 srl(scratch, scratch, 8);
3753 sb(scratch, MemOperand(dst, 2));
3754 srl(scratch, scratch, 8);
3755 sb(scratch, MemOperand(dst, 1));
3756 srl(scratch, scratch, 8);
3757 sb(scratch, MemOperand(dst, 0));
3762 Subu(length, length, Operand(kPointerSize));
3765 // Copy the last bytes if any left.
3767 Branch(&done, eq, length, Operand(zero_reg));
3769 lbu(scratch, MemOperand(src));
3771 sb(scratch, MemOperand(dst));
3773 Subu(length, length, Operand(1));
3774 Branch(&byte_loop_1, ne, length, Operand(zero_reg));
3779 void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
3780 Register end_offset,
3785 sw(filler, MemOperand(start_offset));
3786 Addu(start_offset, start_offset, kPointerSize);
3788 Branch(&loop, ult, start_offset, Operand(end_offset));
3792 void MacroAssembler::CheckFastElements(Register map,
3795 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
3796 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
3797 STATIC_ASSERT(FAST_ELEMENTS == 2);
3798 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
3799 lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset));
3800 Branch(fail, hi, scratch,
3801 Operand(Map::kMaximumBitField2FastHoleyElementValue));
3805 void MacroAssembler::CheckFastObjectElements(Register map,
3808 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
3809 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
3810 STATIC_ASSERT(FAST_ELEMENTS == 2);
3811 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
3812 lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset));
3813 Branch(fail, ls, scratch,
3814 Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
3815 Branch(fail, hi, scratch,
3816 Operand(Map::kMaximumBitField2FastHoleyElementValue));
3820 void MacroAssembler::CheckFastSmiElements(Register map,
3823 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
3824 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
3825 lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset));
3826 Branch(fail, hi, scratch,
3827 Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
3831 void MacroAssembler::StoreNumberToDoubleElements(Register value_reg,
3833 Register elements_reg,
3838 int elements_offset) {
3839 Label smi_value, maybe_nan, have_double_value, is_nan, done;
3840 Register mantissa_reg = scratch2;
3841 Register exponent_reg = scratch3;
3843 // Handle smi values specially.
3844 JumpIfSmi(value_reg, &smi_value);
3846 // Ensure that the object is a heap number
3849 Heap::kHeapNumberMapRootIndex,
3853 // Check for nan: all NaN values have a value greater (signed) than 0x7ff00000
3855 li(scratch1, Operand(kHoleNanUpper32 & HeapNumber::kExponentMask));
3856 lw(exponent_reg, FieldMemOperand(value_reg, HeapNumber::kExponentOffset));
3857 Branch(&maybe_nan, ge, exponent_reg, Operand(scratch1));
3859 lw(mantissa_reg, FieldMemOperand(value_reg, HeapNumber::kMantissaOffset));
3861 bind(&have_double_value);
3862 sll(scratch1, key_reg, kDoubleSizeLog2 - kSmiTagSize);
3863 Addu(scratch1, scratch1, elements_reg);
3865 FieldMemOperand(scratch1, FixedDoubleArray::kHeaderSize - elements_offset
3866 + kHoleNanLower32Offset));
3868 FieldMemOperand(scratch1, FixedDoubleArray::kHeaderSize - elements_offset
3869 + kHoleNanUpper32Offset));
3873 // Could be NaN or Infinity. If fraction is not zero, it's NaN, otherwise
3874 // it's an Infinity, and the non-NaN code path applies.
3875 Branch(&is_nan, gt, exponent_reg, Operand(scratch1));
3876 lw(mantissa_reg, FieldMemOperand(value_reg, HeapNumber::kMantissaOffset));
3877 Branch(&have_double_value, eq, mantissa_reg, Operand(zero_reg));
3879 // Load canonical NaN for storing into the double array.
3880 LoadRoot(at, Heap::kNanValueRootIndex);
3881 lw(mantissa_reg, FieldMemOperand(at, HeapNumber::kMantissaOffset));
3882 lw(exponent_reg, FieldMemOperand(at, HeapNumber::kExponentOffset));
3883 jmp(&have_double_value);
3886 Addu(scratch1, elements_reg,
3887 Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag -
3889 sll(scratch2, key_reg, kDoubleSizeLog2 - kSmiTagSize);
3890 Addu(scratch1, scratch1, scratch2);
3891 // scratch1 is now effective address of the double element
3893 Register untagged_value = elements_reg;
3894 SmiUntag(untagged_value, value_reg);
3895 mtc1(untagged_value, f2);
3897 sdc1(f0, MemOperand(scratch1, 0));
3902 void MacroAssembler::CompareMapAndBranch(Register obj,
3905 Label* early_success,
3908 lw(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
3909 CompareMapAndBranch(scratch, map, early_success, cond, branch_to);
3913 void MacroAssembler::CompareMapAndBranch(Register obj_map,
3915 Label* early_success,
3918 Branch(branch_to, cond, obj_map, Operand(map));
3922 void MacroAssembler::CheckMap(Register obj,
3926 SmiCheckType smi_check_type) {
3927 if (smi_check_type == DO_SMI_CHECK) {
3928 JumpIfSmi(obj, fail);
3931 CompareMapAndBranch(obj, scratch, map, &success, ne, fail);
3936 void MacroAssembler::DispatchWeakMap(Register obj, Register scratch1,
3937 Register scratch2, Handle<WeakCell> cell,
3938 Handle<Code> success,
3939 SmiCheckType smi_check_type) {
3941 if (smi_check_type == DO_SMI_CHECK) {
3942 JumpIfSmi(obj, &fail);
3944 lw(scratch1, FieldMemOperand(obj, HeapObject::kMapOffset));
3945 GetWeakValue(scratch2, cell);
3946 Jump(success, RelocInfo::CODE_TARGET, eq, scratch1, Operand(scratch2));
3951 void MacroAssembler::CheckMap(Register obj,
3953 Heap::RootListIndex index,
3955 SmiCheckType smi_check_type) {
3956 if (smi_check_type == DO_SMI_CHECK) {
3957 JumpIfSmi(obj, fail);
3959 lw(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
3960 LoadRoot(at, index);
3961 Branch(fail, ne, scratch, Operand(at));
3965 void MacroAssembler::GetWeakValue(Register value, Handle<WeakCell> cell) {
3966 li(value, Operand(cell));
3967 lw(value, FieldMemOperand(value, WeakCell::kValueOffset));
3971 void MacroAssembler::LoadWeakValue(Register value, Handle<WeakCell> cell,
3973 GetWeakValue(value, cell);
3974 JumpIfSmi(value, miss);
3978 void MacroAssembler::MovFromFloatResult(DoubleRegister dst) {
3979 if (IsMipsSoftFloatABI) {
3980 if (kArchEndian == kLittle) {
3986 Move(dst, f0); // Reg f0 is o32 ABI FP return value.
3991 void MacroAssembler::MovFromFloatParameter(DoubleRegister dst) {
3992 if (IsMipsSoftFloatABI) {
3993 if (kArchEndian == kLittle) {
3999 Move(dst, f12); // Reg f12 is o32 ABI FP first argument value.
4004 void MacroAssembler::MovToFloatParameter(DoubleRegister src) {
4005 if (!IsMipsSoftFloatABI) {
4008 if (kArchEndian == kLittle) {
4017 void MacroAssembler::MovToFloatResult(DoubleRegister src) {
4018 if (!IsMipsSoftFloatABI) {
4021 if (kArchEndian == kLittle) {
4030 void MacroAssembler::MovToFloatParameters(DoubleRegister src1,
4031 DoubleRegister src2) {
4032 if (!IsMipsSoftFloatABI) {
4034 DCHECK(!src1.is(f14));
4042 if (kArchEndian == kLittle) {
4053 // -----------------------------------------------------------------------------
4054 // JavaScript invokes.
4056 void MacroAssembler::InvokePrologue(const ParameterCount& expected,
4057 const ParameterCount& actual,
4058 Handle<Code> code_constant,
4061 bool* definitely_mismatches,
4063 const CallWrapper& call_wrapper) {
4064 bool definitely_matches = false;
4065 *definitely_mismatches = false;
4066 Label regular_invoke;
4068 // Check whether the expected and actual arguments count match. If not,
4069 // setup registers according to contract with ArgumentsAdaptorTrampoline:
4070 // a0: actual arguments count
4071 // a1: function (passed through to callee)
4072 // a2: expected arguments count
4074 // The code below is made a lot easier because the calling code already sets
4075 // up actual and expected registers according to the contract if values are
4076 // passed in registers.
4077 DCHECK(actual.is_immediate() || actual.reg().is(a0));
4078 DCHECK(expected.is_immediate() || expected.reg().is(a2));
4079 DCHECK((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(a3));
4081 if (expected.is_immediate()) {
4082 DCHECK(actual.is_immediate());
4083 if (expected.immediate() == actual.immediate()) {
4084 definitely_matches = true;
4086 li(a0, Operand(actual.immediate()));
4087 const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
4088 if (expected.immediate() == sentinel) {
4089 // Don't worry about adapting arguments for builtins that
4090 // don't want that done. Skip adaption code by making it look
4091 // like we have a match between expected and actual number of
4093 definitely_matches = true;
4095 *definitely_mismatches = true;
4096 li(a2, Operand(expected.immediate()));
4099 } else if (actual.is_immediate()) {
4100 Branch(®ular_invoke, eq, expected.reg(), Operand(actual.immediate()));
4101 li(a0, Operand(actual.immediate()));
4103 Branch(®ular_invoke, eq, expected.reg(), Operand(actual.reg()));
4106 if (!definitely_matches) {
4107 if (!code_constant.is_null()) {
4108 li(a3, Operand(code_constant));
4109 addiu(a3, a3, Code::kHeaderSize - kHeapObjectTag);
4112 Handle<Code> adaptor =
4113 isolate()->builtins()->ArgumentsAdaptorTrampoline();
4114 if (flag == CALL_FUNCTION) {
4115 call_wrapper.BeforeCall(CallSize(adaptor));
4117 call_wrapper.AfterCall();
4118 if (!*definitely_mismatches) {
4122 Jump(adaptor, RelocInfo::CODE_TARGET);
4124 bind(®ular_invoke);
4129 void MacroAssembler::InvokeCode(Register code,
4130 const ParameterCount& expected,
4131 const ParameterCount& actual,
4133 const CallWrapper& call_wrapper) {
4134 // You can't call a function without a valid frame.
4135 DCHECK(flag == JUMP_FUNCTION || has_frame());
4139 bool definitely_mismatches = false;
4140 InvokePrologue(expected, actual, Handle<Code>::null(), code,
4141 &done, &definitely_mismatches, flag,
4143 if (!definitely_mismatches) {
4144 if (flag == CALL_FUNCTION) {
4145 call_wrapper.BeforeCall(CallSize(code));
4147 call_wrapper.AfterCall();
4149 DCHECK(flag == JUMP_FUNCTION);
4152 // Continue here if InvokePrologue does handle the invocation due to
4153 // mismatched parameter counts.
4159 void MacroAssembler::InvokeFunction(Register function,
4160 const ParameterCount& actual,
4162 const CallWrapper& call_wrapper) {
4163 // You can't call a function without a valid frame.
4164 DCHECK(flag == JUMP_FUNCTION || has_frame());
4166 // Contract with called JS functions requires that function is passed in a1.
4167 DCHECK(function.is(a1));
4168 Register expected_reg = a2;
4169 Register code_reg = a3;
4171 lw(code_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
4172 lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
4174 FieldMemOperand(code_reg,
4175 SharedFunctionInfo::kFormalParameterCountOffset));
4176 sra(expected_reg, expected_reg, kSmiTagSize);
4177 lw(code_reg, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
4179 ParameterCount expected(expected_reg);
4180 InvokeCode(code_reg, expected, actual, flag, call_wrapper);
4184 void MacroAssembler::InvokeFunction(Register function,
4185 const ParameterCount& expected,
4186 const ParameterCount& actual,
4188 const CallWrapper& call_wrapper) {
4189 // You can't call a function without a valid frame.
4190 DCHECK(flag == JUMP_FUNCTION || has_frame());
4192 // Contract with called JS functions requires that function is passed in a1.
4193 DCHECK(function.is(a1));
4195 // Get the function and setup the context.
4196 lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
4198 // We call indirectly through the code field in the function to
4199 // allow recompilation to take effect without changing any of the
4201 lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
4202 InvokeCode(a3, expected, actual, flag, call_wrapper);
4206 void MacroAssembler::InvokeFunction(Handle<JSFunction> function,
4207 const ParameterCount& expected,
4208 const ParameterCount& actual,
4210 const CallWrapper& call_wrapper) {
4212 InvokeFunction(a1, expected, actual, flag, call_wrapper);
4216 void MacroAssembler::IsObjectJSObjectType(Register heap_object,
4220 lw(map, FieldMemOperand(heap_object, HeapObject::kMapOffset));
4221 IsInstanceJSObjectType(map, scratch, fail);
4225 void MacroAssembler::IsInstanceJSObjectType(Register map,
4228 lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset));
4229 Branch(fail, lt, scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
4230 Branch(fail, gt, scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
4234 void MacroAssembler::IsObjectJSStringType(Register object,
4237 DCHECK(kNotStringTag != 0);
4239 lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
4240 lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
4241 And(scratch, scratch, Operand(kIsNotStringMask));
4242 Branch(fail, ne, scratch, Operand(zero_reg));
4246 void MacroAssembler::IsObjectNameType(Register object,
4249 lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
4250 lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
4251 Branch(fail, hi, scratch, Operand(LAST_NAME_TYPE));
4255 // ---------------------------------------------------------------------------
4256 // Support functions.
4259 void MacroAssembler::GetMapConstructor(Register result, Register map,
4260 Register temp, Register temp2) {
4262 lw(result, FieldMemOperand(map, Map::kConstructorOrBackPointerOffset));
4264 JumpIfSmi(result, &done);
4265 GetObjectType(result, temp, temp2);
4266 Branch(&done, ne, temp2, Operand(MAP_TYPE));
4267 lw(result, FieldMemOperand(result, Map::kConstructorOrBackPointerOffset));
4273 void MacroAssembler::TryGetFunctionPrototype(Register function, Register result,
4274 Register scratch, Label* miss) {
4275 // Get the prototype or initial map from the function.
4277 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
4279 // If the prototype or initial map is the hole, don't return it and
4280 // simply miss the cache instead. This will allow us to allocate a
4281 // prototype object on-demand in the runtime system.
4282 LoadRoot(t8, Heap::kTheHoleValueRootIndex);
4283 Branch(miss, eq, result, Operand(t8));
4285 // If the function does not have an initial map, we're done.
4287 GetObjectType(result, scratch, scratch);
4288 Branch(&done, ne, scratch, Operand(MAP_TYPE));
4290 // Get the prototype from the initial map.
4291 lw(result, FieldMemOperand(result, Map::kPrototypeOffset));
4298 void MacroAssembler::GetObjectType(Register object,
4300 Register type_reg) {
4301 lw(map, FieldMemOperand(object, HeapObject::kMapOffset));
4302 lbu(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
4306 // -----------------------------------------------------------------------------
4309 void MacroAssembler::CallStub(CodeStub* stub,
4310 TypeFeedbackId ast_id,
4314 BranchDelaySlot bd) {
4315 DCHECK(AllowThisStubCall(stub)); // Stub calls are not allowed in some stubs.
4316 Call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id,
4321 void MacroAssembler::TailCallStub(CodeStub* stub,
4325 BranchDelaySlot bd) {
4326 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond, r1, r2, bd);
4330 bool MacroAssembler::AllowThisStubCall(CodeStub* stub) {
4331 return has_frame_ || !stub->SometimesSetsUpAFrame();
4335 void MacroAssembler::IndexFromHash(Register hash, Register index) {
4336 // If the hash field contains an array index pick it out. The assert checks
4337 // that the constants for the maximum number of digits for an array index
4338 // cached in the hash field and the number of bits reserved for it does not
4340 DCHECK(TenToThe(String::kMaxCachedArrayIndexLength) <
4341 (1 << String::kArrayIndexValueBits));
4342 DecodeFieldToSmi<String::ArrayIndexValueBits>(index, hash);
4346 void MacroAssembler::ObjectToDoubleFPURegister(Register object,
4350 Register heap_number_map,
4352 ObjectToDoubleFlags flags) {
4354 if ((flags & OBJECT_NOT_SMI) == 0) {
4356 JumpIfNotSmi(object, ¬_smi);
4357 // Remove smi tag and convert to double.
4358 sra(scratch1, object, kSmiTagSize);
4359 mtc1(scratch1, result);
4360 cvt_d_w(result, result);
4364 // Check for heap number and load double value from it.
4365 lw(scratch1, FieldMemOperand(object, HeapObject::kMapOffset));
4366 Branch(not_number, ne, scratch1, Operand(heap_number_map));
4368 if ((flags & AVOID_NANS_AND_INFINITIES) != 0) {
4369 // If exponent is all ones the number is either a NaN or +/-Infinity.
4370 Register exponent = scratch1;
4371 Register mask_reg = scratch2;
4372 lw(exponent, FieldMemOperand(object, HeapNumber::kExponentOffset));
4373 li(mask_reg, HeapNumber::kExponentMask);
4375 And(exponent, exponent, mask_reg);
4376 Branch(not_number, eq, exponent, Operand(mask_reg));
4378 ldc1(result, FieldMemOperand(object, HeapNumber::kValueOffset));
4383 void MacroAssembler::SmiToDoubleFPURegister(Register smi,
4385 Register scratch1) {
4386 sra(scratch1, smi, kSmiTagSize);
4387 mtc1(scratch1, value);
4388 cvt_d_w(value, value);
4392 void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left,
4393 const Operand& right,
4394 Register overflow_dst,
4396 if (right.is_reg()) {
4397 AdduAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
4400 mov(scratch, left); // Preserve left.
4401 Addu(dst, left, right.immediate()); // Left is overwritten.
4402 xor_(scratch, dst, scratch); // Original left.
4403 // Load right since xori takes uint16 as immediate.
4404 Addu(t9, zero_reg, right);
4405 xor_(overflow_dst, dst, t9);
4406 and_(overflow_dst, overflow_dst, scratch);
4408 Addu(dst, left, right.immediate());
4409 xor_(overflow_dst, dst, left);
4410 // Load right since xori takes uint16 as immediate.
4411 Addu(t9, zero_reg, right);
4412 xor_(scratch, dst, t9);
4413 and_(overflow_dst, scratch, overflow_dst);
4419 void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left,
4421 Register overflow_dst,
4423 DCHECK(!dst.is(overflow_dst));
4424 DCHECK(!dst.is(scratch));
4425 DCHECK(!overflow_dst.is(scratch));
4426 DCHECK(!overflow_dst.is(left));
4427 DCHECK(!overflow_dst.is(right));
4429 if (left.is(right) && dst.is(left)) {
4430 DCHECK(!dst.is(t9));
4431 DCHECK(!scratch.is(t9));
4432 DCHECK(!left.is(t9));
4433 DCHECK(!right.is(t9));
4434 DCHECK(!overflow_dst.is(t9));
4440 mov(scratch, left); // Preserve left.
4441 addu(dst, left, right); // Left is overwritten.
4442 xor_(scratch, dst, scratch); // Original left.
4443 xor_(overflow_dst, dst, right);
4444 and_(overflow_dst, overflow_dst, scratch);
4445 } else if (dst.is(right)) {
4446 mov(scratch, right); // Preserve right.
4447 addu(dst, left, right); // Right is overwritten.
4448 xor_(scratch, dst, scratch); // Original right.
4449 xor_(overflow_dst, dst, left);
4450 and_(overflow_dst, overflow_dst, scratch);
4452 addu(dst, left, right);
4453 xor_(overflow_dst, dst, left);
4454 xor_(scratch, dst, right);
4455 and_(overflow_dst, scratch, overflow_dst);
4460 void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left,
4461 const Operand& right,
4462 Register overflow_dst,
4464 if (right.is_reg()) {
4465 SubuAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
4468 mov(scratch, left); // Preserve left.
4469 Subu(dst, left, right); // Left is overwritten.
4470 xor_(overflow_dst, dst, scratch); // scratch is original left.
4471 // Load right since xori takes uint16 as immediate.
4472 Addu(t9, zero_reg, right);
4473 xor_(scratch, scratch, t9); // scratch is original left.
4474 and_(overflow_dst, scratch, overflow_dst);
4476 Subu(dst, left, right);
4477 xor_(overflow_dst, dst, left);
4478 // Load right since xori takes uint16 as immediate.
4479 Addu(t9, zero_reg, right);
4480 xor_(scratch, left, t9);
4481 and_(overflow_dst, scratch, overflow_dst);
4487 void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left,
4489 Register overflow_dst,
4491 DCHECK(!dst.is(overflow_dst));
4492 DCHECK(!dst.is(scratch));
4493 DCHECK(!overflow_dst.is(scratch));
4494 DCHECK(!overflow_dst.is(left));
4495 DCHECK(!overflow_dst.is(right));
4496 DCHECK(!scratch.is(left));
4497 DCHECK(!scratch.is(right));
4499 // This happens with some crankshaft code. Since Subu works fine if
4500 // left == right, let's not make that restriction here.
4501 if (left.is(right)) {
4503 mov(overflow_dst, zero_reg);
4508 mov(scratch, left); // Preserve left.
4509 subu(dst, left, right); // Left is overwritten.
4510 xor_(overflow_dst, dst, scratch); // scratch is original left.
4511 xor_(scratch, scratch, right); // scratch is original left.
4512 and_(overflow_dst, scratch, overflow_dst);
4513 } else if (dst.is(right)) {
4514 mov(scratch, right); // Preserve right.
4515 subu(dst, left, right); // Right is overwritten.
4516 xor_(overflow_dst, dst, left);
4517 xor_(scratch, left, scratch); // Original right.
4518 and_(overflow_dst, scratch, overflow_dst);
4520 subu(dst, left, right);
4521 xor_(overflow_dst, dst, left);
4522 xor_(scratch, left, right);
4523 and_(overflow_dst, scratch, overflow_dst);
4528 void MacroAssembler::CallRuntime(const Runtime::Function* f, int num_arguments,
4529 SaveFPRegsMode save_doubles,
4530 BranchDelaySlot bd) {
4531 // All parameters are on the stack. v0 has the return value after call.
4533 // If the expected number of arguments of the runtime function is
4534 // constant, we check that the actual number of arguments match the
4536 CHECK(f->nargs < 0 || f->nargs == num_arguments);
4538 // TODO(1236192): Most runtime routines don't need the number of
4539 // arguments passed in because it is constant. At some point we
4540 // should remove this need and make the runtime routine entry code
4542 PrepareCEntryArgs(num_arguments);
4543 PrepareCEntryFunction(ExternalReference(f, isolate()));
4544 CEntryStub stub(isolate(), 1, save_doubles);
4545 CallStub(&stub, TypeFeedbackId::None(), al, zero_reg, Operand(zero_reg), bd);
4549 void MacroAssembler::CallExternalReference(const ExternalReference& ext,
4551 BranchDelaySlot bd) {
4552 PrepareCEntryArgs(num_arguments);
4553 PrepareCEntryFunction(ext);
4555 CEntryStub stub(isolate(), 1);
4556 CallStub(&stub, TypeFeedbackId::None(), al, zero_reg, Operand(zero_reg), bd);
4560 void MacroAssembler::TailCallExternalReference(const ExternalReference& ext,
4563 // TODO(1236192): Most runtime routines don't need the number of
4564 // arguments passed in because it is constant. At some point we
4565 // should remove this need and make the runtime routine entry code
4567 PrepareCEntryArgs(num_arguments);
4568 JumpToExternalReference(ext);
4572 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
4575 TailCallExternalReference(ExternalReference(fid, isolate()),
4581 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin,
4582 BranchDelaySlot bd) {
4583 PrepareCEntryFunction(builtin);
4584 CEntryStub stub(isolate(), 1);
4585 Jump(stub.GetCode(),
4586 RelocInfo::CODE_TARGET,
4594 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
4596 const CallWrapper& call_wrapper) {
4597 // You can't call a builtin without a valid frame.
4598 DCHECK(flag == JUMP_FUNCTION || has_frame());
4600 GetBuiltinEntry(t9, id);
4601 if (flag == CALL_FUNCTION) {
4602 call_wrapper.BeforeCall(CallSize(t9));
4604 call_wrapper.AfterCall();
4606 DCHECK(flag == JUMP_FUNCTION);
4612 void MacroAssembler::GetBuiltinFunction(Register target,
4613 Builtins::JavaScript id) {
4614 // Load the builtins object into target register.
4615 lw(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
4616 lw(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset));
4617 // Load the JavaScript builtin function from the builtins object.
4618 lw(target, FieldMemOperand(target,
4619 JSBuiltinsObject::OffsetOfFunctionWithId(id)));
4623 void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
4624 DCHECK(!target.is(a1));
4625 GetBuiltinFunction(a1, id);
4626 // Load the code entry point from the builtins object.
4627 lw(target, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
4631 void MacroAssembler::SetCounter(StatsCounter* counter, int value,
4632 Register scratch1, Register scratch2) {
4633 if (FLAG_native_code_counters && counter->Enabled()) {
4634 li(scratch1, Operand(value));
4635 li(scratch2, Operand(ExternalReference(counter)));
4636 sw(scratch1, MemOperand(scratch2));
4641 void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
4642 Register scratch1, Register scratch2) {
4644 if (FLAG_native_code_counters && counter->Enabled()) {
4645 li(scratch2, Operand(ExternalReference(counter)));
4646 lw(scratch1, MemOperand(scratch2));
4647 Addu(scratch1, scratch1, Operand(value));
4648 sw(scratch1, MemOperand(scratch2));
4653 void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
4654 Register scratch1, Register scratch2) {
4656 if (FLAG_native_code_counters && counter->Enabled()) {
4657 li(scratch2, Operand(ExternalReference(counter)));
4658 lw(scratch1, MemOperand(scratch2));
4659 Subu(scratch1, scratch1, Operand(value));
4660 sw(scratch1, MemOperand(scratch2));
4665 // -----------------------------------------------------------------------------
4668 void MacroAssembler::Assert(Condition cc, BailoutReason reason,
4669 Register rs, Operand rt) {
4670 if (emit_debug_code())
4671 Check(cc, reason, rs, rt);
4675 void MacroAssembler::AssertFastElements(Register elements) {
4676 if (emit_debug_code()) {
4677 DCHECK(!elements.is(at));
4680 lw(elements, FieldMemOperand(elements, HeapObject::kMapOffset));
4681 LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4682 Branch(&ok, eq, elements, Operand(at));
4683 LoadRoot(at, Heap::kFixedDoubleArrayMapRootIndex);
4684 Branch(&ok, eq, elements, Operand(at));
4685 LoadRoot(at, Heap::kFixedCOWArrayMapRootIndex);
4686 Branch(&ok, eq, elements, Operand(at));
4687 Abort(kJSObjectWithFastElementsMapHasSlowElements);
4694 void MacroAssembler::Check(Condition cc, BailoutReason reason,
4695 Register rs, Operand rt) {
4697 Branch(&L, cc, rs, rt);
4699 // Will not return here.
4704 void MacroAssembler::Abort(BailoutReason reason) {
4708 const char* msg = GetBailoutReason(reason);
4710 RecordComment("Abort message: ");
4714 if (FLAG_trap_on_abort) {
4720 li(a0, Operand(Smi::FromInt(reason)));
4722 // Disable stub call restrictions to always allow calls to abort.
4724 // We don't actually want to generate a pile of code for this, so just
4725 // claim there is a stack frame, without generating one.
4726 FrameScope scope(this, StackFrame::NONE);
4727 CallRuntime(Runtime::kAbort, 1);
4729 CallRuntime(Runtime::kAbort, 1);
4731 // Will not return here.
4732 if (is_trampoline_pool_blocked()) {
4733 // If the calling code cares about the exact number of
4734 // instructions generated, we insert padding here to keep the size
4735 // of the Abort macro constant.
4736 // Currently in debug mode with debug_code enabled the number of
4737 // generated instructions is 10, so we use this as a maximum value.
4738 static const int kExpectedAbortInstructions = 10;
4739 int abort_instructions = InstructionsGeneratedSince(&abort_start);
4740 DCHECK(abort_instructions <= kExpectedAbortInstructions);
4741 while (abort_instructions++ < kExpectedAbortInstructions) {
4748 void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
4749 if (context_chain_length > 0) {
4750 // Move up the chain of contexts to the context containing the slot.
4751 lw(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX)));
4752 for (int i = 1; i < context_chain_length; i++) {
4753 lw(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX)));
4756 // Slot is in the current function context. Move it into the
4757 // destination register in case we store into it (the write barrier
4758 // cannot be allowed to destroy the context in esi).
4764 void MacroAssembler::LoadTransitionedArrayMapConditional(
4765 ElementsKind expected_kind,
4766 ElementsKind transitioned_kind,
4767 Register map_in_out,
4769 Label* no_map_match) {
4770 // Load the global or builtins object from the current context.
4772 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
4773 lw(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
4775 // Check that the function's map is the same as the expected cached map.
4778 Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX)));
4779 size_t offset = expected_kind * kPointerSize +
4780 FixedArrayBase::kHeaderSize;
4781 lw(at, FieldMemOperand(scratch, offset));
4782 Branch(no_map_match, ne, map_in_out, Operand(at));
4784 // Use the transitioned cached map.
4785 offset = transitioned_kind * kPointerSize +
4786 FixedArrayBase::kHeaderSize;
4787 lw(map_in_out, FieldMemOperand(scratch, offset));
4791 void MacroAssembler::LoadGlobalFunction(int index, Register function) {
4792 // Load the global or builtins object from the current context.
4794 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
4795 // Load the native context from the global or builtins object.
4796 lw(function, FieldMemOperand(function,
4797 GlobalObject::kNativeContextOffset));
4798 // Load the function from the native context.
4799 lw(function, MemOperand(function, Context::SlotOffset(index)));
4803 void MacroAssembler::LoadGlobalFunctionInitialMap(Register function,
4806 // Load the initial map. The global functions all have initial maps.
4807 lw(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
4808 if (emit_debug_code()) {
4810 CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK);
4813 Abort(kGlobalFunctionsMustHaveInitialMap);
4819 void MacroAssembler::StubPrologue() {
4821 Push(Smi::FromInt(StackFrame::STUB));
4822 // Adjust FP to point to saved FP.
4823 Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
4827 void MacroAssembler::Prologue(bool code_pre_aging) {
4828 PredictableCodeSizeScope predictible_code_size_scope(
4829 this, kNoCodeAgeSequenceLength);
4830 // The following three instructions must remain together and unmodified
4831 // for code aging to work properly.
4832 if (code_pre_aging) {
4833 // Pre-age the code.
4834 Code* stub = Code::GetPreAgedCodeAgeStub(isolate());
4835 nop(Assembler::CODE_AGE_MARKER_NOP);
4836 // Load the stub address to t9 and call it,
4837 // GetCodeAgeAndParity() extracts the stub address from this instruction.
4839 Operand(reinterpret_cast<uint32_t>(stub->instruction_start())),
4841 nop(); // Prevent jalr to jal optimization.
4843 nop(); // Branch delay slot nop.
4844 nop(); // Pad the empty space.
4846 Push(ra, fp, cp, a1);
4847 nop(Assembler::CODE_AGE_SEQUENCE_NOP);
4848 // Adjust fp to point to caller's fp.
4849 Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
4854 void MacroAssembler::EnterFrame(StackFrame::Type type,
4855 bool load_constant_pool_pointer_reg) {
4856 // Out-of-line constant pool not implemented on mips.
4861 void MacroAssembler::EnterFrame(StackFrame::Type type) {
4862 addiu(sp, sp, -5 * kPointerSize);
4863 li(t8, Operand(Smi::FromInt(type)));
4864 li(t9, Operand(CodeObject()), CONSTANT_SIZE);
4865 sw(ra, MemOperand(sp, 4 * kPointerSize));
4866 sw(fp, MemOperand(sp, 3 * kPointerSize));
4867 sw(cp, MemOperand(sp, 2 * kPointerSize));
4868 sw(t8, MemOperand(sp, 1 * kPointerSize));
4869 sw(t9, MemOperand(sp, 0 * kPointerSize));
4870 // Adjust FP to point to saved FP.
4872 Operand(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize));
4876 void MacroAssembler::LeaveFrame(StackFrame::Type type) {
4878 lw(fp, MemOperand(sp, 0 * kPointerSize));
4879 lw(ra, MemOperand(sp, 1 * kPointerSize));
4880 addiu(sp, sp, 2 * kPointerSize);
4884 void MacroAssembler::EnterExitFrame(bool save_doubles,
4886 // Set up the frame structure on the stack.
4887 STATIC_ASSERT(2 * kPointerSize == ExitFrameConstants::kCallerSPDisplacement);
4888 STATIC_ASSERT(1 * kPointerSize == ExitFrameConstants::kCallerPCOffset);
4889 STATIC_ASSERT(0 * kPointerSize == ExitFrameConstants::kCallerFPOffset);
4891 // This is how the stack will look:
4892 // fp + 2 (==kCallerSPDisplacement) - old stack's end
4893 // [fp + 1 (==kCallerPCOffset)] - saved old ra
4894 // [fp + 0 (==kCallerFPOffset)] - saved old fp
4895 // [fp - 1 (==kSPOffset)] - sp of the called function
4896 // [fp - 2 (==kCodeOffset)] - CodeObject
4897 // fp - (2 + stack_space + alignment) == sp == [fp - kSPOffset] - top of the
4898 // new stack (will contain saved ra)
4901 addiu(sp, sp, -4 * kPointerSize);
4902 sw(ra, MemOperand(sp, 3 * kPointerSize));
4903 sw(fp, MemOperand(sp, 2 * kPointerSize));
4904 addiu(fp, sp, 2 * kPointerSize); // Set up new frame pointer.
4906 if (emit_debug_code()) {
4907 sw(zero_reg, MemOperand(fp, ExitFrameConstants::kSPOffset));
4910 // Accessed from ExitFrame::code_slot.
4911 li(t8, Operand(CodeObject()), CONSTANT_SIZE);
4912 sw(t8, MemOperand(fp, ExitFrameConstants::kCodeOffset));
4914 // Save the frame pointer and the context in top.
4915 li(t8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
4916 sw(fp, MemOperand(t8));
4917 li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
4918 sw(cp, MemOperand(t8));
4920 const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
4922 // The stack must be allign to 0 modulo 8 for stores with sdc1.
4923 DCHECK(kDoubleSize == frame_alignment);
4924 if (frame_alignment > 0) {
4925 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4926 And(sp, sp, Operand(-frame_alignment)); // Align stack.
4928 int space = FPURegister::kMaxNumRegisters * kDoubleSize;
4929 Subu(sp, sp, Operand(space));
4930 // Remember: we only need to save every 2nd double FPU value.
4931 for (int i = 0; i < FPURegister::kMaxNumRegisters; i+=2) {
4932 FPURegister reg = FPURegister::from_code(i);
4933 sdc1(reg, MemOperand(sp, i * kDoubleSize));
4937 // Reserve place for the return address, stack space and an optional slot
4938 // (used by the DirectCEntryStub to hold the return value if a struct is
4939 // returned) and align the frame preparing for calling the runtime function.
4940 DCHECK(stack_space >= 0);
4941 Subu(sp, sp, Operand((stack_space + 2) * kPointerSize));
4942 if (frame_alignment > 0) {
4943 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
4944 And(sp, sp, Operand(-frame_alignment)); // Align stack.
4947 // Set the exit frame sp value to point just before the return address
4949 addiu(at, sp, kPointerSize);
4950 sw(at, MemOperand(fp, ExitFrameConstants::kSPOffset));
4954 void MacroAssembler::LeaveExitFrame(bool save_doubles, Register argument_count,
4955 bool restore_context, bool do_return,
4956 bool argument_count_is_length) {
4957 // Optionally restore all double registers.
4959 // Remember: we only need to restore every 2nd double FPU value.
4960 lw(t8, MemOperand(fp, ExitFrameConstants::kSPOffset));
4961 for (int i = 0; i < FPURegister::kMaxNumRegisters; i+=2) {
4962 FPURegister reg = FPURegister::from_code(i);
4963 ldc1(reg, MemOperand(t8, i * kDoubleSize + kPointerSize));
4968 li(t8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
4969 sw(zero_reg, MemOperand(t8));
4971 // Restore current context from top and clear it in debug mode.
4972 if (restore_context) {
4973 li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
4974 lw(cp, MemOperand(t8));
4977 li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
4978 sw(a3, MemOperand(t8));
4981 // Pop the arguments, restore registers, and return.
4982 mov(sp, fp); // Respect ABI stack constraint.
4983 lw(fp, MemOperand(sp, ExitFrameConstants::kCallerFPOffset));
4984 lw(ra, MemOperand(sp, ExitFrameConstants::kCallerPCOffset));
4986 if (argument_count.is_valid()) {
4987 if (argument_count_is_length) {
4988 addu(sp, sp, argument_count);
4990 sll(t8, argument_count, kPointerSizeLog2);
4996 Ret(USE_DELAY_SLOT);
4997 // If returning, the instruction in the delay slot will be the addiu below.
5003 void MacroAssembler::InitializeNewString(Register string,
5005 Heap::RootListIndex map_index,
5007 Register scratch2) {
5008 sll(scratch1, length, kSmiTagSize);
5009 LoadRoot(scratch2, map_index);
5010 sw(scratch1, FieldMemOperand(string, String::kLengthOffset));
5011 li(scratch1, Operand(String::kEmptyHashField));
5012 sw(scratch2, FieldMemOperand(string, HeapObject::kMapOffset));
5013 sw(scratch1, FieldMemOperand(string, String::kHashFieldOffset));
5017 int MacroAssembler::ActivationFrameAlignment() {
5018 #if V8_HOST_ARCH_MIPS
5019 // Running on the real platform. Use the alignment as mandated by the local
5021 // Note: This will break if we ever start generating snapshots on one Mips
5022 // platform for another Mips platform with a different alignment.
5023 return base::OS::ActivationFrameAlignment();
5024 #else // V8_HOST_ARCH_MIPS
5025 // If we are using the simulator then we should always align to the expected
5026 // alignment. As the simulator is used to generate snapshots we do not know
5027 // if the target platform will need alignment, so this is controlled from a
5029 return FLAG_sim_stack_alignment;
5030 #endif // V8_HOST_ARCH_MIPS
5034 void MacroAssembler::AssertStackIsAligned() {
5035 if (emit_debug_code()) {
5036 const int frame_alignment = ActivationFrameAlignment();
5037 const int frame_alignment_mask = frame_alignment - 1;
5039 if (frame_alignment > kPointerSize) {
5040 Label alignment_as_expected;
5041 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5042 andi(at, sp, frame_alignment_mask);
5043 Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
5044 // Don't use Check here, as it will call Runtime_Abort re-entering here.
5045 stop("Unexpected stack alignment");
5046 bind(&alignment_as_expected);
5052 void MacroAssembler::JumpIfNotPowerOfTwoOrZero(
5055 Label* not_power_of_two_or_zero) {
5056 Subu(scratch, reg, Operand(1));
5057 Branch(USE_DELAY_SLOT, not_power_of_two_or_zero, lt,
5058 scratch, Operand(zero_reg));
5059 and_(at, scratch, reg); // In the delay slot.
5060 Branch(not_power_of_two_or_zero, ne, at, Operand(zero_reg));
5064 void MacroAssembler::SmiTagCheckOverflow(Register reg, Register overflow) {
5065 DCHECK(!reg.is(overflow));
5066 mov(overflow, reg); // Save original value.
5068 xor_(overflow, overflow, reg); // Overflow if (value ^ 2 * value) < 0.
5072 void MacroAssembler::SmiTagCheckOverflow(Register dst,
5074 Register overflow) {
5076 // Fall back to slower case.
5077 SmiTagCheckOverflow(dst, overflow);
5079 DCHECK(!dst.is(src));
5080 DCHECK(!dst.is(overflow));
5081 DCHECK(!src.is(overflow));
5083 xor_(overflow, dst, src); // Overflow if (value ^ 2 * value) < 0.
5088 void MacroAssembler::UntagAndJumpIfSmi(Register dst,
5091 JumpIfSmi(src, smi_case, at, USE_DELAY_SLOT);
5096 void MacroAssembler::UntagAndJumpIfNotSmi(Register dst,
5098 Label* non_smi_case) {
5099 JumpIfNotSmi(src, non_smi_case, at, USE_DELAY_SLOT);
5103 void MacroAssembler::JumpIfSmi(Register value,
5106 BranchDelaySlot bd) {
5107 DCHECK_EQ(0, kSmiTag);
5108 andi(scratch, value, kSmiTagMask);
5109 Branch(bd, smi_label, eq, scratch, Operand(zero_reg));
5112 void MacroAssembler::JumpIfNotSmi(Register value,
5113 Label* not_smi_label,
5115 BranchDelaySlot bd) {
5116 DCHECK_EQ(0, kSmiTag);
5117 andi(scratch, value, kSmiTagMask);
5118 Branch(bd, not_smi_label, ne, scratch, Operand(zero_reg));
5122 void MacroAssembler::JumpIfNotBothSmi(Register reg1,
5124 Label* on_not_both_smi) {
5125 STATIC_ASSERT(kSmiTag == 0);
5126 DCHECK_EQ(1, kSmiTagMask);
5127 or_(at, reg1, reg2);
5128 JumpIfNotSmi(at, on_not_both_smi);
5132 void MacroAssembler::JumpIfEitherSmi(Register reg1,
5134 Label* on_either_smi) {
5135 STATIC_ASSERT(kSmiTag == 0);
5136 DCHECK_EQ(1, kSmiTagMask);
5137 // Both Smi tags must be 1 (not Smi).
5138 and_(at, reg1, reg2);
5139 JumpIfSmi(at, on_either_smi);
5143 void MacroAssembler::AssertNotSmi(Register object) {
5144 if (emit_debug_code()) {
5145 STATIC_ASSERT(kSmiTag == 0);
5146 andi(at, object, kSmiTagMask);
5147 Check(ne, kOperandIsASmi, at, Operand(zero_reg));
5152 void MacroAssembler::AssertSmi(Register object) {
5153 if (emit_debug_code()) {
5154 STATIC_ASSERT(kSmiTag == 0);
5155 andi(at, object, kSmiTagMask);
5156 Check(eq, kOperandIsASmi, at, Operand(zero_reg));
5161 void MacroAssembler::AssertString(Register object) {
5162 if (emit_debug_code()) {
5163 STATIC_ASSERT(kSmiTag == 0);
5165 Check(ne, kOperandIsASmiAndNotAString, t0, Operand(zero_reg));
5167 lw(object, FieldMemOperand(object, HeapObject::kMapOffset));
5168 lbu(object, FieldMemOperand(object, Map::kInstanceTypeOffset));
5169 Check(lo, kOperandIsNotAString, object, Operand(FIRST_NONSTRING_TYPE));
5175 void MacroAssembler::AssertName(Register object) {
5176 if (emit_debug_code()) {
5177 STATIC_ASSERT(kSmiTag == 0);
5179 Check(ne, kOperandIsASmiAndNotAName, t0, Operand(zero_reg));
5181 lw(object, FieldMemOperand(object, HeapObject::kMapOffset));
5182 lbu(object, FieldMemOperand(object, Map::kInstanceTypeOffset));
5183 Check(le, kOperandIsNotAName, object, Operand(LAST_NAME_TYPE));
5189 void MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
5191 if (emit_debug_code()) {
5192 Label done_checking;
5193 AssertNotSmi(object);
5194 LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5195 Branch(&done_checking, eq, object, Operand(scratch));
5197 lw(object, FieldMemOperand(object, HeapObject::kMapOffset));
5198 LoadRoot(scratch, Heap::kAllocationSiteMapRootIndex);
5199 Assert(eq, kExpectedUndefinedOrCell, object, Operand(scratch));
5201 bind(&done_checking);
5206 void MacroAssembler::AssertIsRoot(Register reg, Heap::RootListIndex index) {
5207 if (emit_debug_code()) {
5208 DCHECK(!reg.is(at));
5209 LoadRoot(at, index);
5210 Check(eq, kHeapNumberMapRegisterClobbered, reg, Operand(at));
5215 void MacroAssembler::JumpIfNotHeapNumber(Register object,
5216 Register heap_number_map,
5218 Label* on_not_heap_number) {
5219 lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
5220 AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
5221 Branch(on_not_heap_number, ne, scratch, Operand(heap_number_map));
5225 void MacroAssembler::LookupNumberStringCache(Register object,
5231 // Use of registers. Register result is used as a temporary.
5232 Register number_string_cache = result;
5233 Register mask = scratch3;
5235 // Load the number string cache.
5236 LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex);
5238 // Make the hash mask from the length of the number string cache. It
5239 // contains two elements (number and string) for each cache entry.
5240 lw(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset));
5241 // Divide length by two (length is a smi).
5242 sra(mask, mask, kSmiTagSize + 1);
5243 Addu(mask, mask, -1); // Make mask.
5245 // Calculate the entry in the number string cache. The hash value in the
5246 // number string cache for smis is just the smi value, and the hash for
5247 // doubles is the xor of the upper and lower words. See
5248 // Heap::GetNumberStringCache.
5250 Label load_result_from_cache;
5251 JumpIfSmi(object, &is_smi);
5254 Heap::kHeapNumberMapRootIndex,
5258 STATIC_ASSERT(8 == kDoubleSize);
5261 Operand(HeapNumber::kValueOffset - kHeapObjectTag));
5262 lw(scratch2, MemOperand(scratch1, kPointerSize));
5263 lw(scratch1, MemOperand(scratch1, 0));
5264 Xor(scratch1, scratch1, Operand(scratch2));
5265 And(scratch1, scratch1, Operand(mask));
5267 // Calculate address of entry in string cache: each entry consists
5268 // of two pointer sized fields.
5269 sll(scratch1, scratch1, kPointerSizeLog2 + 1);
5270 Addu(scratch1, number_string_cache, scratch1);
5272 Register probe = mask;
5273 lw(probe, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
5274 JumpIfSmi(probe, not_found);
5275 ldc1(f12, FieldMemOperand(object, HeapNumber::kValueOffset));
5276 ldc1(f14, FieldMemOperand(probe, HeapNumber::kValueOffset));
5277 BranchF(&load_result_from_cache, NULL, eq, f12, f14);
5281 Register scratch = scratch1;
5282 sra(scratch, object, 1); // Shift away the tag.
5283 And(scratch, mask, Operand(scratch));
5285 // Calculate address of entry in string cache: each entry consists
5286 // of two pointer sized fields.
5287 sll(scratch, scratch, kPointerSizeLog2 + 1);
5288 Addu(scratch, number_string_cache, scratch);
5290 // Check if the entry is the smi we are looking for.
5291 lw(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize));
5292 Branch(not_found, ne, object, Operand(probe));
5294 // Get the result from the cache.
5295 bind(&load_result_from_cache);
5296 lw(result, FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize));
5298 IncrementCounter(isolate()->counters()->number_to_string_native(),
5305 void MacroAssembler::JumpIfNonSmisNotBothSequentialOneByteStrings(
5306 Register first, Register second, Register scratch1, Register scratch2,
5308 // Test that both first and second are sequential one-byte strings.
5309 // Assume that they are non-smis.
5310 lw(scratch1, FieldMemOperand(first, HeapObject::kMapOffset));
5311 lw(scratch2, FieldMemOperand(second, HeapObject::kMapOffset));
5312 lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
5313 lbu(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset));
5315 JumpIfBothInstanceTypesAreNotSequentialOneByte(scratch1, scratch2, scratch1,
5320 void MacroAssembler::JumpIfNotBothSequentialOneByteStrings(Register first,
5325 // Check that neither is a smi.
5326 STATIC_ASSERT(kSmiTag == 0);
5327 And(scratch1, first, Operand(second));
5328 JumpIfSmi(scratch1, failure);
5329 JumpIfNonSmisNotBothSequentialOneByteStrings(first, second, scratch1,
5334 void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialOneByte(
5335 Register first, Register second, Register scratch1, Register scratch2,
5337 const int kFlatOneByteStringMask =
5338 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
5339 const int kFlatOneByteStringTag =
5340 kStringTag | kOneByteStringTag | kSeqStringTag;
5341 DCHECK(kFlatOneByteStringTag <= 0xffff); // Ensure this fits 16-bit immed.
5342 andi(scratch1, first, kFlatOneByteStringMask);
5343 Branch(failure, ne, scratch1, Operand(kFlatOneByteStringTag));
5344 andi(scratch2, second, kFlatOneByteStringMask);
5345 Branch(failure, ne, scratch2, Operand(kFlatOneByteStringTag));
5349 void MacroAssembler::JumpIfInstanceTypeIsNotSequentialOneByte(Register type,
5352 const int kFlatOneByteStringMask =
5353 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
5354 const int kFlatOneByteStringTag =
5355 kStringTag | kOneByteStringTag | kSeqStringTag;
5356 And(scratch, type, Operand(kFlatOneByteStringMask));
5357 Branch(failure, ne, scratch, Operand(kFlatOneByteStringTag));
5361 static const int kRegisterPassedArguments = 4;
5363 int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments,
5364 int num_double_arguments) {
5365 int stack_passed_words = 0;
5366 num_reg_arguments += 2 * num_double_arguments;
5368 // Up to four simple arguments are passed in registers a0..a3.
5369 if (num_reg_arguments > kRegisterPassedArguments) {
5370 stack_passed_words += num_reg_arguments - kRegisterPassedArguments;
5372 stack_passed_words += kCArgSlotCount;
5373 return stack_passed_words;
5377 void MacroAssembler::EmitSeqStringSetCharCheck(Register string,
5381 uint32_t encoding_mask) {
5384 Check(ne, kNonObject, at, Operand(zero_reg));
5386 lw(at, FieldMemOperand(string, HeapObject::kMapOffset));
5387 lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset));
5389 andi(at, at, kStringRepresentationMask | kStringEncodingMask);
5390 li(scratch, Operand(encoding_mask));
5391 Check(eq, kUnexpectedStringType, at, Operand(scratch));
5393 // The index is assumed to be untagged coming in, tag it to compare with the
5394 // string length without using a temp register, it is restored at the end of
5396 Label index_tag_ok, index_tag_bad;
5397 TrySmiTag(index, scratch, &index_tag_bad);
5398 Branch(&index_tag_ok);
5399 bind(&index_tag_bad);
5400 Abort(kIndexIsTooLarge);
5401 bind(&index_tag_ok);
5403 lw(at, FieldMemOperand(string, String::kLengthOffset));
5404 Check(lt, kIndexIsTooLarge, index, Operand(at));
5406 DCHECK(Smi::FromInt(0) == 0);
5407 Check(ge, kIndexIsNegative, index, Operand(zero_reg));
5409 SmiUntag(index, index);
5413 void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
5414 int num_double_arguments,
5416 int frame_alignment = ActivationFrameAlignment();
5418 // Up to four simple arguments are passed in registers a0..a3.
5419 // Those four arguments must have reserved argument slots on the stack for
5420 // mips, even though those argument slots are not normally used.
5421 // Remaining arguments are pushed on the stack, above (higher address than)
5422 // the argument slots.
5423 int stack_passed_arguments = CalculateStackPassedWords(
5424 num_reg_arguments, num_double_arguments);
5425 if (frame_alignment > kPointerSize) {
5426 // Make stack end at alignment and make room for num_arguments - 4 words
5427 // and the original value of sp.
5429 Subu(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
5430 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5431 And(sp, sp, Operand(-frame_alignment));
5432 sw(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
5434 Subu(sp, sp, Operand(stack_passed_arguments * kPointerSize));
5439 void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
5441 PrepareCallCFunction(num_reg_arguments, 0, scratch);
5445 void MacroAssembler::CallCFunction(ExternalReference function,
5446 int num_reg_arguments,
5447 int num_double_arguments) {
5448 li(t8, Operand(function));
5449 CallCFunctionHelper(t8, num_reg_arguments, num_double_arguments);
5453 void MacroAssembler::CallCFunction(Register function,
5454 int num_reg_arguments,
5455 int num_double_arguments) {
5456 CallCFunctionHelper(function, num_reg_arguments, num_double_arguments);
5460 void MacroAssembler::CallCFunction(ExternalReference function,
5461 int num_arguments) {
5462 CallCFunction(function, num_arguments, 0);
5466 void MacroAssembler::CallCFunction(Register function,
5467 int num_arguments) {
5468 CallCFunction(function, num_arguments, 0);
5472 void MacroAssembler::CallCFunctionHelper(Register function,
5473 int num_reg_arguments,
5474 int num_double_arguments) {
5475 DCHECK(has_frame());
5476 // Make sure that the stack is aligned before calling a C function unless
5477 // running in the simulator. The simulator has its own alignment check which
5478 // provides more information.
5479 // The argument stots are presumed to have been set up by
5480 // PrepareCallCFunction. The C function must be called via t9, for mips ABI.
5482 #if V8_HOST_ARCH_MIPS
5483 if (emit_debug_code()) {
5484 int frame_alignment = base::OS::ActivationFrameAlignment();
5485 int frame_alignment_mask = frame_alignment - 1;
5486 if (frame_alignment > kPointerSize) {
5487 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5488 Label alignment_as_expected;
5489 And(at, sp, Operand(frame_alignment_mask));
5490 Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
5491 // Don't use Check here, as it will call Runtime_Abort possibly
5492 // re-entering here.
5493 stop("Unexpected alignment in CallCFunction");
5494 bind(&alignment_as_expected);
5497 #endif // V8_HOST_ARCH_MIPS
5499 // Just call directly. The function called cannot cause a GC, or
5500 // allow preemption, so the return address in the link register
5503 if (!function.is(t9)) {
5510 int stack_passed_arguments = CalculateStackPassedWords(
5511 num_reg_arguments, num_double_arguments);
5513 if (base::OS::ActivationFrameAlignment() > kPointerSize) {
5514 lw(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
5516 Addu(sp, sp, Operand(stack_passed_arguments * kPointerSize));
5521 #undef BRANCH_ARGS_CHECK
5524 void MacroAssembler::CheckPageFlag(
5529 Label* condition_met) {
5530 And(scratch, object, Operand(~Page::kPageAlignmentMask));
5531 lw(scratch, MemOperand(scratch, MemoryChunk::kFlagsOffset));
5532 And(scratch, scratch, Operand(mask));
5533 Branch(condition_met, cc, scratch, Operand(zero_reg));
5537 void MacroAssembler::JumpIfBlack(Register object,
5541 HasColor(object, scratch0, scratch1, on_black, 1, 0); // kBlackBitPattern.
5542 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
5546 void MacroAssembler::HasColor(Register object,
5547 Register bitmap_scratch,
5548 Register mask_scratch,
5552 DCHECK(!AreAliased(object, bitmap_scratch, mask_scratch, t8));
5553 DCHECK(!AreAliased(object, bitmap_scratch, mask_scratch, t9));
5555 GetMarkBits(object, bitmap_scratch, mask_scratch);
5557 Label other_color, word_boundary;
5558 lw(t9, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5559 And(t8, t9, Operand(mask_scratch));
5560 Branch(&other_color, first_bit == 1 ? eq : ne, t8, Operand(zero_reg));
5561 // Shift left 1 by adding.
5562 Addu(mask_scratch, mask_scratch, Operand(mask_scratch));
5563 Branch(&word_boundary, eq, mask_scratch, Operand(zero_reg));
5564 And(t8, t9, Operand(mask_scratch));
5565 Branch(has_color, second_bit == 1 ? ne : eq, t8, Operand(zero_reg));
5568 bind(&word_boundary);
5569 lw(t9, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize));
5570 And(t9, t9, Operand(1));
5571 Branch(has_color, second_bit == 1 ? ne : eq, t9, Operand(zero_reg));
5576 // Detect some, but not all, common pointer-free objects. This is used by the
5577 // incremental write barrier which doesn't care about oddballs (they are always
5578 // marked black immediately so this code is not hit).
5579 void MacroAssembler::JumpIfDataObject(Register value,
5581 Label* not_data_object) {
5582 DCHECK(!AreAliased(value, scratch, t8, no_reg));
5583 Label is_data_object;
5584 lw(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5585 LoadRoot(t8, Heap::kHeapNumberMapRootIndex);
5586 Branch(&is_data_object, eq, t8, Operand(scratch));
5587 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
5588 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
5589 // If it's a string and it's not a cons string then it's an object containing
5591 lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
5592 And(t8, scratch, Operand(kIsIndirectStringMask | kIsNotStringMask));
5593 Branch(not_data_object, ne, t8, Operand(zero_reg));
5594 bind(&is_data_object);
5598 void MacroAssembler::GetMarkBits(Register addr_reg,
5599 Register bitmap_reg,
5600 Register mask_reg) {
5601 DCHECK(!AreAliased(addr_reg, bitmap_reg, mask_reg, no_reg));
5602 And(bitmap_reg, addr_reg, Operand(~Page::kPageAlignmentMask));
5603 Ext(mask_reg, addr_reg, kPointerSizeLog2, Bitmap::kBitsPerCellLog2);
5604 const int kLowBits = kPointerSizeLog2 + Bitmap::kBitsPerCellLog2;
5605 Ext(t8, addr_reg, kLowBits, kPageSizeBits - kLowBits);
5606 sll(t8, t8, kPointerSizeLog2);
5607 Addu(bitmap_reg, bitmap_reg, t8);
5609 sllv(mask_reg, t8, mask_reg);
5613 void MacroAssembler::EnsureNotWhite(
5615 Register bitmap_scratch,
5616 Register mask_scratch,
5617 Register load_scratch,
5618 Label* value_is_white_and_not_data) {
5619 DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, t8));
5620 GetMarkBits(value, bitmap_scratch, mask_scratch);
5622 // If the value is black or grey we don't need to do anything.
5623 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0);
5624 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
5625 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0);
5626 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
5630 // Since both black and grey have a 1 in the first position and white does
5631 // not have a 1 there we only need to check one bit.
5632 lw(load_scratch, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5633 And(t8, mask_scratch, load_scratch);
5634 Branch(&done, ne, t8, Operand(zero_reg));
5636 if (emit_debug_code()) {
5637 // Check for impossible bit pattern.
5639 // sll may overflow, making the check conservative.
5640 sll(t8, mask_scratch, 1);
5641 And(t8, load_scratch, t8);
5642 Branch(&ok, eq, t8, Operand(zero_reg));
5643 stop("Impossible marking bit pattern");
5647 // Value is white. We check whether it is data that doesn't need scanning.
5648 // Currently only checks for HeapNumber and non-cons strings.
5649 Register map = load_scratch; // Holds map while checking type.
5650 Register length = load_scratch; // Holds length of object after testing type.
5651 Label is_data_object;
5653 // Check for heap-number
5654 lw(map, FieldMemOperand(value, HeapObject::kMapOffset));
5655 LoadRoot(t8, Heap::kHeapNumberMapRootIndex);
5658 Branch(&skip, ne, t8, Operand(map));
5659 li(length, HeapNumber::kSize);
5660 Branch(&is_data_object);
5664 // Check for strings.
5665 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
5666 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
5667 // If it's a string and it's not a cons string then it's an object containing
5669 Register instance_type = load_scratch;
5670 lbu(instance_type, FieldMemOperand(map, Map::kInstanceTypeOffset));
5671 And(t8, instance_type, Operand(kIsIndirectStringMask | kIsNotStringMask));
5672 Branch(value_is_white_and_not_data, ne, t8, Operand(zero_reg));
5673 // It's a non-indirect (non-cons and non-slice) string.
5674 // If it's external, the length is just ExternalString::kSize.
5675 // Otherwise it's String::kHeaderSize + string->length() * (1 or 2).
5676 // External strings are the only ones with the kExternalStringTag bit
5678 DCHECK_EQ(0, kSeqStringTag & kExternalStringTag);
5679 DCHECK_EQ(0, kConsStringTag & kExternalStringTag);
5680 And(t8, instance_type, Operand(kExternalStringTag));
5683 Branch(&skip, eq, t8, Operand(zero_reg));
5684 li(length, ExternalString::kSize);
5685 Branch(&is_data_object);
5689 // Sequential string, either Latin1 or UC16.
5690 // For Latin1 (char-size of 1) we shift the smi tag away to get the length.
5691 // For UC16 (char-size of 2) we just leave the smi tag in place, thereby
5692 // getting the length multiplied by 2.
5693 DCHECK(kOneByteStringTag == 4 && kStringEncodingMask == 4);
5694 DCHECK(kSmiTag == 0 && kSmiTagSize == 1);
5695 lw(t9, FieldMemOperand(value, String::kLengthOffset));
5696 And(t8, instance_type, Operand(kStringEncodingMask));
5699 Branch(&skip, eq, t8, Operand(zero_reg));
5703 Addu(length, t9, Operand(SeqString::kHeaderSize + kObjectAlignmentMask));
5704 And(length, length, Operand(~kObjectAlignmentMask));
5706 bind(&is_data_object);
5707 // Value is a data object, and it is white. Mark it black. Since we know
5708 // that the object is white we can make it black by flipping one bit.
5709 lw(t8, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5710 Or(t8, t8, Operand(mask_scratch));
5711 sw(t8, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5713 And(bitmap_scratch, bitmap_scratch, Operand(~Page::kPageAlignmentMask));
5714 lw(t8, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
5715 Addu(t8, t8, Operand(length));
5716 sw(t8, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
5722 void MacroAssembler::LoadInstanceDescriptors(Register map,
5723 Register descriptors) {
5724 lw(descriptors, FieldMemOperand(map, Map::kDescriptorsOffset));
5728 void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) {
5729 lw(dst, FieldMemOperand(map, Map::kBitField3Offset));
5730 DecodeField<Map::NumberOfOwnDescriptorsBits>(dst);
5734 void MacroAssembler::EnumLength(Register dst, Register map) {
5735 STATIC_ASSERT(Map::EnumLengthBits::kShift == 0);
5736 lw(dst, FieldMemOperand(map, Map::kBitField3Offset));
5737 And(dst, dst, Operand(Map::EnumLengthBits::kMask));
5742 void MacroAssembler::LoadAccessor(Register dst, Register holder,
5744 AccessorComponent accessor) {
5745 lw(dst, FieldMemOperand(holder, HeapObject::kMapOffset));
5746 LoadInstanceDescriptors(dst, dst);
5748 FieldMemOperand(dst, DescriptorArray::GetValueOffset(accessor_index)));
5749 int offset = accessor == ACCESSOR_GETTER ? AccessorPair::kGetterOffset
5750 : AccessorPair::kSetterOffset;
5751 lw(dst, FieldMemOperand(dst, offset));
5755 void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) {
5756 Register empty_fixed_array_value = t2;
5757 LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex);
5761 // Check if the enum length field is properly initialized, indicating that
5762 // there is an enum cache.
5763 lw(a1, FieldMemOperand(a2, HeapObject::kMapOffset));
5767 call_runtime, eq, a3, Operand(Smi::FromInt(kInvalidEnumCacheSentinel)));
5772 lw(a1, FieldMemOperand(a2, HeapObject::kMapOffset));
5774 // For all objects but the receiver, check that the cache is empty.
5776 Branch(call_runtime, ne, a3, Operand(Smi::FromInt(0)));
5780 // Check that there are no elements. Register a2 contains the current JS
5781 // object we've reached through the prototype chain.
5783 lw(a2, FieldMemOperand(a2, JSObject::kElementsOffset));
5784 Branch(&no_elements, eq, a2, Operand(empty_fixed_array_value));
5786 // Second chance, the object may be using the empty slow element dictionary.
5787 LoadRoot(at, Heap::kEmptySlowElementDictionaryRootIndex);
5788 Branch(call_runtime, ne, a2, Operand(at));
5791 lw(a2, FieldMemOperand(a1, Map::kPrototypeOffset));
5792 Branch(&next, ne, a2, Operand(null_value));
5796 void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) {
5797 DCHECK(!output_reg.is(input_reg));
5799 li(output_reg, Operand(255));
5800 // Normal branch: nop in delay slot.
5801 Branch(&done, gt, input_reg, Operand(output_reg));
5802 // Use delay slot in this branch.
5803 Branch(USE_DELAY_SLOT, &done, lt, input_reg, Operand(zero_reg));
5804 mov(output_reg, zero_reg); // In delay slot.
5805 mov(output_reg, input_reg); // Value is in range 0..255.
5810 void MacroAssembler::ClampDoubleToUint8(Register result_reg,
5811 DoubleRegister input_reg,
5812 DoubleRegister temp_double_reg) {
5817 Move(temp_double_reg, 0.0);
5818 BranchF(&above_zero, NULL, gt, input_reg, temp_double_reg);
5820 // Double value is less than zero, NaN or Inf, return 0.
5821 mov(result_reg, zero_reg);
5824 // Double value is >= 255, return 255.
5826 Move(temp_double_reg, 255.0);
5827 BranchF(&in_bounds, NULL, le, input_reg, temp_double_reg);
5828 li(result_reg, Operand(255));
5831 // In 0-255 range, round and truncate.
5833 cvt_w_d(temp_double_reg, input_reg);
5834 mfc1(result_reg, temp_double_reg);
5839 void MacroAssembler::TestJSArrayForAllocationMemento(
5840 Register receiver_reg,
5841 Register scratch_reg,
5842 Label* no_memento_found,
5844 Label* allocation_memento_present) {
5845 ExternalReference new_space_start =
5846 ExternalReference::new_space_start(isolate());
5847 ExternalReference new_space_allocation_top =
5848 ExternalReference::new_space_allocation_top_address(isolate());
5849 Addu(scratch_reg, receiver_reg,
5850 Operand(JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag));
5851 Branch(no_memento_found, lt, scratch_reg, Operand(new_space_start));
5852 li(at, Operand(new_space_allocation_top));
5853 lw(at, MemOperand(at));
5854 Branch(no_memento_found, gt, scratch_reg, Operand(at));
5855 lw(scratch_reg, MemOperand(scratch_reg, -AllocationMemento::kSize));
5856 if (allocation_memento_present) {
5857 Branch(allocation_memento_present, cond, scratch_reg,
5858 Operand(isolate()->factory()->allocation_memento_map()));
5863 Register GetRegisterThatIsNotOneOf(Register reg1,
5870 if (reg1.is_valid()) regs |= reg1.bit();
5871 if (reg2.is_valid()) regs |= reg2.bit();
5872 if (reg3.is_valid()) regs |= reg3.bit();
5873 if (reg4.is_valid()) regs |= reg4.bit();
5874 if (reg5.is_valid()) regs |= reg5.bit();
5875 if (reg6.is_valid()) regs |= reg6.bit();
5877 for (int i = 0; i < Register::NumAllocatableRegisters(); i++) {
5878 Register candidate = Register::FromAllocationIndex(i);
5879 if (regs & candidate.bit()) continue;
5887 void MacroAssembler::JumpIfDictionaryInPrototypeChain(
5892 DCHECK(!scratch1.is(scratch0));
5893 Factory* factory = isolate()->factory();
5894 Register current = scratch0;
5895 Label loop_again, end;
5897 // Scratch contained elements pointer.
5898 Move(current, object);
5899 lw(current, FieldMemOperand(current, HeapObject::kMapOffset));
5900 lw(current, FieldMemOperand(current, Map::kPrototypeOffset));
5901 Branch(&end, eq, current, Operand(factory->null_value()));
5903 // Loop based on the map going up the prototype chain.
5905 lw(current, FieldMemOperand(current, HeapObject::kMapOffset));
5906 lbu(scratch1, FieldMemOperand(current, Map::kInstanceTypeOffset));
5907 STATIC_ASSERT(JS_VALUE_TYPE < JS_OBJECT_TYPE);
5908 STATIC_ASSERT(JS_PROXY_TYPE < JS_OBJECT_TYPE);
5909 Branch(found, lo, scratch1, Operand(JS_OBJECT_TYPE));
5910 lb(scratch1, FieldMemOperand(current, Map::kBitField2Offset));
5911 DecodeField<Map::ElementsKindBits>(scratch1);
5912 Branch(found, eq, scratch1, Operand(DICTIONARY_ELEMENTS));
5913 lw(current, FieldMemOperand(current, Map::kPrototypeOffset));
5914 Branch(&loop_again, ne, current, Operand(factory->null_value()));
5920 bool AreAliased(Register reg1,
5928 int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() +
5929 reg3.is_valid() + reg4.is_valid() + reg5.is_valid() + reg6.is_valid() +
5930 reg7.is_valid() + reg8.is_valid();
5933 if (reg1.is_valid()) regs |= reg1.bit();
5934 if (reg2.is_valid()) regs |= reg2.bit();
5935 if (reg3.is_valid()) regs |= reg3.bit();
5936 if (reg4.is_valid()) regs |= reg4.bit();
5937 if (reg5.is_valid()) regs |= reg5.bit();
5938 if (reg6.is_valid()) regs |= reg6.bit();
5939 if (reg7.is_valid()) regs |= reg7.bit();
5940 if (reg8.is_valid()) regs |= reg8.bit();
5941 int n_of_non_aliasing_regs = NumRegs(regs);
5943 return n_of_valid_regs != n_of_non_aliasing_regs;
5947 CodePatcher::CodePatcher(byte* address,
5949 FlushICache flush_cache)
5950 : address_(address),
5951 size_(instructions * Assembler::kInstrSize),
5952 masm_(NULL, address, size_ + Assembler::kGap),
5953 flush_cache_(flush_cache) {
5954 // Create a new macro assembler pointing to the address of the code to patch.
5955 // The size is adjusted with kGap on order for the assembler to generate size
5956 // bytes of instructions without failing with buffer size constraints.
5957 DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
5961 CodePatcher::~CodePatcher() {
5962 // Indicate that code has changed.
5963 if (flush_cache_ == FLUSH) {
5964 CpuFeatures::FlushICache(address_, size_);
5967 // Check that the code was patched as expected.
5968 DCHECK(masm_.pc_ == address_ + size_);
5969 DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
5973 void CodePatcher::Emit(Instr instr) {
5974 masm()->emit(instr);
5978 void CodePatcher::Emit(Address addr) {
5979 masm()->emit(reinterpret_cast<Instr>(addr));
5983 void CodePatcher::ChangeBranchCondition(Condition cond) {
5984 Instr instr = Assembler::instr_at(masm_.pc_);
5985 DCHECK(Assembler::IsBranch(instr));
5986 uint32_t opcode = Assembler::GetOpcodeField(instr);
5987 // Currently only the 'eq' and 'ne' cond values are supported and the simple
5988 // branch instructions (with opcode being the branch type).
5989 // There are some special cases (see Assembler::IsBranch()) so extending this
5991 DCHECK(opcode == BEQ ||
5999 opcode = (cond == eq) ? BEQ : BNE;
6000 instr = (instr & ~kOpcodeMask) | opcode;
6005 void MacroAssembler::TruncatingDiv(Register result,
6008 DCHECK(!dividend.is(result));
6009 DCHECK(!dividend.is(at));
6010 DCHECK(!result.is(at));
6011 base::MagicNumbersForDivision<uint32_t> mag =
6012 base::SignedDivisionByConstant(static_cast<uint32_t>(divisor));
6013 li(at, Operand(mag.multiplier));
6014 Mulh(result, dividend, Operand(at));
6015 bool neg = (mag.multiplier & (static_cast<uint32_t>(1) << 31)) != 0;
6016 if (divisor > 0 && neg) {
6017 Addu(result, result, Operand(dividend));
6019 if (divisor < 0 && !neg && mag.multiplier > 0) {
6020 Subu(result, result, Operand(dividend));
6022 if (mag.shift > 0) sra(result, result, mag.shift);
6023 srl(at, dividend, 31);
6024 Addu(result, result, Operand(at));
6028 } // namespace internal
6031 #endif // V8_TARGET_ARCH_MIPS