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 #ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
6 #define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
8 #include "src/assembler.h"
9 #include "src/globals.h"
10 #include "src/mips64/assembler-mips64.h"
15 // Give alias names to registers for calling conventions.
16 const Register kReturnRegister0 = {kRegister_v0_Code};
17 const Register kReturnRegister1 = {kRegister_v1_Code};
18 const Register kJSFunctionRegister = {kRegister_a1_Code};
19 const Register kContextRegister = {kRegister_s7_Code};
20 const Register kInterpreterAccumulatorRegister = {kRegister_v0_Code};
21 const Register kInterpreterRegisterFileRegister = {kRegister_a7_Code};
22 const Register kInterpreterBytecodeOffsetRegister = {kRegister_t0_Code};
23 const Register kInterpreterBytecodeArrayRegister = {kRegister_t1_Code};
24 const Register kInterpreterDispatchTableRegister = {kRegister_t2_Code};
25 const Register kRuntimeCallFunctionRegister = {kRegister_a1_Code};
26 const Register kRuntimeCallArgCountRegister = {kRegister_a0_Code};
28 // Forward declaration.
31 // Reserved Register Usage Summary.
33 // Registers t8, t9, and at are reserved for use by the MacroAssembler.
35 // The programmer should know that the MacroAssembler may clobber these three,
36 // but won't touch other registers except in special cases.
38 // Per the MIPS ABI, register t9 must be used for indirect function call
39 // via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
40 // trying to update gp register for position-independent-code. Whenever
41 // MIPS generated code calls C code, it must be via t9 register.
44 // Flags used for LeaveExitFrame function.
45 enum LeaveExitFrameMode {
47 NO_EMIT_RETURN = false
50 // Flags used for AllocateHeapNumber
58 // Flags used for the ObjectToDoubleFPURegister function.
59 enum ObjectToDoubleFlags {
61 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
62 // Object is known to be a non smi.
63 OBJECT_NOT_SMI = 1 << 0,
64 // Don't load NaNs or infinities, branch to the non number case instead.
65 AVOID_NANS_AND_INFINITIES = 1 << 1
68 // Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
69 enum BranchDelaySlot {
74 // Flags used for the li macro-assembler function.
76 // If the constant value can be represented in just 16 bits, then
77 // optimize the li to use a single instruction, rather than lui/ori/dsll
80 // Always use 6 instructions (lui/ori/dsll sequence), even if the constant
81 // could be loaded with just one, so that this value is patchable later.
83 // For address loads only 4 instruction are required. Used to mark
84 // constant load that will be used as address without relocation
85 // information. It ensures predictable code size, so specific sites
86 // in code are patchable.
91 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
92 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
93 enum PointersToHereCheck {
94 kPointersToHereMaybeInteresting,
95 kPointersToHereAreAlwaysInteresting
97 enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
99 Register GetRegisterThatIsNotOneOf(Register reg1,
100 Register reg2 = no_reg,
101 Register reg3 = no_reg,
102 Register reg4 = no_reg,
103 Register reg5 = no_reg,
104 Register reg6 = no_reg);
106 bool AreAliased(Register reg1,
108 Register reg3 = no_reg,
109 Register reg4 = no_reg,
110 Register reg5 = no_reg,
111 Register reg6 = no_reg,
112 Register reg7 = no_reg,
113 Register reg8 = no_reg);
116 // -----------------------------------------------------------------------------
117 // Static helper functions.
119 inline MemOperand ContextOperand(Register context, int index) {
120 return MemOperand(context, Context::SlotOffset(index));
124 inline MemOperand GlobalObjectOperand() {
125 return ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX);
129 // Generate a MemOperand for loading a field from an object.
130 inline MemOperand FieldMemOperand(Register object, int offset) {
131 return MemOperand(object, offset - kHeapObjectTag);
135 inline MemOperand UntagSmiMemOperand(Register rm, int offset) {
136 // Assumes that Smis are shifted by 32 bits and little endianness.
137 STATIC_ASSERT(kSmiShift == 32);
138 return MemOperand(rm, offset + (kSmiShift / kBitsPerByte));
142 inline MemOperand UntagSmiFieldMemOperand(Register rm, int offset) {
143 return UntagSmiMemOperand(rm, offset - kHeapObjectTag);
147 // Generate a MemOperand for storing arguments 5..N on the stack
148 // when calling CallCFunction().
149 // TODO(plind): Currently ONLY used for O32. Should be fixed for
150 // n64, and used in RegExp code, and other places
151 // with more than 8 arguments.
152 inline MemOperand CFunctionArgumentOperand(int index) {
153 DCHECK(index > kCArgSlotCount);
154 // Argument 5 takes the slot just past the four Arg-slots.
155 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
156 return MemOperand(sp, offset);
160 // MacroAssembler implements a collection of frequently used macros.
161 class MacroAssembler: public Assembler {
163 // The isolate parameter can be NULL if the macro assembler should
164 // not use isolate-dependent functionality. In this case, it's the
165 // responsibility of the caller to never invoke such function on the
167 MacroAssembler(Isolate* isolate, void* buffer, int size);
170 #define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
171 #define COND_ARGS cond, r1, r2
173 // Cases when relocation is not needed.
174 #define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
175 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
176 inline void Name(BranchDelaySlot bd, target_type target) { \
179 void Name(target_type target, \
181 BranchDelaySlot bd = PROTECT); \
182 inline void Name(BranchDelaySlot bd, \
183 target_type target, \
185 Name(target, COND_ARGS, bd); \
188 #define DECLARE_BRANCH_PROTOTYPES(Name) \
189 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
190 DECLARE_NORELOC_PROTOTYPE(Name, int16_t)
192 DECLARE_BRANCH_PROTOTYPES(Branch)
193 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
194 DECLARE_BRANCH_PROTOTYPES(BranchShort)
196 #undef DECLARE_BRANCH_PROTOTYPES
197 #undef COND_TYPED_ARGS
201 // Jump, Call, and Ret pseudo instructions implementing inter-working.
202 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
203 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
205 void Jump(Register target, COND_ARGS);
206 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
207 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
208 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
209 static int CallSize(Register target, COND_ARGS);
210 void Call(Register target, COND_ARGS);
211 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
212 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
213 int CallSize(Handle<Code> code,
214 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
215 TypeFeedbackId ast_id = TypeFeedbackId::None(),
217 void Call(Handle<Code> code,
218 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
219 TypeFeedbackId ast_id = TypeFeedbackId::None(),
222 inline void Ret(BranchDelaySlot bd, Condition cond = al,
223 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
224 Ret(cond, rs, rt, bd);
227 void Branch(Label* L,
230 Heap::RootListIndex index,
231 BranchDelaySlot bdslot = PROTECT);
235 // Emit code to discard a non-negative number of pointer-sized elements
236 // from the stack, clobbering only the sp register.
238 Condition cond = cc_always,
239 Register reg = no_reg,
240 const Operand& op = Operand(no_reg));
242 // Trivial case of DropAndRet that utilizes the delay slot and only emits
244 void DropAndRet(int drop);
246 void DropAndRet(int drop,
251 // Swap two registers. If the scratch register is omitted then a slightly
252 // less efficient form using xor instead of mov is emitted.
253 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
255 void Call(Label* target);
257 inline void Move(Register dst, Register src) {
263 inline void Move(FPURegister dst, FPURegister src) {
269 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
271 mfhc1(dst_high, src);
274 inline void FmoveHigh(Register dst_high, FPURegister src) {
275 mfhc1(dst_high, src);
278 inline void FmoveHigh(FPURegister dst, Register src_high) {
279 mthc1(src_high, dst);
282 inline void FmoveLow(Register dst_low, FPURegister src) {
286 void FmoveLow(FPURegister dst, Register src_low);
288 inline void Move(FPURegister dst, Register src_low, Register src_high) {
290 mthc1(src_high, dst);
293 void Move(FPURegister dst, float imm);
294 void Move(FPURegister dst, double imm);
297 void Movz(Register rd, Register rs, Register rt);
298 void Movn(Register rd, Register rs, Register rt);
299 void Movt(Register rd, Register rs, uint16_t cc = 0);
300 void Movf(Register rd, Register rs, uint16_t cc = 0);
302 void Clz(Register rd, Register rs);
304 // Jump unconditionally to given label.
305 // We NEED a nop in the branch delay slot, as it used by v8, for example in
306 // CodeGenerator::ProcessDeferred().
307 // Currently the branch delay slot is filled by the MacroAssembler.
308 // Use rather b(Label) for code generation.
313 void Load(Register dst, const MemOperand& src, Representation r);
314 void Store(Register src, const MemOperand& dst, Representation r);
316 // Load an object from the root table.
317 void LoadRoot(Register destination,
318 Heap::RootListIndex index);
319 void LoadRoot(Register destination,
320 Heap::RootListIndex index,
321 Condition cond, Register src1, const Operand& src2);
323 // Store an object to the root table.
324 void StoreRoot(Register source,
325 Heap::RootListIndex index);
326 void StoreRoot(Register source,
327 Heap::RootListIndex index,
328 Condition cond, Register src1, const Operand& src2);
330 // ---------------------------------------------------------------------------
333 void IncrementalMarkingRecordWriteHelper(Register object,
337 enum RememberedSetFinalAction {
343 // Record in the remembered set the fact that we have a pointer to new space
344 // at the address pointed to by the addr register. Only works if addr is not
346 void RememberedSetHelper(Register object, // Used for debug code.
349 SaveFPRegsMode save_fp,
350 RememberedSetFinalAction and_then);
352 void CheckPageFlag(Register object,
356 Label* condition_met);
358 // Check if object is in new space. Jumps if the object is not in new space.
359 // The register scratch can be object itself, but it will be clobbered.
360 void JumpIfNotInNewSpace(Register object,
363 InNewSpace(object, scratch, ne, branch);
366 // Check if object is in new space. Jumps if the object is in new space.
367 // The register scratch can be object itself, but scratch will be clobbered.
368 void JumpIfInNewSpace(Register object,
371 InNewSpace(object, scratch, eq, branch);
374 // Check if an object has a given incremental marking color.
375 void HasColor(Register object,
382 void JumpIfBlack(Register object,
387 // Checks the color of an object. If the object is already grey or black
388 // then we just fall through, since it is already live. If it is white and
389 // we can determine that it doesn't need to be scanned, then we just mark it
390 // black and fall through. For the rest we jump to the label so the
391 // incremental marker can fix its assumptions.
392 void EnsureNotWhite(Register object,
396 Label* object_is_white_and_not_data);
398 // Detects conservatively whether an object is data-only, i.e. it does need to
399 // be scanned by the garbage collector.
400 void JumpIfDataObject(Register value,
402 Label* not_data_object);
404 // Notify the garbage collector that we wrote a pointer into an object.
405 // |object| is the object being stored into, |value| is the object being
406 // stored. value and scratch registers are clobbered by the operation.
407 // The offset is the offset from the start of the object, not the offset from
408 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
409 void RecordWriteField(
415 SaveFPRegsMode save_fp,
416 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
417 SmiCheck smi_check = INLINE_SMI_CHECK,
418 PointersToHereCheck pointers_to_here_check_for_value =
419 kPointersToHereMaybeInteresting);
421 // As above, but the offset has the tag presubtracted. For use with
422 // MemOperand(reg, off).
423 inline void RecordWriteContextSlot(
429 SaveFPRegsMode save_fp,
430 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
431 SmiCheck smi_check = INLINE_SMI_CHECK,
432 PointersToHereCheck pointers_to_here_check_for_value =
433 kPointersToHereMaybeInteresting) {
434 RecordWriteField(context,
435 offset + kHeapObjectTag,
440 remembered_set_action,
442 pointers_to_here_check_for_value);
445 void RecordWriteForMap(
450 SaveFPRegsMode save_fp);
452 // For a given |object| notify the garbage collector that the slot |address|
453 // has been written. |value| is the object being stored. The value and
454 // address registers are clobbered by the operation.
460 SaveFPRegsMode save_fp,
461 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
462 SmiCheck smi_check = INLINE_SMI_CHECK,
463 PointersToHereCheck pointers_to_here_check_for_value =
464 kPointersToHereMaybeInteresting);
467 // ---------------------------------------------------------------------------
468 // Inline caching support.
470 // Generate code for checking access rights - used for security checks
471 // on access to global objects across environments. The holder register
472 // is left untouched, whereas both scratch registers are clobbered.
473 void CheckAccessGlobalProxy(Register holder_reg,
477 void GetNumberHash(Register reg0, Register scratch);
479 void LoadFromNumberDictionary(Label* miss,
488 inline void MarkCode(NopMarkerTypes type) {
492 // Check if the given instruction is a 'type' marker.
493 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
494 // nop(type)). These instructions are generated to mark special location in
495 // the code, like some special IC code.
496 static inline bool IsMarkedCode(Instr instr, int type) {
497 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
498 return IsNop(instr, type);
502 static inline int GetCodeMarker(Instr instr) {
503 uint32_t opcode = ((instr & kOpcodeMask));
504 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
505 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
506 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
508 // Return <n> if we have a sll zero_reg, zero_reg, n
510 bool sllzz = (opcode == SLL &&
511 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
512 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
514 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
515 DCHECK((type == -1) ||
516 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
522 // ---------------------------------------------------------------------------
523 // Allocation support.
525 // Allocate an object in new space or old space. The object_size is
526 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
527 // is passed. If the space is exhausted control continues at the gc_required
528 // label. The allocated object is returned in result. If the flag
529 // tag_allocated_object is true the result is tagged as as a heap object.
530 // All registers are clobbered also when control continues at the gc_required
532 void Allocate(int object_size,
537 AllocationFlags flags);
539 void Allocate(Register object_size,
544 AllocationFlags flags);
546 void AllocateTwoByteString(Register result,
552 void AllocateOneByteString(Register result, Register length,
553 Register scratch1, Register scratch2,
554 Register scratch3, Label* gc_required);
555 void AllocateTwoByteConsString(Register result,
560 void AllocateOneByteConsString(Register result, Register length,
561 Register scratch1, Register scratch2,
563 void AllocateTwoByteSlicedString(Register result,
568 void AllocateOneByteSlicedString(Register result, Register length,
569 Register scratch1, Register scratch2,
572 // Allocates a heap number or jumps to the gc_required label if the young
573 // space is full and a scavenge is needed. All registers are clobbered also
574 // when control continues at the gc_required label.
575 void AllocateHeapNumber(Register result,
578 Register heap_number_map,
580 TaggingMode tagging_mode = TAG_RESULT,
581 MutableMode mode = IMMUTABLE);
583 void AllocateHeapNumberWithValue(Register result,
589 // ---------------------------------------------------------------------------
590 // Instruction macros.
592 #define DEFINE_INSTRUCTION(instr) \
593 void instr(Register rd, Register rs, const Operand& rt); \
594 void instr(Register rd, Register rs, Register rt) { \
595 instr(rd, rs, Operand(rt)); \
597 void instr(Register rs, Register rt, int32_t j) { \
598 instr(rs, rt, Operand(j)); \
601 #define DEFINE_INSTRUCTION2(instr) \
602 void instr(Register rs, const Operand& rt); \
603 void instr(Register rs, Register rt) { \
604 instr(rs, Operand(rt)); \
606 void instr(Register rs, int32_t j) { \
607 instr(rs, Operand(j)); \
610 DEFINE_INSTRUCTION(Addu);
611 DEFINE_INSTRUCTION(Daddu);
612 DEFINE_INSTRUCTION(Div);
613 DEFINE_INSTRUCTION(Divu);
614 DEFINE_INSTRUCTION(Ddivu);
615 DEFINE_INSTRUCTION(Mod);
616 DEFINE_INSTRUCTION(Modu);
617 DEFINE_INSTRUCTION(Ddiv);
618 DEFINE_INSTRUCTION(Subu);
619 DEFINE_INSTRUCTION(Dsubu);
620 DEFINE_INSTRUCTION(Dmod);
621 DEFINE_INSTRUCTION(Dmodu);
622 DEFINE_INSTRUCTION(Mul);
623 DEFINE_INSTRUCTION(Mulh);
624 DEFINE_INSTRUCTION(Mulhu);
625 DEFINE_INSTRUCTION(Dmul);
626 DEFINE_INSTRUCTION(Dmulh);
627 DEFINE_INSTRUCTION2(Mult);
628 DEFINE_INSTRUCTION2(Dmult);
629 DEFINE_INSTRUCTION2(Multu);
630 DEFINE_INSTRUCTION2(Dmultu);
631 DEFINE_INSTRUCTION2(Div);
632 DEFINE_INSTRUCTION2(Ddiv);
633 DEFINE_INSTRUCTION2(Divu);
634 DEFINE_INSTRUCTION2(Ddivu);
636 DEFINE_INSTRUCTION(And);
637 DEFINE_INSTRUCTION(Or);
638 DEFINE_INSTRUCTION(Xor);
639 DEFINE_INSTRUCTION(Nor);
640 DEFINE_INSTRUCTION2(Neg);
642 DEFINE_INSTRUCTION(Slt);
643 DEFINE_INSTRUCTION(Sltu);
645 // MIPS32 R2 instruction macro.
646 DEFINE_INSTRUCTION(Ror);
647 DEFINE_INSTRUCTION(Dror);
649 #undef DEFINE_INSTRUCTION
650 #undef DEFINE_INSTRUCTION2
652 void Pref(int32_t hint, const MemOperand& rs);
655 // ---------------------------------------------------------------------------
656 // Pseudo-instructions.
658 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
660 void Ulw(Register rd, const MemOperand& rs);
661 void Usw(Register rd, const MemOperand& rs);
662 void Uld(Register rd, const MemOperand& rs, Register scratch = at);
663 void Usd(Register rd, const MemOperand& rs, Register scratch = at);
665 // Load int32 in the rd register.
666 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
667 inline void li(Register rd, int64_t j, LiFlags mode = OPTIMIZE_SIZE) {
668 li(rd, Operand(j), mode);
670 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
672 // Push multiple registers on the stack.
673 // Registers are saved in numerical order, with higher numbered registers
674 // saved in higher memory addresses.
675 void MultiPush(RegList regs);
676 void MultiPushReversed(RegList regs);
678 void MultiPushFPU(RegList regs);
679 void MultiPushReversedFPU(RegList regs);
681 void push(Register src) {
682 Daddu(sp, sp, Operand(-kPointerSize));
683 sd(src, MemOperand(sp, 0));
685 void Push(Register src) { push(src); }
688 void Push(Handle<Object> handle);
689 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
691 // Push two registers. Pushes leftmost register first (to highest address).
692 void Push(Register src1, Register src2) {
693 Dsubu(sp, sp, Operand(2 * kPointerSize));
694 sd(src1, MemOperand(sp, 1 * kPointerSize));
695 sd(src2, MemOperand(sp, 0 * kPointerSize));
698 // Push three registers. Pushes leftmost register first (to highest address).
699 void Push(Register src1, Register src2, Register src3) {
700 Dsubu(sp, sp, Operand(3 * kPointerSize));
701 sd(src1, MemOperand(sp, 2 * kPointerSize));
702 sd(src2, MemOperand(sp, 1 * kPointerSize));
703 sd(src3, MemOperand(sp, 0 * kPointerSize));
706 // Push four registers. Pushes leftmost register first (to highest address).
707 void Push(Register src1, Register src2, Register src3, Register src4) {
708 Dsubu(sp, sp, Operand(4 * kPointerSize));
709 sd(src1, MemOperand(sp, 3 * kPointerSize));
710 sd(src2, MemOperand(sp, 2 * kPointerSize));
711 sd(src3, MemOperand(sp, 1 * kPointerSize));
712 sd(src4, MemOperand(sp, 0 * kPointerSize));
715 // Push five registers. Pushes leftmost register first (to highest address).
716 void Push(Register src1, Register src2, Register src3, Register src4,
718 Dsubu(sp, sp, Operand(5 * kPointerSize));
719 sd(src1, MemOperand(sp, 4 * kPointerSize));
720 sd(src2, MemOperand(sp, 3 * kPointerSize));
721 sd(src3, MemOperand(sp, 2 * kPointerSize));
722 sd(src4, MemOperand(sp, 1 * kPointerSize));
723 sd(src5, MemOperand(sp, 0 * kPointerSize));
726 void Push(Register src, Condition cond, Register tst1, Register tst2) {
727 // Since we don't have conditional execution we use a Branch.
728 Branch(3, cond, tst1, Operand(tst2));
729 Dsubu(sp, sp, Operand(kPointerSize));
730 sd(src, MemOperand(sp, 0));
733 void PushRegisterAsTwoSmis(Register src, Register scratch = at);
734 void PopRegisterAsTwoSmis(Register dst, Register scratch = at);
736 // Pops multiple values from the stack and load them in the
737 // registers specified in regs. Pop order is the opposite as in MultiPush.
738 void MultiPop(RegList regs);
739 void MultiPopReversed(RegList regs);
741 void MultiPopFPU(RegList regs);
742 void MultiPopReversedFPU(RegList regs);
744 void pop(Register dst) {
745 ld(dst, MemOperand(sp, 0));
746 Daddu(sp, sp, Operand(kPointerSize));
748 void Pop(Register dst) { pop(dst); }
750 // Pop two registers. Pops rightmost register first (from lower address).
751 void Pop(Register src1, Register src2) {
752 DCHECK(!src1.is(src2));
753 ld(src2, MemOperand(sp, 0 * kPointerSize));
754 ld(src1, MemOperand(sp, 1 * kPointerSize));
755 Daddu(sp, sp, 2 * kPointerSize);
758 // Pop three registers. Pops rightmost register first (from lower address).
759 void Pop(Register src1, Register src2, Register src3) {
760 ld(src3, MemOperand(sp, 0 * kPointerSize));
761 ld(src2, MemOperand(sp, 1 * kPointerSize));
762 ld(src1, MemOperand(sp, 2 * kPointerSize));
763 Daddu(sp, sp, 3 * kPointerSize);
766 void Pop(uint32_t count = 1) {
767 Daddu(sp, sp, Operand(count * kPointerSize));
770 // Push and pop the registers that can hold pointers, as defined by the
771 // RegList constant kSafepointSavedRegisters.
772 void PushSafepointRegisters();
773 void PopSafepointRegisters();
774 // Store value in register src in the safepoint stack slot for
776 void StoreToSafepointRegisterSlot(Register src, Register dst);
777 // Load the value of the src register from its safepoint stack slot
778 // into register dst.
779 void LoadFromSafepointRegisterSlot(Register dst, Register src);
781 // Flush the I-cache from asm code. You should use CpuFeatures::FlushICache
783 // Does not handle errors.
784 void FlushICache(Register address, unsigned instructions);
786 // MIPS64 R2 instruction macro.
787 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
788 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
789 void Dext(Register rt, Register rs, uint16_t pos, uint16_t size);
791 // ---------------------------------------------------------------------------
792 // FPU macros. These do not handle special cases like NaN or +- inf.
794 // Convert unsigned word to double.
795 void Cvt_d_uw(FPURegister fd, FPURegister fs, FPURegister scratch);
796 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
798 // Convert double to unsigned long.
799 void Trunc_l_ud(FPURegister fd, FPURegister fs, FPURegister scratch);
801 void Trunc_l_d(FPURegister fd, FPURegister fs);
802 void Round_l_d(FPURegister fd, FPURegister fs);
803 void Floor_l_d(FPURegister fd, FPURegister fs);
804 void Ceil_l_d(FPURegister fd, FPURegister fs);
806 // Convert double to unsigned word.
807 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
808 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
810 void Trunc_w_d(FPURegister fd, FPURegister fs);
811 void Round_w_d(FPURegister fd, FPURegister fs);
812 void Floor_w_d(FPURegister fd, FPURegister fs);
813 void Ceil_w_d(FPURegister fd, FPURegister fs);
815 void Madd_d(FPURegister fd,
819 FPURegister scratch);
821 // Wrapper functions for the different cmp/branch types.
822 inline void BranchF32(Label* target, Label* nan, Condition cc,
823 FPURegister cmp1, FPURegister cmp2,
824 BranchDelaySlot bd = PROTECT) {
825 BranchFCommon(S, target, nan, cc, cmp1, cmp2, bd);
828 inline void BranchF64(Label* target, Label* nan, Condition cc,
829 FPURegister cmp1, FPURegister cmp2,
830 BranchDelaySlot bd = PROTECT) {
831 BranchFCommon(D, target, nan, cc, cmp1, cmp2, bd);
834 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
835 inline void BranchF64(BranchDelaySlot bd, Label* target, Label* nan,
836 Condition cc, FPURegister cmp1, FPURegister cmp2) {
837 BranchF64(target, nan, cc, cmp1, cmp2, bd);
840 inline void BranchF32(BranchDelaySlot bd, Label* target, Label* nan,
841 Condition cc, FPURegister cmp1, FPURegister cmp2) {
842 BranchF32(target, nan, cc, cmp1, cmp2, bd);
845 // Alias functions for backward compatibility.
846 inline void BranchF(Label* target, Label* nan, Condition cc, FPURegister cmp1,
847 FPURegister cmp2, BranchDelaySlot bd = PROTECT) {
848 BranchF64(target, nan, cc, cmp1, cmp2, bd);
851 inline void BranchF(BranchDelaySlot bd, Label* target, Label* nan,
852 Condition cc, FPURegister cmp1, FPURegister cmp2) {
853 BranchF64(bd, target, nan, cc, cmp1, cmp2);
856 // Truncates a double using a specific rounding mode, and writes the value
857 // to the result register.
858 // The except_flag will contain any exceptions caused by the instruction.
859 // If check_inexact is kDontCheckForInexactConversion, then the inexact
860 // exception is masked.
861 void EmitFPUTruncate(FPURoundingMode rounding_mode,
863 DoubleRegister double_input,
865 DoubleRegister double_scratch,
866 Register except_flag,
867 CheckForInexactConversion check_inexact
868 = kDontCheckForInexactConversion);
870 // Performs a truncating conversion of a floating point number as used by
871 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
872 // succeeds, otherwise falls through if result is saturated. On return
873 // 'result' either holds answer, or is clobbered on fall through.
875 // Only public for the test code in test-code-stubs-arm.cc.
876 void TryInlineTruncateDoubleToI(Register result,
877 DoubleRegister input,
880 // Performs a truncating conversion of a floating point number as used by
881 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
882 // Exits with 'result' holding the answer.
883 void TruncateDoubleToI(Register result, DoubleRegister double_input);
885 // Performs a truncating conversion of a heap number as used by
886 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
887 // must be different registers. Exits with 'result' holding the answer.
888 void TruncateHeapNumberToI(Register result, Register object);
890 // Converts the smi or heap number in object to an int32 using the rules
891 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
892 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
893 // different registers.
894 void TruncateNumberToI(Register object,
896 Register heap_number_map,
900 // Loads the number from object into dst register.
901 // If |object| is neither smi nor heap number, |not_number| is jumped to
902 // with |object| still intact.
903 void LoadNumber(Register object,
905 Register heap_number_map,
909 // Loads the number from object into double_dst in the double format.
910 // Control will jump to not_int32 if the value cannot be exactly represented
911 // by a 32-bit integer.
912 // Floating point value in the 32-bit integer range that are not exact integer
914 void LoadNumberAsInt32Double(Register object,
915 DoubleRegister double_dst,
916 Register heap_number_map,
919 FPURegister double_scratch,
922 // Loads the number from object into dst as a 32-bit integer.
923 // Control will jump to not_int32 if the object cannot be exactly represented
924 // by a 32-bit integer.
925 // Floating point value in the 32-bit integer range that are not exact integer
926 // won't be converted.
927 void LoadNumberAsInt32(Register object,
929 Register heap_number_map,
932 FPURegister double_scratch0,
933 FPURegister double_scratch1,
937 // argc - argument count to be dropped by LeaveExitFrame.
938 // save_doubles - saves FPU registers on stack, currently disabled.
939 // stack_space - extra stack space.
940 void EnterExitFrame(bool save_doubles,
941 int stack_space = 0);
943 // Leave the current exit frame.
944 void LeaveExitFrame(bool save_doubles, Register arg_count,
945 bool restore_context, bool do_return = NO_EMIT_RETURN,
946 bool argument_count_is_length = false);
948 // Get the actual activation frame alignment for target environment.
949 static int ActivationFrameAlignment();
951 // Make sure the stack is aligned. Only emits code in debug mode.
952 void AssertStackIsAligned();
954 void LoadContext(Register dst, int context_chain_length);
956 // Conditionally load the cached Array transitioned map of type
957 // transitioned_kind from the native context if the map in register
958 // map_in_out is the cached Array map in the native context of
960 void LoadTransitionedArrayMapConditional(
961 ElementsKind expected_kind,
962 ElementsKind transitioned_kind,
965 Label* no_map_match);
967 void LoadGlobalFunction(int index, Register function);
969 // Load the initial map from the global function. The registers
970 // function and map can be the same, function is then overwritten.
971 void LoadGlobalFunctionInitialMap(Register function,
975 void InitializeRootRegister() {
976 ExternalReference roots_array_start =
977 ExternalReference::roots_array_start(isolate());
978 li(kRootRegister, Operand(roots_array_start));
981 // -------------------------------------------------------------------------
982 // JavaScript invokes.
984 // Invoke the JavaScript function code by either calling or jumping.
985 void InvokeCode(Register code,
986 const ParameterCount& expected,
987 const ParameterCount& actual,
989 const CallWrapper& call_wrapper);
991 // Invoke the JavaScript function in the given register. Changes the
992 // current context to the context in the function before invoking.
993 void InvokeFunction(Register function,
994 const ParameterCount& actual,
996 const CallWrapper& call_wrapper);
998 void InvokeFunction(Register function,
999 const ParameterCount& expected,
1000 const ParameterCount& actual,
1002 const CallWrapper& call_wrapper);
1004 void InvokeFunction(Handle<JSFunction> function,
1005 const ParameterCount& expected,
1006 const ParameterCount& actual,
1008 const CallWrapper& call_wrapper);
1011 void IsObjectJSStringType(Register object,
1015 void IsObjectNameType(Register object,
1019 // -------------------------------------------------------------------------
1020 // Debugger Support.
1024 // -------------------------------------------------------------------------
1025 // Exception handling.
1027 // Push a new stack handler and link into stack handler chain.
1028 void PushStackHandler();
1030 // Unlink the stack handler on top of the stack from the stack handler chain.
1031 // Must preserve the result register.
1032 void PopStackHandler();
1034 // Copies a fixed number of fields of heap objects from src to dst.
1035 void CopyFields(Register dst, Register src, RegList temps, int field_count);
1037 // Copies a number of bytes from src to dst. All registers are clobbered. On
1038 // exit src and dst will point to the place just after where the last byte was
1039 // read or written and length will be zero.
1040 void CopyBytes(Register src,
1045 // Initialize fields with filler values. Fields starting at |start_offset|
1046 // not including end_offset are overwritten with the value in |filler|. At
1047 // the end the loop, |start_offset| takes the value of |end_offset|.
1048 void InitializeFieldsWithFiller(Register start_offset,
1049 Register end_offset,
1052 // -------------------------------------------------------------------------
1053 // Support functions.
1055 // Machine code version of Map::GetConstructor().
1056 // |temp| holds |result|'s map when done, and |temp2| its instance type.
1057 void GetMapConstructor(Register result, Register map, Register temp,
1060 // Try to get function prototype of a function and puts the value in
1061 // the result register. Checks that the function really is a
1062 // function and jumps to the miss label if the fast checks fail. The
1063 // function register will be untouched; the other registers may be
1065 void TryGetFunctionPrototype(Register function, Register result,
1066 Register scratch, Label* miss);
1068 void GetObjectType(Register function,
1072 // Check if a map for a JSObject indicates that the object has fast elements.
1073 // Jump to the specified label if it does not.
1074 void CheckFastElements(Register map,
1078 // Check if a map for a JSObject indicates that the object can have both smi
1079 // and HeapObject elements. Jump to the specified label if it does not.
1080 void CheckFastObjectElements(Register map,
1084 // Check if a map for a JSObject indicates that the object has fast smi only
1085 // elements. Jump to the specified label if it does not.
1086 void CheckFastSmiElements(Register map,
1090 // Check to see if maybe_number can be stored as a double in
1091 // FastDoubleElements. If it can, store it at the index specified by key in
1092 // the FastDoubleElements array elements. Otherwise jump to fail.
1093 void StoreNumberToDoubleElements(Register value_reg,
1095 Register elements_reg,
1099 int elements_offset = 0);
1101 // Compare an object's map with the specified map and its transitioned
1102 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1103 // "branch_to" if the result of the comparison is "cond". If multiple map
1104 // compares are required, the compare sequences branches to early_success.
1105 void CompareMapAndBranch(Register obj,
1108 Label* early_success,
1112 // As above, but the map of the object is already loaded into the register
1113 // which is preserved by the code generated.
1114 void CompareMapAndBranch(Register obj_map,
1116 Label* early_success,
1120 // Check if the map of an object is equal to a specified map and branch to
1121 // label if not. Skip the smi check if not required (object is known to be a
1122 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1123 // against maps that are ElementsKind transition maps of the specificed map.
1124 void CheckMap(Register obj,
1128 SmiCheckType smi_check_type);
1131 void CheckMap(Register obj,
1133 Heap::RootListIndex index,
1135 SmiCheckType smi_check_type);
1137 // Check if the map of an object is equal to a specified weak map and branch
1138 // to a specified target if equal. Skip the smi check if not required
1139 // (object is known to be a heap object)
1140 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1141 Handle<WeakCell> cell, Handle<Code> success,
1142 SmiCheckType smi_check_type);
1144 // If the value is a NaN, canonicalize the value else, do nothing.
1145 void FPUCanonicalizeNaN(const DoubleRegister dst, const DoubleRegister src);
1148 // Get value of the weak cell.
1149 void GetWeakValue(Register value, Handle<WeakCell> cell);
1151 // Load the value of the weak cell in the value register. Branch to the
1152 // given miss label is the weak cell was cleared.
1153 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
1155 // Load and check the instance type of an object for being a string.
1156 // Loads the type into the second argument register.
1157 // Returns a condition that will be enabled if the object was a string.
1158 Condition IsObjectStringType(Register obj,
1161 ld(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1162 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1163 And(type, type, Operand(kIsNotStringMask));
1164 DCHECK_EQ(0u, kStringTag);
1169 // Picks out an array index from the hash field.
1171 // hash - holds the index's hash. Clobbered.
1172 // index - holds the overwritten index on exit.
1173 void IndexFromHash(Register hash, Register index);
1175 // Get the number of least significant bits from a register.
1176 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1177 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1179 // Load the value of a number object into a FPU double register. If the
1180 // object is not a number a jump to the label not_number is performed
1181 // and the FPU double register is unchanged.
1182 void ObjectToDoubleFPURegister(
1187 Register heap_number_map,
1189 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1191 // Load the value of a smi object into a FPU double register. The register
1192 // scratch1 can be the same register as smi in which case smi will hold the
1193 // untagged value afterwards.
1194 void SmiToDoubleFPURegister(Register smi,
1198 // -------------------------------------------------------------------------
1199 // Overflow handling functions.
1200 // Usage: first call the appropriate arithmetic function, then call one of the
1201 // jump functions with the overflow_dst register as the second parameter.
1203 void AdduAndCheckForOverflow(Register dst,
1206 Register overflow_dst,
1207 Register scratch = at);
1209 void AdduAndCheckForOverflow(Register dst, Register left,
1210 const Operand& right, Register overflow_dst,
1213 void SubuAndCheckForOverflow(Register dst,
1216 Register overflow_dst,
1217 Register scratch = at);
1219 void SubuAndCheckForOverflow(Register dst, Register left,
1220 const Operand& right, Register overflow_dst,
1223 void DadduAndCheckForOverflow(Register dst, Register left, Register right,
1224 Register overflow_dst, Register scratch = at);
1226 void DadduAndCheckForOverflow(Register dst, Register left,
1227 const Operand& right, Register overflow_dst,
1230 void DsubuAndCheckForOverflow(Register dst, Register left, Register right,
1231 Register overflow_dst, Register scratch = at);
1233 void DsubuAndCheckForOverflow(Register dst, Register left,
1234 const Operand& right, Register overflow_dst,
1237 void BranchOnOverflow(Label* label,
1238 Register overflow_check,
1239 BranchDelaySlot bd = PROTECT) {
1240 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1243 void BranchOnNoOverflow(Label* label,
1244 Register overflow_check,
1245 BranchDelaySlot bd = PROTECT) {
1246 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1249 void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1250 Ret(lt, overflow_check, Operand(zero_reg), bd);
1253 void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1254 Ret(ge, overflow_check, Operand(zero_reg), bd);
1257 // -------------------------------------------------------------------------
1260 // See comments at the beginning of CEntryStub::Generate.
1261 inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); }
1263 inline void PrepareCEntryFunction(const ExternalReference& ref) {
1264 li(a1, Operand(ref));
1267 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1268 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1270 // Call a code stub.
1271 void CallStub(CodeStub* stub,
1272 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1275 // Tail call a code stub (jump).
1276 void TailCallStub(CodeStub* stub, COND_ARGS);
1280 void CallJSExitStub(CodeStub* stub);
1282 // Call a runtime routine.
1283 void CallRuntime(const Runtime::Function* f, int num_arguments,
1284 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1285 BranchDelaySlot bd = PROTECT);
1286 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1287 const Runtime::Function* function = Runtime::FunctionForId(id);
1288 CallRuntime(function, function->nargs, kSaveFPRegs);
1291 // Convenience function: Same as above, but takes the fid instead.
1292 void CallRuntime(Runtime::FunctionId id, int num_arguments,
1293 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1294 BranchDelaySlot bd = PROTECT) {
1295 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles, bd);
1298 // Convenience function: call an external reference.
1299 void CallExternalReference(const ExternalReference& ext,
1301 BranchDelaySlot bd = PROTECT);
1303 // Tail call of a runtime routine (jump).
1304 // Like JumpToExternalReference, but also takes care of passing the number
1306 void TailCallExternalReference(const ExternalReference& ext,
1310 // Convenience function: tail call a runtime routine (jump).
1311 void TailCallRuntime(Runtime::FunctionId fid,
1315 int CalculateStackPassedWords(int num_reg_arguments,
1316 int num_double_arguments);
1318 // Before calling a C-function from generated code, align arguments on stack
1319 // and add space for the four mips argument slots.
1320 // After aligning the frame, non-register arguments must be stored on the
1321 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1322 // The argument count assumes all arguments are word sized.
1323 // Some compilers/platforms require the stack to be aligned when calling
1325 // Needs a scratch register to do some arithmetic. This register will be
1327 void PrepareCallCFunction(int num_reg_arguments,
1328 int num_double_registers,
1330 void PrepareCallCFunction(int num_reg_arguments,
1333 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1334 // Arguments 5..n are stored to stack using following:
1335 // sw(a4, CFunctionArgumentOperand(5));
1337 // Calls a C function and cleans up the space for arguments allocated
1338 // by PrepareCallCFunction. The called function is not allowed to trigger a
1339 // garbage collection, since that might move the code and invalidate the
1340 // return address (unless this is somehow accounted for by the called
1342 void CallCFunction(ExternalReference function, int num_arguments);
1343 void CallCFunction(Register function, int num_arguments);
1344 void CallCFunction(ExternalReference function,
1345 int num_reg_arguments,
1346 int num_double_arguments);
1347 void CallCFunction(Register function,
1348 int num_reg_arguments,
1349 int num_double_arguments);
1350 void MovFromFloatResult(DoubleRegister dst);
1351 void MovFromFloatParameter(DoubleRegister dst);
1353 // There are two ways of passing double arguments on MIPS, depending on
1354 // whether soft or hard floating point ABI is used. These functions
1355 // abstract parameter passing for the three different ways we call
1356 // C functions from generated code.
1357 void MovToFloatParameter(DoubleRegister src);
1358 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1359 void MovToFloatResult(DoubleRegister src);
1361 // Jump to the builtin routine.
1362 void JumpToExternalReference(const ExternalReference& builtin,
1363 BranchDelaySlot bd = PROTECT);
1365 // Invoke specified builtin JavaScript function.
1366 void InvokeBuiltin(int native_context_index, InvokeFlag flag,
1367 const CallWrapper& call_wrapper = NullCallWrapper());
1369 // Store the code object for the given builtin in the target register and
1370 // setup the function in a1.
1371 void GetBuiltinEntry(Register target, int native_context_index);
1373 // Store the function for the given builtin in the target register.
1374 void GetBuiltinFunction(Register target, int native_context_index);
1378 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
1382 Handle<Object> CodeObject() {
1383 DCHECK(!code_object_.is_null());
1384 return code_object_;
1387 // Emit code for a truncating division by a constant. The dividend register is
1388 // unchanged and at gets clobbered. Dividend and result must be different.
1389 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1391 // -------------------------------------------------------------------------
1392 // StatsCounter support.
1394 void SetCounter(StatsCounter* counter, int value,
1395 Register scratch1, Register scratch2);
1396 void IncrementCounter(StatsCounter* counter, int value,
1397 Register scratch1, Register scratch2);
1398 void DecrementCounter(StatsCounter* counter, int value,
1399 Register scratch1, Register scratch2);
1402 // -------------------------------------------------------------------------
1405 // Calls Abort(msg) if the condition cc is not satisfied.
1406 // Use --debug_code to enable.
1407 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
1408 void AssertFastElements(Register elements);
1410 // Like Assert(), but always enabled.
1411 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
1413 // Print a message to stdout and abort execution.
1414 void Abort(BailoutReason msg);
1416 // Verify restrictions about code generated in stubs.
1417 void set_generating_stub(bool value) { generating_stub_ = value; }
1418 bool generating_stub() { return generating_stub_; }
1419 void set_has_frame(bool value) { has_frame_ = value; }
1420 bool has_frame() { return has_frame_; }
1421 inline bool AllowThisStubCall(CodeStub* stub);
1423 // ---------------------------------------------------------------------------
1424 // Number utilities.
1426 // Check whether the value of reg is a power of two and not zero. If not
1427 // control continues at the label not_power_of_two. If reg is a power of two
1428 // the register scratch contains the value of (reg - 1) when control falls
1430 void JumpIfNotPowerOfTwoOrZero(Register reg,
1432 Label* not_power_of_two_or_zero);
1434 // -------------------------------------------------------------------------
1437 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1438 void SmiTagCheckOverflow(Register reg, Register overflow);
1439 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1441 void SmiTag(Register dst, Register src) {
1442 STATIC_ASSERT(kSmiTag == 0);
1443 if (SmiValuesAre32Bits()) {
1444 STATIC_ASSERT(kSmiShift == 32);
1445 dsll32(dst, src, 0);
1447 Addu(dst, src, src);
1451 void SmiTag(Register reg) {
1455 // Try to convert int32 to smi. If the value is to large, preserve
1456 // the original value and jump to not_a_smi. Destroys scratch and
1458 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1459 TrySmiTag(reg, reg, scratch, not_a_smi);
1462 void TrySmiTag(Register dst,
1466 if (SmiValuesAre32Bits()) {
1469 SmiTagCheckOverflow(at, src, scratch);
1470 BranchOnOverflow(not_a_smi, scratch);
1475 void SmiUntag(Register dst, Register src) {
1476 if (SmiValuesAre32Bits()) {
1477 STATIC_ASSERT(kSmiShift == 32);
1478 dsra32(dst, src, 0);
1480 sra(dst, src, kSmiTagSize);
1484 void SmiUntag(Register reg) {
1488 // Left-shifted from int32 equivalent of Smi.
1489 void SmiScale(Register dst, Register src, int scale) {
1490 if (SmiValuesAre32Bits()) {
1491 // The int portion is upper 32-bits of 64-bit word.
1492 dsra(dst, src, kSmiShift - scale);
1494 DCHECK(scale >= kSmiTagSize);
1495 sll(dst, src, scale - kSmiTagSize);
1499 // Combine load with untagging or scaling.
1500 void SmiLoadUntag(Register dst, MemOperand src);
1502 void SmiLoadScale(Register dst, MemOperand src, int scale);
1504 // Returns 2 values: the Smi and a scaled version of the int within the Smi.
1505 void SmiLoadWithScale(Register d_smi,
1510 // Returns 2 values: the untagged Smi (int32) and scaled version of that int.
1511 void SmiLoadUntagWithScale(Register d_int,
1517 // Test if the register contains a smi.
1518 inline void SmiTst(Register value, Register scratch) {
1519 And(scratch, value, Operand(kSmiTagMask));
1521 inline void NonNegativeSmiTst(Register value, Register scratch) {
1522 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1525 // Untag the source value into destination and jump if source is a smi.
1526 // Source and destination can be the same register.
1527 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1529 // Untag the source value into destination and jump if source is not a smi.
1530 // Source and destination can be the same register.
1531 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1533 // Jump the register contains a smi.
1534 void JumpIfSmi(Register value,
1536 Register scratch = at,
1537 BranchDelaySlot bd = PROTECT);
1539 // Jump if the register contains a non-smi.
1540 void JumpIfNotSmi(Register value,
1541 Label* not_smi_label,
1542 Register scratch = at,
1543 BranchDelaySlot bd = PROTECT);
1545 // Jump if either of the registers contain a non-smi.
1546 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1547 // Jump if either of the registers contain a smi.
1548 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1550 // Abort execution if argument is a smi, enabled via --debug-code.
1551 void AssertNotSmi(Register object);
1552 void AssertSmi(Register object);
1554 // Abort execution if argument is not a string, enabled via --debug-code.
1555 void AssertString(Register object);
1557 // Abort execution if argument is not a name, enabled via --debug-code.
1558 void AssertName(Register object);
1560 // Abort execution if argument is not undefined or an AllocationSite, enabled
1561 // via --debug-code.
1562 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1564 // Abort execution if reg is not the root value with the given index,
1565 // enabled via --debug-code.
1566 void AssertIsRoot(Register reg, Heap::RootListIndex index);
1568 // ---------------------------------------------------------------------------
1569 // HeapNumber utilities.
1571 void JumpIfNotHeapNumber(Register object,
1572 Register heap_number_map,
1574 Label* on_not_heap_number);
1576 // -------------------------------------------------------------------------
1577 // String utilities.
1579 // Generate code to do a lookup in the number string cache. If the number in
1580 // the register object is found in the cache the generated code falls through
1581 // with the result in the result register. The object and the result register
1582 // can be the same. If the number is not found in the cache the code jumps to
1583 // the label not_found with only the content of register object unchanged.
1584 void LookupNumberStringCache(Register object,
1591 // Checks if both instance types are sequential one-byte strings and jumps to
1592 // label if either is not.
1593 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1594 Register first_object_instance_type, Register second_object_instance_type,
1595 Register scratch1, Register scratch2, Label* failure);
1597 // Check if instance type is sequential one-byte string and jump to label if
1599 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1602 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
1604 void EmitSeqStringSetCharCheck(Register string,
1608 uint32_t encoding_mask);
1610 // Checks if both objects are sequential one-byte strings and jumps to label
1611 // if either is not. Assumes that neither object is a smi.
1612 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first,
1618 // Checks if both objects are sequential one-byte strings and jumps to label
1619 // if either is not.
1620 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1623 Label* not_flat_one_byte_strings);
1625 void ClampUint8(Register output_reg, Register input_reg);
1627 void ClampDoubleToUint8(Register result_reg,
1628 DoubleRegister input_reg,
1629 DoubleRegister temp_double_reg);
1632 void LoadInstanceDescriptors(Register map, Register descriptors);
1633 void EnumLength(Register dst, Register map);
1634 void NumberOfOwnDescriptors(Register dst, Register map);
1635 void LoadAccessor(Register dst, Register holder, int accessor_index,
1636 AccessorComponent accessor);
1638 template<typename Field>
1639 void DecodeField(Register dst, Register src) {
1640 Ext(dst, src, Field::kShift, Field::kSize);
1643 template<typename Field>
1644 void DecodeField(Register reg) {
1645 DecodeField<Field>(reg, reg);
1648 template<typename Field>
1649 void DecodeFieldToSmi(Register dst, Register src) {
1650 static const int shift = Field::kShift;
1651 static const int mask = Field::kMask >> shift;
1652 dsrl(dst, src, shift);
1653 And(dst, dst, Operand(mask));
1654 dsll32(dst, dst, 0);
1657 template<typename Field>
1658 void DecodeFieldToSmi(Register reg) {
1659 DecodeField<Field>(reg, reg);
1661 // Generates function and stub prologue code.
1662 void StubPrologue();
1663 void Prologue(bool code_pre_aging);
1665 // Activation support.
1666 void EnterFrame(StackFrame::Type type);
1667 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1668 void LeaveFrame(StackFrame::Type type);
1670 // Expects object in a0 and returns map with validated enum cache
1671 // in a0. Assumes that any other register can be used as a scratch.
1672 void CheckEnumCache(Register null_value, Label* call_runtime);
1674 // AllocationMemento support. Arrays may have an associated
1675 // AllocationMemento object that can be checked for in order to pretransition
1677 // On entry, receiver_reg should point to the array object.
1678 // scratch_reg gets clobbered.
1679 // If allocation info is present, jump to allocation_memento_present.
1680 void TestJSArrayForAllocationMemento(
1681 Register receiver_reg,
1682 Register scratch_reg,
1683 Label* no_memento_found,
1684 Condition cond = al,
1685 Label* allocation_memento_present = NULL);
1687 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1688 Register scratch_reg,
1689 Label* memento_found) {
1690 Label no_memento_found;
1691 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1692 &no_memento_found, eq, memento_found);
1693 bind(&no_memento_found);
1696 // Jumps to found label if a prototype map has dictionary elements.
1697 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1698 Register scratch1, Label* found);
1701 void CallCFunctionHelper(Register function,
1702 int num_reg_arguments,
1703 int num_double_arguments);
1705 void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1706 void BranchAndLinkShort(int16_t offset, Condition cond, Register rs,
1708 BranchDelaySlot bdslot = PROTECT);
1709 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1710 void BranchAndLinkShort(Label* L, Condition cond, Register rs,
1712 BranchDelaySlot bdslot = PROTECT);
1713 void J(Label* L, BranchDelaySlot bdslot);
1714 void Jal(Label* L, BranchDelaySlot bdslot);
1715 void Jr(Label* L, BranchDelaySlot bdslot);
1716 void Jalr(Label* L, BranchDelaySlot bdslot);
1718 // Common implementation of BranchF functions for the different formats.
1719 void BranchFCommon(SecondaryField sizeField, Label* target, Label* nan,
1720 Condition cc, FPURegister cmp1, FPURegister cmp2,
1721 BranchDelaySlot bd = PROTECT);
1723 void BranchShortF(SecondaryField sizeField, Label* target, Condition cc,
1724 FPURegister cmp1, FPURegister cmp2,
1725 BranchDelaySlot bd = PROTECT);
1728 // Helper functions for generating invokes.
1729 void InvokePrologue(const ParameterCount& expected,
1730 const ParameterCount& actual,
1731 Handle<Code> code_constant,
1734 bool* definitely_mismatches,
1736 const CallWrapper& call_wrapper);
1738 void InitializeNewString(Register string,
1740 Heap::RootListIndex map_index,
1744 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1745 void InNewSpace(Register object,
1747 Condition cond, // eq for new space, ne otherwise.
1750 // Helper for finding the mark bits for an address. Afterwards, the
1751 // bitmap register points at the word with the mark bits and the mask
1752 // the position of the first bit. Leaves addr_reg unchanged.
1753 inline void GetMarkBits(Register addr_reg,
1754 Register bitmap_reg,
1757 // Compute memory operands for safepoint stack slots.
1758 static int SafepointRegisterStackIndex(int reg_code);
1759 MemOperand SafepointRegisterSlot(Register reg);
1760 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1762 bool generating_stub_;
1764 bool has_double_zero_reg_set_;
1765 // This handle will be patched with the code object on installation.
1766 Handle<Object> code_object_;
1768 // Needs access to SafepointRegisterStackIndex for compiled frame
1770 friend class StandardFrame;
1774 // The code patcher is used to patch (typically) small parts of code e.g. for
1775 // debugging and other types of instrumentation. When using the code patcher
1776 // the exact number of bytes specified must be emitted. It is not legal to emit
1777 // relocation information. If any of these constraints are violated it causes
1778 // an assertion to fail.
1786 CodePatcher(byte* address,
1788 FlushICache flush_cache = FLUSH);
1791 // Macro assembler to emit code.
1792 MacroAssembler* masm() { return &masm_; }
1794 // Emit an instruction directly.
1795 void Emit(Instr instr);
1797 // Emit an address directly.
1798 void Emit(Address addr);
1800 // Change the condition part of an instruction leaving the rest of the current
1801 // instruction unchanged.
1802 void ChangeBranchCondition(Condition cond);
1805 byte* address_; // The address of the code being patched.
1806 int size_; // Number of bytes of the expected patch size.
1807 MacroAssembler masm_; // Macro assembler used to generate the code.
1808 FlushICache flush_cache_; // Whether to flush the I cache after patching.
1813 #ifdef GENERATED_CODE_COVERAGE
1814 #define CODE_COVERAGE_STRINGIFY(x) #x
1815 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1816 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1817 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1819 #define ACCESS_MASM(masm) masm->
1822 } } // namespace v8::internal
1824 #endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_