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_
9 #include "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 RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
76 Register GetRegisterThatIsNotOneOf(Register reg1,
77 Register reg2 = no_reg,
78 Register reg3 = no_reg,
79 Register reg4 = no_reg,
80 Register reg5 = no_reg,
81 Register reg6 = no_reg);
83 bool AreAliased(Register r1, Register r2, Register r3, Register r4);
86 // -----------------------------------------------------------------------------
87 // Static helper functions.
89 inline MemOperand ContextOperand(Register context, int index) {
90 return MemOperand(context, Context::SlotOffset(index));
94 inline MemOperand GlobalObjectOperand() {
95 return ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX);
99 // Generate a MemOperand for loading a field from an object.
100 inline MemOperand FieldMemOperand(Register object, int offset) {
101 return MemOperand(object, offset - kHeapObjectTag);
105 // Generate a MemOperand for storing arguments 5..N on the stack
106 // when calling CallCFunction().
107 inline MemOperand CFunctionArgumentOperand(int index) {
108 ASSERT(index > kCArgSlotCount);
109 // Argument 5 takes the slot just past the four Arg-slots.
110 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
111 return MemOperand(sp, offset);
115 // MacroAssembler implements a collection of frequently used macros.
116 class MacroAssembler: public Assembler {
118 // The isolate parameter can be NULL if the macro assembler should
119 // not use isolate-dependent functionality. In this case, it's the
120 // responsibility of the caller to never invoke such function on the
122 MacroAssembler(Isolate* isolate, void* buffer, int size);
125 #define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
126 #define COND_ARGS cond, r1, r2
128 // Cases when relocation is not needed.
129 #define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
130 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
131 inline void Name(BranchDelaySlot bd, target_type target) { \
134 void Name(target_type target, \
136 BranchDelaySlot bd = PROTECT); \
137 inline void Name(BranchDelaySlot bd, \
138 target_type target, \
140 Name(target, COND_ARGS, bd); \
143 #define DECLARE_BRANCH_PROTOTYPES(Name) \
144 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
145 DECLARE_NORELOC_PROTOTYPE(Name, int16_t)
147 DECLARE_BRANCH_PROTOTYPES(Branch)
148 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
149 DECLARE_BRANCH_PROTOTYPES(BranchShort)
151 #undef DECLARE_BRANCH_PROTOTYPES
152 #undef COND_TYPED_ARGS
156 // Jump, Call, and Ret pseudo instructions implementing inter-working.
157 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
158 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
160 void Jump(Register target, COND_ARGS);
161 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
162 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
163 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
164 static int CallSize(Register target, COND_ARGS);
165 void Call(Register target, COND_ARGS);
166 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
167 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
168 int CallSize(Handle<Code> code,
169 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
170 TypeFeedbackId ast_id = TypeFeedbackId::None(),
172 void Call(Handle<Code> code,
173 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
174 TypeFeedbackId ast_id = TypeFeedbackId::None(),
177 inline void Ret(BranchDelaySlot bd, Condition cond = al,
178 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
179 Ret(cond, rs, rt, bd);
182 void Branch(Label* L,
185 Heap::RootListIndex index,
186 BranchDelaySlot bdslot = PROTECT);
190 // Emit code to discard a non-negative number of pointer-sized elements
191 // from the stack, clobbering only the sp register.
193 Condition cond = cc_always,
194 Register reg = no_reg,
195 const Operand& op = Operand(no_reg));
197 // Trivial case of DropAndRet that utilizes the delay slot and only emits
199 void DropAndRet(int drop);
201 void DropAndRet(int drop,
206 // Swap two registers. If the scratch register is omitted then a slightly
207 // less efficient form using xor instead of mov is emitted.
208 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
210 void Call(Label* target);
212 inline void Move(Register dst, Register src) {
218 inline void Move(FPURegister dst, FPURegister src) {
224 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
226 mfc1(dst_high, FPURegister::from_code(src.code() + 1));
229 inline void FmoveHigh(Register dst_high, FPURegister src) {
230 mfc1(dst_high, FPURegister::from_code(src.code() + 1));
233 inline void FmoveLow(Register dst_low, FPURegister src) {
237 inline void Move(FPURegister dst, Register src_low, Register src_high) {
239 mtc1(src_high, FPURegister::from_code(dst.code() + 1));
243 void Move(FPURegister dst, double imm);
244 void Movz(Register rd, Register rs, Register rt);
245 void Movn(Register rd, Register rs, Register rt);
246 void Movt(Register rd, Register rs, uint16_t cc = 0);
247 void Movf(Register rd, Register rs, uint16_t cc = 0);
249 void Clz(Register rd, Register rs);
251 // Jump unconditionally to given label.
252 // We NEED a nop in the branch delay slot, as it used by v8, for example in
253 // CodeGenerator::ProcessDeferred().
254 // Currently the branch delay slot is filled by the MacroAssembler.
255 // Use rather b(Label) for code generation.
260 void Load(Register dst, const MemOperand& src, Representation r);
261 void Store(Register src, const MemOperand& dst, Representation r);
263 // Load an object from the root table.
264 void LoadRoot(Register destination,
265 Heap::RootListIndex index);
266 void LoadRoot(Register destination,
267 Heap::RootListIndex index,
268 Condition cond, Register src1, const Operand& src2);
270 // Store an object to the root table.
271 void StoreRoot(Register source,
272 Heap::RootListIndex index);
273 void StoreRoot(Register source,
274 Heap::RootListIndex index,
275 Condition cond, Register src1, const Operand& src2);
277 // ---------------------------------------------------------------------------
280 void IncrementalMarkingRecordWriteHelper(Register object,
284 enum RememberedSetFinalAction {
290 // Record in the remembered set the fact that we have a pointer to new space
291 // at the address pointed to by the addr register. Only works if addr is not
293 void RememberedSetHelper(Register object, // Used for debug code.
296 SaveFPRegsMode save_fp,
297 RememberedSetFinalAction and_then);
299 void CheckPageFlag(Register object,
303 Label* condition_met);
305 void CheckMapDeprecated(Handle<Map> map,
307 Label* if_deprecated);
309 // Check if object is in new space. Jumps if the object is not in new space.
310 // The register scratch can be object itself, but it will be clobbered.
311 void JumpIfNotInNewSpace(Register object,
314 InNewSpace(object, scratch, ne, branch);
317 // Check if object is in new space. Jumps if the object is in new space.
318 // The register scratch can be object itself, but scratch will be clobbered.
319 void JumpIfInNewSpace(Register object,
322 InNewSpace(object, scratch, eq, branch);
325 // Check if an object has a given incremental marking color.
326 void HasColor(Register object,
333 void JumpIfBlack(Register object,
338 // Checks the color of an object. If the object is already grey or black
339 // then we just fall through, since it is already live. If it is white and
340 // we can determine that it doesn't need to be scanned, then we just mark it
341 // black and fall through. For the rest we jump to the label so the
342 // incremental marker can fix its assumptions.
343 void EnsureNotWhite(Register object,
347 Label* object_is_white_and_not_data);
349 // Detects conservatively whether an object is data-only, i.e. it does need to
350 // be scanned by the garbage collector.
351 void JumpIfDataObject(Register value,
353 Label* not_data_object);
355 // Notify the garbage collector that we wrote a pointer into an object.
356 // |object| is the object being stored into, |value| is the object being
357 // stored. value and scratch registers are clobbered by the operation.
358 // The offset is the offset from the start of the object, not the offset from
359 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
360 void RecordWriteField(
366 SaveFPRegsMode save_fp,
367 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
368 SmiCheck smi_check = INLINE_SMI_CHECK);
370 // As above, but the offset has the tag presubtracted. For use with
371 // MemOperand(reg, off).
372 inline void RecordWriteContextSlot(
378 SaveFPRegsMode save_fp,
379 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
380 SmiCheck smi_check = INLINE_SMI_CHECK) {
381 RecordWriteField(context,
382 offset + kHeapObjectTag,
387 remembered_set_action,
391 // For a given |object| notify the garbage collector that the slot |address|
392 // has been written. |value| is the object being stored. The value and
393 // address registers are clobbered by the operation.
399 SaveFPRegsMode save_fp,
400 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
401 SmiCheck smi_check = INLINE_SMI_CHECK);
404 // ---------------------------------------------------------------------------
405 // Inline caching support.
407 // Generate code for checking access rights - used for security checks
408 // on access to global objects across environments. The holder register
409 // is left untouched, whereas both scratch registers are clobbered.
410 void CheckAccessGlobalProxy(Register holder_reg,
414 void GetNumberHash(Register reg0, Register scratch);
416 void LoadFromNumberDictionary(Label* miss,
425 inline void MarkCode(NopMarkerTypes type) {
429 // Check if the given instruction is a 'type' marker.
430 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
431 // nop(type)). These instructions are generated to mark special location in
432 // the code, like some special IC code.
433 static inline bool IsMarkedCode(Instr instr, int type) {
434 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
435 return IsNop(instr, type);
439 static inline int GetCodeMarker(Instr instr) {
440 uint32_t opcode = ((instr & kOpcodeMask));
441 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
442 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
443 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
445 // Return <n> if we have a sll zero_reg, zero_reg, n
447 bool sllzz = (opcode == SLL &&
448 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
449 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
451 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
452 ASSERT((type == -1) ||
453 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
459 // ---------------------------------------------------------------------------
460 // Allocation support.
462 // Allocate an object in new space or old pointer space. The object_size is
463 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
464 // is passed. If the space is exhausted control continues at the gc_required
465 // label. The allocated object is returned in result. If the flag
466 // tag_allocated_object is true the result is tagged as as a heap object.
467 // All registers are clobbered also when control continues at the gc_required
469 void Allocate(int object_size,
474 AllocationFlags flags);
476 void Allocate(Register object_size,
481 AllocationFlags flags);
483 // Undo allocation in new space. The object passed and objects allocated after
484 // it will no longer be allocated. The caller must make sure that no pointers
485 // are left to the object(s) no longer allocated as they would be invalid when
486 // allocation is undone.
487 void UndoAllocationInNewSpace(Register object, Register scratch);
490 void AllocateTwoByteString(Register result,
496 void AllocateAsciiString(Register result,
502 void AllocateTwoByteConsString(Register result,
507 void AllocateAsciiConsString(Register result,
512 void AllocateTwoByteSlicedString(Register result,
517 void AllocateAsciiSlicedString(Register result,
523 // Allocates a heap number or jumps to the gc_required label if the young
524 // space is full and a scavenge is needed. All registers are clobbered also
525 // when control continues at the gc_required label.
526 void AllocateHeapNumber(Register result,
529 Register heap_number_map,
531 TaggingMode tagging_mode = TAG_RESULT);
532 void AllocateHeapNumberWithValue(Register result,
538 // ---------------------------------------------------------------------------
539 // Instruction macros.
541 #define DEFINE_INSTRUCTION(instr) \
542 void instr(Register rd, Register rs, const Operand& rt); \
543 void instr(Register rd, Register rs, Register rt) { \
544 instr(rd, rs, Operand(rt)); \
546 void instr(Register rs, Register rt, int32_t j) { \
547 instr(rs, rt, Operand(j)); \
550 #define DEFINE_INSTRUCTION2(instr) \
551 void instr(Register rs, const Operand& rt); \
552 void instr(Register rs, Register rt) { \
553 instr(rs, Operand(rt)); \
555 void instr(Register rs, int32_t j) { \
556 instr(rs, Operand(j)); \
559 DEFINE_INSTRUCTION(Addu);
560 DEFINE_INSTRUCTION(Subu);
561 DEFINE_INSTRUCTION(Mul);
562 DEFINE_INSTRUCTION2(Mult);
563 DEFINE_INSTRUCTION2(Multu);
564 DEFINE_INSTRUCTION2(Div);
565 DEFINE_INSTRUCTION2(Divu);
567 DEFINE_INSTRUCTION(And);
568 DEFINE_INSTRUCTION(Or);
569 DEFINE_INSTRUCTION(Xor);
570 DEFINE_INSTRUCTION(Nor);
571 DEFINE_INSTRUCTION2(Neg);
573 DEFINE_INSTRUCTION(Slt);
574 DEFINE_INSTRUCTION(Sltu);
576 // MIPS32 R2 instruction macro.
577 DEFINE_INSTRUCTION(Ror);
579 #undef DEFINE_INSTRUCTION
580 #undef DEFINE_INSTRUCTION2
582 void Pref(int32_t hint, const MemOperand& rs);
585 // ---------------------------------------------------------------------------
586 // Pseudo-instructions.
588 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
590 void Ulw(Register rd, const MemOperand& rs);
591 void Usw(Register rd, const MemOperand& rs);
593 // Load int32 in the rd register.
594 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
595 inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
596 li(rd, Operand(j), mode);
598 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
600 // Push multiple registers on the stack.
601 // Registers are saved in numerical order, with higher numbered registers
602 // saved in higher memory addresses.
603 void MultiPush(RegList regs);
604 void MultiPushReversed(RegList regs);
606 void MultiPushFPU(RegList regs);
607 void MultiPushReversedFPU(RegList regs);
609 void push(Register src) {
610 Addu(sp, sp, Operand(-kPointerSize));
611 sw(src, MemOperand(sp, 0));
613 void Push(Register src) { push(src); }
616 void Push(Handle<Object> handle);
617 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
619 // Push two registers. Pushes leftmost register first (to highest address).
620 void Push(Register src1, Register src2) {
621 Subu(sp, sp, Operand(2 * kPointerSize));
622 sw(src1, MemOperand(sp, 1 * kPointerSize));
623 sw(src2, MemOperand(sp, 0 * kPointerSize));
626 // Push three registers. Pushes leftmost register first (to highest address).
627 void Push(Register src1, Register src2, Register src3) {
628 Subu(sp, sp, Operand(3 * kPointerSize));
629 sw(src1, MemOperand(sp, 2 * kPointerSize));
630 sw(src2, MemOperand(sp, 1 * kPointerSize));
631 sw(src3, MemOperand(sp, 0 * kPointerSize));
634 // Push four registers. Pushes leftmost register first (to highest address).
635 void Push(Register src1, Register src2, Register src3, Register src4) {
636 Subu(sp, sp, Operand(4 * kPointerSize));
637 sw(src1, MemOperand(sp, 3 * kPointerSize));
638 sw(src2, MemOperand(sp, 2 * kPointerSize));
639 sw(src3, MemOperand(sp, 1 * kPointerSize));
640 sw(src4, MemOperand(sp, 0 * kPointerSize));
643 void Push(Register src, Condition cond, Register tst1, Register tst2) {
644 // Since we don't have conditional execution we use a Branch.
645 Branch(3, cond, tst1, Operand(tst2));
646 Subu(sp, sp, Operand(kPointerSize));
647 sw(src, MemOperand(sp, 0));
650 // Pops multiple values from the stack and load them in the
651 // registers specified in regs. Pop order is the opposite as in MultiPush.
652 void MultiPop(RegList regs);
653 void MultiPopReversed(RegList regs);
655 void MultiPopFPU(RegList regs);
656 void MultiPopReversedFPU(RegList regs);
658 void pop(Register dst) {
659 lw(dst, MemOperand(sp, 0));
660 Addu(sp, sp, Operand(kPointerSize));
662 void Pop(Register dst) { pop(dst); }
664 // Pop two registers. Pops rightmost register first (from lower address).
665 void Pop(Register src1, Register src2) {
666 ASSERT(!src1.is(src2));
667 lw(src2, MemOperand(sp, 0 * kPointerSize));
668 lw(src1, MemOperand(sp, 1 * kPointerSize));
669 Addu(sp, sp, 2 * kPointerSize);
672 // Pop three registers. Pops rightmost register first (from lower address).
673 void Pop(Register src1, Register src2, Register src3) {
674 lw(src3, MemOperand(sp, 0 * kPointerSize));
675 lw(src2, MemOperand(sp, 1 * kPointerSize));
676 lw(src1, MemOperand(sp, 2 * kPointerSize));
677 Addu(sp, sp, 3 * kPointerSize);
680 void Pop(uint32_t count = 1) {
681 Addu(sp, sp, Operand(count * kPointerSize));
684 // Push and pop the registers that can hold pointers, as defined by the
685 // RegList constant kSafepointSavedRegisters.
686 void PushSafepointRegisters();
687 void PopSafepointRegisters();
688 void PushSafepointRegistersAndDoubles();
689 void PopSafepointRegistersAndDoubles();
690 // Store value in register src in the safepoint stack slot for
692 void StoreToSafepointRegisterSlot(Register src, Register dst);
693 void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst);
694 // Load the value of the src register from its safepoint stack slot
695 // into register dst.
696 void LoadFromSafepointRegisterSlot(Register dst, Register src);
698 // Flush the I-cache from asm code. You should use CPU::FlushICache from C.
699 // Does not handle errors.
700 void FlushICache(Register address, unsigned instructions);
702 // MIPS32 R2 instruction macro.
703 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
704 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
706 // ---------------------------------------------------------------------------
707 // FPU macros. These do not handle special cases like NaN or +- inf.
709 // Convert unsigned word to double.
710 void Cvt_d_uw(FPURegister fd, FPURegister fs, FPURegister scratch);
711 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
713 // Convert double to unsigned word.
714 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
715 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
717 void Trunc_w_d(FPURegister fd, FPURegister fs);
718 void Round_w_d(FPURegister fd, FPURegister fs);
719 void Floor_w_d(FPURegister fd, FPURegister fs);
720 void Ceil_w_d(FPURegister fd, FPURegister fs);
721 // Wrapper function for the different cmp/branch types.
722 void BranchF(Label* target,
727 BranchDelaySlot bd = PROTECT);
729 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
730 inline void BranchF(BranchDelaySlot bd,
736 BranchF(target, nan, cc, cmp1, cmp2, bd);
739 // Truncates a double using a specific rounding mode, and writes the value
740 // to the result register.
741 // The except_flag will contain any exceptions caused by the instruction.
742 // If check_inexact is kDontCheckForInexactConversion, then the inexact
743 // exception is masked.
744 void EmitFPUTruncate(FPURoundingMode rounding_mode,
746 DoubleRegister double_input,
748 DoubleRegister double_scratch,
749 Register except_flag,
750 CheckForInexactConversion check_inexact
751 = kDontCheckForInexactConversion);
753 // Performs a truncating conversion of a floating point number as used by
754 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
755 // succeeds, otherwise falls through if result is saturated. On return
756 // 'result' either holds answer, or is clobbered on fall through.
758 // Only public for the test code in test-code-stubs-arm.cc.
759 void TryInlineTruncateDoubleToI(Register result,
760 DoubleRegister input,
763 // Performs a truncating conversion of a floating point number as used by
764 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
765 // Exits with 'result' holding the answer.
766 void TruncateDoubleToI(Register result, DoubleRegister double_input);
768 // Performs a truncating conversion of a heap number as used by
769 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
770 // must be different registers. Exits with 'result' holding the answer.
771 void TruncateHeapNumberToI(Register result, Register object);
773 // Converts the smi or heap number in object to an int32 using the rules
774 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
775 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
776 // different registers.
777 void TruncateNumberToI(Register object,
779 Register heap_number_map,
783 // Loads the number from object into dst register.
784 // If |object| is neither smi nor heap number, |not_number| is jumped to
785 // with |object| still intact.
786 void LoadNumber(Register object,
788 Register heap_number_map,
792 // Loads the number from object into double_dst in the double format.
793 // Control will jump to not_int32 if the value cannot be exactly represented
794 // by a 32-bit integer.
795 // Floating point value in the 32-bit integer range that are not exact integer
797 void LoadNumberAsInt32Double(Register object,
798 DoubleRegister double_dst,
799 Register heap_number_map,
802 FPURegister double_scratch,
805 // Loads the number from object into dst as a 32-bit integer.
806 // Control will jump to not_int32 if the object cannot be exactly represented
807 // by a 32-bit integer.
808 // Floating point value in the 32-bit integer range that are not exact integer
809 // won't be converted.
810 void LoadNumberAsInt32(Register object,
812 Register heap_number_map,
815 FPURegister double_scratch0,
816 FPURegister double_scratch1,
820 // argc - argument count to be dropped by LeaveExitFrame.
821 // save_doubles - saves FPU registers on stack, currently disabled.
822 // stack_space - extra stack space.
823 void EnterExitFrame(bool save_doubles,
824 int stack_space = 0);
826 // Leave the current exit frame.
827 void LeaveExitFrame(bool save_doubles,
829 bool restore_context,
830 bool do_return = NO_EMIT_RETURN);
832 // Get the actual activation frame alignment for target environment.
833 static int ActivationFrameAlignment();
835 // Make sure the stack is aligned. Only emits code in debug mode.
836 void AssertStackIsAligned();
838 void LoadContext(Register dst, int context_chain_length);
840 // Conditionally load the cached Array transitioned map of type
841 // transitioned_kind from the native context if the map in register
842 // map_in_out is the cached Array map in the native context of
844 void LoadTransitionedArrayMapConditional(
845 ElementsKind expected_kind,
846 ElementsKind transitioned_kind,
849 Label* no_map_match);
851 void LoadGlobalFunction(int index, Register function);
853 // Load the initial map from the global function. The registers
854 // function and map can be the same, function is then overwritten.
855 void LoadGlobalFunctionInitialMap(Register function,
859 void InitializeRootRegister() {
860 ExternalReference roots_array_start =
861 ExternalReference::roots_array_start(isolate());
862 li(kRootRegister, Operand(roots_array_start));
865 // -------------------------------------------------------------------------
866 // JavaScript invokes.
868 // Invoke the JavaScript function code by either calling or jumping.
869 void InvokeCode(Register code,
870 const ParameterCount& expected,
871 const ParameterCount& actual,
873 const CallWrapper& call_wrapper);
875 // Invoke the JavaScript function in the given register. Changes the
876 // current context to the context in the function before invoking.
877 void InvokeFunction(Register function,
878 const ParameterCount& actual,
880 const CallWrapper& call_wrapper);
882 void InvokeFunction(Register function,
883 const ParameterCount& expected,
884 const ParameterCount& actual,
886 const CallWrapper& call_wrapper);
888 void InvokeFunction(Handle<JSFunction> function,
889 const ParameterCount& expected,
890 const ParameterCount& actual,
892 const CallWrapper& call_wrapper);
895 void IsObjectJSObjectType(Register heap_object,
900 void IsInstanceJSObjectType(Register map,
904 void IsObjectJSStringType(Register object,
908 void IsObjectNameType(Register object,
912 // -------------------------------------------------------------------------
917 // -------------------------------------------------------------------------
918 // Exception handling.
920 // Push a new try handler and link into try handler chain.
921 void PushTryHandler(StackHandler::Kind kind, int handler_index);
923 // Unlink the stack handler on top of the stack from the try handler chain.
924 // Must preserve the result register.
925 void PopTryHandler();
927 // Passes thrown value to the handler of top of the try handler chain.
928 void Throw(Register value);
930 // Propagates an uncatchable exception to the top of the current JS stack's
932 void ThrowUncatchable(Register value);
934 // Copies a fixed number of fields of heap objects from src to dst.
935 void CopyFields(Register dst, Register src, RegList temps, int field_count);
937 // Copies a number of bytes from src to dst. All registers are clobbered. On
938 // exit src and dst will point to the place just after where the last byte was
939 // read or written and length will be zero.
940 void CopyBytes(Register src,
945 // Initialize fields with filler values. Fields starting at |start_offset|
946 // not including end_offset are overwritten with the value in |filler|. At
947 // the end the loop, |start_offset| takes the value of |end_offset|.
948 void InitializeFieldsWithFiller(Register start_offset,
952 // -------------------------------------------------------------------------
953 // Support functions.
955 // Try to get function prototype of a function and puts the value in
956 // the result register. Checks that the function really is a
957 // function and jumps to the miss label if the fast checks fail. The
958 // function register will be untouched; the other registers may be
960 void TryGetFunctionPrototype(Register function,
964 bool miss_on_bound_function = false);
966 void GetObjectType(Register function,
970 // Check if a map for a JSObject indicates that the object has fast elements.
971 // Jump to the specified label if it does not.
972 void CheckFastElements(Register map,
976 // Check if a map for a JSObject indicates that the object can have both smi
977 // and HeapObject elements. Jump to the specified label if it does not.
978 void CheckFastObjectElements(Register map,
982 // Check if a map for a JSObject indicates that the object has fast smi only
983 // elements. Jump to the specified label if it does not.
984 void CheckFastSmiElements(Register map,
988 // Check to see if maybe_number can be stored as a double in
989 // FastDoubleElements. If it can, store it at the index specified by key in
990 // the FastDoubleElements array elements. Otherwise jump to fail.
991 void StoreNumberToDoubleElements(Register value_reg,
993 Register elements_reg,
998 int elements_offset = 0);
1000 // Compare an object's map with the specified map and its transitioned
1001 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1002 // "branch_to" if the result of the comparison is "cond". If multiple map
1003 // compares are required, the compare sequences branches to early_success.
1004 void CompareMapAndBranch(Register obj,
1007 Label* early_success,
1011 // As above, but the map of the object is already loaded into the register
1012 // which is preserved by the code generated.
1013 void CompareMapAndBranch(Register obj_map,
1015 Label* early_success,
1019 // Check if the map of an object is equal to a specified map and branch to
1020 // label if not. Skip the smi check if not required (object is known to be a
1021 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1022 // against maps that are ElementsKind transition maps of the specificed map.
1023 void CheckMap(Register obj,
1027 SmiCheckType smi_check_type);
1030 void CheckMap(Register obj,
1032 Heap::RootListIndex index,
1034 SmiCheckType smi_check_type);
1036 // Check if the map of an object is equal to a specified map and branch to a
1037 // specified target if equal. Skip the smi check if not required (object is
1038 // known to be a heap object)
1039 void DispatchMap(Register obj,
1042 Handle<Code> success,
1043 SmiCheckType smi_check_type);
1046 // Load and check the instance type of an object for being a string.
1047 // Loads the type into the second argument register.
1048 // Returns a condition that will be enabled if the object was a string.
1049 Condition IsObjectStringType(Register obj,
1052 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1053 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1054 And(type, type, Operand(kIsNotStringMask));
1055 ASSERT_EQ(0, kStringTag);
1060 // Picks out an array index from the hash field.
1062 // hash - holds the index's hash. Clobbered.
1063 // index - holds the overwritten index on exit.
1064 void IndexFromHash(Register hash, Register index);
1066 // Get the number of least significant bits from a register.
1067 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1068 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1070 // Load the value of a number object into a FPU double register. If the
1071 // object is not a number a jump to the label not_number is performed
1072 // and the FPU double register is unchanged.
1073 void ObjectToDoubleFPURegister(
1078 Register heap_number_map,
1080 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1082 // Load the value of a smi object into a FPU double register. The register
1083 // scratch1 can be the same register as smi in which case smi will hold the
1084 // untagged value afterwards.
1085 void SmiToDoubleFPURegister(Register smi,
1089 // -------------------------------------------------------------------------
1090 // Overflow handling functions.
1091 // Usage: first call the appropriate arithmetic function, then call one of the
1092 // jump functions with the overflow_dst register as the second parameter.
1094 void AdduAndCheckForOverflow(Register dst,
1097 Register overflow_dst,
1098 Register scratch = at);
1100 void SubuAndCheckForOverflow(Register dst,
1103 Register overflow_dst,
1104 Register scratch = at);
1106 void BranchOnOverflow(Label* label,
1107 Register overflow_check,
1108 BranchDelaySlot bd = PROTECT) {
1109 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1112 void BranchOnNoOverflow(Label* label,
1113 Register overflow_check,
1114 BranchDelaySlot bd = PROTECT) {
1115 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1118 void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1119 Ret(lt, overflow_check, Operand(zero_reg), bd);
1122 void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1123 Ret(ge, overflow_check, Operand(zero_reg), bd);
1126 // -------------------------------------------------------------------------
1129 // See comments at the beginning of CEntryStub::Generate.
1130 inline void PrepareCEntryArgs(int num_args) {
1132 li(s1, (num_args - 1) * kPointerSize);
1135 inline void PrepareCEntryFunction(const ExternalReference& ref) {
1136 li(s2, Operand(ref));
1139 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1140 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1142 // Call a code stub.
1143 void CallStub(CodeStub* stub,
1144 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1147 // Tail call a code stub (jump).
1148 void TailCallStub(CodeStub* stub, COND_ARGS);
1152 void CallJSExitStub(CodeStub* stub);
1154 // Call a runtime routine.
1155 void CallRuntime(const Runtime::Function* f,
1157 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1158 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1159 const Runtime::Function* function = Runtime::FunctionForId(id);
1160 CallRuntime(function, function->nargs, kSaveFPRegs);
1163 // Convenience function: Same as above, but takes the fid instead.
1164 void CallRuntime(Runtime::FunctionId id,
1166 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1167 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1170 // Convenience function: call an external reference.
1171 void CallExternalReference(const ExternalReference& ext,
1173 BranchDelaySlot bd = PROTECT);
1175 // Tail call of a runtime routine (jump).
1176 // Like JumpToExternalReference, but also takes care of passing the number
1178 void TailCallExternalReference(const ExternalReference& ext,
1182 // Convenience function: tail call a runtime routine (jump).
1183 void TailCallRuntime(Runtime::FunctionId fid,
1187 int CalculateStackPassedWords(int num_reg_arguments,
1188 int num_double_arguments);
1190 // Before calling a C-function from generated code, align arguments on stack
1191 // and add space for the four mips argument slots.
1192 // After aligning the frame, non-register arguments must be stored on the
1193 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1194 // The argument count assumes all arguments are word sized.
1195 // Some compilers/platforms require the stack to be aligned when calling
1197 // Needs a scratch register to do some arithmetic. This register will be
1199 void PrepareCallCFunction(int num_reg_arguments,
1200 int num_double_registers,
1202 void PrepareCallCFunction(int num_reg_arguments,
1205 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1206 // Arguments 5..n are stored to stack using following:
1207 // sw(t0, CFunctionArgumentOperand(5));
1209 // Calls a C function and cleans up the space for arguments allocated
1210 // by PrepareCallCFunction. The called function is not allowed to trigger a
1211 // garbage collection, since that might move the code and invalidate the
1212 // return address (unless this is somehow accounted for by the called
1214 void CallCFunction(ExternalReference function, int num_arguments);
1215 void CallCFunction(Register function, int num_arguments);
1216 void CallCFunction(ExternalReference function,
1217 int num_reg_arguments,
1218 int num_double_arguments);
1219 void CallCFunction(Register function,
1220 int num_reg_arguments,
1221 int num_double_arguments);
1222 void MovFromFloatResult(DoubleRegister dst);
1223 void MovFromFloatParameter(DoubleRegister dst);
1225 // There are two ways of passing double arguments on MIPS, depending on
1226 // whether soft or hard floating point ABI is used. These functions
1227 // abstract parameter passing for the three different ways we call
1228 // C functions from generated code.
1229 void MovToFloatParameter(DoubleRegister src);
1230 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1231 void MovToFloatResult(DoubleRegister src);
1233 // Calls an API function. Allocates HandleScope, extracts returned value
1234 // from handle and propagates exceptions. Restores context. stack_space
1235 // - space to be unwound on exit (includes the call JS arguments space and
1236 // the additional space allocated for the fast call).
1237 void CallApiFunctionAndReturn(Register function_address,
1238 ExternalReference thunk_ref,
1240 MemOperand return_value_operand,
1241 MemOperand* context_restore_operand);
1243 // Jump to the builtin routine.
1244 void JumpToExternalReference(const ExternalReference& builtin,
1245 BranchDelaySlot bd = PROTECT);
1247 // Invoke specified builtin JavaScript function. Adds an entry to
1248 // the unresolved list if the name does not resolve.
1249 void InvokeBuiltin(Builtins::JavaScript id,
1251 const CallWrapper& call_wrapper = NullCallWrapper());
1253 // Store the code object for the given builtin in the target register and
1254 // setup the function in a1.
1255 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1257 // Store the function for the given builtin in the target register.
1258 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1262 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
1266 Handle<Object> CodeObject() {
1267 ASSERT(!code_object_.is_null());
1268 return code_object_;
1271 // Emit code for a truncating division by a constant. The dividend register is
1272 // unchanged and at gets clobbered. Dividend and result must be different.
1273 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1275 // -------------------------------------------------------------------------
1276 // StatsCounter support.
1278 void SetCounter(StatsCounter* counter, int value,
1279 Register scratch1, Register scratch2);
1280 void IncrementCounter(StatsCounter* counter, int value,
1281 Register scratch1, Register scratch2);
1282 void DecrementCounter(StatsCounter* counter, int value,
1283 Register scratch1, Register scratch2);
1286 // -------------------------------------------------------------------------
1289 // Calls Abort(msg) if the condition cc is not satisfied.
1290 // Use --debug_code to enable.
1291 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
1292 void AssertFastElements(Register elements);
1294 // Like Assert(), but always enabled.
1295 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
1297 // Print a message to stdout and abort execution.
1298 void Abort(BailoutReason msg);
1300 // Verify restrictions about code generated in stubs.
1301 void set_generating_stub(bool value) { generating_stub_ = value; }
1302 bool generating_stub() { return generating_stub_; }
1303 void set_has_frame(bool value) { has_frame_ = value; }
1304 bool has_frame() { return has_frame_; }
1305 inline bool AllowThisStubCall(CodeStub* stub);
1307 // ---------------------------------------------------------------------------
1308 // Number utilities.
1310 // Check whether the value of reg is a power of two and not zero. If not
1311 // control continues at the label not_power_of_two. If reg is a power of two
1312 // the register scratch contains the value of (reg - 1) when control falls
1314 void JumpIfNotPowerOfTwoOrZero(Register reg,
1316 Label* not_power_of_two_or_zero);
1318 // -------------------------------------------------------------------------
1321 void SmiTag(Register reg) {
1322 Addu(reg, reg, reg);
1325 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1326 void SmiTagCheckOverflow(Register reg, Register overflow);
1327 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1329 void SmiTag(Register dst, Register src) {
1330 Addu(dst, src, src);
1333 // Try to convert int32 to smi. If the value is to large, preserve
1334 // the original value and jump to not_a_smi. Destroys scratch and
1336 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1337 TrySmiTag(reg, reg, scratch, not_a_smi);
1339 void TrySmiTag(Register dst,
1343 SmiTagCheckOverflow(at, src, scratch);
1344 BranchOnOverflow(not_a_smi, scratch);
1348 void SmiUntag(Register reg) {
1349 sra(reg, reg, kSmiTagSize);
1352 void SmiUntag(Register dst, Register src) {
1353 sra(dst, src, kSmiTagSize);
1356 // Test if the register contains a smi.
1357 inline void SmiTst(Register value, Register scratch) {
1358 And(scratch, value, Operand(kSmiTagMask));
1360 inline void NonNegativeSmiTst(Register value, Register scratch) {
1361 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1364 // Untag the source value into destination and jump if source is a smi.
1365 // Souce and destination can be the same register.
1366 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1368 // Untag the source value into destination and jump if source is not a smi.
1369 // Souce and destination can be the same register.
1370 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1372 // Jump the register contains a smi.
1373 void JumpIfSmi(Register value,
1375 Register scratch = at,
1376 BranchDelaySlot bd = PROTECT);
1378 // Jump if the register contains a non-smi.
1379 void JumpIfNotSmi(Register value,
1380 Label* not_smi_label,
1381 Register scratch = at,
1382 BranchDelaySlot bd = PROTECT);
1384 // Jump if either of the registers contain a non-smi.
1385 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1386 // Jump if either of the registers contain a smi.
1387 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1389 // Abort execution if argument is a smi, enabled via --debug-code.
1390 void AssertNotSmi(Register object);
1391 void AssertSmi(Register object);
1393 // Abort execution if argument is not a string, enabled via --debug-code.
1394 void AssertString(Register object);
1396 // Abort execution if argument is not a name, enabled via --debug-code.
1397 void AssertName(Register object);
1399 // Abort execution if argument is not undefined or an AllocationSite, enabled
1400 // via --debug-code.
1401 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1403 // Abort execution if reg is not the root value with the given index,
1404 // enabled via --debug-code.
1405 void AssertIsRoot(Register reg, Heap::RootListIndex index);
1407 // ---------------------------------------------------------------------------
1408 // HeapNumber utilities.
1410 void JumpIfNotHeapNumber(Register object,
1411 Register heap_number_map,
1413 Label* on_not_heap_number);
1415 // -------------------------------------------------------------------------
1416 // String utilities.
1418 // Generate code to do a lookup in the number string cache. If the number in
1419 // the register object is found in the cache the generated code falls through
1420 // with the result in the result register. The object and the result register
1421 // can be the same. If the number is not found in the cache the code jumps to
1422 // the label not_found with only the content of register object unchanged.
1423 void LookupNumberStringCache(Register object,
1430 // Checks if both instance types are sequential ASCII strings and jumps to
1431 // label if either is not.
1432 void JumpIfBothInstanceTypesAreNotSequentialAscii(
1433 Register first_object_instance_type,
1434 Register second_object_instance_type,
1439 // Check if instance type is sequential ASCII string and jump to label if
1441 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1445 void JumpIfNotUniqueName(Register reg, Label* not_unique_name);
1447 void EmitSeqStringSetCharCheck(Register string,
1451 uint32_t encoding_mask);
1453 // Test that both first and second are sequential ASCII strings.
1454 // Assume that they are non-smis.
1455 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register first,
1461 // Test that both first and second are sequential ASCII strings.
1462 // Check that they are non-smis.
1463 void JumpIfNotBothSequentialAsciiStrings(Register first,
1469 void ClampUint8(Register output_reg, Register input_reg);
1471 void ClampDoubleToUint8(Register result_reg,
1472 DoubleRegister input_reg,
1473 DoubleRegister temp_double_reg);
1476 void LoadInstanceDescriptors(Register map, Register descriptors);
1477 void EnumLength(Register dst, Register map);
1478 void NumberOfOwnDescriptors(Register dst, Register map);
1480 template<typename Field>
1481 void DecodeField(Register dst, Register src) {
1482 Ext(dst, src, Field::kShift, Field::kSize);
1485 template<typename Field>
1486 void DecodeField(Register reg) {
1487 DecodeField<Field>(reg, reg);
1490 template<typename Field>
1491 void DecodeFieldToSmi(Register dst, Register src) {
1492 static const int shift = Field::kShift;
1493 static const int mask = Field::kMask >> shift << kSmiTagSize;
1494 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1495 STATIC_ASSERT(kSmiTag == 0);
1496 if (shift < kSmiTagSize) {
1497 sll(dst, src, kSmiTagSize - shift);
1498 And(dst, dst, Operand(mask));
1499 } else if (shift > kSmiTagSize) {
1500 srl(dst, src, shift - kSmiTagSize);
1501 And(dst, dst, Operand(mask));
1503 And(dst, src, Operand(mask));
1507 template<typename Field>
1508 void DecodeFieldToSmi(Register reg) {
1509 DecodeField<Field>(reg, reg);
1512 // Generates function and stub prologue code.
1513 void StubPrologue();
1514 void Prologue(bool code_pre_aging);
1516 // Activation support.
1517 void EnterFrame(StackFrame::Type type);
1518 void LeaveFrame(StackFrame::Type type);
1520 // Patch the relocated value (lui/ori pair).
1521 void PatchRelocatedValue(Register li_location,
1523 Register new_value);
1524 // Get the relocatad value (loaded data) from the lui/ori pair.
1525 void GetRelocatedValue(Register li_location,
1529 // Expects object in a0 and returns map with validated enum cache
1530 // in a0. Assumes that any other register can be used as a scratch.
1531 void CheckEnumCache(Register null_value, Label* call_runtime);
1533 // AllocationMemento support. Arrays may have an associated
1534 // AllocationMemento object that can be checked for in order to pretransition
1536 // On entry, receiver_reg should point to the array object.
1537 // scratch_reg gets clobbered.
1538 // If allocation info is present, jump to allocation_memento_present.
1539 void TestJSArrayForAllocationMemento(
1540 Register receiver_reg,
1541 Register scratch_reg,
1542 Label* no_memento_found,
1543 Condition cond = al,
1544 Label* allocation_memento_present = NULL);
1546 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1547 Register scratch_reg,
1548 Label* memento_found) {
1549 Label no_memento_found;
1550 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1551 &no_memento_found, eq, memento_found);
1552 bind(&no_memento_found);
1555 // Jumps to found label if a prototype map has dictionary elements.
1556 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1557 Register scratch1, Label* found);
1560 void CallCFunctionHelper(Register function,
1561 int num_reg_arguments,
1562 int num_double_arguments);
1564 void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1565 void BranchAndLinkShort(int16_t offset, Condition cond, Register rs,
1567 BranchDelaySlot bdslot = PROTECT);
1568 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1569 void BranchAndLinkShort(Label* L, Condition cond, Register rs,
1571 BranchDelaySlot bdslot = PROTECT);
1572 void J(Label* L, BranchDelaySlot bdslot);
1573 void Jr(Label* L, BranchDelaySlot bdslot);
1574 void Jalr(Label* L, BranchDelaySlot bdslot);
1576 // Helper functions for generating invokes.
1577 void InvokePrologue(const ParameterCount& expected,
1578 const ParameterCount& actual,
1579 Handle<Code> code_constant,
1582 bool* definitely_mismatches,
1584 const CallWrapper& call_wrapper);
1586 // Get the code for the given builtin. Returns if able to resolve
1587 // the function in the 'resolved' flag.
1588 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
1590 void InitializeNewString(Register string,
1592 Heap::RootListIndex map_index,
1596 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1597 void InNewSpace(Register object,
1599 Condition cond, // eq for new space, ne otherwise.
1602 // Helper for finding the mark bits for an address. Afterwards, the
1603 // bitmap register points at the word with the mark bits and the mask
1604 // the position of the first bit. Leaves addr_reg unchanged.
1605 inline void GetMarkBits(Register addr_reg,
1606 Register bitmap_reg,
1609 // Helper for throwing exceptions. Compute a handler address and jump to
1610 // it. See the implementation for register usage.
1611 void JumpToHandlerEntry();
1613 // Compute memory operands for safepoint stack slots.
1614 static int SafepointRegisterStackIndex(int reg_code);
1615 MemOperand SafepointRegisterSlot(Register reg);
1616 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1618 bool generating_stub_;
1620 // This handle will be patched with the code object on installation.
1621 Handle<Object> code_object_;
1623 // Needs access to SafepointRegisterStackIndex for compiled frame
1625 friend class StandardFrame;
1629 // The code patcher is used to patch (typically) small parts of code e.g. for
1630 // debugging and other types of instrumentation. When using the code patcher
1631 // the exact number of bytes specified must be emitted. It is not legal to emit
1632 // relocation information. If any of these constraints are violated it causes
1633 // an assertion to fail.
1641 CodePatcher(byte* address,
1643 FlushICache flush_cache = FLUSH);
1644 virtual ~CodePatcher();
1646 // Macro assembler to emit code.
1647 MacroAssembler* masm() { return &masm_; }
1649 // Emit an instruction directly.
1650 void Emit(Instr instr);
1652 // Emit an address directly.
1653 void Emit(Address addr);
1655 // Change the condition part of an instruction leaving the rest of the current
1656 // instruction unchanged.
1657 void ChangeBranchCondition(Condition cond);
1660 byte* address_; // The address of the code being patched.
1661 int size_; // Number of bytes of the expected patch size.
1662 MacroAssembler masm_; // Macro assembler used to generate the code.
1663 FlushICache flush_cache_; // Whether to flush the I cache after patching.
1668 #ifdef GENERATED_CODE_COVERAGE
1669 #define CODE_COVERAGE_STRINGIFY(x) #x
1670 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1671 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1672 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1674 #define ACCESS_MASM(masm) masm->
1677 } } // namespace v8::internal
1679 #endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_