• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
6 #define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
7 
8 #include "src/assembler.h"
9 #include "src/globals.h"
10 #include "src/mips/assembler-mips.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 // Give alias names to registers for calling conventions.
16 const Register kReturnRegister0 = {Register::kCode_v0};
17 const Register kReturnRegister1 = {Register::kCode_v1};
18 const Register kJSFunctionRegister = {Register::kCode_a1};
19 const Register kContextRegister = {Register::kCpRegister};
20 const Register kInterpreterAccumulatorRegister = {Register::kCode_v0};
21 const Register kInterpreterRegisterFileRegister = {Register::kCode_t3};
22 const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_t4};
23 const Register kInterpreterBytecodeArrayRegister = {Register::kCode_t5};
24 const Register kInterpreterDispatchTableRegister = {Register::kCode_t6};
25 const Register kJavaScriptCallArgCountRegister = {Register::kCode_a0};
26 const Register kJavaScriptCallNewTargetRegister = {Register::kCode_a3};
27 const Register kRuntimeCallFunctionRegister = {Register::kCode_a1};
28 const Register kRuntimeCallArgCountRegister = {Register::kCode_a0};
29 
30 // Forward declaration.
31 class JumpTarget;
32 
33 // Reserved Register Usage Summary.
34 //
35 // Registers t8, t9, and at are reserved for use by the MacroAssembler.
36 //
37 // The programmer should know that the MacroAssembler may clobber these three,
38 // but won't touch other registers except in special cases.
39 //
40 // Per the MIPS ABI, register t9 must be used for indirect function call
41 // via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
42 // trying to update gp register for position-independent-code. Whenever
43 // MIPS generated code calls C code, it must be via t9 register.
44 
45 
46 // Flags used for LeaveExitFrame function.
47 enum LeaveExitFrameMode {
48   EMIT_RETURN = true,
49   NO_EMIT_RETURN = false
50 };
51 
52 // Flags used for AllocateHeapNumber
53 enum TaggingMode {
54   // Tag the result.
55   TAG_RESULT,
56   // Don't tag
57   DONT_TAG_RESULT
58 };
59 
60 // Flags used for the ObjectToDoubleFPURegister function.
61 enum ObjectToDoubleFlags {
62   // No special flags.
63   NO_OBJECT_TO_DOUBLE_FLAGS = 0,
64   // Object is known to be a non smi.
65   OBJECT_NOT_SMI = 1 << 0,
66   // Don't load NaNs or infinities, branch to the non number case instead.
67   AVOID_NANS_AND_INFINITIES = 1 << 1
68 };
69 
70 // Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
71 enum BranchDelaySlot {
72   USE_DELAY_SLOT,
73   PROTECT
74 };
75 
76 // Flags used for the li macro-assembler function.
77 enum LiFlags {
78   // If the constant value can be represented in just 16 bits, then
79   // optimize the li to use a single instruction, rather than lui/ori pair.
80   OPTIMIZE_SIZE = 0,
81   // Always use 2 instructions (lui/ori pair), even if the constant could
82   // be loaded with just one, so that this value is patchable later.
83   CONSTANT_SIZE = 1
84 };
85 
86 
87 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
88 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
89 enum PointersToHereCheck {
90   kPointersToHereMaybeInteresting,
91   kPointersToHereAreAlwaysInteresting
92 };
93 enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
94 
95 Register GetRegisterThatIsNotOneOf(Register reg1,
96                                    Register reg2 = no_reg,
97                                    Register reg3 = no_reg,
98                                    Register reg4 = no_reg,
99                                    Register reg5 = no_reg,
100                                    Register reg6 = no_reg);
101 
102 bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg,
103                 Register reg4 = no_reg, Register reg5 = no_reg,
104                 Register reg6 = no_reg, Register reg7 = no_reg,
105                 Register reg8 = no_reg, Register reg9 = no_reg,
106                 Register reg10 = no_reg);
107 
108 
109 // -----------------------------------------------------------------------------
110 // Static helper functions.
111 
ContextMemOperand(Register context,int index)112 inline MemOperand ContextMemOperand(Register context, int index) {
113   return MemOperand(context, Context::SlotOffset(index));
114 }
115 
116 
NativeContextMemOperand()117 inline MemOperand NativeContextMemOperand() {
118   return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
119 }
120 
121 
122 // Generate a MemOperand for loading a field from an object.
FieldMemOperand(Register object,int offset)123 inline MemOperand FieldMemOperand(Register object, int offset) {
124   return MemOperand(object, offset - kHeapObjectTag);
125 }
126 
127 
128 // Generate a MemOperand for storing arguments 5..N on the stack
129 // when calling CallCFunction().
CFunctionArgumentOperand(int index)130 inline MemOperand CFunctionArgumentOperand(int index) {
131   DCHECK(index > kCArgSlotCount);
132   // Argument 5 takes the slot just past the four Arg-slots.
133   int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
134   return MemOperand(sp, offset);
135 }
136 
137 
138 // MacroAssembler implements a collection of frequently used macros.
139 class MacroAssembler: public Assembler {
140  public:
141   MacroAssembler(Isolate* isolate, void* buffer, int size,
142                  CodeObjectRequired create_code_object);
143 
144   // Arguments macros.
145 #define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
146 #define COND_ARGS cond, r1, r2
147 
148   // Cases when relocation is not needed.
149 #define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
150   void Name(target_type target, BranchDelaySlot bd = PROTECT); \
151   inline void Name(BranchDelaySlot bd, target_type target) { \
152     Name(target, bd); \
153   } \
154   void Name(target_type target, \
155             COND_TYPED_ARGS, \
156             BranchDelaySlot bd = PROTECT); \
157   inline void Name(BranchDelaySlot bd, \
158                    target_type target, \
159                    COND_TYPED_ARGS) { \
160     Name(target, COND_ARGS, bd); \
161   }
162 
163 #define DECLARE_BRANCH_PROTOTYPES(Name)   \
164   DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
165   DECLARE_NORELOC_PROTOTYPE(Name, int32_t)
166 
167   DECLARE_BRANCH_PROTOTYPES(Branch)
168   DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
169   DECLARE_BRANCH_PROTOTYPES(BranchShort)
170 
171 #undef DECLARE_BRANCH_PROTOTYPES
172 #undef COND_TYPED_ARGS
173 #undef COND_ARGS
174 
175 
176   // Jump, Call, and Ret pseudo instructions implementing inter-working.
177 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
178   const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
179 
180   void Jump(Register target, COND_ARGS);
181   void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
182   void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
183   void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
184   static int CallSize(Register target, COND_ARGS);
185   void Call(Register target, COND_ARGS);
186   static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
187   void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
188   int CallSize(Handle<Code> code,
189                RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
190                TypeFeedbackId ast_id = TypeFeedbackId::None(),
191                COND_ARGS);
192   void Call(Handle<Code> code,
193             RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
194             TypeFeedbackId ast_id = TypeFeedbackId::None(),
195             COND_ARGS);
196   void Ret(COND_ARGS);
197   inline void Ret(BranchDelaySlot bd, Condition cond = al,
198     Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
199     Ret(cond, rs, rt, bd);
200   }
201 
202   bool IsNear(Label* L, Condition cond, int rs_reg);
203 
204   void Branch(Label* L,
205               Condition cond,
206               Register rs,
207               Heap::RootListIndex index,
208               BranchDelaySlot bdslot = PROTECT);
209 
210 #undef COND_ARGS
211 
212   // Emit code to discard a non-negative number of pointer-sized elements
213   // from the stack, clobbering only the sp register.
214   void Drop(int count,
215             Condition cond = cc_always,
216             Register reg = no_reg,
217             const Operand& op = Operand(no_reg));
218 
219   // Trivial case of DropAndRet that utilizes the delay slot and only emits
220   // 2 instructions.
221   void DropAndRet(int drop);
222 
223   void DropAndRet(int drop,
224                   Condition cond,
225                   Register reg,
226                   const Operand& op);
227 
228   // Swap two registers.  If the scratch register is omitted then a slightly
229   // less efficient form using xor instead of mov is emitted.
230   void Swap(Register reg1, Register reg2, Register scratch = no_reg);
231 
232   void Call(Label* target);
233 
Move(Register dst,Smi * smi)234   void Move(Register dst, Smi* smi) { li(dst, Operand(smi)); }
235 
Move(Register dst,Register src)236   inline void Move(Register dst, Register src) {
237     if (!dst.is(src)) {
238       mov(dst, src);
239     }
240   }
241 
Move(FPURegister dst,FPURegister src)242   inline void Move(FPURegister dst, FPURegister src) {
243     if (!dst.is(src)) {
244       mov_d(dst, src);
245     }
246   }
247 
Move(Register dst_low,Register dst_high,FPURegister src)248   inline void Move(Register dst_low, Register dst_high, FPURegister src) {
249     mfc1(dst_low, src);
250     Mfhc1(dst_high, src);
251   }
252 
FmoveHigh(Register dst_high,FPURegister src)253   inline void FmoveHigh(Register dst_high, FPURegister src) {
254     Mfhc1(dst_high, src);
255   }
256 
FmoveHigh(FPURegister dst,Register src_high)257   inline void FmoveHigh(FPURegister dst, Register src_high) {
258     Mthc1(src_high, dst);
259   }
260 
FmoveLow(Register dst_low,FPURegister src)261   inline void FmoveLow(Register dst_low, FPURegister src) {
262     mfc1(dst_low, src);
263   }
264 
265   void FmoveLow(FPURegister dst, Register src_low);
266 
Move(FPURegister dst,Register src_low,Register src_high)267   inline void Move(FPURegister dst, Register src_low, Register src_high) {
268     mtc1(src_low, dst);
269     Mthc1(src_high, dst);
270   }
271 
272   void Move(FPURegister dst, float imm);
273   void Move(FPURegister dst, double imm);
274 
275   // Conditional move.
276   void Movz(Register rd, Register rs, Register rt);
277   void Movn(Register rd, Register rs, Register rt);
278   void Movt(Register rd, Register rs, uint16_t cc = 0);
279   void Movf(Register rd, Register rs, uint16_t cc = 0);
280 
281   void Clz(Register rd, Register rs);
282 
283   // Jump unconditionally to given label.
284   // We NEED a nop in the branch delay slot, as it used by v8, for example in
285   // CodeGenerator::ProcessDeferred().
286   // Currently the branch delay slot is filled by the MacroAssembler.
287   // Use rather b(Label) for code generation.
jmp(Label * L)288   void jmp(Label* L) {
289     Branch(L);
290   }
291 
292   void Load(Register dst, const MemOperand& src, Representation r);
293   void Store(Register src, const MemOperand& dst, Representation r);
294 
PushRoot(Heap::RootListIndex index)295   void PushRoot(Heap::RootListIndex index) {
296     LoadRoot(at, index);
297     Push(at);
298   }
299 
300   // Compare the object in a register to a value and jump if they are equal.
JumpIfRoot(Register with,Heap::RootListIndex index,Label * if_equal)301   void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
302     LoadRoot(at, index);
303     Branch(if_equal, eq, with, Operand(at));
304   }
305 
306   // Compare the object in a register to a value and jump if they are not equal.
JumpIfNotRoot(Register with,Heap::RootListIndex index,Label * if_not_equal)307   void JumpIfNotRoot(Register with, Heap::RootListIndex index,
308                      Label* if_not_equal) {
309     LoadRoot(at, index);
310     Branch(if_not_equal, ne, with, Operand(at));
311   }
312 
313   // Load an object from the root table.
314   void LoadRoot(Register destination,
315                 Heap::RootListIndex index);
316   void LoadRoot(Register destination,
317                 Heap::RootListIndex index,
318                 Condition cond, Register src1, const Operand& src2);
319 
320   // Store an object to the root table.
321   void StoreRoot(Register source,
322                  Heap::RootListIndex index);
323   void StoreRoot(Register source,
324                  Heap::RootListIndex index,
325                  Condition cond, Register src1, const Operand& src2);
326 
327   // ---------------------------------------------------------------------------
328   // GC Support
329 
330   void IncrementalMarkingRecordWriteHelper(Register object,
331                                            Register value,
332                                            Register address);
333 
334   enum RememberedSetFinalAction {
335     kReturnAtEnd,
336     kFallThroughAtEnd
337   };
338 
339 
340   // Record in the remembered set the fact that we have a pointer to new space
341   // at the address pointed to by the addr register.  Only works if addr is not
342   // in new space.
343   void RememberedSetHelper(Register object,  // Used for debug code.
344                            Register addr,
345                            Register scratch,
346                            SaveFPRegsMode save_fp,
347                            RememberedSetFinalAction and_then);
348 
349   void CheckPageFlag(Register object,
350                      Register scratch,
351                      int mask,
352                      Condition cc,
353                      Label* condition_met);
354 
355   // Check if object is in new space.  Jumps if the object is not in new space.
356   // The register scratch can be object itself, but it will be clobbered.
JumpIfNotInNewSpace(Register object,Register scratch,Label * branch)357   void JumpIfNotInNewSpace(Register object,
358                            Register scratch,
359                            Label* branch) {
360     InNewSpace(object, scratch, ne, branch);
361   }
362 
363   // Check if object is in new space.  Jumps if the object is in new space.
364   // The register scratch can be object itself, but scratch will be clobbered.
JumpIfInNewSpace(Register object,Register scratch,Label * branch)365   void JumpIfInNewSpace(Register object,
366                         Register scratch,
367                         Label* branch) {
368     InNewSpace(object, scratch, eq, branch);
369   }
370 
371   // Check if an object has a given incremental marking color.
372   void HasColor(Register object,
373                 Register scratch0,
374                 Register scratch1,
375                 Label* has_color,
376                 int first_bit,
377                 int second_bit);
378 
379   void JumpIfBlack(Register object,
380                    Register scratch0,
381                    Register scratch1,
382                    Label* on_black);
383 
384   // Checks the color of an object.  If the object is white we jump to the
385   // incremental marker.
386   void JumpIfWhite(Register value, Register scratch1, Register scratch2,
387                    Register scratch3, Label* value_is_white);
388 
389   // Notify the garbage collector that we wrote a pointer into an object.
390   // |object| is the object being stored into, |value| is the object being
391   // stored.  value and scratch registers are clobbered by the operation.
392   // The offset is the offset from the start of the object, not the offset from
393   // the tagged HeapObject pointer.  For use with FieldOperand(reg, off).
394   void RecordWriteField(
395       Register object,
396       int offset,
397       Register value,
398       Register scratch,
399       RAStatus ra_status,
400       SaveFPRegsMode save_fp,
401       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
402       SmiCheck smi_check = INLINE_SMI_CHECK,
403       PointersToHereCheck pointers_to_here_check_for_value =
404           kPointersToHereMaybeInteresting);
405 
406   // As above, but the offset has the tag presubtracted.  For use with
407   // MemOperand(reg, off).
408   inline void RecordWriteContextSlot(
409       Register context,
410       int offset,
411       Register value,
412       Register scratch,
413       RAStatus ra_status,
414       SaveFPRegsMode save_fp,
415       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
416       SmiCheck smi_check = INLINE_SMI_CHECK,
417       PointersToHereCheck pointers_to_here_check_for_value =
418           kPointersToHereMaybeInteresting) {
419     RecordWriteField(context,
420                      offset + kHeapObjectTag,
421                      value,
422                      scratch,
423                      ra_status,
424                      save_fp,
425                      remembered_set_action,
426                      smi_check,
427                      pointers_to_here_check_for_value);
428   }
429 
430   void RecordWriteForMap(
431       Register object,
432       Register map,
433       Register dst,
434       RAStatus ra_status,
435       SaveFPRegsMode save_fp);
436 
437   // For a given |object| notify the garbage collector that the slot |address|
438   // has been written.  |value| is the object being stored. The value and
439   // address registers are clobbered by the operation.
440   void RecordWrite(
441       Register object,
442       Register address,
443       Register value,
444       RAStatus ra_status,
445       SaveFPRegsMode save_fp,
446       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
447       SmiCheck smi_check = INLINE_SMI_CHECK,
448       PointersToHereCheck pointers_to_here_check_for_value =
449           kPointersToHereMaybeInteresting);
450 
451 
452   // ---------------------------------------------------------------------------
453   // Inline caching support.
454 
455   // Generate code for checking access rights - used for security checks
456   // on access to global objects across environments. The holder register
457   // is left untouched, whereas both scratch registers are clobbered.
458   void CheckAccessGlobalProxy(Register holder_reg,
459                               Register scratch,
460                               Label* miss);
461 
462   void GetNumberHash(Register reg0, Register scratch);
463 
464   void LoadFromNumberDictionary(Label* miss,
465                                 Register elements,
466                                 Register key,
467                                 Register result,
468                                 Register reg0,
469                                 Register reg1,
470                                 Register reg2);
471 
472 
MarkCode(NopMarkerTypes type)473   inline void MarkCode(NopMarkerTypes type) {
474     nop(type);
475   }
476 
477   // Check if the given instruction is a 'type' marker.
478   // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
479   // nop(type)). These instructions are generated to mark special location in
480   // the code, like some special IC code.
IsMarkedCode(Instr instr,int type)481   static inline bool IsMarkedCode(Instr instr, int type) {
482     DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
483     return IsNop(instr, type);
484   }
485 
486 
GetCodeMarker(Instr instr)487   static inline int GetCodeMarker(Instr instr) {
488     uint32_t opcode = ((instr & kOpcodeMask));
489     uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
490     uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
491     uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
492 
493     // Return <n> if we have a sll zero_reg, zero_reg, n
494     // else return -1.
495     bool sllzz = (opcode == SLL &&
496                   rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
497                   rs == static_cast<uint32_t>(ToNumber(zero_reg)));
498     int type =
499         (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
500     DCHECK((type == -1) ||
501            ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
502     return type;
503   }
504 
505 
506 
507   // ---------------------------------------------------------------------------
508   // Allocation support.
509 
510   // Allocate an object in new space or old space. The object_size is
511   // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
512   // is passed. If the space is exhausted control continues at the gc_required
513   // label. The allocated object is returned in result. If the flag
514   // tag_allocated_object is true the result is tagged as as a heap object.
515   // All registers are clobbered also when control continues at the gc_required
516   // label.
517   void Allocate(int object_size,
518                 Register result,
519                 Register scratch1,
520                 Register scratch2,
521                 Label* gc_required,
522                 AllocationFlags flags);
523 
524   void Allocate(Register object_size, Register result, Register result_new,
525                 Register scratch, Label* gc_required, AllocationFlags flags);
526 
527   void AllocateTwoByteString(Register result,
528                              Register length,
529                              Register scratch1,
530                              Register scratch2,
531                              Register scratch3,
532                              Label* gc_required);
533   void AllocateOneByteString(Register result, Register length,
534                              Register scratch1, Register scratch2,
535                              Register scratch3, Label* gc_required);
536   void AllocateTwoByteConsString(Register result,
537                                  Register length,
538                                  Register scratch1,
539                                  Register scratch2,
540                                  Label* gc_required);
541   void AllocateOneByteConsString(Register result, Register length,
542                                  Register scratch1, Register scratch2,
543                                  Label* gc_required);
544   void AllocateTwoByteSlicedString(Register result,
545                                    Register length,
546                                    Register scratch1,
547                                    Register scratch2,
548                                    Label* gc_required);
549   void AllocateOneByteSlicedString(Register result, Register length,
550                                    Register scratch1, Register scratch2,
551                                    Label* gc_required);
552 
553   // Allocates a heap number or jumps to the gc_required label if the young
554   // space is full and a scavenge is needed. All registers are clobbered also
555   // when control continues at the gc_required label.
556   void AllocateHeapNumber(Register result,
557                           Register scratch1,
558                           Register scratch2,
559                           Register heap_number_map,
560                           Label* gc_required,
561                           TaggingMode tagging_mode = TAG_RESULT,
562                           MutableMode mode = IMMUTABLE);
563   void AllocateHeapNumberWithValue(Register result,
564                                    FPURegister value,
565                                    Register scratch1,
566                                    Register scratch2,
567                                    Label* gc_required);
568 
569   // Allocate and initialize a JSValue wrapper with the specified {constructor}
570   // and {value}.
571   void AllocateJSValue(Register result, Register constructor, Register value,
572                        Register scratch1, Register scratch2,
573                        Label* gc_required);
574 
575   // ---------------------------------------------------------------------------
576   // Instruction macros.
577 
578 #define DEFINE_INSTRUCTION(instr)                                              \
579   void instr(Register rd, Register rs, const Operand& rt);                     \
580   void instr(Register rd, Register rs, Register rt) {                          \
581     instr(rd, rs, Operand(rt));                                                \
582   }                                                                            \
583   void instr(Register rs, Register rt, int32_t j) {                            \
584     instr(rs, rt, Operand(j));                                                 \
585   }
586 
587 #define DEFINE_INSTRUCTION2(instr)                                             \
588   void instr(Register rs, const Operand& rt);                                  \
589   void instr(Register rs, Register rt) {                                       \
590     instr(rs, Operand(rt));                                                    \
591   }                                                                            \
592   void instr(Register rs, int32_t j) {                                         \
593     instr(rs, Operand(j));                                                     \
594   }
595 
596 #define DEFINE_INSTRUCTION3(instr)                                             \
597   void instr(Register rd_hi, Register rd_lo, Register rs, const Operand& rt);  \
598   void instr(Register rd_hi, Register rd_lo, Register rs, Register rt) {       \
599     instr(rd_hi, rd_lo, rs, Operand(rt));                                      \
600   }                                                                            \
601   void instr(Register rd_hi, Register rd_lo, Register rs, int32_t j) {         \
602     instr(rd_hi, rd_lo, rs, Operand(j));                                       \
603   }
604 
605   DEFINE_INSTRUCTION(Addu);
606   DEFINE_INSTRUCTION(Subu);
607   DEFINE_INSTRUCTION(Mul);
608   DEFINE_INSTRUCTION(Div);
609   DEFINE_INSTRUCTION(Divu);
610   DEFINE_INSTRUCTION(Mod);
611   DEFINE_INSTRUCTION(Modu);
612   DEFINE_INSTRUCTION(Mulh);
613   DEFINE_INSTRUCTION2(Mult);
614   DEFINE_INSTRUCTION(Mulhu);
615   DEFINE_INSTRUCTION2(Multu);
616   DEFINE_INSTRUCTION2(Div);
617   DEFINE_INSTRUCTION2(Divu);
618 
619   DEFINE_INSTRUCTION3(Div);
620   DEFINE_INSTRUCTION3(Mul);
621 
622   DEFINE_INSTRUCTION(And);
623   DEFINE_INSTRUCTION(Or);
624   DEFINE_INSTRUCTION(Xor);
625   DEFINE_INSTRUCTION(Nor);
626   DEFINE_INSTRUCTION2(Neg);
627 
628   DEFINE_INSTRUCTION(Slt);
629   DEFINE_INSTRUCTION(Sltu);
630 
631   // MIPS32 R2 instruction macro.
632   DEFINE_INSTRUCTION(Ror);
633 
634 #undef DEFINE_INSTRUCTION
635 #undef DEFINE_INSTRUCTION2
636 #undef DEFINE_INSTRUCTION3
637 
638   void Lsa(Register rd, Register rs, Register rt, uint8_t sa,
639            Register scratch = at);
640   void Pref(int32_t hint, const MemOperand& rs);
641 
642 
643   // ---------------------------------------------------------------------------
644   // Pseudo-instructions.
645 
mov(Register rd,Register rt)646   void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
647 
648   void Ulw(Register rd, const MemOperand& rs);
649   void Usw(Register rd, const MemOperand& rs);
650 
651   // Load int32 in the rd register.
652   void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
653   inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
654     li(rd, Operand(j), mode);
655   }
656   void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
657 
658   // Push multiple registers on the stack.
659   // Registers are saved in numerical order, with higher numbered registers
660   // saved in higher memory addresses.
661   void MultiPush(RegList regs);
662   void MultiPushReversed(RegList regs);
663 
664   void MultiPushFPU(RegList regs);
665   void MultiPushReversedFPU(RegList regs);
666 
push(Register src)667   void push(Register src) {
668     Addu(sp, sp, Operand(-kPointerSize));
669     sw(src, MemOperand(sp, 0));
670   }
Push(Register src)671   void Push(Register src) { push(src); }
672 
673   // Push a handle.
674   void Push(Handle<Object> handle);
Push(Smi * smi)675   void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
676 
677   // Push two registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2)678   void Push(Register src1, Register src2) {
679     Subu(sp, sp, Operand(2 * kPointerSize));
680     sw(src1, MemOperand(sp, 1 * kPointerSize));
681     sw(src2, MemOperand(sp, 0 * kPointerSize));
682   }
683 
684   // Push three registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2,Register src3)685   void Push(Register src1, Register src2, Register src3) {
686     Subu(sp, sp, Operand(3 * kPointerSize));
687     sw(src1, MemOperand(sp, 2 * kPointerSize));
688     sw(src2, MemOperand(sp, 1 * kPointerSize));
689     sw(src3, MemOperand(sp, 0 * kPointerSize));
690   }
691 
692   // Push four registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2,Register src3,Register src4)693   void Push(Register src1, Register src2, Register src3, Register src4) {
694     Subu(sp, sp, Operand(4 * kPointerSize));
695     sw(src1, MemOperand(sp, 3 * kPointerSize));
696     sw(src2, MemOperand(sp, 2 * kPointerSize));
697     sw(src3, MemOperand(sp, 1 * kPointerSize));
698     sw(src4, MemOperand(sp, 0 * kPointerSize));
699   }
700 
701   // Push five registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2,Register src3,Register src4,Register src5)702   void Push(Register src1, Register src2, Register src3, Register src4,
703             Register src5) {
704     Subu(sp, sp, Operand(5 * kPointerSize));
705     sw(src1, MemOperand(sp, 4 * kPointerSize));
706     sw(src2, MemOperand(sp, 3 * kPointerSize));
707     sw(src3, MemOperand(sp, 2 * kPointerSize));
708     sw(src4, MemOperand(sp, 1 * kPointerSize));
709     sw(src5, MemOperand(sp, 0 * kPointerSize));
710   }
711 
Push(Register src,Condition cond,Register tst1,Register tst2)712   void Push(Register src, Condition cond, Register tst1, Register tst2) {
713     // Since we don't have conditional execution we use a Branch.
714     Branch(3, cond, tst1, Operand(tst2));
715     Subu(sp, sp, Operand(kPointerSize));
716     sw(src, MemOperand(sp, 0));
717   }
718 
719   // Pops multiple values from the stack and load them in the
720   // registers specified in regs. Pop order is the opposite as in MultiPush.
721   void MultiPop(RegList regs);
722   void MultiPopReversed(RegList regs);
723 
724   void MultiPopFPU(RegList regs);
725   void MultiPopReversedFPU(RegList regs);
726 
pop(Register dst)727   void pop(Register dst) {
728     lw(dst, MemOperand(sp, 0));
729     Addu(sp, sp, Operand(kPointerSize));
730   }
Pop(Register dst)731   void Pop(Register dst) { pop(dst); }
732 
733   // Pop two registers. Pops rightmost register first (from lower address).
Pop(Register src1,Register src2)734   void Pop(Register src1, Register src2) {
735     DCHECK(!src1.is(src2));
736     lw(src2, MemOperand(sp, 0 * kPointerSize));
737     lw(src1, MemOperand(sp, 1 * kPointerSize));
738     Addu(sp, sp, 2 * kPointerSize);
739   }
740 
741   // Pop three registers. Pops rightmost register first (from lower address).
Pop(Register src1,Register src2,Register src3)742   void Pop(Register src1, Register src2, Register src3) {
743     lw(src3, MemOperand(sp, 0 * kPointerSize));
744     lw(src2, MemOperand(sp, 1 * kPointerSize));
745     lw(src1, MemOperand(sp, 2 * kPointerSize));
746     Addu(sp, sp, 3 * kPointerSize);
747   }
748 
749   void Pop(uint32_t count = 1) {
750     Addu(sp, sp, Operand(count * kPointerSize));
751   }
752 
753   // Push and pop the registers that can hold pointers, as defined by the
754   // RegList constant kSafepointSavedRegisters.
755   void PushSafepointRegisters();
756   void PopSafepointRegisters();
757   // Store value in register src in the safepoint stack slot for
758   // register dst.
759   void StoreToSafepointRegisterSlot(Register src, Register dst);
760   // Load the value of the src register from its safepoint stack slot
761   // into register dst.
762   void LoadFromSafepointRegisterSlot(Register dst, Register src);
763 
764   // MIPS32 R2 instruction macro.
765   void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
766   void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
767 
768   // ---------------------------------------------------------------------------
769   // FPU macros. These do not handle special cases like NaN or +- inf.
770 
771   // Convert unsigned word to double.
772   void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
773 
774   // Convert double to unsigned word.
775   void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
776   void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
777 
778   void Trunc_w_d(FPURegister fd, FPURegister fs);
779   void Round_w_d(FPURegister fd, FPURegister fs);
780   void Floor_w_d(FPURegister fd, FPURegister fs);
781   void Ceil_w_d(FPURegister fd, FPURegister fs);
782 
783   // FP32 mode: Move the general purpose register into
784   // the high part of the double-register pair.
785   // FP64 mode: Move the general-purpose register into
786   // the higher 32 bits of the 64-bit coprocessor register,
787   // while leaving the low bits unchanged.
788   void Mthc1(Register rt, FPURegister fs);
789 
790   // FP32 mode: move the high part of the double-register pair into
791   // general purpose register.
792   // FP64 mode: Move the higher 32 bits of the 64-bit coprocessor register into
793   // general-purpose register.
794   void Mfhc1(Register rt, FPURegister fs);
795 
796   // Wrapper functions for the different cmp/branch types.
797   inline void BranchF32(Label* target, Label* nan, Condition cc,
798                         FPURegister cmp1, FPURegister cmp2,
799                         BranchDelaySlot bd = PROTECT) {
800     BranchFCommon(S, target, nan, cc, cmp1, cmp2, bd);
801   }
802 
803   inline void BranchF64(Label* target, Label* nan, Condition cc,
804                         FPURegister cmp1, FPURegister cmp2,
805                         BranchDelaySlot bd = PROTECT) {
806     BranchFCommon(D, target, nan, cc, cmp1, cmp2, bd);
807   }
808 
809   // Alternate (inline) version for better readability with USE_DELAY_SLOT.
BranchF64(BranchDelaySlot bd,Label * target,Label * nan,Condition cc,FPURegister cmp1,FPURegister cmp2)810   inline void BranchF64(BranchDelaySlot bd, Label* target, Label* nan,
811                         Condition cc, FPURegister cmp1, FPURegister cmp2) {
812     BranchF64(target, nan, cc, cmp1, cmp2, bd);
813   }
814 
BranchF32(BranchDelaySlot bd,Label * target,Label * nan,Condition cc,FPURegister cmp1,FPURegister cmp2)815   inline void BranchF32(BranchDelaySlot bd, Label* target, Label* nan,
816                         Condition cc, FPURegister cmp1, FPURegister cmp2) {
817     BranchF32(target, nan, cc, cmp1, cmp2, bd);
818   }
819 
820   // Alias functions for backward compatibility.
821   inline void BranchF(Label* target, Label* nan, Condition cc, FPURegister cmp1,
822                       FPURegister cmp2, BranchDelaySlot bd = PROTECT) {
823     BranchF64(target, nan, cc, cmp1, cmp2, bd);
824   }
825 
BranchF(BranchDelaySlot bd,Label * target,Label * nan,Condition cc,FPURegister cmp1,FPURegister cmp2)826   inline void BranchF(BranchDelaySlot bd, Label* target, Label* nan,
827                       Condition cc, FPURegister cmp1, FPURegister cmp2) {
828     BranchF64(bd, target, nan, cc, cmp1, cmp2);
829   }
830 
831   // Truncates a double using a specific rounding mode, and writes the value
832   // to the result register.
833   // The except_flag will contain any exceptions caused by the instruction.
834   // If check_inexact is kDontCheckForInexactConversion, then the inexact
835   // exception is masked.
836   void EmitFPUTruncate(FPURoundingMode rounding_mode,
837                        Register result,
838                        DoubleRegister double_input,
839                        Register scratch,
840                        DoubleRegister double_scratch,
841                        Register except_flag,
842                        CheckForInexactConversion check_inexact
843                            = kDontCheckForInexactConversion);
844 
845   // Performs a truncating conversion of a floating point number as used by
846   // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
847   // succeeds, otherwise falls through if result is saturated. On return
848   // 'result' either holds answer, or is clobbered on fall through.
849   //
850   // Only public for the test code in test-code-stubs-arm.cc.
851   void TryInlineTruncateDoubleToI(Register result,
852                                   DoubleRegister input,
853                                   Label* done);
854 
855   // Performs a truncating conversion of a floating point number as used by
856   // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
857   // Exits with 'result' holding the answer.
858   void TruncateDoubleToI(Register result, DoubleRegister double_input);
859 
860   // Performs a truncating conversion of a heap number as used by
861   // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
862   // must be different registers. Exits with 'result' holding the answer.
863   void TruncateHeapNumberToI(Register result, Register object);
864 
865   // Converts the smi or heap number in object to an int32 using the rules
866   // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
867   // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
868   // different registers.
869   void TruncateNumberToI(Register object,
870                          Register result,
871                          Register heap_number_map,
872                          Register scratch,
873                          Label* not_int32);
874 
875   // Loads the number from object into dst register.
876   // If |object| is neither smi nor heap number, |not_number| is jumped to
877   // with |object| still intact.
878   void LoadNumber(Register object,
879                   FPURegister dst,
880                   Register heap_number_map,
881                   Register scratch,
882                   Label* not_number);
883 
884   // Loads the number from object into double_dst in the double format.
885   // Control will jump to not_int32 if the value cannot be exactly represented
886   // by a 32-bit integer.
887   // Floating point value in the 32-bit integer range that are not exact integer
888   // won't be loaded.
889   void LoadNumberAsInt32Double(Register object,
890                                DoubleRegister double_dst,
891                                Register heap_number_map,
892                                Register scratch1,
893                                Register scratch2,
894                                FPURegister double_scratch,
895                                Label* not_int32);
896 
897   // Loads the number from object into dst as a 32-bit integer.
898   // Control will jump to not_int32 if the object cannot be exactly represented
899   // by a 32-bit integer.
900   // Floating point value in the 32-bit integer range that are not exact integer
901   // won't be converted.
902   void LoadNumberAsInt32(Register object,
903                          Register dst,
904                          Register heap_number_map,
905                          Register scratch1,
906                          Register scratch2,
907                          FPURegister double_scratch0,
908                          FPURegister double_scratch1,
909                          Label* not_int32);
910 
911   // Enter exit frame.
912   // argc - argument count to be dropped by LeaveExitFrame.
913   // save_doubles - saves FPU registers on stack, currently disabled.
914   // stack_space - extra stack space.
915   void EnterExitFrame(bool save_doubles,
916                       int stack_space = 0);
917 
918   // Leave the current exit frame.
919   void LeaveExitFrame(bool save_doubles, Register arg_count,
920                       bool restore_context, bool do_return = NO_EMIT_RETURN,
921                       bool argument_count_is_length = false);
922 
923   // Get the actual activation frame alignment for target environment.
924   static int ActivationFrameAlignment();
925 
926   // Make sure the stack is aligned. Only emits code in debug mode.
927   void AssertStackIsAligned();
928 
929   void LoadContext(Register dst, int context_chain_length);
930 
931   // Load the global object from the current context.
LoadGlobalObject(Register dst)932   void LoadGlobalObject(Register dst) {
933     LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
934   }
935 
936   // Load the global proxy from the current context.
LoadGlobalProxy(Register dst)937   void LoadGlobalProxy(Register dst) {
938     LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
939   }
940 
941   // Conditionally load the cached Array transitioned map of type
942   // transitioned_kind from the native context if the map in register
943   // map_in_out is the cached Array map in the native context of
944   // expected_kind.
945   void LoadTransitionedArrayMapConditional(
946       ElementsKind expected_kind,
947       ElementsKind transitioned_kind,
948       Register map_in_out,
949       Register scratch,
950       Label* no_map_match);
951 
952   void LoadNativeContextSlot(int index, Register dst);
953 
954   // Load the initial map from the global function. The registers
955   // function and map can be the same, function is then overwritten.
956   void LoadGlobalFunctionInitialMap(Register function,
957                                     Register map,
958                                     Register scratch);
959 
InitializeRootRegister()960   void InitializeRootRegister() {
961     ExternalReference roots_array_start =
962         ExternalReference::roots_array_start(isolate());
963     li(kRootRegister, Operand(roots_array_start));
964   }
965 
966   // -------------------------------------------------------------------------
967   // JavaScript invokes.
968 
969   // Invoke the JavaScript function code by either calling or jumping.
970 
971   void InvokeFunctionCode(Register function, Register new_target,
972                           const ParameterCount& expected,
973                           const ParameterCount& actual, InvokeFlag flag,
974                           const CallWrapper& call_wrapper);
975 
976   void FloodFunctionIfStepping(Register fun, Register new_target,
977                                const ParameterCount& expected,
978                                const ParameterCount& actual);
979 
980   // Invoke the JavaScript function in the given register. Changes the
981   // current context to the context in the function before invoking.
982   void InvokeFunction(Register function,
983                       Register new_target,
984                       const ParameterCount& actual,
985                       InvokeFlag flag,
986                       const CallWrapper& call_wrapper);
987 
988   void InvokeFunction(Register function,
989                       const ParameterCount& expected,
990                       const ParameterCount& actual,
991                       InvokeFlag flag,
992                       const CallWrapper& call_wrapper);
993 
994   void InvokeFunction(Handle<JSFunction> function,
995                       const ParameterCount& expected,
996                       const ParameterCount& actual,
997                       InvokeFlag flag,
998                       const CallWrapper& call_wrapper);
999 
1000   void IsObjectJSStringType(Register object,
1001                             Register scratch,
1002                             Label* fail);
1003 
1004   void IsObjectNameType(Register object,
1005                         Register scratch,
1006                         Label* fail);
1007 
1008   // -------------------------------------------------------------------------
1009   // Debugger Support.
1010 
1011   void DebugBreak();
1012 
1013   // -------------------------------------------------------------------------
1014   // Exception handling.
1015 
1016   // Push a new stack handler and link into stack handler chain.
1017   void PushStackHandler();
1018 
1019   // Unlink the stack handler on top of the stack from the stack handler chain.
1020   // Must preserve the result register.
1021   void PopStackHandler();
1022 
1023   // Copies a number of bytes from src to dst. All registers are clobbered. On
1024   // exit src and dst will point to the place just after where the last byte was
1025   // read or written and length will be zero.
1026   void CopyBytes(Register src,
1027                  Register dst,
1028                  Register length,
1029                  Register scratch);
1030 
1031   // Initialize fields with filler values.  Fields starting at |current_address|
1032   // not including |end_address| are overwritten with the value in |filler|.  At
1033   // the end the loop, |current_address| takes the value of |end_address|.
1034   void InitializeFieldsWithFiller(Register current_address,
1035                                   Register end_address, Register filler);
1036 
1037   // -------------------------------------------------------------------------
1038   // Support functions.
1039 
1040   // Machine code version of Map::GetConstructor().
1041   // |temp| holds |result|'s map when done, and |temp2| its instance type.
1042   void GetMapConstructor(Register result, Register map, Register temp,
1043                          Register temp2);
1044 
1045   // Try to get function prototype of a function and puts the value in
1046   // the result register. Checks that the function really is a
1047   // function and jumps to the miss label if the fast checks fail. The
1048   // function register will be untouched; the other registers may be
1049   // clobbered.
1050   void TryGetFunctionPrototype(Register function, Register result,
1051                                Register scratch, Label* miss);
1052 
1053   void GetObjectType(Register function,
1054                      Register map,
1055                      Register type_reg);
1056 
1057   // Check if a map for a JSObject indicates that the object has fast elements.
1058   // Jump to the specified label if it does not.
1059   void CheckFastElements(Register map,
1060                          Register scratch,
1061                          Label* fail);
1062 
1063   // Check if a map for a JSObject indicates that the object can have both smi
1064   // and HeapObject elements.  Jump to the specified label if it does not.
1065   void CheckFastObjectElements(Register map,
1066                                Register scratch,
1067                                Label* fail);
1068 
1069   // Check if a map for a JSObject indicates that the object has fast smi only
1070   // elements.  Jump to the specified label if it does not.
1071   void CheckFastSmiElements(Register map,
1072                             Register scratch,
1073                             Label* fail);
1074 
1075   // Check to see if maybe_number can be stored as a double in
1076   // FastDoubleElements. If it can, store it at the index specified by key in
1077   // the FastDoubleElements array elements. Otherwise jump to fail.
1078   void StoreNumberToDoubleElements(Register value_reg,
1079                                    Register key_reg,
1080                                    Register elements_reg,
1081                                    Register scratch1,
1082                                    Register scratch2,
1083                                    Register scratch3,
1084                                    Label* fail,
1085                                    int elements_offset = 0);
1086 
1087   // Compare an object's map with the specified map and its transitioned
1088   // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1089   // "branch_to" if the result of the comparison is "cond". If multiple map
1090   // compares are required, the compare sequences branches to early_success.
1091   void CompareMapAndBranch(Register obj,
1092                            Register scratch,
1093                            Handle<Map> map,
1094                            Label* early_success,
1095                            Condition cond,
1096                            Label* branch_to);
1097 
1098   // As above, but the map of the object is already loaded into the register
1099   // which is preserved by the code generated.
1100   void CompareMapAndBranch(Register obj_map,
1101                            Handle<Map> map,
1102                            Label* early_success,
1103                            Condition cond,
1104                            Label* branch_to);
1105 
1106   // Check if the map of an object is equal to a specified map and branch to
1107   // label if not. Skip the smi check if not required (object is known to be a
1108   // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1109   // against maps that are ElementsKind transition maps of the specificed map.
1110   void CheckMap(Register obj,
1111                 Register scratch,
1112                 Handle<Map> map,
1113                 Label* fail,
1114                 SmiCheckType smi_check_type);
1115 
1116 
1117   void CheckMap(Register obj,
1118                 Register scratch,
1119                 Heap::RootListIndex index,
1120                 Label* fail,
1121                 SmiCheckType smi_check_type);
1122 
1123   // Check if the map of an object is equal to a specified weak map and branch
1124   // to a specified target if equal. Skip the smi check if not required
1125   // (object is known to be a heap object)
1126   void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1127                        Handle<WeakCell> cell, Handle<Code> success,
1128                        SmiCheckType smi_check_type);
1129 
1130   // Get value of the weak cell.
1131   void GetWeakValue(Register value, Handle<WeakCell> cell);
1132 
1133   // Load the value of the weak cell in the value register. Branch to the
1134   // given miss label is the weak cell was cleared.
1135   void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
1136 
1137   // Load and check the instance type of an object for being a string.
1138   // Loads the type into the second argument register.
1139   // Returns a condition that will be enabled if the object was a string.
IsObjectStringType(Register obj,Register type,Register result)1140   Condition IsObjectStringType(Register obj,
1141                                Register type,
1142                                Register result) {
1143     lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1144     lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1145     And(type, type, Operand(kIsNotStringMask));
1146     DCHECK_EQ(0u, kStringTag);
1147     return eq;
1148   }
1149 
1150 
1151   // Picks out an array index from the hash field.
1152   // Register use:
1153   //   hash - holds the index's hash. Clobbered.
1154   //   index - holds the overwritten index on exit.
1155   void IndexFromHash(Register hash, Register index);
1156 
1157   // Get the number of least significant bits from a register.
1158   void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1159   void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1160 
1161   // Load the value of a number object into a FPU double register. If the
1162   // object is not a number a jump to the label not_number is performed
1163   // and the FPU double register is unchanged.
1164   void ObjectToDoubleFPURegister(
1165       Register object,
1166       FPURegister value,
1167       Register scratch1,
1168       Register scratch2,
1169       Register heap_number_map,
1170       Label* not_number,
1171       ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1172 
1173   // Load the value of a smi object into a FPU double register. The register
1174   // scratch1 can be the same register as smi in which case smi will hold the
1175   // untagged value afterwards.
1176   void SmiToDoubleFPURegister(Register smi,
1177                               FPURegister value,
1178                               Register scratch1);
1179 
1180   // -------------------------------------------------------------------------
1181   // Overflow handling functions.
1182   // Usage: first call the appropriate arithmetic function, then call one of the
1183   // jump functions with the overflow_dst register as the second parameter.
1184 
1185   inline void AddBranchOvf(Register dst, Register left, const Operand& right,
1186                            Label* overflow_label, Register scratch = at) {
1187     AddBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
1188   }
1189 
1190   inline void AddBranchNoOvf(Register dst, Register left, const Operand& right,
1191                              Label* no_overflow_label, Register scratch = at) {
1192     AddBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
1193   }
1194 
1195   void AddBranchOvf(Register dst, Register left, const Operand& right,
1196                     Label* overflow_label, Label* no_overflow_label,
1197                     Register scratch = at);
1198 
1199   void AddBranchOvf(Register dst, Register left, Register right,
1200                     Label* overflow_label, Label* no_overflow_label,
1201                     Register scratch = at);
1202 
1203 
1204   inline void SubBranchOvf(Register dst, Register left, const Operand& right,
1205                            Label* overflow_label, Register scratch = at) {
1206     SubBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
1207   }
1208 
1209   inline void SubBranchNoOvf(Register dst, Register left, const Operand& right,
1210                              Label* no_overflow_label, Register scratch = at) {
1211     SubBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
1212   }
1213 
1214   void SubBranchOvf(Register dst, Register left, const Operand& right,
1215                     Label* overflow_label, Label* no_overflow_label,
1216                     Register scratch = at);
1217 
1218   void SubBranchOvf(Register dst, Register left, Register right,
1219                     Label* overflow_label, Label* no_overflow_label,
1220                     Register scratch = at);
1221 
1222   // -------------------------------------------------------------------------
1223   // Runtime calls.
1224 
1225   // See comments at the beginning of CEntryStub::Generate.
PrepareCEntryArgs(int num_args)1226   inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); }
1227 
PrepareCEntryFunction(const ExternalReference & ref)1228   inline void PrepareCEntryFunction(const ExternalReference& ref) {
1229     li(a1, Operand(ref));
1230   }
1231 
1232 #define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1233 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1234 
1235   // Call a code stub.
1236   void CallStub(CodeStub* stub,
1237                 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1238                 COND_ARGS);
1239 
1240   // Tail call a code stub (jump).
1241   void TailCallStub(CodeStub* stub, COND_ARGS);
1242 
1243 #undef COND_ARGS
1244 
1245   void CallJSExitStub(CodeStub* stub);
1246 
1247   // Call a runtime routine.
1248   void CallRuntime(const Runtime::Function* f, int num_arguments,
1249                    SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1250                    BranchDelaySlot bd = PROTECT);
CallRuntimeSaveDoubles(Runtime::FunctionId id)1251   void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1252     const Runtime::Function* function = Runtime::FunctionForId(id);
1253     CallRuntime(function, function->nargs, kSaveFPRegs);
1254   }
1255 
1256   // Convenience function: Same as above, but takes the fid instead.
1257   void CallRuntime(Runtime::FunctionId fid,
1258                    SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1259                    BranchDelaySlot bd = PROTECT) {
1260     const Runtime::Function* function = Runtime::FunctionForId(fid);
1261     CallRuntime(function, function->nargs, save_doubles, bd);
1262   }
1263 
1264   // Convenience function: Same as above, but takes the fid instead.
1265   void CallRuntime(Runtime::FunctionId id, int num_arguments,
1266                    SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1267                    BranchDelaySlot bd = PROTECT) {
1268     CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles, bd);
1269   }
1270 
1271   // Convenience function: call an external reference.
1272   void CallExternalReference(const ExternalReference& ext,
1273                              int num_arguments,
1274                              BranchDelaySlot bd = PROTECT);
1275 
1276 
1277   // Convenience function: tail call a runtime routine (jump).
1278   void TailCallRuntime(Runtime::FunctionId fid);
1279 
1280   int CalculateStackPassedWords(int num_reg_arguments,
1281                                 int num_double_arguments);
1282 
1283   // Before calling a C-function from generated code, align arguments on stack
1284   // and add space for the four mips argument slots.
1285   // After aligning the frame, non-register arguments must be stored on the
1286   // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1287   // The argument count assumes all arguments are word sized.
1288   // Some compilers/platforms require the stack to be aligned when calling
1289   // C++ code.
1290   // Needs a scratch register to do some arithmetic. This register will be
1291   // trashed.
1292   void PrepareCallCFunction(int num_reg_arguments,
1293                             int num_double_registers,
1294                             Register scratch);
1295   void PrepareCallCFunction(int num_reg_arguments,
1296                             Register scratch);
1297 
1298   // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1299   // Arguments 5..n are stored to stack using following:
1300   //  sw(t0, CFunctionArgumentOperand(5));
1301 
1302   // Calls a C function and cleans up the space for arguments allocated
1303   // by PrepareCallCFunction. The called function is not allowed to trigger a
1304   // garbage collection, since that might move the code and invalidate the
1305   // return address (unless this is somehow accounted for by the called
1306   // function).
1307   void CallCFunction(ExternalReference function, int num_arguments);
1308   void CallCFunction(Register function, int num_arguments);
1309   void CallCFunction(ExternalReference function,
1310                      int num_reg_arguments,
1311                      int num_double_arguments);
1312   void CallCFunction(Register function,
1313                      int num_reg_arguments,
1314                      int num_double_arguments);
1315   void MovFromFloatResult(DoubleRegister dst);
1316   void MovFromFloatParameter(DoubleRegister dst);
1317 
1318   // There are two ways of passing double arguments on MIPS, depending on
1319   // whether soft or hard floating point ABI is used. These functions
1320   // abstract parameter passing for the three different ways we call
1321   // C functions from generated code.
1322   void MovToFloatParameter(DoubleRegister src);
1323   void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1324   void MovToFloatResult(DoubleRegister src);
1325 
1326   // Jump to the builtin routine.
1327   void JumpToExternalReference(const ExternalReference& builtin,
1328                                BranchDelaySlot bd = PROTECT);
1329 
1330   // Invoke specified builtin JavaScript function.
1331   void InvokeBuiltin(int native_context_index, InvokeFlag flag,
1332                      const CallWrapper& call_wrapper = NullCallWrapper());
1333 
1334   struct Unresolved {
1335     int pc;
1336     uint32_t flags;  // See Bootstrapper::FixupFlags decoders/encoders.
1337     const char* name;
1338   };
1339 
CodeObject()1340   Handle<Object> CodeObject() {
1341     DCHECK(!code_object_.is_null());
1342     return code_object_;
1343   }
1344 
1345   // Emit code for a truncating division by a constant. The dividend register is
1346   // unchanged and at gets clobbered. Dividend and result must be different.
1347   void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1348 
1349   // -------------------------------------------------------------------------
1350   // StatsCounter support.
1351 
1352   void SetCounter(StatsCounter* counter, int value,
1353                   Register scratch1, Register scratch2);
1354   void IncrementCounter(StatsCounter* counter, int value,
1355                         Register scratch1, Register scratch2);
1356   void DecrementCounter(StatsCounter* counter, int value,
1357                         Register scratch1, Register scratch2);
1358 
1359 
1360   // -------------------------------------------------------------------------
1361   // Debugging.
1362 
1363   // Calls Abort(msg) if the condition cc is not satisfied.
1364   // Use --debug_code to enable.
1365   void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
1366   void AssertFastElements(Register elements);
1367 
1368   // Like Assert(), but always enabled.
1369   void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
1370 
1371   // Print a message to stdout and abort execution.
1372   void Abort(BailoutReason msg);
1373 
1374   // Verify restrictions about code generated in stubs.
set_generating_stub(bool value)1375   void set_generating_stub(bool value) { generating_stub_ = value; }
generating_stub()1376   bool generating_stub() { return generating_stub_; }
set_has_frame(bool value)1377   void set_has_frame(bool value) { has_frame_ = value; }
has_frame()1378   bool has_frame() { return has_frame_; }
1379   inline bool AllowThisStubCall(CodeStub* stub);
1380 
1381   // ---------------------------------------------------------------------------
1382   // Number utilities.
1383 
1384   // Check whether the value of reg is a power of two and not zero. If not
1385   // control continues at the label not_power_of_two. If reg is a power of two
1386   // the register scratch contains the value of (reg - 1) when control falls
1387   // through.
1388   void JumpIfNotPowerOfTwoOrZero(Register reg,
1389                                  Register scratch,
1390                                  Label* not_power_of_two_or_zero);
1391 
1392   // -------------------------------------------------------------------------
1393   // Smi utilities.
1394 
SmiTag(Register reg)1395   void SmiTag(Register reg) {
1396     Addu(reg, reg, reg);
1397   }
1398 
SmiTag(Register dst,Register src)1399   void SmiTag(Register dst, Register src) { Addu(dst, src, src); }
1400 
1401   // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1402   void SmiTagCheckOverflow(Register reg, Register overflow);
1403   void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1404 
1405   void BranchOnOverflow(Label* label, Register overflow_check,
1406                         BranchDelaySlot bd = PROTECT) {
1407     Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1408   }
1409 
1410   void BranchOnNoOverflow(Label* label, Register overflow_check,
1411                           BranchDelaySlot bd = PROTECT) {
1412     Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1413   }
1414 
1415 
1416   // Try to convert int32 to smi. If the value is to large, preserve
1417   // the original value and jump to not_a_smi. Destroys scratch and
1418   // sets flags.
TrySmiTag(Register reg,Register scratch,Label * not_a_smi)1419   void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1420     TrySmiTag(reg, reg, scratch, not_a_smi);
1421   }
TrySmiTag(Register dst,Register src,Register scratch,Label * not_a_smi)1422   void TrySmiTag(Register dst,
1423                  Register src,
1424                  Register scratch,
1425                  Label* not_a_smi) {
1426     SmiTagCheckOverflow(at, src, scratch);
1427     BranchOnOverflow(not_a_smi, scratch);
1428     mov(dst, at);
1429   }
1430 
SmiUntag(Register reg)1431   void SmiUntag(Register reg) {
1432     sra(reg, reg, kSmiTagSize);
1433   }
1434 
SmiUntag(Register dst,Register src)1435   void SmiUntag(Register dst, Register src) {
1436     sra(dst, src, kSmiTagSize);
1437   }
1438 
1439   // Test if the register contains a smi.
SmiTst(Register value,Register scratch)1440   inline void SmiTst(Register value, Register scratch) {
1441     And(scratch, value, Operand(kSmiTagMask));
1442   }
NonNegativeSmiTst(Register value,Register scratch)1443   inline void NonNegativeSmiTst(Register value, Register scratch) {
1444     And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1445   }
1446 
1447   // Untag the source value into destination and jump if source is a smi.
1448   // Souce and destination can be the same register.
1449   void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1450 
1451   // Untag the source value into destination and jump if source is not a smi.
1452   // Souce and destination can be the same register.
1453   void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1454 
1455   // Jump the register contains a smi.
1456   void JumpIfSmi(Register value,
1457                  Label* smi_label,
1458                  Register scratch = at,
1459                  BranchDelaySlot bd = PROTECT);
1460 
1461   // Jump if the register contains a non-smi.
1462   void JumpIfNotSmi(Register value,
1463                     Label* not_smi_label,
1464                     Register scratch = at,
1465                     BranchDelaySlot bd = PROTECT);
1466 
1467   // Jump if either of the registers contain a non-smi.
1468   void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1469   // Jump if either of the registers contain a smi.
1470   void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1471 
1472   // Abort execution if argument is a smi, enabled via --debug-code.
1473   void AssertNotSmi(Register object);
1474   void AssertSmi(Register object);
1475 
1476   // Abort execution if argument is not a string, enabled via --debug-code.
1477   void AssertString(Register object);
1478 
1479   // Abort execution if argument is not a name, enabled via --debug-code.
1480   void AssertName(Register object);
1481 
1482   // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1483   void AssertFunction(Register object);
1484 
1485   // Abort execution if argument is not a JSBoundFunction,
1486   // enabled via --debug-code.
1487   void AssertBoundFunction(Register object);
1488 
1489   // Abort execution if argument is not undefined or an AllocationSite, enabled
1490   // via --debug-code.
1491   void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1492 
1493   // Abort execution if reg is not the root value with the given index,
1494   // enabled via --debug-code.
1495   void AssertIsRoot(Register reg, Heap::RootListIndex index);
1496 
1497   // ---------------------------------------------------------------------------
1498   // HeapNumber utilities.
1499 
1500   void JumpIfNotHeapNumber(Register object,
1501                            Register heap_number_map,
1502                            Register scratch,
1503                            Label* on_not_heap_number);
1504 
1505   // -------------------------------------------------------------------------
1506   // String utilities.
1507 
1508   // Checks if both instance types are sequential ASCII strings and jumps to
1509   // label if either is not.
1510   void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1511       Register first_object_instance_type, Register second_object_instance_type,
1512       Register scratch1, Register scratch2, Label* failure);
1513 
1514   // Check if instance type is sequential one-byte string and jump to label if
1515   // it is not.
1516   void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1517                                                 Label* failure);
1518 
1519   void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
1520 
1521   void EmitSeqStringSetCharCheck(Register string,
1522                                  Register index,
1523                                  Register value,
1524                                  Register scratch,
1525                                  uint32_t encoding_mask);
1526 
1527   // Checks if both objects are sequential one-byte strings and jumps to label
1528   // if either is not. Assumes that neither object is a smi.
1529   void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first,
1530                                                     Register second,
1531                                                     Register scratch1,
1532                                                     Register scratch2,
1533                                                     Label* failure);
1534 
1535   // Checks if both objects are sequential one-byte strings and jumps to label
1536   // if either is not.
1537   void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1538                                              Register scratch1,
1539                                              Register scratch2,
1540                                              Label* not_flat_one_byte_strings);
1541 
1542   void ClampUint8(Register output_reg, Register input_reg);
1543 
1544   void ClampDoubleToUint8(Register result_reg,
1545                           DoubleRegister input_reg,
1546                           DoubleRegister temp_double_reg);
1547 
1548 
1549   void LoadInstanceDescriptors(Register map, Register descriptors);
1550   void EnumLength(Register dst, Register map);
1551   void NumberOfOwnDescriptors(Register dst, Register map);
1552   void LoadAccessor(Register dst, Register holder, int accessor_index,
1553                     AccessorComponent accessor);
1554 
1555   template<typename Field>
DecodeField(Register dst,Register src)1556   void DecodeField(Register dst, Register src) {
1557     Ext(dst, src, Field::kShift, Field::kSize);
1558   }
1559 
1560   template<typename Field>
DecodeField(Register reg)1561   void DecodeField(Register reg) {
1562     DecodeField<Field>(reg, reg);
1563   }
1564 
1565   template<typename Field>
DecodeFieldToSmi(Register dst,Register src)1566   void DecodeFieldToSmi(Register dst, Register src) {
1567     static const int shift = Field::kShift;
1568     static const int mask = Field::kMask >> shift << kSmiTagSize;
1569     STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1570     STATIC_ASSERT(kSmiTag == 0);
1571     if (shift < kSmiTagSize) {
1572       sll(dst, src, kSmiTagSize - shift);
1573       And(dst, dst, Operand(mask));
1574     } else if (shift > kSmiTagSize) {
1575       srl(dst, src, shift - kSmiTagSize);
1576       And(dst, dst, Operand(mask));
1577     } else {
1578       And(dst, src, Operand(mask));
1579     }
1580   }
1581 
1582   template<typename Field>
DecodeFieldToSmi(Register reg)1583   void DecodeFieldToSmi(Register reg) {
1584     DecodeField<Field>(reg, reg);
1585   }
1586 
1587   // Generates function and stub prologue code.
1588   void StubPrologue();
1589   void Prologue(bool code_pre_aging);
1590 
1591   // Load the type feedback vector from a JavaScript frame.
1592   void EmitLoadTypeFeedbackVector(Register vector);
1593 
1594   // Activation support.
1595   void EnterFrame(StackFrame::Type type);
1596   void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1597   void LeaveFrame(StackFrame::Type type);
1598 
1599   // Expects object in a0 and returns map with validated enum cache
1600   // in a0.  Assumes that any other register can be used as a scratch.
1601   void CheckEnumCache(Register null_value, Label* call_runtime);
1602 
1603   // AllocationMemento support. Arrays may have an associated
1604   // AllocationMemento object that can be checked for in order to pretransition
1605   // to another type.
1606   // On entry, receiver_reg should point to the array object.
1607   // scratch_reg gets clobbered.
1608   // If allocation info is present, jump to allocation_memento_present.
1609   void TestJSArrayForAllocationMemento(
1610       Register receiver_reg,
1611       Register scratch_reg,
1612       Label* no_memento_found,
1613       Condition cond = al,
1614       Label* allocation_memento_present = NULL);
1615 
JumpIfJSArrayHasAllocationMemento(Register receiver_reg,Register scratch_reg,Label * memento_found)1616   void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1617                                          Register scratch_reg,
1618                                          Label* memento_found) {
1619     Label no_memento_found;
1620     TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1621                                     &no_memento_found, eq, memento_found);
1622     bind(&no_memento_found);
1623   }
1624 
1625   // Jumps to found label if a prototype map has dictionary elements.
1626   void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1627                                         Register scratch1, Label* found);
1628 
IsDoubleZeroRegSet()1629   bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; }
1630 
1631  private:
1632   void CallCFunctionHelper(Register function,
1633                            int num_reg_arguments,
1634                            int num_double_arguments);
1635 
1636   inline Register GetRtAsRegisterHelper(const Operand& rt, Register scratch);
1637   inline int32_t GetOffset(int32_t offset, Label* L, OffsetSize bits);
1638   void BranchShortHelperR6(int32_t offset, Label* L);
1639   void BranchShortHelper(int16_t offset, Label* L, BranchDelaySlot bdslot);
1640   bool BranchShortHelperR6(int32_t offset, Label* L, Condition cond,
1641                            Register rs, const Operand& rt);
1642   bool BranchShortHelper(int16_t offset, Label* L, Condition cond, Register rs,
1643                          const Operand& rt, BranchDelaySlot bdslot);
1644   bool BranchShortCheck(int32_t offset, Label* L, Condition cond, Register rs,
1645                         const Operand& rt, BranchDelaySlot bdslot);
1646 
1647   void BranchAndLinkShortHelperR6(int32_t offset, Label* L);
1648   void BranchAndLinkShortHelper(int16_t offset, Label* L,
1649                                 BranchDelaySlot bdslot);
1650   void BranchAndLinkShort(int32_t offset, BranchDelaySlot bdslot = PROTECT);
1651   void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1652   bool BranchAndLinkShortHelperR6(int32_t offset, Label* L, Condition cond,
1653                                   Register rs, const Operand& rt);
1654   bool BranchAndLinkShortHelper(int16_t offset, Label* L, Condition cond,
1655                                 Register rs, const Operand& rt,
1656                                 BranchDelaySlot bdslot);
1657   bool BranchAndLinkShortCheck(int32_t offset, Label* L, Condition cond,
1658                                Register rs, const Operand& rt,
1659                                BranchDelaySlot bdslot);
1660   void BranchLong(Label* L, BranchDelaySlot bdslot);
1661   void BranchAndLinkLong(Label* L, BranchDelaySlot bdslot);
1662 
1663   // Common implementation of BranchF functions for the different formats.
1664   void BranchFCommon(SecondaryField sizeField, Label* target, Label* nan,
1665                      Condition cc, FPURegister cmp1, FPURegister cmp2,
1666                      BranchDelaySlot bd = PROTECT);
1667 
1668   void BranchShortF(SecondaryField sizeField, Label* target, Condition cc,
1669                     FPURegister cmp1, FPURegister cmp2,
1670                     BranchDelaySlot bd = PROTECT);
1671 
1672   // Helper functions for generating invokes.
1673   void InvokePrologue(const ParameterCount& expected,
1674                       const ParameterCount& actual,
1675                       Label* done,
1676                       bool* definitely_mismatches,
1677                       InvokeFlag flag,
1678                       const CallWrapper& call_wrapper);
1679 
1680   void InitializeNewString(Register string,
1681                            Register length,
1682                            Heap::RootListIndex map_index,
1683                            Register scratch1,
1684                            Register scratch2);
1685 
1686   // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1687   void InNewSpace(Register object,
1688                   Register scratch,
1689                   Condition cond,  // eq for new space, ne otherwise.
1690                   Label* branch);
1691 
1692   // Helper for finding the mark bits for an address.  Afterwards, the
1693   // bitmap register points at the word with the mark bits and the mask
1694   // the position of the first bit.  Leaves addr_reg unchanged.
1695   inline void GetMarkBits(Register addr_reg,
1696                           Register bitmap_reg,
1697                           Register mask_reg);
1698 
1699   // Compute memory operands for safepoint stack slots.
1700   static int SafepointRegisterStackIndex(int reg_code);
1701   MemOperand SafepointRegisterSlot(Register reg);
1702   MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1703 
1704   bool generating_stub_;
1705   bool has_frame_;
1706   bool has_double_zero_reg_set_;
1707   // This handle will be patched with the code object on installation.
1708   Handle<Object> code_object_;
1709 
1710   // Needs access to SafepointRegisterStackIndex for compiled frame
1711   // traversal.
1712   friend class StandardFrame;
1713 };
1714 
1715 
1716 // The code patcher is used to patch (typically) small parts of code e.g. for
1717 // debugging and other types of instrumentation. When using the code patcher
1718 // the exact number of bytes specified must be emitted. It is not legal to emit
1719 // relocation information. If any of these constraints are violated it causes
1720 // an assertion to fail.
1721 class CodePatcher {
1722  public:
1723   enum FlushICache {
1724     FLUSH,
1725     DONT_FLUSH
1726   };
1727 
1728   CodePatcher(Isolate* isolate, byte* address, int instructions,
1729               FlushICache flush_cache = FLUSH);
1730   ~CodePatcher();
1731 
1732   // Macro assembler to emit code.
masm()1733   MacroAssembler* masm() { return &masm_; }
1734 
1735   // Emit an instruction directly.
1736   void Emit(Instr instr);
1737 
1738   // Emit an address directly.
1739   void Emit(Address addr);
1740 
1741   // Change the condition part of an instruction leaving the rest of the current
1742   // instruction unchanged.
1743   void ChangeBranchCondition(Instr current_instr, uint32_t new_opcode);
1744 
1745  private:
1746   byte* address_;  // The address of the code being patched.
1747   int size_;  // Number of bytes of the expected patch size.
1748   MacroAssembler masm_;  // Macro assembler used to generate the code.
1749   FlushICache flush_cache_;  // Whether to flush the I cache after patching.
1750 };
1751 
1752 
1753 
1754 #ifdef GENERATED_CODE_COVERAGE
1755 #define CODE_COVERAGE_STRINGIFY(x) #x
1756 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1757 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1758 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1759 #else
1760 #define ACCESS_MASM(masm) masm->
1761 #endif
1762 
1763 }  // namespace internal
1764 }  // namespace v8
1765 
1766 #endif  // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
1767