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/mips/assembler-mips.h"
15 // Forward declaration.
18 // Reserved Register Usage Summary.
20 // Registers t8, t9, and at are reserved for use by the MacroAssembler.
22 // The programmer should know that the MacroAssembler may clobber these three,
23 // but won't touch other registers except in special cases.
25 // Per the MIPS ABI, register t9 must be used for indirect function call
26 // via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
27 // trying to update gp register for position-independent-code. Whenever
28 // MIPS generated code calls C code, it must be via t9 register.
31 // Flags used for LeaveExitFrame function.
32 enum LeaveExitFrameMode {
34 NO_EMIT_RETURN = false
37 // Flags used for AllocateHeapNumber
45 // Flags used for the ObjectToDoubleFPURegister function.
46 enum ObjectToDoubleFlags {
48 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
49 // Object is known to be a non smi.
50 OBJECT_NOT_SMI = 1 << 0,
51 // Don't load NaNs or infinities, branch to the non number case instead.
52 AVOID_NANS_AND_INFINITIES = 1 << 1
55 // Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
56 enum BranchDelaySlot {
61 // Flags used for the li macro-assembler function.
63 // If the constant value can be represented in just 16 bits, then
64 // optimize the li to use a single instruction, rather than lui/ori pair.
66 // Always use 2 instructions (lui/ori pair), even if the constant could
67 // be loaded with just one, so that this value is patchable later.
72 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
73 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
74 enum PointersToHereCheck {
75 kPointersToHereMaybeInteresting,
76 kPointersToHereAreAlwaysInteresting
78 enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
80 Register GetRegisterThatIsNotOneOf(Register reg1,
81 Register reg2 = no_reg,
82 Register reg3 = no_reg,
83 Register reg4 = no_reg,
84 Register reg5 = no_reg,
85 Register reg6 = no_reg);
87 bool AreAliased(Register reg1,
89 Register reg3 = no_reg,
90 Register reg4 = no_reg,
91 Register reg5 = no_reg,
92 Register reg6 = no_reg,
93 Register reg7 = no_reg,
94 Register reg8 = no_reg);
97 // -----------------------------------------------------------------------------
98 // Static helper functions.
100 inline MemOperand ContextOperand(Register context, int index) {
101 return MemOperand(context, Context::SlotOffset(index));
105 inline MemOperand GlobalObjectOperand() {
106 return ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX);
110 // Generate a MemOperand for loading a field from an object.
111 inline MemOperand FieldMemOperand(Register object, int offset) {
112 return MemOperand(object, offset - kHeapObjectTag);
116 // Generate a MemOperand for storing arguments 5..N on the stack
117 // when calling CallCFunction().
118 inline MemOperand CFunctionArgumentOperand(int index) {
119 DCHECK(index > kCArgSlotCount);
120 // Argument 5 takes the slot just past the four Arg-slots.
121 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
122 return MemOperand(sp, offset);
126 // MacroAssembler implements a collection of frequently used macros.
127 class MacroAssembler: public Assembler {
129 // The isolate parameter can be NULL if the macro assembler should
130 // not use isolate-dependent functionality. In this case, it's the
131 // responsibility of the caller to never invoke such function on the
133 MacroAssembler(Isolate* isolate, void* buffer, int size);
136 #define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
137 #define COND_ARGS cond, r1, r2
139 // Cases when relocation is not needed.
140 #define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
141 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
142 inline void Name(BranchDelaySlot bd, target_type target) { \
145 void Name(target_type target, \
147 BranchDelaySlot bd = PROTECT); \
148 inline void Name(BranchDelaySlot bd, \
149 target_type target, \
151 Name(target, COND_ARGS, bd); \
154 #define DECLARE_BRANCH_PROTOTYPES(Name) \
155 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
156 DECLARE_NORELOC_PROTOTYPE(Name, int16_t)
158 DECLARE_BRANCH_PROTOTYPES(Branch)
159 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
160 DECLARE_BRANCH_PROTOTYPES(BranchShort)
162 #undef DECLARE_BRANCH_PROTOTYPES
163 #undef COND_TYPED_ARGS
167 // Jump, Call, and Ret pseudo instructions implementing inter-working.
168 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
169 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
171 void Jump(Register target, COND_ARGS);
172 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
173 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
174 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
175 static int CallSize(Register target, COND_ARGS);
176 void Call(Register target, COND_ARGS);
177 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
178 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
179 int CallSize(Handle<Code> code,
180 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
181 TypeFeedbackId ast_id = TypeFeedbackId::None(),
183 void Call(Handle<Code> code,
184 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
185 TypeFeedbackId ast_id = TypeFeedbackId::None(),
188 inline void Ret(BranchDelaySlot bd, Condition cond = al,
189 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
190 Ret(cond, rs, rt, bd);
193 void Branch(Label* L,
196 Heap::RootListIndex index,
197 BranchDelaySlot bdslot = PROTECT);
201 // Emit code to discard a non-negative number of pointer-sized elements
202 // from the stack, clobbering only the sp register.
204 Condition cond = cc_always,
205 Register reg = no_reg,
206 const Operand& op = Operand(no_reg));
208 // Trivial case of DropAndRet that utilizes the delay slot and only emits
210 void DropAndRet(int drop);
212 void DropAndRet(int drop,
217 // Swap two registers. If the scratch register is omitted then a slightly
218 // less efficient form using xor instead of mov is emitted.
219 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
221 void Call(Label* target);
223 inline void Move(Register dst, Register src) {
229 inline void Move(FPURegister dst, FPURegister src) {
235 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
237 Mfhc1(dst_high, src);
240 inline void FmoveHigh(Register dst_high, FPURegister src) {
241 Mfhc1(dst_high, src);
244 inline void FmoveLow(Register dst_low, FPURegister src) {
248 inline void Move(FPURegister dst, Register src_low, Register src_high) {
250 Mthc1(src_high, dst);
254 void Move(FPURegister dst, double imm);
255 void Movz(Register rd, Register rs, Register rt);
256 void Movn(Register rd, Register rs, Register rt);
257 void Movt(Register rd, Register rs, uint16_t cc = 0);
258 void Movf(Register rd, Register rs, uint16_t cc = 0);
260 void Clz(Register rd, Register rs);
262 // Jump unconditionally to given label.
263 // We NEED a nop in the branch delay slot, as it used by v8, for example in
264 // CodeGenerator::ProcessDeferred().
265 // Currently the branch delay slot is filled by the MacroAssembler.
266 // Use rather b(Label) for code generation.
271 void Load(Register dst, const MemOperand& src, Representation r);
272 void Store(Register src, const MemOperand& dst, Representation r);
274 // Load an object from the root table.
275 void LoadRoot(Register destination,
276 Heap::RootListIndex index);
277 void LoadRoot(Register destination,
278 Heap::RootListIndex index,
279 Condition cond, Register src1, const Operand& src2);
281 // Store an object to the root table.
282 void StoreRoot(Register source,
283 Heap::RootListIndex index);
284 void StoreRoot(Register source,
285 Heap::RootListIndex index,
286 Condition cond, Register src1, const Operand& src2);
288 // ---------------------------------------------------------------------------
291 void IncrementalMarkingRecordWriteHelper(Register object,
295 enum RememberedSetFinalAction {
301 // Record in the remembered set the fact that we have a pointer to new space
302 // at the address pointed to by the addr register. Only works if addr is not
304 void RememberedSetHelper(Register object, // Used for debug code.
307 SaveFPRegsMode save_fp,
308 RememberedSetFinalAction and_then);
310 void CheckPageFlag(Register object,
314 Label* condition_met);
316 void CheckMapDeprecated(Handle<Map> map,
318 Label* if_deprecated);
320 // Check if object is in new space. Jumps if the object is not in new space.
321 // The register scratch can be object itself, but it will be clobbered.
322 void JumpIfNotInNewSpace(Register object,
325 InNewSpace(object, scratch, ne, branch);
328 // Check if object is in new space. Jumps if the object is in new space.
329 // The register scratch can be object itself, but scratch will be clobbered.
330 void JumpIfInNewSpace(Register object,
333 InNewSpace(object, scratch, eq, branch);
336 // Check if an object has a given incremental marking color.
337 void HasColor(Register object,
344 void JumpIfBlack(Register object,
349 // Checks the color of an object. If the object is already grey or black
350 // then we just fall through, since it is already live. If it is white and
351 // we can determine that it doesn't need to be scanned, then we just mark it
352 // black and fall through. For the rest we jump to the label so the
353 // incremental marker can fix its assumptions.
354 void EnsureNotWhite(Register object,
358 Label* object_is_white_and_not_data);
360 // Detects conservatively whether an object is data-only, i.e. it does need to
361 // be scanned by the garbage collector.
362 void JumpIfDataObject(Register value,
364 Label* not_data_object);
366 // Notify the garbage collector that we wrote a pointer into an object.
367 // |object| is the object being stored into, |value| is the object being
368 // stored. value and scratch registers are clobbered by the operation.
369 // The offset is the offset from the start of the object, not the offset from
370 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
371 void RecordWriteField(
377 SaveFPRegsMode save_fp,
378 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
379 SmiCheck smi_check = INLINE_SMI_CHECK,
380 PointersToHereCheck pointers_to_here_check_for_value =
381 kPointersToHereMaybeInteresting);
383 // As above, but the offset has the tag presubtracted. For use with
384 // MemOperand(reg, off).
385 inline void RecordWriteContextSlot(
391 SaveFPRegsMode save_fp,
392 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
393 SmiCheck smi_check = INLINE_SMI_CHECK,
394 PointersToHereCheck pointers_to_here_check_for_value =
395 kPointersToHereMaybeInteresting) {
396 RecordWriteField(context,
397 offset + kHeapObjectTag,
402 remembered_set_action,
404 pointers_to_here_check_for_value);
407 void RecordWriteForMap(
412 SaveFPRegsMode save_fp);
414 // For a given |object| notify the garbage collector that the slot |address|
415 // has been written. |value| is the object being stored. The value and
416 // address registers are clobbered by the operation.
422 SaveFPRegsMode save_fp,
423 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
424 SmiCheck smi_check = INLINE_SMI_CHECK,
425 PointersToHereCheck pointers_to_here_check_for_value =
426 kPointersToHereMaybeInteresting);
429 // ---------------------------------------------------------------------------
430 // Inline caching support.
432 // Generate code for checking access rights - used for security checks
433 // on access to global objects across environments. The holder register
434 // is left untouched, whereas both scratch registers are clobbered.
435 void CheckAccessGlobalProxy(Register holder_reg,
439 void GetNumberHash(Register reg0, Register scratch);
441 void LoadFromNumberDictionary(Label* miss,
450 inline void MarkCode(NopMarkerTypes type) {
454 // Check if the given instruction is a 'type' marker.
455 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
456 // nop(type)). These instructions are generated to mark special location in
457 // the code, like some special IC code.
458 static inline bool IsMarkedCode(Instr instr, int type) {
459 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
460 return IsNop(instr, type);
464 static inline int GetCodeMarker(Instr instr) {
465 uint32_t opcode = ((instr & kOpcodeMask));
466 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
467 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
468 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
470 // Return <n> if we have a sll zero_reg, zero_reg, n
472 bool sllzz = (opcode == SLL &&
473 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
474 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
476 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
477 DCHECK((type == -1) ||
478 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
484 // ---------------------------------------------------------------------------
485 // Allocation support.
487 // Allocate an object in new space or old pointer space. The object_size is
488 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
489 // is passed. If the space is exhausted control continues at the gc_required
490 // label. The allocated object is returned in result. If the flag
491 // tag_allocated_object is true the result is tagged as as a heap object.
492 // All registers are clobbered also when control continues at the gc_required
494 void Allocate(int object_size,
499 AllocationFlags flags);
501 void Allocate(Register object_size,
506 AllocationFlags flags);
508 // Undo allocation in new space. The object passed and objects allocated after
509 // it will no longer be allocated. The caller must make sure that no pointers
510 // are left to the object(s) no longer allocated as they would be invalid when
511 // allocation is undone.
512 void UndoAllocationInNewSpace(Register object, Register scratch);
515 void AllocateTwoByteString(Register result,
521 void AllocateAsciiString(Register result,
527 void AllocateTwoByteConsString(Register result,
532 void AllocateAsciiConsString(Register result,
537 void AllocateTwoByteSlicedString(Register result,
542 void AllocateAsciiSlicedString(Register result,
548 // Allocates a heap number or jumps to the gc_required label if the young
549 // space is full and a scavenge is needed. All registers are clobbered also
550 // when control continues at the gc_required label.
551 void AllocateHeapNumber(Register result,
554 Register heap_number_map,
556 TaggingMode tagging_mode = TAG_RESULT,
557 MutableMode mode = IMMUTABLE);
558 void AllocateHeapNumberWithValue(Register result,
564 // ---------------------------------------------------------------------------
565 // Instruction macros.
567 #define DEFINE_INSTRUCTION(instr) \
568 void instr(Register rd, Register rs, const Operand& rt); \
569 void instr(Register rd, Register rs, Register rt) { \
570 instr(rd, rs, Operand(rt)); \
572 void instr(Register rs, Register rt, int32_t j) { \
573 instr(rs, rt, Operand(j)); \
576 #define DEFINE_INSTRUCTION2(instr) \
577 void instr(Register rs, const Operand& rt); \
578 void instr(Register rs, Register rt) { \
579 instr(rs, Operand(rt)); \
581 void instr(Register rs, int32_t j) { \
582 instr(rs, Operand(j)); \
585 #define DEFINE_INSTRUCTION3(instr) \
586 void instr(Register rd_hi, Register rd_lo, Register rs, const Operand& rt); \
587 void instr(Register rd_hi, Register rd_lo, Register rs, Register rt) { \
588 instr(rd_hi, rd_lo, rs, Operand(rt)); \
590 void instr(Register rd_hi, Register rd_lo, Register rs, int32_t j) { \
591 instr(rd_hi, rd_lo, rs, Operand(j)); \
594 DEFINE_INSTRUCTION(Addu);
595 DEFINE_INSTRUCTION(Subu);
596 DEFINE_INSTRUCTION(Mul);
597 DEFINE_INSTRUCTION(Mod);
598 DEFINE_INSTRUCTION(Mulh);
599 DEFINE_INSTRUCTION2(Mult);
600 DEFINE_INSTRUCTION2(Multu);
601 DEFINE_INSTRUCTION2(Div);
602 DEFINE_INSTRUCTION2(Divu);
604 DEFINE_INSTRUCTION3(Div);
605 DEFINE_INSTRUCTION3(Mul);
607 DEFINE_INSTRUCTION(And);
608 DEFINE_INSTRUCTION(Or);
609 DEFINE_INSTRUCTION(Xor);
610 DEFINE_INSTRUCTION(Nor);
611 DEFINE_INSTRUCTION2(Neg);
613 DEFINE_INSTRUCTION(Slt);
614 DEFINE_INSTRUCTION(Sltu);
616 // MIPS32 R2 instruction macro.
617 DEFINE_INSTRUCTION(Ror);
619 #undef DEFINE_INSTRUCTION
620 #undef DEFINE_INSTRUCTION2
622 void Pref(int32_t hint, const MemOperand& rs);
625 // ---------------------------------------------------------------------------
626 // Pseudo-instructions.
628 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
630 void Ulw(Register rd, const MemOperand& rs);
631 void Usw(Register rd, const MemOperand& rs);
633 // Load int32 in the rd register.
634 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
635 inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
636 li(rd, Operand(j), mode);
638 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
640 // Push multiple registers on the stack.
641 // Registers are saved in numerical order, with higher numbered registers
642 // saved in higher memory addresses.
643 void MultiPush(RegList regs);
644 void MultiPushReversed(RegList regs);
646 void MultiPushFPU(RegList regs);
647 void MultiPushReversedFPU(RegList regs);
649 void push(Register src) {
650 Addu(sp, sp, Operand(-kPointerSize));
651 sw(src, MemOperand(sp, 0));
653 void Push(Register src) { push(src); }
656 void Push(Handle<Object> handle);
657 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
659 // Push two registers. Pushes leftmost register first (to highest address).
660 void Push(Register src1, Register src2) {
661 Subu(sp, sp, Operand(2 * kPointerSize));
662 sw(src1, MemOperand(sp, 1 * kPointerSize));
663 sw(src2, MemOperand(sp, 0 * kPointerSize));
666 // Push three registers. Pushes leftmost register first (to highest address).
667 void Push(Register src1, Register src2, Register src3) {
668 Subu(sp, sp, Operand(3 * kPointerSize));
669 sw(src1, MemOperand(sp, 2 * kPointerSize));
670 sw(src2, MemOperand(sp, 1 * kPointerSize));
671 sw(src3, MemOperand(sp, 0 * kPointerSize));
674 // Push four registers. Pushes leftmost register first (to highest address).
675 void Push(Register src1, Register src2, Register src3, Register src4) {
676 Subu(sp, sp, Operand(4 * kPointerSize));
677 sw(src1, MemOperand(sp, 3 * kPointerSize));
678 sw(src2, MemOperand(sp, 2 * kPointerSize));
679 sw(src3, MemOperand(sp, 1 * kPointerSize));
680 sw(src4, MemOperand(sp, 0 * kPointerSize));
683 void Push(Register src, Condition cond, Register tst1, Register tst2) {
684 // Since we don't have conditional execution we use a Branch.
685 Branch(3, cond, tst1, Operand(tst2));
686 Subu(sp, sp, Operand(kPointerSize));
687 sw(src, MemOperand(sp, 0));
690 // Pops multiple values from the stack and load them in the
691 // registers specified in regs. Pop order is the opposite as in MultiPush.
692 void MultiPop(RegList regs);
693 void MultiPopReversed(RegList regs);
695 void MultiPopFPU(RegList regs);
696 void MultiPopReversedFPU(RegList regs);
698 void pop(Register dst) {
699 lw(dst, MemOperand(sp, 0));
700 Addu(sp, sp, Operand(kPointerSize));
702 void Pop(Register dst) { pop(dst); }
704 // Pop two registers. Pops rightmost register first (from lower address).
705 void Pop(Register src1, Register src2) {
706 DCHECK(!src1.is(src2));
707 lw(src2, MemOperand(sp, 0 * kPointerSize));
708 lw(src1, MemOperand(sp, 1 * kPointerSize));
709 Addu(sp, sp, 2 * kPointerSize);
712 // Pop three registers. Pops rightmost register first (from lower address).
713 void Pop(Register src1, Register src2, Register src3) {
714 lw(src3, MemOperand(sp, 0 * kPointerSize));
715 lw(src2, MemOperand(sp, 1 * kPointerSize));
716 lw(src1, MemOperand(sp, 2 * kPointerSize));
717 Addu(sp, sp, 3 * kPointerSize);
720 void Pop(uint32_t count = 1) {
721 Addu(sp, sp, Operand(count * kPointerSize));
724 // Push and pop the registers that can hold pointers, as defined by the
725 // RegList constant kSafepointSavedRegisters.
726 void PushSafepointRegisters();
727 void PopSafepointRegisters();
728 // Store value in register src in the safepoint stack slot for
730 void StoreToSafepointRegisterSlot(Register src, Register dst);
731 // Load the value of the src register from its safepoint stack slot
732 // into register dst.
733 void LoadFromSafepointRegisterSlot(Register dst, Register src);
735 // Flush the I-cache from asm code. You should use CpuFeatures::FlushICache
737 // Does not handle errors.
738 void FlushICache(Register address, unsigned instructions);
740 // MIPS32 R2 instruction macro.
741 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
742 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
744 // ---------------------------------------------------------------------------
745 // FPU macros. These do not handle special cases like NaN or +- inf.
747 // Convert unsigned word to double.
748 void Cvt_d_uw(FPURegister fd, FPURegister fs, FPURegister scratch);
749 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
751 // Convert double to unsigned word.
752 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
753 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
755 void Trunc_w_d(FPURegister fd, FPURegister fs);
756 void Round_w_d(FPURegister fd, FPURegister fs);
757 void Floor_w_d(FPURegister fd, FPURegister fs);
758 void Ceil_w_d(FPURegister fd, FPURegister fs);
760 // FP32 mode: Move the general purpose register into
761 // the high part of the double-register pair.
762 // FP64 mode: Move the general-purpose register into
763 // the higher 32 bits of the 64-bit coprocessor register,
764 // while leaving the low bits unchanged.
765 void Mthc1(Register rt, FPURegister fs);
767 // FP32 mode: move the high part of the double-register pair into
768 // general purpose register.
769 // FP64 mode: Move the higher 32 bits of the 64-bit coprocessor register into
770 // general-purpose register.
771 void Mfhc1(Register rt, FPURegister fs);
773 // Wrapper function for the different cmp/branch types.
774 void BranchF(Label* target,
779 BranchDelaySlot bd = PROTECT);
781 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
782 inline void BranchF(BranchDelaySlot bd,
788 BranchF(target, nan, cc, cmp1, cmp2, bd);
791 // Truncates a double using a specific rounding mode, and writes the value
792 // to the result register.
793 // The except_flag will contain any exceptions caused by the instruction.
794 // If check_inexact is kDontCheckForInexactConversion, then the inexact
795 // exception is masked.
796 void EmitFPUTruncate(FPURoundingMode rounding_mode,
798 DoubleRegister double_input,
800 DoubleRegister double_scratch,
801 Register except_flag,
802 CheckForInexactConversion check_inexact
803 = kDontCheckForInexactConversion);
805 // Performs a truncating conversion of a floating point number as used by
806 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
807 // succeeds, otherwise falls through if result is saturated. On return
808 // 'result' either holds answer, or is clobbered on fall through.
810 // Only public for the test code in test-code-stubs-arm.cc.
811 void TryInlineTruncateDoubleToI(Register result,
812 DoubleRegister input,
815 // Performs a truncating conversion of a floating point number as used by
816 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
817 // Exits with 'result' holding the answer.
818 void TruncateDoubleToI(Register result, DoubleRegister double_input);
820 // Performs a truncating conversion of a heap number as used by
821 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
822 // must be different registers. Exits with 'result' holding the answer.
823 void TruncateHeapNumberToI(Register result, Register object);
825 // Converts the smi or heap number in object to an int32 using the rules
826 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
827 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
828 // different registers.
829 void TruncateNumberToI(Register object,
831 Register heap_number_map,
835 // Loads the number from object into dst register.
836 // If |object| is neither smi nor heap number, |not_number| is jumped to
837 // with |object| still intact.
838 void LoadNumber(Register object,
840 Register heap_number_map,
844 // Loads the number from object into double_dst in the double format.
845 // Control will jump to not_int32 if the value cannot be exactly represented
846 // by a 32-bit integer.
847 // Floating point value in the 32-bit integer range that are not exact integer
849 void LoadNumberAsInt32Double(Register object,
850 DoubleRegister double_dst,
851 Register heap_number_map,
854 FPURegister double_scratch,
857 // Loads the number from object into dst as a 32-bit integer.
858 // Control will jump to not_int32 if the object cannot be exactly represented
859 // by a 32-bit integer.
860 // Floating point value in the 32-bit integer range that are not exact integer
861 // won't be converted.
862 void LoadNumberAsInt32(Register object,
864 Register heap_number_map,
867 FPURegister double_scratch0,
868 FPURegister double_scratch1,
872 // argc - argument count to be dropped by LeaveExitFrame.
873 // save_doubles - saves FPU registers on stack, currently disabled.
874 // stack_space - extra stack space.
875 void EnterExitFrame(bool save_doubles,
876 int stack_space = 0);
878 // Leave the current exit frame.
879 void LeaveExitFrame(bool save_doubles,
881 bool restore_context,
882 bool do_return = NO_EMIT_RETURN);
884 // Get the actual activation frame alignment for target environment.
885 static int ActivationFrameAlignment();
887 // Make sure the stack is aligned. Only emits code in debug mode.
888 void AssertStackIsAligned();
890 void LoadContext(Register dst, int context_chain_length);
892 // Conditionally load the cached Array transitioned map of type
893 // transitioned_kind from the native context if the map in register
894 // map_in_out is the cached Array map in the native context of
896 void LoadTransitionedArrayMapConditional(
897 ElementsKind expected_kind,
898 ElementsKind transitioned_kind,
901 Label* no_map_match);
903 void LoadGlobalFunction(int index, Register function);
905 // Load the initial map from the global function. The registers
906 // function and map can be the same, function is then overwritten.
907 void LoadGlobalFunctionInitialMap(Register function,
911 void InitializeRootRegister() {
912 ExternalReference roots_array_start =
913 ExternalReference::roots_array_start(isolate());
914 li(kRootRegister, Operand(roots_array_start));
917 // -------------------------------------------------------------------------
918 // JavaScript invokes.
920 // Invoke the JavaScript function code by either calling or jumping.
921 void InvokeCode(Register code,
922 const ParameterCount& expected,
923 const ParameterCount& actual,
925 const CallWrapper& call_wrapper);
927 // Invoke the JavaScript function in the given register. Changes the
928 // current context to the context in the function before invoking.
929 void InvokeFunction(Register function,
930 const ParameterCount& actual,
932 const CallWrapper& call_wrapper);
934 void InvokeFunction(Register function,
935 const ParameterCount& expected,
936 const ParameterCount& actual,
938 const CallWrapper& call_wrapper);
940 void InvokeFunction(Handle<JSFunction> function,
941 const ParameterCount& expected,
942 const ParameterCount& actual,
944 const CallWrapper& call_wrapper);
947 void IsObjectJSObjectType(Register heap_object,
952 void IsInstanceJSObjectType(Register map,
956 void IsObjectJSStringType(Register object,
960 void IsObjectNameType(Register object,
964 // -------------------------------------------------------------------------
969 // -------------------------------------------------------------------------
970 // Exception handling.
972 // Push a new try handler and link into try handler chain.
973 void PushTryHandler(StackHandler::Kind kind, int handler_index);
975 // Unlink the stack handler on top of the stack from the try handler chain.
976 // Must preserve the result register.
977 void PopTryHandler();
979 // Passes thrown value to the handler of top of the try handler chain.
980 void Throw(Register value);
982 // Propagates an uncatchable exception to the top of the current JS stack's
984 void ThrowUncatchable(Register value);
986 // Copies a fixed number of fields of heap objects from src to dst.
987 void CopyFields(Register dst, Register src, RegList temps, int field_count);
989 // Copies a number of bytes from src to dst. All registers are clobbered. On
990 // exit src and dst will point to the place just after where the last byte was
991 // read or written and length will be zero.
992 void CopyBytes(Register src,
997 // Initialize fields with filler values. Fields starting at |start_offset|
998 // not including end_offset are overwritten with the value in |filler|. At
999 // the end the loop, |start_offset| takes the value of |end_offset|.
1000 void InitializeFieldsWithFiller(Register start_offset,
1001 Register end_offset,
1004 // -------------------------------------------------------------------------
1005 // Support functions.
1007 // Try to get function prototype of a function and puts the value in
1008 // the result register. Checks that the function really is a
1009 // function and jumps to the miss label if the fast checks fail. The
1010 // function register will be untouched; the other registers may be
1012 void TryGetFunctionPrototype(Register function,
1016 bool miss_on_bound_function = false);
1018 void GetObjectType(Register function,
1022 // Check if a map for a JSObject indicates that the object has fast elements.
1023 // Jump to the specified label if it does not.
1024 void CheckFastElements(Register map,
1028 // Check if a map for a JSObject indicates that the object can have both smi
1029 // and HeapObject elements. Jump to the specified label if it does not.
1030 void CheckFastObjectElements(Register map,
1034 // Check if a map for a JSObject indicates that the object has fast smi only
1035 // elements. Jump to the specified label if it does not.
1036 void CheckFastSmiElements(Register map,
1040 // Check to see if maybe_number can be stored as a double in
1041 // FastDoubleElements. If it can, store it at the index specified by key in
1042 // the FastDoubleElements array elements. Otherwise jump to fail.
1043 void StoreNumberToDoubleElements(Register value_reg,
1045 Register elements_reg,
1050 int elements_offset = 0);
1052 // Compare an object's map with the specified map and its transitioned
1053 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1054 // "branch_to" if the result of the comparison is "cond". If multiple map
1055 // compares are required, the compare sequences branches to early_success.
1056 void CompareMapAndBranch(Register obj,
1059 Label* early_success,
1063 // As above, but the map of the object is already loaded into the register
1064 // which is preserved by the code generated.
1065 void CompareMapAndBranch(Register obj_map,
1067 Label* early_success,
1071 // Check if the map of an object is equal to a specified map and branch to
1072 // label if not. Skip the smi check if not required (object is known to be a
1073 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1074 // against maps that are ElementsKind transition maps of the specificed map.
1075 void CheckMap(Register obj,
1079 SmiCheckType smi_check_type);
1082 void CheckMap(Register obj,
1084 Heap::RootListIndex index,
1086 SmiCheckType smi_check_type);
1088 // Check if the map of an object is equal to a specified map and branch to a
1089 // specified target if equal. Skip the smi check if not required (object is
1090 // known to be a heap object)
1091 void DispatchMap(Register obj,
1094 Handle<Code> success,
1095 SmiCheckType smi_check_type);
1098 // Load and check the instance type of an object for being a string.
1099 // Loads the type into the second argument register.
1100 // Returns a condition that will be enabled if the object was a string.
1101 Condition IsObjectStringType(Register obj,
1104 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1105 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1106 And(type, type, Operand(kIsNotStringMask));
1107 DCHECK_EQ(0, kStringTag);
1112 // Picks out an array index from the hash field.
1114 // hash - holds the index's hash. Clobbered.
1115 // index - holds the overwritten index on exit.
1116 void IndexFromHash(Register hash, Register index);
1118 // Get the number of least significant bits from a register.
1119 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1120 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1122 // Load the value of a number object into a FPU double register. If the
1123 // object is not a number a jump to the label not_number is performed
1124 // and the FPU double register is unchanged.
1125 void ObjectToDoubleFPURegister(
1130 Register heap_number_map,
1132 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1134 // Load the value of a smi object into a FPU double register. The register
1135 // scratch1 can be the same register as smi in which case smi will hold the
1136 // untagged value afterwards.
1137 void SmiToDoubleFPURegister(Register smi,
1141 // -------------------------------------------------------------------------
1142 // Overflow handling functions.
1143 // Usage: first call the appropriate arithmetic function, then call one of the
1144 // jump functions with the overflow_dst register as the second parameter.
1146 void AdduAndCheckForOverflow(Register dst,
1149 Register overflow_dst,
1150 Register scratch = at);
1152 void SubuAndCheckForOverflow(Register dst,
1155 Register overflow_dst,
1156 Register scratch = at);
1158 void BranchOnOverflow(Label* label,
1159 Register overflow_check,
1160 BranchDelaySlot bd = PROTECT) {
1161 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1164 void BranchOnNoOverflow(Label* label,
1165 Register overflow_check,
1166 BranchDelaySlot bd = PROTECT) {
1167 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1170 void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1171 Ret(lt, overflow_check, Operand(zero_reg), bd);
1174 void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1175 Ret(ge, overflow_check, Operand(zero_reg), bd);
1178 // -------------------------------------------------------------------------
1181 // See comments at the beginning of CEntryStub::Generate.
1182 inline void PrepareCEntryArgs(int num_args) {
1184 li(s1, (num_args - 1) * kPointerSize);
1187 inline void PrepareCEntryFunction(const ExternalReference& ref) {
1188 li(s2, Operand(ref));
1191 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1192 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1194 // Call a code stub.
1195 void CallStub(CodeStub* stub,
1196 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1199 // Tail call a code stub (jump).
1200 void TailCallStub(CodeStub* stub, COND_ARGS);
1204 void CallJSExitStub(CodeStub* stub);
1206 // Call a runtime routine.
1207 void CallRuntime(const Runtime::Function* f,
1209 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1210 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1211 const Runtime::Function* function = Runtime::FunctionForId(id);
1212 CallRuntime(function, function->nargs, kSaveFPRegs);
1215 // Convenience function: Same as above, but takes the fid instead.
1216 void CallRuntime(Runtime::FunctionId id,
1218 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1219 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1222 // Convenience function: call an external reference.
1223 void CallExternalReference(const ExternalReference& ext,
1225 BranchDelaySlot bd = PROTECT);
1227 // Tail call of a runtime routine (jump).
1228 // Like JumpToExternalReference, but also takes care of passing the number
1230 void TailCallExternalReference(const ExternalReference& ext,
1234 // Convenience function: tail call a runtime routine (jump).
1235 void TailCallRuntime(Runtime::FunctionId fid,
1239 int CalculateStackPassedWords(int num_reg_arguments,
1240 int num_double_arguments);
1242 // Before calling a C-function from generated code, align arguments on stack
1243 // and add space for the four mips argument slots.
1244 // After aligning the frame, non-register arguments must be stored on the
1245 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1246 // The argument count assumes all arguments are word sized.
1247 // Some compilers/platforms require the stack to be aligned when calling
1249 // Needs a scratch register to do some arithmetic. This register will be
1251 void PrepareCallCFunction(int num_reg_arguments,
1252 int num_double_registers,
1254 void PrepareCallCFunction(int num_reg_arguments,
1257 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1258 // Arguments 5..n are stored to stack using following:
1259 // sw(t0, CFunctionArgumentOperand(5));
1261 // Calls a C function and cleans up the space for arguments allocated
1262 // by PrepareCallCFunction. The called function is not allowed to trigger a
1263 // garbage collection, since that might move the code and invalidate the
1264 // return address (unless this is somehow accounted for by the called
1266 void CallCFunction(ExternalReference function, int num_arguments);
1267 void CallCFunction(Register function, int num_arguments);
1268 void CallCFunction(ExternalReference function,
1269 int num_reg_arguments,
1270 int num_double_arguments);
1271 void CallCFunction(Register function,
1272 int num_reg_arguments,
1273 int num_double_arguments);
1274 void MovFromFloatResult(DoubleRegister dst);
1275 void MovFromFloatParameter(DoubleRegister dst);
1277 // There are two ways of passing double arguments on MIPS, depending on
1278 // whether soft or hard floating point ABI is used. These functions
1279 // abstract parameter passing for the three different ways we call
1280 // C functions from generated code.
1281 void MovToFloatParameter(DoubleRegister src);
1282 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1283 void MovToFloatResult(DoubleRegister src);
1285 // Calls an API function. Allocates HandleScope, extracts returned value
1286 // from handle and propagates exceptions. Restores context. stack_space
1287 // - space to be unwound on exit (includes the call JS arguments space and
1288 // the additional space allocated for the fast call).
1289 void CallApiFunctionAndReturn(Register function_address,
1290 ExternalReference thunk_ref,
1292 MemOperand return_value_operand,
1293 MemOperand* context_restore_operand);
1295 // Jump to the builtin routine.
1296 void JumpToExternalReference(const ExternalReference& builtin,
1297 BranchDelaySlot bd = PROTECT);
1299 // Invoke specified builtin JavaScript function. Adds an entry to
1300 // the unresolved list if the name does not resolve.
1301 void InvokeBuiltin(Builtins::JavaScript id,
1303 const CallWrapper& call_wrapper = NullCallWrapper());
1305 // Store the code object for the given builtin in the target register and
1306 // setup the function in a1.
1307 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1309 // Store the function for the given builtin in the target register.
1310 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1314 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
1318 Handle<Object> CodeObject() {
1319 DCHECK(!code_object_.is_null());
1320 return code_object_;
1323 // Emit code for a truncating division by a constant. The dividend register is
1324 // unchanged and at gets clobbered. Dividend and result must be different.
1325 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1327 // -------------------------------------------------------------------------
1328 // StatsCounter support.
1330 void SetCounter(StatsCounter* counter, int value,
1331 Register scratch1, Register scratch2);
1332 void IncrementCounter(StatsCounter* counter, int value,
1333 Register scratch1, Register scratch2);
1334 void DecrementCounter(StatsCounter* counter, int value,
1335 Register scratch1, Register scratch2);
1338 // -------------------------------------------------------------------------
1341 // Calls Abort(msg) if the condition cc is not satisfied.
1342 // Use --debug_code to enable.
1343 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
1344 void AssertFastElements(Register elements);
1346 // Like Assert(), but always enabled.
1347 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
1349 // Print a message to stdout and abort execution.
1350 void Abort(BailoutReason msg);
1352 // Verify restrictions about code generated in stubs.
1353 void set_generating_stub(bool value) { generating_stub_ = value; }
1354 bool generating_stub() { return generating_stub_; }
1355 void set_has_frame(bool value) { has_frame_ = value; }
1356 bool has_frame() { return has_frame_; }
1357 inline bool AllowThisStubCall(CodeStub* stub);
1359 // ---------------------------------------------------------------------------
1360 // Number utilities.
1362 // Check whether the value of reg is a power of two and not zero. If not
1363 // control continues at the label not_power_of_two. If reg is a power of two
1364 // the register scratch contains the value of (reg - 1) when control falls
1366 void JumpIfNotPowerOfTwoOrZero(Register reg,
1368 Label* not_power_of_two_or_zero);
1370 // -------------------------------------------------------------------------
1373 void SmiTag(Register reg) {
1374 Addu(reg, reg, reg);
1377 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1378 void SmiTagCheckOverflow(Register reg, Register overflow);
1379 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1381 void SmiTag(Register dst, Register src) {
1382 Addu(dst, src, src);
1385 // Try to convert int32 to smi. If the value is to large, preserve
1386 // the original value and jump to not_a_smi. Destroys scratch and
1388 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1389 TrySmiTag(reg, reg, scratch, not_a_smi);
1391 void TrySmiTag(Register dst,
1395 SmiTagCheckOverflow(at, src, scratch);
1396 BranchOnOverflow(not_a_smi, scratch);
1400 void SmiUntag(Register reg) {
1401 sra(reg, reg, kSmiTagSize);
1404 void SmiUntag(Register dst, Register src) {
1405 sra(dst, src, kSmiTagSize);
1408 // Test if the register contains a smi.
1409 inline void SmiTst(Register value, Register scratch) {
1410 And(scratch, value, Operand(kSmiTagMask));
1412 inline void NonNegativeSmiTst(Register value, Register scratch) {
1413 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1416 // Untag the source value into destination and jump if source is a smi.
1417 // Souce and destination can be the same register.
1418 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1420 // Untag the source value into destination and jump if source is not a smi.
1421 // Souce and destination can be the same register.
1422 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1424 // Jump the register contains a smi.
1425 void JumpIfSmi(Register value,
1427 Register scratch = at,
1428 BranchDelaySlot bd = PROTECT);
1430 // Jump if the register contains a non-smi.
1431 void JumpIfNotSmi(Register value,
1432 Label* not_smi_label,
1433 Register scratch = at,
1434 BranchDelaySlot bd = PROTECT);
1436 // Jump if either of the registers contain a non-smi.
1437 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1438 // Jump if either of the registers contain a smi.
1439 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1441 // Abort execution if argument is a smi, enabled via --debug-code.
1442 void AssertNotSmi(Register object);
1443 void AssertSmi(Register object);
1445 // Abort execution if argument is not a string, enabled via --debug-code.
1446 void AssertString(Register object);
1448 // Abort execution if argument is not a name, enabled via --debug-code.
1449 void AssertName(Register object);
1451 // Abort execution if argument is not undefined or an AllocationSite, enabled
1452 // via --debug-code.
1453 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1455 // Abort execution if reg is not the root value with the given index,
1456 // enabled via --debug-code.
1457 void AssertIsRoot(Register reg, Heap::RootListIndex index);
1459 // ---------------------------------------------------------------------------
1460 // HeapNumber utilities.
1462 void JumpIfNotHeapNumber(Register object,
1463 Register heap_number_map,
1465 Label* on_not_heap_number);
1467 // -------------------------------------------------------------------------
1468 // String utilities.
1470 // Generate code to do a lookup in the number string cache. If the number in
1471 // the register object is found in the cache the generated code falls through
1472 // with the result in the result register. The object and the result register
1473 // can be the same. If the number is not found in the cache the code jumps to
1474 // the label not_found with only the content of register object unchanged.
1475 void LookupNumberStringCache(Register object,
1482 // Checks if both instance types are sequential ASCII strings and jumps to
1483 // label if either is not.
1484 void JumpIfBothInstanceTypesAreNotSequentialAscii(
1485 Register first_object_instance_type,
1486 Register second_object_instance_type,
1491 // Check if instance type is sequential ASCII string and jump to label if
1493 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1497 void JumpIfNotUniqueName(Register reg, Label* not_unique_name);
1499 void EmitSeqStringSetCharCheck(Register string,
1503 uint32_t encoding_mask);
1505 // Test that both first and second are sequential ASCII strings.
1506 // Assume that they are non-smis.
1507 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register first,
1513 // Test that both first and second are sequential ASCII strings.
1514 // Check that they are non-smis.
1515 void JumpIfNotBothSequentialAsciiStrings(Register first,
1521 void ClampUint8(Register output_reg, Register input_reg);
1523 void ClampDoubleToUint8(Register result_reg,
1524 DoubleRegister input_reg,
1525 DoubleRegister temp_double_reg);
1528 void LoadInstanceDescriptors(Register map, Register descriptors);
1529 void EnumLength(Register dst, Register map);
1530 void NumberOfOwnDescriptors(Register dst, Register map);
1532 template<typename Field>
1533 void DecodeField(Register dst, Register src) {
1534 Ext(dst, src, Field::kShift, Field::kSize);
1537 template<typename Field>
1538 void DecodeField(Register reg) {
1539 DecodeField<Field>(reg, reg);
1542 template<typename Field>
1543 void DecodeFieldToSmi(Register dst, Register src) {
1544 static const int shift = Field::kShift;
1545 static const int mask = Field::kMask >> shift << kSmiTagSize;
1546 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1547 STATIC_ASSERT(kSmiTag == 0);
1548 if (shift < kSmiTagSize) {
1549 sll(dst, src, kSmiTagSize - shift);
1550 And(dst, dst, Operand(mask));
1551 } else if (shift > kSmiTagSize) {
1552 srl(dst, src, shift - kSmiTagSize);
1553 And(dst, dst, Operand(mask));
1555 And(dst, src, Operand(mask));
1559 template<typename Field>
1560 void DecodeFieldToSmi(Register reg) {
1561 DecodeField<Field>(reg, reg);
1564 // Generates function and stub prologue code.
1565 void StubPrologue();
1566 void Prologue(bool code_pre_aging);
1568 // Activation support.
1569 void EnterFrame(StackFrame::Type type);
1570 void LeaveFrame(StackFrame::Type type);
1572 // Patch the relocated value (lui/ori pair).
1573 void PatchRelocatedValue(Register li_location,
1575 Register new_value);
1576 // Get the relocatad value (loaded data) from the lui/ori pair.
1577 void GetRelocatedValue(Register li_location,
1581 // Expects object in a0 and returns map with validated enum cache
1582 // in a0. Assumes that any other register can be used as a scratch.
1583 void CheckEnumCache(Register null_value, Label* call_runtime);
1585 // AllocationMemento support. Arrays may have an associated
1586 // AllocationMemento object that can be checked for in order to pretransition
1588 // On entry, receiver_reg should point to the array object.
1589 // scratch_reg gets clobbered.
1590 // If allocation info is present, jump to allocation_memento_present.
1591 void TestJSArrayForAllocationMemento(
1592 Register receiver_reg,
1593 Register scratch_reg,
1594 Label* no_memento_found,
1595 Condition cond = al,
1596 Label* allocation_memento_present = NULL);
1598 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1599 Register scratch_reg,
1600 Label* memento_found) {
1601 Label no_memento_found;
1602 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1603 &no_memento_found, eq, memento_found);
1604 bind(&no_memento_found);
1607 // Jumps to found label if a prototype map has dictionary elements.
1608 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1609 Register scratch1, Label* found);
1612 void CallCFunctionHelper(Register function,
1613 int num_reg_arguments,
1614 int num_double_arguments);
1616 void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1617 void BranchAndLinkShort(int16_t offset, Condition cond, Register rs,
1619 BranchDelaySlot bdslot = PROTECT);
1620 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1621 void BranchAndLinkShort(Label* L, Condition cond, Register rs,
1623 BranchDelaySlot bdslot = PROTECT);
1624 void J(Label* L, BranchDelaySlot bdslot);
1625 void Jr(Label* L, BranchDelaySlot bdslot);
1626 void Jalr(Label* L, BranchDelaySlot bdslot);
1628 // Helper functions for generating invokes.
1629 void InvokePrologue(const ParameterCount& expected,
1630 const ParameterCount& actual,
1631 Handle<Code> code_constant,
1634 bool* definitely_mismatches,
1636 const CallWrapper& call_wrapper);
1638 // Get the code for the given builtin. Returns if able to resolve
1639 // the function in the 'resolved' flag.
1640 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
1642 void InitializeNewString(Register string,
1644 Heap::RootListIndex map_index,
1648 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1649 void InNewSpace(Register object,
1651 Condition cond, // eq for new space, ne otherwise.
1654 // Helper for finding the mark bits for an address. Afterwards, the
1655 // bitmap register points at the word with the mark bits and the mask
1656 // the position of the first bit. Leaves addr_reg unchanged.
1657 inline void GetMarkBits(Register addr_reg,
1658 Register bitmap_reg,
1661 // Helper for throwing exceptions. Compute a handler address and jump to
1662 // it. See the implementation for register usage.
1663 void JumpToHandlerEntry();
1665 // Compute memory operands for safepoint stack slots.
1666 static int SafepointRegisterStackIndex(int reg_code);
1667 MemOperand SafepointRegisterSlot(Register reg);
1668 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1670 bool generating_stub_;
1672 // This handle will be patched with the code object on installation.
1673 Handle<Object> code_object_;
1675 // Needs access to SafepointRegisterStackIndex for compiled frame
1677 friend class StandardFrame;
1681 // The code patcher is used to patch (typically) small parts of code e.g. for
1682 // debugging and other types of instrumentation. When using the code patcher
1683 // the exact number of bytes specified must be emitted. It is not legal to emit
1684 // relocation information. If any of these constraints are violated it causes
1685 // an assertion to fail.
1693 CodePatcher(byte* address,
1695 FlushICache flush_cache = FLUSH);
1696 virtual ~CodePatcher();
1698 // Macro assembler to emit code.
1699 MacroAssembler* masm() { return &masm_; }
1701 // Emit an instruction directly.
1702 void Emit(Instr instr);
1704 // Emit an address directly.
1705 void Emit(Address addr);
1707 // Change the condition part of an instruction leaving the rest of the current
1708 // instruction unchanged.
1709 void ChangeBranchCondition(Condition cond);
1712 byte* address_; // The address of the code being patched.
1713 int size_; // Number of bytes of the expected patch size.
1714 MacroAssembler masm_; // Macro assembler used to generate the code.
1715 FlushICache flush_cache_; // Whether to flush the I cache after patching.
1720 #ifdef GENERATED_CODE_COVERAGE
1721 #define CODE_COVERAGE_STRINGIFY(x) #x
1722 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1723 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1724 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1726 #define ACCESS_MASM(masm) masm->
1729 } } // namespace v8::internal
1731 #endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_