deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / arm64 / macro-assembler-arm64.h
1 // Copyright 2013 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_ARM64_MACRO_ASSEMBLER_ARM64_H_
6 #define V8_ARM64_MACRO_ASSEMBLER_ARM64_H_
7
8 #include <vector>
9
10 #include "src/bailout-reason.h"
11 #include "src/globals.h"
12
13 #include "src/arm64/assembler-arm64-inl.h"
14 #include "src/base/bits.h"
15
16 // Simulator specific helpers.
17 #if USE_SIMULATOR
18   // TODO(all): If possible automatically prepend an indicator like
19   // UNIMPLEMENTED or LOCATION.
20   #define ASM_UNIMPLEMENTED(message)                                         \
21   __ Debug(message, __LINE__, NO_PARAM)
22   #define ASM_UNIMPLEMENTED_BREAK(message)                                   \
23   __ Debug(message, __LINE__,                                                \
24            FLAG_ignore_asm_unimplemented_break ? NO_PARAM : BREAK)
25   #define ASM_LOCATION(message)                                              \
26   __ Debug("LOCATION: " message, __LINE__, NO_PARAM)
27 #else
28   #define ASM_UNIMPLEMENTED(message)
29   #define ASM_UNIMPLEMENTED_BREAK(message)
30   #define ASM_LOCATION(message)
31 #endif
32
33
34 namespace v8 {
35 namespace internal {
36
37 #define LS_MACRO_LIST(V)                                      \
38   V(Ldrb, Register&, rt, LDRB_w)                              \
39   V(Strb, Register&, rt, STRB_w)                              \
40   V(Ldrsb, Register&, rt, rt.Is64Bits() ? LDRSB_x : LDRSB_w)  \
41   V(Ldrh, Register&, rt, LDRH_w)                              \
42   V(Strh, Register&, rt, STRH_w)                              \
43   V(Ldrsh, Register&, rt, rt.Is64Bits() ? LDRSH_x : LDRSH_w)  \
44   V(Ldr, CPURegister&, rt, LoadOpFor(rt))                     \
45   V(Str, CPURegister&, rt, StoreOpFor(rt))                    \
46   V(Ldrsw, Register&, rt, LDRSW_x)
47
48 #define LSPAIR_MACRO_LIST(V)                             \
49   V(Ldp, CPURegister&, rt, rt2, LoadPairOpFor(rt, rt2))  \
50   V(Stp, CPURegister&, rt, rt2, StorePairOpFor(rt, rt2)) \
51   V(Ldpsw, CPURegister&, rt, rt2, LDPSW_x)
52
53
54 // ----------------------------------------------------------------------------
55 // Static helper functions
56
57 // Generate a MemOperand for loading a field from an object.
58 inline MemOperand FieldMemOperand(Register object, int offset);
59 inline MemOperand UntagSmiFieldMemOperand(Register object, int offset);
60
61 // Generate a MemOperand for loading a SMI from memory.
62 inline MemOperand UntagSmiMemOperand(Register object, int offset);
63
64
65 // ----------------------------------------------------------------------------
66 // MacroAssembler
67
68 enum BranchType {
69   // Copies of architectural conditions.
70   // The associated conditions can be used in place of those, the code will
71   // take care of reinterpreting them with the correct type.
72   integer_eq = eq,
73   integer_ne = ne,
74   integer_hs = hs,
75   integer_lo = lo,
76   integer_mi = mi,
77   integer_pl = pl,
78   integer_vs = vs,
79   integer_vc = vc,
80   integer_hi = hi,
81   integer_ls = ls,
82   integer_ge = ge,
83   integer_lt = lt,
84   integer_gt = gt,
85   integer_le = le,
86   integer_al = al,
87   integer_nv = nv,
88
89   // These two are *different* from the architectural codes al and nv.
90   // 'always' is used to generate unconditional branches.
91   // 'never' is used to not generate a branch (generally as the inverse
92   // branch type of 'always).
93   always, never,
94   // cbz and cbnz
95   reg_zero, reg_not_zero,
96   // tbz and tbnz
97   reg_bit_clear, reg_bit_set,
98
99   // Aliases.
100   kBranchTypeFirstCondition = eq,
101   kBranchTypeLastCondition = nv,
102   kBranchTypeFirstUsingReg = reg_zero,
103   kBranchTypeFirstUsingBit = reg_bit_clear
104 };
105
106 inline BranchType InvertBranchType(BranchType type) {
107   if (kBranchTypeFirstCondition <= type && type <= kBranchTypeLastCondition) {
108     return static_cast<BranchType>(
109         NegateCondition(static_cast<Condition>(type)));
110   } else {
111     return static_cast<BranchType>(type ^ 1);
112   }
113 }
114
115 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
116 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
117 enum PointersToHereCheck {
118   kPointersToHereMaybeInteresting,
119   kPointersToHereAreAlwaysInteresting
120 };
121 enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved };
122 enum TargetAddressStorageMode {
123   CAN_INLINE_TARGET_ADDRESS,
124   NEVER_INLINE_TARGET_ADDRESS
125 };
126 enum UntagMode { kNotSpeculativeUntag, kSpeculativeUntag };
127 enum ArrayHasHoles { kArrayCantHaveHoles, kArrayCanHaveHoles };
128 enum CopyHint { kCopyUnknown, kCopyShort, kCopyLong };
129 enum DiscardMoveMode { kDontDiscardForSameWReg, kDiscardForSameWReg };
130 enum SeqStringSetCharCheckIndexType { kIndexIsSmi, kIndexIsInteger32 };
131
132 class MacroAssembler : public Assembler {
133  public:
134   MacroAssembler(Isolate* isolate, byte * buffer, unsigned buffer_size);
135
136   inline Handle<Object> CodeObject();
137
138   // Instruction set functions ------------------------------------------------
139   // Logical macros.
140   inline void And(const Register& rd,
141                   const Register& rn,
142                   const Operand& operand);
143   inline void Ands(const Register& rd,
144                    const Register& rn,
145                    const Operand& operand);
146   inline void Bic(const Register& rd,
147                   const Register& rn,
148                   const Operand& operand);
149   inline void Bics(const Register& rd,
150                    const Register& rn,
151                    const Operand& operand);
152   inline void Orr(const Register& rd,
153                   const Register& rn,
154                   const Operand& operand);
155   inline void Orn(const Register& rd,
156                   const Register& rn,
157                   const Operand& operand);
158   inline void Eor(const Register& rd,
159                   const Register& rn,
160                   const Operand& operand);
161   inline void Eon(const Register& rd,
162                   const Register& rn,
163                   const Operand& operand);
164   inline void Tst(const Register& rn, const Operand& operand);
165   void LogicalMacro(const Register& rd,
166                     const Register& rn,
167                     const Operand& operand,
168                     LogicalOp op);
169
170   // Add and sub macros.
171   inline void Add(const Register& rd,
172                   const Register& rn,
173                   const Operand& operand);
174   inline void Adds(const Register& rd,
175                    const Register& rn,
176                    const Operand& operand);
177   inline void Sub(const Register& rd,
178                   const Register& rn,
179                   const Operand& operand);
180   inline void Subs(const Register& rd,
181                    const Register& rn,
182                    const Operand& operand);
183   inline void Cmn(const Register& rn, const Operand& operand);
184   inline void Cmp(const Register& rn, const Operand& operand);
185   inline void Neg(const Register& rd,
186                   const Operand& operand);
187   inline void Negs(const Register& rd,
188                    const Operand& operand);
189
190   void AddSubMacro(const Register& rd,
191                    const Register& rn,
192                    const Operand& operand,
193                    FlagsUpdate S,
194                    AddSubOp op);
195
196   // Add/sub with carry macros.
197   inline void Adc(const Register& rd,
198                   const Register& rn,
199                   const Operand& operand);
200   inline void Adcs(const Register& rd,
201                    const Register& rn,
202                    const Operand& operand);
203   inline void Sbc(const Register& rd,
204                   const Register& rn,
205                   const Operand& operand);
206   inline void Sbcs(const Register& rd,
207                    const Register& rn,
208                    const Operand& operand);
209   inline void Ngc(const Register& rd,
210                   const Operand& operand);
211   inline void Ngcs(const Register& rd,
212                    const Operand& operand);
213   void AddSubWithCarryMacro(const Register& rd,
214                             const Register& rn,
215                             const Operand& operand,
216                             FlagsUpdate S,
217                             AddSubWithCarryOp op);
218
219   // Move macros.
220   void Mov(const Register& rd,
221            const Operand& operand,
222            DiscardMoveMode discard_mode = kDontDiscardForSameWReg);
223   void Mov(const Register& rd, uint64_t imm);
224   inline void Mvn(const Register& rd, uint64_t imm);
225   void Mvn(const Register& rd, const Operand& operand);
226   static bool IsImmMovn(uint64_t imm, unsigned reg_size);
227   static bool IsImmMovz(uint64_t imm, unsigned reg_size);
228   static unsigned CountClearHalfWords(uint64_t imm, unsigned reg_size);
229
230   // Try to move an immediate into the destination register in a single
231   // instruction. Returns true for success, and updates the contents of dst.
232   // Returns false, otherwise.
233   bool TryOneInstrMoveImmediate(const Register& dst, int64_t imm);
234
235   // Move an immediate into register dst, and return an Operand object for use
236   // with a subsequent instruction that accepts a shift. The value moved into
237   // dst is not necessarily equal to imm; it may have had a shifting operation
238   // applied to it that will be subsequently undone by the shift applied in the
239   // Operand.
240   Operand MoveImmediateForShiftedOp(const Register& dst, int64_t imm);
241
242   // Conditional macros.
243   inline void Ccmp(const Register& rn,
244                    const Operand& operand,
245                    StatusFlags nzcv,
246                    Condition cond);
247   inline void Ccmn(const Register& rn,
248                    const Operand& operand,
249                    StatusFlags nzcv,
250                    Condition cond);
251   void ConditionalCompareMacro(const Register& rn,
252                                const Operand& operand,
253                                StatusFlags nzcv,
254                                Condition cond,
255                                ConditionalCompareOp op);
256   void Csel(const Register& rd,
257             const Register& rn,
258             const Operand& operand,
259             Condition cond);
260
261   // Load/store macros.
262 #define DECLARE_FUNCTION(FN, REGTYPE, REG, OP) \
263   inline void FN(const REGTYPE REG, const MemOperand& addr);
264   LS_MACRO_LIST(DECLARE_FUNCTION)
265 #undef DECLARE_FUNCTION
266
267   void LoadStoreMacro(const CPURegister& rt,
268                       const MemOperand& addr,
269                       LoadStoreOp op);
270
271 #define DECLARE_FUNCTION(FN, REGTYPE, REG, REG2, OP) \
272   inline void FN(const REGTYPE REG, const REGTYPE REG2, const MemOperand& addr);
273   LSPAIR_MACRO_LIST(DECLARE_FUNCTION)
274 #undef DECLARE_FUNCTION
275
276   void LoadStorePairMacro(const CPURegister& rt, const CPURegister& rt2,
277                           const MemOperand& addr, LoadStorePairOp op);
278
279   // V8-specific load/store helpers.
280   void Load(const Register& rt, const MemOperand& addr, Representation r);
281   void Store(const Register& rt, const MemOperand& addr, Representation r);
282
283   enum AdrHint {
284     // The target must be within the immediate range of adr.
285     kAdrNear,
286     // The target may be outside of the immediate range of adr. Additional
287     // instructions may be emitted.
288     kAdrFar
289   };
290   void Adr(const Register& rd, Label* label, AdrHint = kAdrNear);
291
292   // Remaining instructions are simple pass-through calls to the assembler.
293   inline void Asr(const Register& rd, const Register& rn, unsigned shift);
294   inline void Asr(const Register& rd, const Register& rn, const Register& rm);
295
296   // Branch type inversion relies on these relations.
297   STATIC_ASSERT((reg_zero      == (reg_not_zero ^ 1)) &&
298                 (reg_bit_clear == (reg_bit_set ^ 1)) &&
299                 (always        == (never ^ 1)));
300
301   void B(Label* label, BranchType type, Register reg = NoReg, int bit = -1);
302
303   inline void B(Label* label);
304   inline void B(Condition cond, Label* label);
305   void B(Label* label, Condition cond);
306   inline void Bfi(const Register& rd,
307                   const Register& rn,
308                   unsigned lsb,
309                   unsigned width);
310   inline void Bfxil(const Register& rd,
311                     const Register& rn,
312                     unsigned lsb,
313                     unsigned width);
314   inline void Bind(Label* label);
315   inline void Bl(Label* label);
316   inline void Blr(const Register& xn);
317   inline void Br(const Register& xn);
318   inline void Brk(int code);
319   void Cbnz(const Register& rt, Label* label);
320   void Cbz(const Register& rt, Label* label);
321   inline void Cinc(const Register& rd, const Register& rn, Condition cond);
322   inline void Cinv(const Register& rd, const Register& rn, Condition cond);
323   inline void Cls(const Register& rd, const Register& rn);
324   inline void Clz(const Register& rd, const Register& rn);
325   inline void Cneg(const Register& rd, const Register& rn, Condition cond);
326   inline void CzeroX(const Register& rd, Condition cond);
327   inline void CmovX(const Register& rd, const Register& rn, Condition cond);
328   inline void Cset(const Register& rd, Condition cond);
329   inline void Csetm(const Register& rd, Condition cond);
330   inline void Csinc(const Register& rd,
331                     const Register& rn,
332                     const Register& rm,
333                     Condition cond);
334   inline void Csinv(const Register& rd,
335                     const Register& rn,
336                     const Register& rm,
337                     Condition cond);
338   inline void Csneg(const Register& rd,
339                     const Register& rn,
340                     const Register& rm,
341                     Condition cond);
342   inline void Dmb(BarrierDomain domain, BarrierType type);
343   inline void Dsb(BarrierDomain domain, BarrierType type);
344   inline void Debug(const char* message, uint32_t code, Instr params = BREAK);
345   inline void Extr(const Register& rd,
346                    const Register& rn,
347                    const Register& rm,
348                    unsigned lsb);
349   inline void Fabs(const FPRegister& fd, const FPRegister& fn);
350   inline void Fadd(const FPRegister& fd,
351                    const FPRegister& fn,
352                    const FPRegister& fm);
353   inline void Fccmp(const FPRegister& fn,
354                     const FPRegister& fm,
355                     StatusFlags nzcv,
356                     Condition cond);
357   inline void Fcmp(const FPRegister& fn, const FPRegister& fm);
358   inline void Fcmp(const FPRegister& fn, double value);
359   inline void Fcsel(const FPRegister& fd,
360                     const FPRegister& fn,
361                     const FPRegister& fm,
362                     Condition cond);
363   inline void Fcvt(const FPRegister& fd, const FPRegister& fn);
364   inline void Fcvtas(const Register& rd, const FPRegister& fn);
365   inline void Fcvtau(const Register& rd, const FPRegister& fn);
366   inline void Fcvtms(const Register& rd, const FPRegister& fn);
367   inline void Fcvtmu(const Register& rd, const FPRegister& fn);
368   inline void Fcvtns(const Register& rd, const FPRegister& fn);
369   inline void Fcvtnu(const Register& rd, const FPRegister& fn);
370   inline void Fcvtzs(const Register& rd, const FPRegister& fn);
371   inline void Fcvtzu(const Register& rd, const FPRegister& fn);
372   inline void Fdiv(const FPRegister& fd,
373                    const FPRegister& fn,
374                    const FPRegister& fm);
375   inline void Fmadd(const FPRegister& fd,
376                     const FPRegister& fn,
377                     const FPRegister& fm,
378                     const FPRegister& fa);
379   inline void Fmax(const FPRegister& fd,
380                    const FPRegister& fn,
381                    const FPRegister& fm);
382   inline void Fmaxnm(const FPRegister& fd,
383                      const FPRegister& fn,
384                      const FPRegister& fm);
385   inline void Fmin(const FPRegister& fd,
386                    const FPRegister& fn,
387                    const FPRegister& fm);
388   inline void Fminnm(const FPRegister& fd,
389                      const FPRegister& fn,
390                      const FPRegister& fm);
391   inline void Fmov(FPRegister fd, FPRegister fn);
392   inline void Fmov(FPRegister fd, Register rn);
393   // Provide explicit double and float interfaces for FP immediate moves, rather
394   // than relying on implicit C++ casts. This allows signalling NaNs to be
395   // preserved when the immediate matches the format of fd. Most systems convert
396   // signalling NaNs to quiet NaNs when converting between float and double.
397   inline void Fmov(FPRegister fd, double imm);
398   inline void Fmov(FPRegister fd, float imm);
399   // Provide a template to allow other types to be converted automatically.
400   template<typename T>
401   void Fmov(FPRegister fd, T imm) {
402     DCHECK(allow_macro_instructions_);
403     Fmov(fd, static_cast<double>(imm));
404   }
405   inline void Fmov(Register rd, FPRegister fn);
406   inline void Fmsub(const FPRegister& fd,
407                     const FPRegister& fn,
408                     const FPRegister& fm,
409                     const FPRegister& fa);
410   inline void Fmul(const FPRegister& fd,
411                    const FPRegister& fn,
412                    const FPRegister& fm);
413   inline void Fneg(const FPRegister& fd, const FPRegister& fn);
414   inline void Fnmadd(const FPRegister& fd,
415                      const FPRegister& fn,
416                      const FPRegister& fm,
417                      const FPRegister& fa);
418   inline void Fnmsub(const FPRegister& fd,
419                      const FPRegister& fn,
420                      const FPRegister& fm,
421                      const FPRegister& fa);
422   inline void Frinta(const FPRegister& fd, const FPRegister& fn);
423   inline void Frintm(const FPRegister& fd, const FPRegister& fn);
424   inline void Frintn(const FPRegister& fd, const FPRegister& fn);
425   inline void Frintp(const FPRegister& fd, const FPRegister& fn);
426   inline void Frintz(const FPRegister& fd, const FPRegister& fn);
427   inline void Fsqrt(const FPRegister& fd, const FPRegister& fn);
428   inline void Fsub(const FPRegister& fd,
429                    const FPRegister& fn,
430                    const FPRegister& fm);
431   inline void Hint(SystemHint code);
432   inline void Hlt(int code);
433   inline void Isb();
434   inline void Ldnp(const CPURegister& rt,
435                    const CPURegister& rt2,
436                    const MemOperand& src);
437   // Load a literal from the inline constant pool.
438   inline void Ldr(const CPURegister& rt, const Immediate& imm);
439   // Helper function for double immediate.
440   inline void Ldr(const CPURegister& rt, double imm);
441   inline void Lsl(const Register& rd, const Register& rn, unsigned shift);
442   inline void Lsl(const Register& rd, const Register& rn, const Register& rm);
443   inline void Lsr(const Register& rd, const Register& rn, unsigned shift);
444   inline void Lsr(const Register& rd, const Register& rn, const Register& rm);
445   inline void Madd(const Register& rd,
446                    const Register& rn,
447                    const Register& rm,
448                    const Register& ra);
449   inline void Mneg(const Register& rd, const Register& rn, const Register& rm);
450   inline void Mov(const Register& rd, const Register& rm);
451   inline void Movk(const Register& rd, uint64_t imm, int shift = -1);
452   inline void Mrs(const Register& rt, SystemRegister sysreg);
453   inline void Msr(SystemRegister sysreg, const Register& rt);
454   inline void Msub(const Register& rd,
455                    const Register& rn,
456                    const Register& rm,
457                    const Register& ra);
458   inline void Mul(const Register& rd, const Register& rn, const Register& rm);
459   inline void Nop() { nop(); }
460   inline void Rbit(const Register& rd, const Register& rn);
461   inline void Ret(const Register& xn = lr);
462   inline void Rev(const Register& rd, const Register& rn);
463   inline void Rev16(const Register& rd, const Register& rn);
464   inline void Rev32(const Register& rd, const Register& rn);
465   inline void Ror(const Register& rd, const Register& rs, unsigned shift);
466   inline void Ror(const Register& rd, const Register& rn, const Register& rm);
467   inline void Sbfiz(const Register& rd,
468                     const Register& rn,
469                     unsigned lsb,
470                     unsigned width);
471   inline void Sbfx(const Register& rd,
472                    const Register& rn,
473                    unsigned lsb,
474                    unsigned width);
475   inline void Scvtf(const FPRegister& fd,
476                     const Register& rn,
477                     unsigned fbits = 0);
478   inline void Sdiv(const Register& rd, const Register& rn, const Register& rm);
479   inline void Smaddl(const Register& rd,
480                      const Register& rn,
481                      const Register& rm,
482                      const Register& ra);
483   inline void Smsubl(const Register& rd,
484                      const Register& rn,
485                      const Register& rm,
486                      const Register& ra);
487   inline void Smull(const Register& rd,
488                     const Register& rn,
489                     const Register& rm);
490   inline void Smulh(const Register& rd,
491                     const Register& rn,
492                     const Register& rm);
493   inline void Umull(const Register& rd, const Register& rn, const Register& rm);
494   inline void Stnp(const CPURegister& rt,
495                    const CPURegister& rt2,
496                    const MemOperand& dst);
497   inline void Sxtb(const Register& rd, const Register& rn);
498   inline void Sxth(const Register& rd, const Register& rn);
499   inline void Sxtw(const Register& rd, const Register& rn);
500   void Tbnz(const Register& rt, unsigned bit_pos, Label* label);
501   void Tbz(const Register& rt, unsigned bit_pos, Label* label);
502   inline void Ubfiz(const Register& rd,
503                     const Register& rn,
504                     unsigned lsb,
505                     unsigned width);
506   inline void Ubfx(const Register& rd,
507                    const Register& rn,
508                    unsigned lsb,
509                    unsigned width);
510   inline void Ucvtf(const FPRegister& fd,
511                     const Register& rn,
512                     unsigned fbits = 0);
513   inline void Udiv(const Register& rd, const Register& rn, const Register& rm);
514   inline void Umaddl(const Register& rd,
515                      const Register& rn,
516                      const Register& rm,
517                      const Register& ra);
518   inline void Umsubl(const Register& rd,
519                      const Register& rn,
520                      const Register& rm,
521                      const Register& ra);
522   inline void Uxtb(const Register& rd, const Register& rn);
523   inline void Uxth(const Register& rd, const Register& rn);
524   inline void Uxtw(const Register& rd, const Register& rn);
525
526   // Pseudo-instructions ------------------------------------------------------
527
528   // Compute rd = abs(rm).
529   // This function clobbers the condition flags. On output the overflow flag is
530   // set iff the negation overflowed.
531   //
532   // If rm is the minimum representable value, the result is not representable.
533   // Handlers for each case can be specified using the relevant labels.
534   void Abs(const Register& rd, const Register& rm,
535            Label * is_not_representable = NULL,
536            Label * is_representable = NULL);
537
538   // Push or pop up to 4 registers of the same width to or from the stack,
539   // using the current stack pointer as set by SetStackPointer.
540   //
541   // If an argument register is 'NoReg', all further arguments are also assumed
542   // to be 'NoReg', and are thus not pushed or popped.
543   //
544   // Arguments are ordered such that "Push(a, b);" is functionally equivalent
545   // to "Push(a); Push(b);".
546   //
547   // It is valid to push the same register more than once, and there is no
548   // restriction on the order in which registers are specified.
549   //
550   // It is not valid to pop into the same register more than once in one
551   // operation, not even into the zero register.
552   //
553   // If the current stack pointer (as set by SetStackPointer) is csp, then it
554   // must be aligned to 16 bytes on entry and the total size of the specified
555   // registers must also be a multiple of 16 bytes.
556   //
557   // Even if the current stack pointer is not the system stack pointer (csp),
558   // Push (and derived methods) will still modify the system stack pointer in
559   // order to comply with ABI rules about accessing memory below the system
560   // stack pointer.
561   //
562   // Other than the registers passed into Pop, the stack pointer and (possibly)
563   // the system stack pointer, these methods do not modify any other registers.
564   void Push(const CPURegister& src0, const CPURegister& src1 = NoReg,
565             const CPURegister& src2 = NoReg, const CPURegister& src3 = NoReg);
566   void Push(const CPURegister& src0, const CPURegister& src1,
567             const CPURegister& src2, const CPURegister& src3,
568             const CPURegister& src4, const CPURegister& src5 = NoReg,
569             const CPURegister& src6 = NoReg, const CPURegister& src7 = NoReg);
570   void Pop(const CPURegister& dst0, const CPURegister& dst1 = NoReg,
571            const CPURegister& dst2 = NoReg, const CPURegister& dst3 = NoReg);
572   void Push(const Register& src0, const FPRegister& src1);
573
574   // Alternative forms of Push and Pop, taking a RegList or CPURegList that
575   // specifies the registers that are to be pushed or popped. Higher-numbered
576   // registers are associated with higher memory addresses (as in the A32 push
577   // and pop instructions).
578   //
579   // (Push|Pop)SizeRegList allow you to specify the register size as a
580   // parameter. Only kXRegSizeInBits, kWRegSizeInBits, kDRegSizeInBits and
581   // kSRegSizeInBits are supported.
582   //
583   // Otherwise, (Push|Pop)(CPU|X|W|D|S)RegList is preferred.
584   void PushCPURegList(CPURegList registers);
585   void PopCPURegList(CPURegList registers);
586
587   inline void PushSizeRegList(RegList registers, unsigned reg_size,
588       CPURegister::RegisterType type = CPURegister::kRegister) {
589     PushCPURegList(CPURegList(type, reg_size, registers));
590   }
591   inline void PopSizeRegList(RegList registers, unsigned reg_size,
592       CPURegister::RegisterType type = CPURegister::kRegister) {
593     PopCPURegList(CPURegList(type, reg_size, registers));
594   }
595   inline void PushXRegList(RegList regs) {
596     PushSizeRegList(regs, kXRegSizeInBits);
597   }
598   inline void PopXRegList(RegList regs) {
599     PopSizeRegList(regs, kXRegSizeInBits);
600   }
601   inline void PushWRegList(RegList regs) {
602     PushSizeRegList(regs, kWRegSizeInBits);
603   }
604   inline void PopWRegList(RegList regs) {
605     PopSizeRegList(regs, kWRegSizeInBits);
606   }
607   inline void PushDRegList(RegList regs) {
608     PushSizeRegList(regs, kDRegSizeInBits, CPURegister::kFPRegister);
609   }
610   inline void PopDRegList(RegList regs) {
611     PopSizeRegList(regs, kDRegSizeInBits, CPURegister::kFPRegister);
612   }
613   inline void PushSRegList(RegList regs) {
614     PushSizeRegList(regs, kSRegSizeInBits, CPURegister::kFPRegister);
615   }
616   inline void PopSRegList(RegList regs) {
617     PopSizeRegList(regs, kSRegSizeInBits, CPURegister::kFPRegister);
618   }
619
620   // Push the specified register 'count' times.
621   void PushMultipleTimes(CPURegister src, Register count);
622   void PushMultipleTimes(CPURegister src, int count);
623
624   // This is a convenience method for pushing a single Handle<Object>.
625   inline void Push(Handle<Object> handle);
626   void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
627
628   // Aliases of Push and Pop, required for V8 compatibility.
629   inline void push(Register src) {
630     Push(src);
631   }
632   inline void pop(Register dst) {
633     Pop(dst);
634   }
635
636   // Sometimes callers need to push or pop multiple registers in a way that is
637   // difficult to structure efficiently for fixed Push or Pop calls. This scope
638   // allows push requests to be queued up, then flushed at once. The
639   // MacroAssembler will try to generate the most efficient sequence required.
640   //
641   // Unlike the other Push and Pop macros, PushPopQueue can handle mixed sets of
642   // register sizes and types.
643   class PushPopQueue {
644    public:
645     explicit PushPopQueue(MacroAssembler* masm) : masm_(masm), size_(0) { }
646
647     ~PushPopQueue() {
648       DCHECK(queued_.empty());
649     }
650
651     void Queue(const CPURegister& rt) {
652       size_ += rt.SizeInBytes();
653       queued_.push_back(rt);
654     }
655
656     enum PreambleDirective {
657       WITH_PREAMBLE,
658       SKIP_PREAMBLE
659     };
660     void PushQueued(PreambleDirective preamble_directive = WITH_PREAMBLE);
661     void PopQueued();
662
663    private:
664     MacroAssembler* masm_;
665     int size_;
666     std::vector<CPURegister> queued_;
667   };
668
669   // Poke 'src' onto the stack. The offset is in bytes.
670   //
671   // If the current stack pointer (according to StackPointer()) is csp, then
672   // csp must be aligned to 16 bytes.
673   void Poke(const CPURegister& src, const Operand& offset);
674
675   // Peek at a value on the stack, and put it in 'dst'. The offset is in bytes.
676   //
677   // If the current stack pointer (according to StackPointer()) is csp, then
678   // csp must be aligned to 16 bytes.
679   void Peek(const CPURegister& dst, const Operand& offset);
680
681   // Poke 'src1' and 'src2' onto the stack. The values written will be adjacent
682   // with 'src2' at a higher address than 'src1'. The offset is in bytes.
683   //
684   // If the current stack pointer (according to StackPointer()) is csp, then
685   // csp must be aligned to 16 bytes.
686   void PokePair(const CPURegister& src1, const CPURegister& src2, int offset);
687
688   // Peek at two values on the stack, and put them in 'dst1' and 'dst2'. The
689   // values peeked will be adjacent, with the value in 'dst2' being from a
690   // higher address than 'dst1'. The offset is in bytes.
691   //
692   // If the current stack pointer (according to StackPointer()) is csp, then
693   // csp must be aligned to 16 bytes.
694   void PeekPair(const CPURegister& dst1, const CPURegister& dst2, int offset);
695
696   // Claim or drop stack space without actually accessing memory.
697   //
698   // In debug mode, both of these will write invalid data into the claimed or
699   // dropped space.
700   //
701   // If the current stack pointer (according to StackPointer()) is csp, then it
702   // must be aligned to 16 bytes and the size claimed or dropped must be a
703   // multiple of 16 bytes.
704   //
705   // Note that unit_size must be specified in bytes. For variants which take a
706   // Register count, the unit size must be a power of two.
707   inline void Claim(uint64_t count, uint64_t unit_size = kXRegSize);
708   inline void Claim(const Register& count,
709                     uint64_t unit_size = kXRegSize);
710   inline void Drop(uint64_t count, uint64_t unit_size = kXRegSize);
711   inline void Drop(const Register& count,
712                    uint64_t unit_size = kXRegSize);
713
714   // Variants of Claim and Drop, where the 'count' parameter is a SMI held in a
715   // register.
716   inline void ClaimBySMI(const Register& count_smi,
717                          uint64_t unit_size = kXRegSize);
718   inline void DropBySMI(const Register& count_smi,
719                         uint64_t unit_size = kXRegSize);
720
721   // Compare a register with an operand, and branch to label depending on the
722   // condition. May corrupt the status flags.
723   inline void CompareAndBranch(const Register& lhs,
724                                const Operand& rhs,
725                                Condition cond,
726                                Label* label);
727
728   // Test the bits of register defined by bit_pattern, and branch if ANY of
729   // those bits are set. May corrupt the status flags.
730   inline void TestAndBranchIfAnySet(const Register& reg,
731                                     const uint64_t bit_pattern,
732                                     Label* label);
733
734   // Test the bits of register defined by bit_pattern, and branch if ALL of
735   // those bits are clear (ie. not set.) May corrupt the status flags.
736   inline void TestAndBranchIfAllClear(const Register& reg,
737                                       const uint64_t bit_pattern,
738                                       Label* label);
739
740   // Insert one or more instructions into the instruction stream that encode
741   // some caller-defined data. The instructions used will be executable with no
742   // side effects.
743   inline void InlineData(uint64_t data);
744
745   // Insert an instrumentation enable marker into the instruction stream.
746   inline void EnableInstrumentation();
747
748   // Insert an instrumentation disable marker into the instruction stream.
749   inline void DisableInstrumentation();
750
751   // Insert an instrumentation event marker into the instruction stream. These
752   // will be picked up by the instrumentation system to annotate an instruction
753   // profile. The argument marker_name must be a printable two character string;
754   // it will be encoded in the event marker.
755   inline void AnnotateInstrumentation(const char* marker_name);
756
757   // If emit_debug_code() is true, emit a run-time check to ensure that
758   // StackPointer() does not point below the system stack pointer.
759   //
760   // Whilst it is architecturally legal for StackPointer() to point below csp,
761   // it can be evidence of a potential bug because the ABI forbids accesses
762   // below csp.
763   //
764   // If StackPointer() is the system stack pointer (csp), then csp will be
765   // dereferenced to cause the processor (or simulator) to abort if it is not
766   // properly aligned.
767   //
768   // If emit_debug_code() is false, this emits no code.
769   void AssertStackConsistency();
770
771   // Preserve the callee-saved registers (as defined by AAPCS64).
772   //
773   // Higher-numbered registers are pushed before lower-numbered registers, and
774   // thus get higher addresses.
775   // Floating-point registers are pushed before general-purpose registers, and
776   // thus get higher addresses.
777   //
778   // Note that registers are not checked for invalid values. Use this method
779   // only if you know that the GC won't try to examine the values on the stack.
780   //
781   // This method must not be called unless the current stack pointer (as set by
782   // SetStackPointer) is the system stack pointer (csp), and is aligned to
783   // ActivationFrameAlignment().
784   void PushCalleeSavedRegisters();
785
786   // Restore the callee-saved registers (as defined by AAPCS64).
787   //
788   // Higher-numbered registers are popped after lower-numbered registers, and
789   // thus come from higher addresses.
790   // Floating-point registers are popped after general-purpose registers, and
791   // thus come from higher addresses.
792   //
793   // This method must not be called unless the current stack pointer (as set by
794   // SetStackPointer) is the system stack pointer (csp), and is aligned to
795   // ActivationFrameAlignment().
796   void PopCalleeSavedRegisters();
797
798   // Set the current stack pointer, but don't generate any code.
799   inline void SetStackPointer(const Register& stack_pointer) {
800     DCHECK(!TmpList()->IncludesAliasOf(stack_pointer));
801     sp_ = stack_pointer;
802   }
803
804   // Return the current stack pointer, as set by SetStackPointer.
805   inline const Register& StackPointer() const {
806     return sp_;
807   }
808
809   // Align csp for a frame, as per ActivationFrameAlignment, and make it the
810   // current stack pointer.
811   inline void AlignAndSetCSPForFrame() {
812     int sp_alignment = ActivationFrameAlignment();
813     // AAPCS64 mandates at least 16-byte alignment.
814     DCHECK(sp_alignment >= 16);
815     DCHECK(base::bits::IsPowerOfTwo32(sp_alignment));
816     Bic(csp, StackPointer(), sp_alignment - 1);
817     SetStackPointer(csp);
818   }
819
820   // Push the system stack pointer (csp) down to allow the same to be done to
821   // the current stack pointer (according to StackPointer()). This must be
822   // called _before_ accessing the memory.
823   //
824   // This is necessary when pushing or otherwise adding things to the stack, to
825   // satisfy the AAPCS64 constraint that the memory below the system stack
826   // pointer is not accessed.  The amount pushed will be increased as necessary
827   // to ensure csp remains aligned to 16 bytes.
828   //
829   // This method asserts that StackPointer() is not csp, since the call does
830   // not make sense in that context.
831   inline void BumpSystemStackPointer(const Operand& space);
832
833   // Re-synchronizes the system stack pointer (csp) with the current stack
834   // pointer (according to StackPointer()).
835   //
836   // This method asserts that StackPointer() is not csp, since the call does
837   // not make sense in that context.
838   inline void SyncSystemStackPointer();
839
840   // Helpers ------------------------------------------------------------------
841   // Root register.
842   inline void InitializeRootRegister();
843
844   void AssertFPCRState(Register fpcr = NoReg);
845   void ConfigureFPCR();
846   void CanonicalizeNaN(const FPRegister& dst, const FPRegister& src);
847   void CanonicalizeNaN(const FPRegister& reg) {
848     CanonicalizeNaN(reg, reg);
849   }
850
851   // Load an object from the root table.
852   void LoadRoot(CPURegister destination,
853                 Heap::RootListIndex index);
854   // Store an object to the root table.
855   void StoreRoot(Register source,
856                  Heap::RootListIndex index);
857
858   // Load both TrueValue and FalseValue roots.
859   void LoadTrueFalseRoots(Register true_root, Register false_root);
860
861   void LoadHeapObject(Register dst, Handle<HeapObject> object);
862
863   void LoadObject(Register result, Handle<Object> object) {
864     AllowDeferredHandleDereference heap_object_check;
865     if (object->IsHeapObject()) {
866       LoadHeapObject(result, Handle<HeapObject>::cast(object));
867     } else {
868       DCHECK(object->IsSmi());
869       Mov(result, Operand(object));
870     }
871   }
872
873   static int SafepointRegisterStackIndex(int reg_code);
874
875   // This is required for compatibility with architecture independant code.
876   // Remove if not needed.
877   inline void Move(Register dst, Register src) { Mov(dst, src); }
878
879   void LoadInstanceDescriptors(Register map,
880                                Register descriptors);
881   void EnumLengthUntagged(Register dst, Register map);
882   void EnumLengthSmi(Register dst, Register map);
883   void NumberOfOwnDescriptors(Register dst, Register map);
884   void LoadAccessor(Register dst, Register holder, int accessor_index,
885                     AccessorComponent accessor);
886
887   template<typename Field>
888   void DecodeField(Register dst, Register src) {
889     static const uint64_t shift = Field::kShift;
890     static const uint64_t setbits = CountSetBits(Field::kMask, 32);
891     Ubfx(dst, src, shift, setbits);
892   }
893
894   template<typename Field>
895   void DecodeField(Register reg) {
896     DecodeField<Field>(reg, reg);
897   }
898
899   // ---- SMI and Number Utilities ----
900
901   inline void SmiTag(Register dst, Register src);
902   inline void SmiTag(Register smi);
903   inline void SmiUntag(Register dst, Register src);
904   inline void SmiUntag(Register smi);
905   inline void SmiUntagToDouble(FPRegister dst,
906                                Register src,
907                                UntagMode mode = kNotSpeculativeUntag);
908   inline void SmiUntagToFloat(FPRegister dst,
909                               Register src,
910                               UntagMode mode = kNotSpeculativeUntag);
911
912   // Tag and push in one step.
913   inline void SmiTagAndPush(Register src);
914   inline void SmiTagAndPush(Register src1, Register src2);
915
916   inline void JumpIfSmi(Register value,
917                         Label* smi_label,
918                         Label* not_smi_label = NULL);
919   inline void JumpIfNotSmi(Register value, Label* not_smi_label);
920   inline void JumpIfBothSmi(Register value1,
921                             Register value2,
922                             Label* both_smi_label,
923                             Label* not_smi_label = NULL);
924   inline void JumpIfEitherSmi(Register value1,
925                               Register value2,
926                               Label* either_smi_label,
927                               Label* not_smi_label = NULL);
928   inline void JumpIfEitherNotSmi(Register value1,
929                                  Register value2,
930                                  Label* not_smi_label);
931   inline void JumpIfBothNotSmi(Register value1,
932                                Register value2,
933                                Label* not_smi_label);
934
935   // Abort execution if argument is a smi, enabled via --debug-code.
936   void AssertNotSmi(Register object, BailoutReason reason = kOperandIsASmi);
937   void AssertSmi(Register object, BailoutReason reason = kOperandIsNotASmi);
938
939   inline void ObjectTag(Register tagged_obj, Register obj);
940   inline void ObjectUntag(Register untagged_obj, Register obj);
941
942   // Abort execution if argument is not a name, enabled via --debug-code.
943   void AssertName(Register object);
944
945   // Abort execution if argument is not undefined or an AllocationSite, enabled
946   // via --debug-code.
947   void AssertUndefinedOrAllocationSite(Register object, Register scratch);
948
949   // Abort execution if argument is not a string, enabled via --debug-code.
950   void AssertString(Register object);
951
952   void JumpIfHeapNumber(Register object, Label* on_heap_number,
953                         SmiCheckType smi_check_type = DONT_DO_SMI_CHECK);
954   void JumpIfNotHeapNumber(Register object, Label* on_not_heap_number,
955                            SmiCheckType smi_check_type = DONT_DO_SMI_CHECK);
956
957   // Sets the vs flag if the input is -0.0.
958   void TestForMinusZero(DoubleRegister input);
959
960   // Jump to label if the input double register contains -0.0.
961   void JumpIfMinusZero(DoubleRegister input, Label* on_negative_zero);
962
963   // Jump to label if the input integer register contains the double precision
964   // floating point representation of -0.0.
965   void JumpIfMinusZero(Register input, Label* on_negative_zero);
966
967   // Generate code to do a lookup in the number string cache. If the number in
968   // the register object is found in the cache the generated code falls through
969   // with the result in the result register. The object and the result register
970   // can be the same. If the number is not found in the cache the code jumps to
971   // the label not_found with only the content of register object unchanged.
972   void LookupNumberStringCache(Register object,
973                                Register result,
974                                Register scratch1,
975                                Register scratch2,
976                                Register scratch3,
977                                Label* not_found);
978
979   // Saturate a signed 32-bit integer in input to an unsigned 8-bit integer in
980   // output.
981   void ClampInt32ToUint8(Register in_out);
982   void ClampInt32ToUint8(Register output, Register input);
983
984   // Saturate a double in input to an unsigned 8-bit integer in output.
985   void ClampDoubleToUint8(Register output,
986                           DoubleRegister input,
987                           DoubleRegister dbl_scratch);
988
989   // Try to represent a double as a signed 32-bit int.
990   // This succeeds if the result compares equal to the input, so inputs of -0.0
991   // are represented as 0 and handled as a success.
992   //
993   // On output the Z flag is set if the operation was successful.
994   void TryRepresentDoubleAsInt32(Register as_int,
995                                  FPRegister value,
996                                  FPRegister scratch_d,
997                                  Label* on_successful_conversion = NULL,
998                                  Label* on_failed_conversion = NULL) {
999     DCHECK(as_int.Is32Bits());
1000     TryRepresentDoubleAsInt(as_int, value, scratch_d, on_successful_conversion,
1001                             on_failed_conversion);
1002   }
1003
1004   // Try to represent a double as a signed 64-bit int.
1005   // This succeeds if the result compares equal to the input, so inputs of -0.0
1006   // are represented as 0 and handled as a success.
1007   //
1008   // On output the Z flag is set if the operation was successful.
1009   void TryRepresentDoubleAsInt64(Register as_int,
1010                                  FPRegister value,
1011                                  FPRegister scratch_d,
1012                                  Label* on_successful_conversion = NULL,
1013                                  Label* on_failed_conversion = NULL) {
1014     DCHECK(as_int.Is64Bits());
1015     TryRepresentDoubleAsInt(as_int, value, scratch_d, on_successful_conversion,
1016                             on_failed_conversion);
1017   }
1018
1019   // ---- Object Utilities ----
1020
1021   // Copy fields from 'src' to 'dst', where both are tagged objects.
1022   // The 'temps' list is a list of X registers which can be used for scratch
1023   // values. The temps list must include at least one register.
1024   //
1025   // Currently, CopyFields cannot make use of more than three registers from
1026   // the 'temps' list.
1027   //
1028   // CopyFields expects to be able to take at least two registers from
1029   // MacroAssembler::TmpList().
1030   void CopyFields(Register dst, Register src, CPURegList temps, unsigned count);
1031
1032   // Starting at address in dst, initialize field_count 64-bit fields with
1033   // 64-bit value in register filler. Register dst is corrupted.
1034   void FillFields(Register dst,
1035                   Register field_count,
1036                   Register filler);
1037
1038   // Copies a number of bytes from src to dst. All passed registers are
1039   // clobbered. On exit src and dst will point to the place just after where the
1040   // last byte was read or written and length will be zero. Hint may be used to
1041   // determine which is the most efficient algorithm to use for copying.
1042   void CopyBytes(Register dst,
1043                  Register src,
1044                  Register length,
1045                  Register scratch,
1046                  CopyHint hint = kCopyUnknown);
1047
1048   // ---- String Utilities ----
1049
1050
1051   // Jump to label if either object is not a sequential one-byte string.
1052   // Optionally perform a smi check on the objects first.
1053   void JumpIfEitherIsNotSequentialOneByteStrings(
1054       Register first, Register second, Register scratch1, Register scratch2,
1055       Label* failure, SmiCheckType smi_check = DO_SMI_CHECK);
1056
1057   // Check if instance type is sequential one-byte string and jump to label if
1058   // it is not.
1059   void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1060                                                 Label* failure);
1061
1062   // Checks if both instance types are sequential one-byte strings and jumps to
1063   // label if either is not.
1064   void JumpIfEitherInstanceTypeIsNotSequentialOneByte(
1065       Register first_object_instance_type, Register second_object_instance_type,
1066       Register scratch1, Register scratch2, Label* failure);
1067
1068   // Checks if both instance types are sequential one-byte strings and jumps to
1069   // label if either is not.
1070   void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1071       Register first_object_instance_type, Register second_object_instance_type,
1072       Register scratch1, Register scratch2, Label* failure);
1073
1074   void JumpIfNotUniqueNameInstanceType(Register type, Label* not_unique_name);
1075
1076   // ---- Calling / Jumping helpers ----
1077
1078   // This is required for compatibility in architecture indepenedant code.
1079   inline void jmp(Label* L) { B(L); }
1080
1081   void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
1082   void TailCallStub(CodeStub* stub);
1083
1084   void CallRuntime(const Runtime::Function* f,
1085                    int num_arguments,
1086                    SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1087
1088   void CallRuntime(Runtime::FunctionId id,
1089                    int num_arguments,
1090                    SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1091     CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1092   }
1093
1094   void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1095     const Runtime::Function* function = Runtime::FunctionForId(id);
1096     CallRuntime(function, function->nargs, kSaveFPRegs);
1097   }
1098
1099   void TailCallRuntime(Runtime::FunctionId fid,
1100                        int num_arguments,
1101                        int result_size);
1102
1103   int ActivationFrameAlignment();
1104
1105   // Calls a C function.
1106   // The called function is not allowed to trigger a
1107   // garbage collection, since that might move the code and invalidate the
1108   // return address (unless this is somehow accounted for by the called
1109   // function).
1110   void CallCFunction(ExternalReference function,
1111                      int num_reg_arguments);
1112   void CallCFunction(ExternalReference function,
1113                      int num_reg_arguments,
1114                      int num_double_arguments);
1115   void CallCFunction(Register function,
1116                      int num_reg_arguments,
1117                      int num_double_arguments);
1118
1119   // Jump to a runtime routine.
1120   void JumpToExternalReference(const ExternalReference& builtin);
1121   // Tail call of a runtime routine (jump).
1122   // Like JumpToExternalReference, but also takes care of passing the number
1123   // of parameters.
1124   void TailCallExternalReference(const ExternalReference& ext,
1125                                  int num_arguments,
1126                                  int result_size);
1127   void CallExternalReference(const ExternalReference& ext,
1128                              int num_arguments);
1129
1130
1131   // Invoke specified builtin JavaScript function. Adds an entry to
1132   // the unresolved list if the name does not resolve.
1133   void InvokeBuiltin(Builtins::JavaScript id,
1134                      InvokeFlag flag,
1135                      const CallWrapper& call_wrapper = NullCallWrapper());
1136
1137   // Store the code object for the given builtin in the target register and
1138   // setup the function in the function register.
1139   void GetBuiltinEntry(Register target,
1140                        Register function,
1141                        Builtins::JavaScript id);
1142
1143   // Store the function for the given builtin in the target register.
1144   void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1145
1146   void Jump(Register target);
1147   void Jump(Address target, RelocInfo::Mode rmode);
1148   void Jump(Handle<Code> code, RelocInfo::Mode rmode);
1149   void Jump(intptr_t target, RelocInfo::Mode rmode);
1150
1151   void Call(Register target);
1152   void Call(Label* target);
1153   void Call(Address target, RelocInfo::Mode rmode);
1154   void Call(Handle<Code> code,
1155             RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
1156             TypeFeedbackId ast_id = TypeFeedbackId::None());
1157
1158   // For every Call variant, there is a matching CallSize function that returns
1159   // the size (in bytes) of the call sequence.
1160   static int CallSize(Register target);
1161   static int CallSize(Label* target);
1162   static int CallSize(Address target, RelocInfo::Mode rmode);
1163   static int CallSize(Handle<Code> code,
1164                       RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
1165                       TypeFeedbackId ast_id = TypeFeedbackId::None());
1166
1167   // Registers used through the invocation chain are hard-coded.
1168   // We force passing the parameters to ensure the contracts are correctly
1169   // honoured by the caller.
1170   // 'function' must be x1.
1171   // 'actual' must use an immediate or x0.
1172   // 'expected' must use an immediate or x2.
1173   // 'call_kind' must be x5.
1174   void InvokePrologue(const ParameterCount& expected,
1175                       const ParameterCount& actual,
1176                       Handle<Code> code_constant,
1177                       Register code_reg,
1178                       Label* done,
1179                       InvokeFlag flag,
1180                       bool* definitely_mismatches,
1181                       const CallWrapper& call_wrapper);
1182   void InvokeCode(Register code,
1183                   const ParameterCount& expected,
1184                   const ParameterCount& actual,
1185                   InvokeFlag flag,
1186                   const CallWrapper& call_wrapper);
1187   // Invoke the JavaScript function in the given register.
1188   // Changes the current context to the context in the function before invoking.
1189   void InvokeFunction(Register function,
1190                       const ParameterCount& actual,
1191                       InvokeFlag flag,
1192                       const CallWrapper& call_wrapper);
1193   void InvokeFunction(Register function,
1194                       const ParameterCount& expected,
1195                       const ParameterCount& actual,
1196                       InvokeFlag flag,
1197                       const CallWrapper& call_wrapper);
1198   void InvokeFunction(Handle<JSFunction> function,
1199                       const ParameterCount& expected,
1200                       const ParameterCount& actual,
1201                       InvokeFlag flag,
1202                       const CallWrapper& call_wrapper);
1203
1204
1205   // ---- Floating point helpers ----
1206
1207   // Perform a conversion from a double to a signed int64. If the input fits in
1208   // range of the 64-bit result, execution branches to done. Otherwise,
1209   // execution falls through, and the sign of the result can be used to
1210   // determine if overflow was towards positive or negative infinity.
1211   //
1212   // On successful conversion, the least significant 32 bits of the result are
1213   // equivalent to the ECMA-262 operation "ToInt32".
1214   //
1215   // Only public for the test code in test-code-stubs-arm64.cc.
1216   void TryConvertDoubleToInt64(Register result,
1217                                DoubleRegister input,
1218                                Label* done);
1219
1220   // Performs a truncating conversion of a floating point number as used by
1221   // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
1222   // Exits with 'result' holding the answer.
1223   void TruncateDoubleToI(Register result, DoubleRegister double_input);
1224
1225   // Performs a truncating conversion of a heap number as used by
1226   // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
1227   // must be different registers.  Exits with 'result' holding the answer.
1228   void TruncateHeapNumberToI(Register result, Register object);
1229
1230   // Converts the smi or heap number in object to an int32 using the rules
1231   // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
1232   // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
1233   // different registers.
1234   void TruncateNumberToI(Register object,
1235                          Register result,
1236                          Register heap_number_map,
1237                          Label* not_int32);
1238
1239   // ---- Code generation helpers ----
1240
1241   void set_generating_stub(bool value) { generating_stub_ = value; }
1242   bool generating_stub() const { return generating_stub_; }
1243 #if DEBUG
1244   void set_allow_macro_instructions(bool value) {
1245     allow_macro_instructions_ = value;
1246   }
1247   bool allow_macro_instructions() const { return allow_macro_instructions_; }
1248 #endif
1249   bool use_real_aborts() const { return use_real_aborts_; }
1250   void set_has_frame(bool value) { has_frame_ = value; }
1251   bool has_frame() const { return has_frame_; }
1252   bool AllowThisStubCall(CodeStub* stub);
1253
1254   class NoUseRealAbortsScope {
1255    public:
1256     explicit NoUseRealAbortsScope(MacroAssembler* masm) :
1257         saved_(masm->use_real_aborts_), masm_(masm) {
1258       masm_->use_real_aborts_ = false;
1259     }
1260     ~NoUseRealAbortsScope() {
1261       masm_->use_real_aborts_ = saved_;
1262     }
1263    private:
1264     bool saved_;
1265     MacroAssembler* masm_;
1266   };
1267
1268   // ---------------------------------------------------------------------------
1269   // Debugger Support
1270
1271   void DebugBreak();
1272
1273   // ---------------------------------------------------------------------------
1274   // Exception handling
1275
1276   // Push a new stack handler and link into stack handler chain.
1277   void PushStackHandler();
1278
1279   // Unlink the stack handler on top of the stack from the stack handler chain.
1280   // Must preserve the result register.
1281   void PopStackHandler();
1282
1283
1284   // ---------------------------------------------------------------------------
1285   // Allocation support
1286
1287   // Allocate an object in new space or old pointer space. The object_size is
1288   // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
1289   // is passed. The allocated object is returned in result.
1290   //
1291   // If the new space is exhausted control continues at the gc_required label.
1292   // In this case, the result and scratch registers may still be clobbered.
1293   // If flags includes TAG_OBJECT, the result is tagged as as a heap object.
1294   void Allocate(Register object_size,
1295                 Register result,
1296                 Register scratch1,
1297                 Register scratch2,
1298                 Label* gc_required,
1299                 AllocationFlags flags);
1300
1301   void Allocate(int object_size,
1302                 Register result,
1303                 Register scratch1,
1304                 Register scratch2,
1305                 Label* gc_required,
1306                 AllocationFlags flags);
1307
1308   // Undo allocation in new space. The object passed and objects allocated after
1309   // it will no longer be allocated. The caller must make sure that no pointers
1310   // are left to the object(s) no longer allocated as they would be invalid when
1311   // allocation is undone.
1312   void UndoAllocationInNewSpace(Register object, Register scratch);
1313
1314   void AllocateTwoByteString(Register result,
1315                              Register length,
1316                              Register scratch1,
1317                              Register scratch2,
1318                              Register scratch3,
1319                              Label* gc_required);
1320   void AllocateOneByteString(Register result, Register length,
1321                              Register scratch1, Register scratch2,
1322                              Register scratch3, Label* gc_required);
1323   void AllocateTwoByteConsString(Register result,
1324                                  Register length,
1325                                  Register scratch1,
1326                                  Register scratch2,
1327                                  Label* gc_required);
1328   void AllocateOneByteConsString(Register result, Register length,
1329                                  Register scratch1, Register scratch2,
1330                                  Label* gc_required);
1331   void AllocateTwoByteSlicedString(Register result,
1332                                    Register length,
1333                                    Register scratch1,
1334                                    Register scratch2,
1335                                    Label* gc_required);
1336   void AllocateOneByteSlicedString(Register result, Register length,
1337                                    Register scratch1, Register scratch2,
1338                                    Label* gc_required);
1339
1340   // Allocates a heap number or jumps to the gc_required label if the young
1341   // space is full and a scavenge is needed.
1342   // All registers are clobbered.
1343   // If no heap_number_map register is provided, the function will take care of
1344   // loading it.
1345   void AllocateHeapNumber(Register result,
1346                           Label* gc_required,
1347                           Register scratch1,
1348                           Register scratch2,
1349                           CPURegister value = NoFPReg,
1350                           CPURegister heap_number_map = NoReg,
1351                           MutableMode mode = IMMUTABLE);
1352
1353   // ---------------------------------------------------------------------------
1354   // Support functions.
1355
1356   // Try to get function prototype of a function and puts the value in the
1357   // result register. Checks that the function really is a function and jumps
1358   // to the miss label if the fast checks fail. The function register will be
1359   // untouched; the other registers may be clobbered.
1360   enum BoundFunctionAction {
1361     kMissOnBoundFunction,
1362     kDontMissOnBoundFunction
1363   };
1364
1365   // Machine code version of Map::GetConstructor().
1366   // |temp| holds |result|'s map when done, and |temp2| its instance type.
1367   void GetMapConstructor(Register result, Register map, Register temp,
1368                          Register temp2);
1369
1370   void TryGetFunctionPrototype(Register function,
1371                                Register result,
1372                                Register scratch,
1373                                Label* miss,
1374                                BoundFunctionAction action =
1375                                  kDontMissOnBoundFunction);
1376
1377   // Compare object type for heap object.  heap_object contains a non-Smi
1378   // whose object type should be compared with the given type.  This both
1379   // sets the flags and leaves the object type in the type_reg register.
1380   // It leaves the map in the map register (unless the type_reg and map register
1381   // are the same register).  It leaves the heap object in the heap_object
1382   // register unless the heap_object register is the same register as one of the
1383   // other registers.
1384   void CompareObjectType(Register heap_object,
1385                          Register map,
1386                          Register type_reg,
1387                          InstanceType type);
1388
1389
1390   // Compare object type for heap object, and branch if equal (or not.)
1391   // heap_object contains a non-Smi whose object type should be compared with
1392   // the given type.  This both sets the flags and leaves the object type in
1393   // the type_reg register. It leaves the map in the map register (unless the
1394   // type_reg and map register are the same register).  It leaves the heap
1395   // object in the heap_object register unless the heap_object register is the
1396   // same register as one of the other registers.
1397   void JumpIfObjectType(Register object,
1398                         Register map,
1399                         Register type_reg,
1400                         InstanceType type,
1401                         Label* if_cond_pass,
1402                         Condition cond = eq);
1403
1404   void JumpIfNotObjectType(Register object,
1405                            Register map,
1406                            Register type_reg,
1407                            InstanceType type,
1408                            Label* if_not_object);
1409
1410   // Compare instance type in a map.  map contains a valid map object whose
1411   // object type should be compared with the given type.  This both
1412   // sets the flags and leaves the object type in the type_reg register.
1413   void CompareInstanceType(Register map,
1414                            Register type_reg,
1415                            InstanceType type);
1416
1417   // Compare an object's map with the specified map. Condition flags are set
1418   // with result of map compare.
1419   void CompareObjectMap(Register obj, Heap::RootListIndex index);
1420
1421   // Compare an object's map with the specified map. Condition flags are set
1422   // with result of map compare.
1423   void CompareObjectMap(Register obj, Register scratch, Handle<Map> map);
1424
1425   // As above, but the map of the object is already loaded into the register
1426   // which is preserved by the code generated.
1427   void CompareMap(Register obj_map,
1428                   Handle<Map> map);
1429
1430   // Check if the map of an object is equal to a specified map and branch to
1431   // label if not. Skip the smi check if not required (object is known to be a
1432   // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1433   // against maps that are ElementsKind transition maps of the specified map.
1434   void CheckMap(Register obj,
1435                 Register scratch,
1436                 Handle<Map> map,
1437                 Label* fail,
1438                 SmiCheckType smi_check_type);
1439
1440
1441   void CheckMap(Register obj,
1442                 Register scratch,
1443                 Heap::RootListIndex index,
1444                 Label* fail,
1445                 SmiCheckType smi_check_type);
1446
1447   // As above, but the map of the object is already loaded into obj_map, and is
1448   // preserved.
1449   void CheckMap(Register obj_map,
1450                 Handle<Map> map,
1451                 Label* fail,
1452                 SmiCheckType smi_check_type);
1453
1454   // Check if the map of an object is equal to a specified weak map and branch
1455   // to a specified target if equal. Skip the smi check if not required
1456   // (object is known to be a heap object)
1457   void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1458                        Handle<WeakCell> cell, Handle<Code> success,
1459                        SmiCheckType smi_check_type);
1460
1461   // Compare the given value and the value of weak cell.
1462   void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
1463
1464   void GetWeakValue(Register value, Handle<WeakCell> cell);
1465
1466   // Load the value of the weak cell in the value register. Branch to the given
1467   // miss label if the weak cell was cleared.
1468   void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
1469
1470   // Test the bitfield of the heap object map with mask and set the condition
1471   // flags. The object register is preserved.
1472   void TestMapBitfield(Register object, uint64_t mask);
1473
1474   // Load the elements kind field from a map, and return it in the result
1475   // register.
1476   void LoadElementsKindFromMap(Register result, Register map);
1477
1478   // Compare the object in a register to a value from the root list.
1479   void CompareRoot(const Register& obj, Heap::RootListIndex index);
1480
1481   // Compare the object in a register to a value and jump if they are equal.
1482   void JumpIfRoot(const Register& obj,
1483                   Heap::RootListIndex index,
1484                   Label* if_equal);
1485
1486   // Compare the object in a register to a value and jump if they are not equal.
1487   void JumpIfNotRoot(const Register& obj,
1488                      Heap::RootListIndex index,
1489                      Label* if_not_equal);
1490
1491   // Load and check the instance type of an object for being a unique name.
1492   // Loads the type into the second argument register.
1493   // The object and type arguments can be the same register; in that case it
1494   // will be overwritten with the type.
1495   // Fall-through if the object was a string and jump on fail otherwise.
1496   inline void IsObjectNameType(Register object, Register type, Label* fail);
1497
1498   inline void IsObjectJSObjectType(Register heap_object,
1499                                    Register map,
1500                                    Register scratch,
1501                                    Label* fail);
1502
1503   // Check the instance type in the given map to see if it corresponds to a
1504   // JS object type. Jump to the fail label if this is not the case and fall
1505   // through otherwise. However if fail label is NULL, no branch will be
1506   // performed and the flag will be updated. You can test the flag for "le"
1507   // condition to test if it is a valid JS object type.
1508   inline void IsInstanceJSObjectType(Register map,
1509                                      Register scratch,
1510                                      Label* fail);
1511
1512   // Load and check the instance type of an object for being a string.
1513   // Loads the type into the second argument register.
1514   // The object and type arguments can be the same register; in that case it
1515   // will be overwritten with the type.
1516   // Jumps to not_string or string appropriate. If the appropriate label is
1517   // NULL, fall through.
1518   inline void IsObjectJSStringType(Register object, Register type,
1519                                    Label* not_string, Label* string = NULL);
1520
1521   // Compare the contents of a register with an operand, and branch to true,
1522   // false or fall through, depending on condition.
1523   void CompareAndSplit(const Register& lhs,
1524                        const Operand& rhs,
1525                        Condition cond,
1526                        Label* if_true,
1527                        Label* if_false,
1528                        Label* fall_through);
1529
1530   // Test the bits of register defined by bit_pattern, and branch to
1531   // if_any_set, if_all_clear or fall_through accordingly.
1532   void TestAndSplit(const Register& reg,
1533                     uint64_t bit_pattern,
1534                     Label* if_all_clear,
1535                     Label* if_any_set,
1536                     Label* fall_through);
1537
1538   // Check if a map for a JSObject indicates that the object has fast elements.
1539   // Jump to the specified label if it does not.
1540   void CheckFastElements(Register map, Register scratch, Label* fail);
1541
1542   // Check if a map for a JSObject indicates that the object can have both smi
1543   // and HeapObject elements.  Jump to the specified label if it does not.
1544   void CheckFastObjectElements(Register map, Register scratch, Label* fail);
1545
1546   // Check to see if number can be stored as a double in FastDoubleElements.
1547   // If it can, store it at the index specified by key_reg in the array,
1548   // otherwise jump to fail.
1549   void StoreNumberToDoubleElements(Register value_reg,
1550                                    Register key_reg,
1551                                    Register elements_reg,
1552                                    Register scratch1,
1553                                    FPRegister fpscratch1,
1554                                    Label* fail,
1555                                    int elements_offset = 0);
1556
1557   // Picks out an array index from the hash field.
1558   // Register use:
1559   //   hash - holds the index's hash. Clobbered.
1560   //   index - holds the overwritten index on exit.
1561   void IndexFromHash(Register hash, Register index);
1562
1563   // ---------------------------------------------------------------------------
1564   // Inline caching support.
1565
1566   void EmitSeqStringSetCharCheck(Register string,
1567                                  Register index,
1568                                  SeqStringSetCharCheckIndexType index_type,
1569                                  Register scratch,
1570                                  uint32_t encoding_mask);
1571
1572   // Generate code for checking access rights - used for security checks
1573   // on access to global objects across environments. The holder register
1574   // is left untouched, whereas both scratch registers are clobbered.
1575   void CheckAccessGlobalProxy(Register holder_reg,
1576                               Register scratch1,
1577                               Register scratch2,
1578                               Label* miss);
1579
1580   // Hash the interger value in 'key' register.
1581   // It uses the same algorithm as ComputeIntegerHash in utils.h.
1582   void GetNumberHash(Register key, Register scratch);
1583
1584   // Load value from the dictionary.
1585   //
1586   // elements - holds the slow-case elements of the receiver on entry.
1587   //            Unchanged unless 'result' is the same register.
1588   //
1589   // key      - holds the smi key on entry.
1590   //            Unchanged unless 'result' is the same register.
1591   //
1592   // result   - holds the result on exit if the load succeeded.
1593   //            Allowed to be the same as 'key' or 'result'.
1594   //            Unchanged on bailout so 'key' or 'result' can be used
1595   //            in further computation.
1596   void LoadFromNumberDictionary(Label* miss,
1597                                 Register elements,
1598                                 Register key,
1599                                 Register result,
1600                                 Register scratch0,
1601                                 Register scratch1,
1602                                 Register scratch2,
1603                                 Register scratch3);
1604
1605   // ---------------------------------------------------------------------------
1606   // Frames.
1607
1608   // Activation support.
1609   void EnterFrame(StackFrame::Type type);
1610   void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1611   void LeaveFrame(StackFrame::Type type);
1612
1613   // Returns map with validated enum cache in object register.
1614   void CheckEnumCache(Register object,
1615                       Register null_value,
1616                       Register scratch0,
1617                       Register scratch1,
1618                       Register scratch2,
1619                       Register scratch3,
1620                       Label* call_runtime);
1621
1622   // AllocationMemento support. Arrays may have an associated
1623   // AllocationMemento object that can be checked for in order to pretransition
1624   // to another type.
1625   // On entry, receiver should point to the array object.
1626   // If allocation info is present, the Z flag is set (so that the eq
1627   // condition will pass).
1628   void TestJSArrayForAllocationMemento(Register receiver,
1629                                        Register scratch1,
1630                                        Register scratch2,
1631                                        Label* no_memento_found);
1632
1633   void JumpIfJSArrayHasAllocationMemento(Register receiver,
1634                                          Register scratch1,
1635                                          Register scratch2,
1636                                          Label* memento_found) {
1637     Label no_memento_found;
1638     TestJSArrayForAllocationMemento(receiver, scratch1, scratch2,
1639                                     &no_memento_found);
1640     B(eq, memento_found);
1641     Bind(&no_memento_found);
1642   }
1643
1644   // The stack pointer has to switch between csp and jssp when setting up and
1645   // destroying the exit frame. Hence preserving/restoring the registers is
1646   // slightly more complicated than simple push/pop operations.
1647   void ExitFramePreserveFPRegs();
1648   void ExitFrameRestoreFPRegs();
1649
1650   // Generates function and stub prologue code.
1651   void StubPrologue();
1652   void Prologue(bool code_pre_aging);
1653
1654   // Enter exit frame. Exit frames are used when calling C code from generated
1655   // (JavaScript) code.
1656   //
1657   // The stack pointer must be jssp on entry, and will be set to csp by this
1658   // function. The frame pointer is also configured, but the only other
1659   // registers modified by this function are the provided scratch register, and
1660   // jssp.
1661   //
1662   // The 'extra_space' argument can be used to allocate some space in the exit
1663   // frame that will be ignored by the GC. This space will be reserved in the
1664   // bottom of the frame immediately above the return address slot.
1665   //
1666   // Set up a stack frame and registers as follows:
1667   //         fp[8]: CallerPC (lr)
1668   //   fp -> fp[0]: CallerFP (old fp)
1669   //         fp[-8]: SPOffset (new csp)
1670   //         fp[-16]: CodeObject()
1671   //         fp[-16 - fp-size]: Saved doubles, if saved_doubles is true.
1672   //         csp[8]: Memory reserved for the caller if extra_space != 0.
1673   //                 Alignment padding, if necessary.
1674   //  csp -> csp[0]: Space reserved for the return address.
1675   //
1676   // This function also stores the new frame information in the top frame, so
1677   // that the new frame becomes the current frame.
1678   void EnterExitFrame(bool save_doubles,
1679                       const Register& scratch,
1680                       int extra_space = 0);
1681
1682   // Leave the current exit frame, after a C function has returned to generated
1683   // (JavaScript) code.
1684   //
1685   // This effectively unwinds the operation of EnterExitFrame:
1686   //  * Preserved doubles are restored (if restore_doubles is true).
1687   //  * The frame information is removed from the top frame.
1688   //  * The exit frame is dropped.
1689   //  * The stack pointer is reset to jssp.
1690   //
1691   // The stack pointer must be csp on entry.
1692   void LeaveExitFrame(bool save_doubles,
1693                       const Register& scratch,
1694                       bool restore_context);
1695
1696   void LoadContext(Register dst, int context_chain_length);
1697
1698   // Emit code for a truncating division by a constant. The dividend register is
1699   // unchanged. Dividend and result must be different.
1700   void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1701
1702   // ---------------------------------------------------------------------------
1703   // StatsCounter support
1704
1705   void SetCounter(StatsCounter* counter, int value, Register scratch1,
1706                   Register scratch2);
1707   void IncrementCounter(StatsCounter* counter, int value, Register scratch1,
1708                         Register scratch2);
1709   void DecrementCounter(StatsCounter* counter, int value, Register scratch1,
1710                         Register scratch2);
1711
1712   // ---------------------------------------------------------------------------
1713   // Garbage collector support (GC).
1714
1715   enum RememberedSetFinalAction {
1716     kReturnAtEnd,
1717     kFallThroughAtEnd
1718   };
1719
1720   // Record in the remembered set the fact that we have a pointer to new space
1721   // at the address pointed to by the addr register. Only works if addr is not
1722   // in new space.
1723   void RememberedSetHelper(Register object,  // Used for debug code.
1724                            Register addr,
1725                            Register scratch1,
1726                            SaveFPRegsMode save_fp,
1727                            RememberedSetFinalAction and_then);
1728
1729   // Push and pop the registers that can hold pointers, as defined by the
1730   // RegList constant kSafepointSavedRegisters.
1731   void PushSafepointRegisters();
1732   void PopSafepointRegisters();
1733
1734   void PushSafepointRegistersAndDoubles();
1735   void PopSafepointRegistersAndDoubles();
1736
1737   // Store value in register src in the safepoint stack slot for register dst.
1738   void StoreToSafepointRegisterSlot(Register src, Register dst) {
1739     Poke(src, SafepointRegisterStackIndex(dst.code()) * kPointerSize);
1740   }
1741
1742   // Load the value of the src register from its safepoint stack slot
1743   // into register dst.
1744   void LoadFromSafepointRegisterSlot(Register dst, Register src) {
1745     Peek(src, SafepointRegisterStackIndex(dst.code()) * kPointerSize);
1746   }
1747
1748   void CheckPageFlagSet(const Register& object,
1749                         const Register& scratch,
1750                         int mask,
1751                         Label* if_any_set);
1752
1753   void CheckPageFlagClear(const Register& object,
1754                           const Register& scratch,
1755                           int mask,
1756                           Label* if_all_clear);
1757
1758   // Check if object is in new space and jump accordingly.
1759   // Register 'object' is preserved.
1760   void JumpIfNotInNewSpace(Register object,
1761                            Label* branch) {
1762     InNewSpace(object, ne, branch);
1763   }
1764
1765   void JumpIfInNewSpace(Register object,
1766                         Label* branch) {
1767     InNewSpace(object, eq, branch);
1768   }
1769
1770   // Notify the garbage collector that we wrote a pointer into an object.
1771   // |object| is the object being stored into, |value| is the object being
1772   // stored.  value and scratch registers are clobbered by the operation.
1773   // The offset is the offset from the start of the object, not the offset from
1774   // the tagged HeapObject pointer.  For use with FieldOperand(reg, off).
1775   void RecordWriteField(
1776       Register object,
1777       int offset,
1778       Register value,
1779       Register scratch,
1780       LinkRegisterStatus lr_status,
1781       SaveFPRegsMode save_fp,
1782       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
1783       SmiCheck smi_check = INLINE_SMI_CHECK,
1784       PointersToHereCheck pointers_to_here_check_for_value =
1785           kPointersToHereMaybeInteresting);
1786
1787   // As above, but the offset has the tag presubtracted. For use with
1788   // MemOperand(reg, off).
1789   inline void RecordWriteContextSlot(
1790       Register context,
1791       int offset,
1792       Register value,
1793       Register scratch,
1794       LinkRegisterStatus lr_status,
1795       SaveFPRegsMode save_fp,
1796       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
1797       SmiCheck smi_check = INLINE_SMI_CHECK,
1798       PointersToHereCheck pointers_to_here_check_for_value =
1799           kPointersToHereMaybeInteresting) {
1800     RecordWriteField(context,
1801                      offset + kHeapObjectTag,
1802                      value,
1803                      scratch,
1804                      lr_status,
1805                      save_fp,
1806                      remembered_set_action,
1807                      smi_check,
1808                      pointers_to_here_check_for_value);
1809   }
1810
1811   void RecordWriteForMap(
1812       Register object,
1813       Register map,
1814       Register dst,
1815       LinkRegisterStatus lr_status,
1816       SaveFPRegsMode save_fp);
1817
1818   // For a given |object| notify the garbage collector that the slot |address|
1819   // has been written.  |value| is the object being stored. The value and
1820   // address registers are clobbered by the operation.
1821   void RecordWrite(
1822       Register object,
1823       Register address,
1824       Register value,
1825       LinkRegisterStatus lr_status,
1826       SaveFPRegsMode save_fp,
1827       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
1828       SmiCheck smi_check = INLINE_SMI_CHECK,
1829       PointersToHereCheck pointers_to_here_check_for_value =
1830           kPointersToHereMaybeInteresting);
1831
1832   // Checks the color of an object. If the object is already grey or black
1833   // then we just fall through, since it is already live. If it is white and
1834   // we can determine that it doesn't need to be scanned, then we just mark it
1835   // black and fall through. For the rest we jump to the label so the
1836   // incremental marker can fix its assumptions.
1837   void EnsureNotWhite(Register object,
1838                       Register scratch1,
1839                       Register scratch2,
1840                       Register scratch3,
1841                       Register scratch4,
1842                       Label* object_is_white_and_not_data);
1843
1844   // Detects conservatively whether an object is data-only, i.e. it does need to
1845   // be scanned by the garbage collector.
1846   void JumpIfDataObject(Register value,
1847                         Register scratch,
1848                         Label* not_data_object);
1849
1850   // Helper for finding the mark bits for an address.
1851   // Note that the behaviour slightly differs from other architectures.
1852   // On exit:
1853   //  - addr_reg is unchanged.
1854   //  - The bitmap register points at the word with the mark bits.
1855   //  - The shift register contains the index of the first color bit for this
1856   //    object in the bitmap.
1857   inline void GetMarkBits(Register addr_reg,
1858                           Register bitmap_reg,
1859                           Register shift_reg);
1860
1861   // Check if an object has a given incremental marking color.
1862   void HasColor(Register object,
1863                 Register scratch0,
1864                 Register scratch1,
1865                 Label* has_color,
1866                 int first_bit,
1867                 int second_bit);
1868
1869   void JumpIfBlack(Register object,
1870                    Register scratch0,
1871                    Register scratch1,
1872                    Label* on_black);
1873
1874
1875   // Get the location of a relocated constant (its address in the constant pool)
1876   // from its load site.
1877   void GetRelocatedValueLocation(Register ldr_location,
1878                                  Register result);
1879
1880
1881   // ---------------------------------------------------------------------------
1882   // Debugging.
1883
1884   // Calls Abort(msg) if the condition cond is not satisfied.
1885   // Use --debug_code to enable.
1886   void Assert(Condition cond, BailoutReason reason);
1887   void AssertRegisterIsClear(Register reg, BailoutReason reason);
1888   void AssertRegisterIsRoot(
1889       Register reg,
1890       Heap::RootListIndex index,
1891       BailoutReason reason = kRegisterDidNotMatchExpectedRoot);
1892   void AssertFastElements(Register elements);
1893
1894   // Abort if the specified register contains the invalid color bit pattern.
1895   // The pattern must be in bits [1:0] of 'reg' register.
1896   //
1897   // If emit_debug_code() is false, this emits no code.
1898   void AssertHasValidColor(const Register& reg);
1899
1900   // Abort if 'object' register doesn't point to a string object.
1901   //
1902   // If emit_debug_code() is false, this emits no code.
1903   void AssertIsString(const Register& object);
1904
1905   // Like Assert(), but always enabled.
1906   void Check(Condition cond, BailoutReason reason);
1907   void CheckRegisterIsClear(Register reg, BailoutReason reason);
1908
1909   // Print a message to stderr and abort execution.
1910   void Abort(BailoutReason reason);
1911
1912   // Conditionally load the cached Array transitioned map of type
1913   // transitioned_kind from the native context if the map in register
1914   // map_in_out is the cached Array map in the native context of
1915   // expected_kind.
1916   void LoadTransitionedArrayMapConditional(
1917       ElementsKind expected_kind,
1918       ElementsKind transitioned_kind,
1919       Register map_in_out,
1920       Register scratch1,
1921       Register scratch2,
1922       Label* no_map_match);
1923
1924   void LoadGlobalFunction(int index, Register function);
1925
1926   // Load the initial map from the global function. The registers function and
1927   // map can be the same, function is then overwritten.
1928   void LoadGlobalFunctionInitialMap(Register function,
1929                                     Register map,
1930                                     Register scratch);
1931
1932   CPURegList* TmpList() { return &tmp_list_; }
1933   CPURegList* FPTmpList() { return &fptmp_list_; }
1934
1935   static CPURegList DefaultTmpList();
1936   static CPURegList DefaultFPTmpList();
1937
1938   // Like printf, but print at run-time from generated code.
1939   //
1940   // The caller must ensure that arguments for floating-point placeholders
1941   // (such as %e, %f or %g) are FPRegisters, and that arguments for integer
1942   // placeholders are Registers.
1943   //
1944   // At the moment it is only possible to print the value of csp if it is the
1945   // current stack pointer. Otherwise, the MacroAssembler will automatically
1946   // update csp on every push (using BumpSystemStackPointer), so determining its
1947   // value is difficult.
1948   //
1949   // Format placeholders that refer to more than one argument, or to a specific
1950   // argument, are not supported. This includes formats like "%1$d" or "%.*d".
1951   //
1952   // This function automatically preserves caller-saved registers so that
1953   // calling code can use Printf at any point without having to worry about
1954   // corruption. The preservation mechanism generates a lot of code. If this is
1955   // a problem, preserve the important registers manually and then call
1956   // PrintfNoPreserve. Callee-saved registers are not used by Printf, and are
1957   // implicitly preserved.
1958   void Printf(const char * format,
1959               CPURegister arg0 = NoCPUReg,
1960               CPURegister arg1 = NoCPUReg,
1961               CPURegister arg2 = NoCPUReg,
1962               CPURegister arg3 = NoCPUReg);
1963
1964   // Like Printf, but don't preserve any caller-saved registers, not even 'lr'.
1965   //
1966   // The return code from the system printf call will be returned in x0.
1967   void PrintfNoPreserve(const char * format,
1968                         const CPURegister& arg0 = NoCPUReg,
1969                         const CPURegister& arg1 = NoCPUReg,
1970                         const CPURegister& arg2 = NoCPUReg,
1971                         const CPURegister& arg3 = NoCPUReg);
1972
1973   // Code ageing support functions.
1974
1975   // Code ageing on ARM64 works similarly to on ARM. When V8 wants to mark a
1976   // function as old, it replaces some of the function prologue (generated by
1977   // FullCodeGenerator::Generate) with a call to a special stub (ultimately
1978   // generated by GenerateMakeCodeYoungAgainCommon). The stub restores the
1979   // function prologue to its initial young state (indicating that it has been
1980   // recently run) and continues. A young function is therefore one which has a
1981   // normal frame setup sequence, and an old function has a code age sequence
1982   // which calls a code ageing stub.
1983
1984   // Set up a basic stack frame for young code (or code exempt from ageing) with
1985   // type FUNCTION. It may be patched later for code ageing support. This is
1986   // done by to Code::PatchPlatformCodeAge and EmitCodeAgeSequence.
1987   //
1988   // This function takes an Assembler so it can be called from either a
1989   // MacroAssembler or a PatchingAssembler context.
1990   static void EmitFrameSetupForCodeAgePatching(Assembler* assm);
1991
1992   // Call EmitFrameSetupForCodeAgePatching from a MacroAssembler context.
1993   void EmitFrameSetupForCodeAgePatching();
1994
1995   // Emit a code age sequence that calls the relevant code age stub. The code
1996   // generated by this sequence is expected to replace the code generated by
1997   // EmitFrameSetupForCodeAgePatching, and represents an old function.
1998   //
1999   // If stub is NULL, this function generates the code age sequence but omits
2000   // the stub address that is normally embedded in the instruction stream. This
2001   // can be used by debug code to verify code age sequences.
2002   static void EmitCodeAgeSequence(Assembler* assm, Code* stub);
2003
2004   // Call EmitCodeAgeSequence from a MacroAssembler context.
2005   void EmitCodeAgeSequence(Code* stub);
2006
2007   // Return true if the sequence is a young sequence geneated by
2008   // EmitFrameSetupForCodeAgePatching. Otherwise, this method asserts that the
2009   // sequence is a code age sequence (emitted by EmitCodeAgeSequence).
2010   static bool IsYoungSequence(Isolate* isolate, byte* sequence);
2011
2012   // Jumps to found label if a prototype map has dictionary elements.
2013   void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
2014                                         Register scratch1, Label* found);
2015
2016   // Perform necessary maintenance operations before a push or after a pop.
2017   //
2018   // Note that size is specified in bytes.
2019   void PushPreamble(Operand total_size);
2020   void PopPostamble(Operand total_size);
2021
2022   void PushPreamble(int count, int size) { PushPreamble(count * size); }
2023   void PopPostamble(int count, int size) { PopPostamble(count * size); }
2024
2025  private:
2026   // Helpers for CopyFields.
2027   // These each implement CopyFields in a different way.
2028   void CopyFieldsLoopPairsHelper(Register dst, Register src, unsigned count,
2029                                  Register scratch1, Register scratch2,
2030                                  Register scratch3, Register scratch4,
2031                                  Register scratch5);
2032   void CopyFieldsUnrolledPairsHelper(Register dst, Register src, unsigned count,
2033                                      Register scratch1, Register scratch2,
2034                                      Register scratch3, Register scratch4);
2035   void CopyFieldsUnrolledHelper(Register dst, Register src, unsigned count,
2036                                 Register scratch1, Register scratch2,
2037                                 Register scratch3);
2038
2039   // The actual Push and Pop implementations. These don't generate any code
2040   // other than that required for the push or pop. This allows
2041   // (Push|Pop)CPURegList to bundle together run-time assertions for a large
2042   // block of registers.
2043   //
2044   // Note that size is per register, and is specified in bytes.
2045   void PushHelper(int count, int size,
2046                   const CPURegister& src0, const CPURegister& src1,
2047                   const CPURegister& src2, const CPURegister& src3);
2048   void PopHelper(int count, int size,
2049                  const CPURegister& dst0, const CPURegister& dst1,
2050                  const CPURegister& dst2, const CPURegister& dst3);
2051
2052   // Call Printf. On a native build, a simple call will be generated, but if the
2053   // simulator is being used then a suitable pseudo-instruction is used. The
2054   // arguments and stack (csp) must be prepared by the caller as for a normal
2055   // AAPCS64 call to 'printf'.
2056   //
2057   // The 'args' argument should point to an array of variable arguments in their
2058   // proper PCS registers (and in calling order). The argument registers can
2059   // have mixed types. The format string (x0) should not be included.
2060   void CallPrintf(int arg_count = 0, const CPURegister * args = NULL);
2061
2062   // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
2063   void InNewSpace(Register object,
2064                   Condition cond,  // eq for new space, ne otherwise.
2065                   Label* branch);
2066
2067   // Try to represent a double as an int so that integer fast-paths may be
2068   // used. Not every valid integer value is guaranteed to be caught.
2069   // It supports both 32-bit and 64-bit integers depending whether 'as_int'
2070   // is a W or X register.
2071   //
2072   // This does not distinguish between +0 and -0, so if this distinction is
2073   // important it must be checked separately.
2074   //
2075   // On output the Z flag is set if the operation was successful.
2076   void TryRepresentDoubleAsInt(Register as_int,
2077                                FPRegister value,
2078                                FPRegister scratch_d,
2079                                Label* on_successful_conversion = NULL,
2080                                Label* on_failed_conversion = NULL);
2081
2082   bool generating_stub_;
2083 #if DEBUG
2084   // Tell whether any of the macro instruction can be used. When false the
2085   // MacroAssembler will assert if a method which can emit a variable number
2086   // of instructions is called.
2087   bool allow_macro_instructions_;
2088 #endif
2089   bool has_frame_;
2090
2091   // The Abort method should call a V8 runtime function, but the CallRuntime
2092   // mechanism depends on CEntryStub. If use_real_aborts is false, Abort will
2093   // use a simpler abort mechanism that doesn't depend on CEntryStub.
2094   //
2095   // The purpose of this is to allow Aborts to be compiled whilst CEntryStub is
2096   // being generated.
2097   bool use_real_aborts_;
2098
2099   // This handle will be patched with the code object on installation.
2100   Handle<Object> code_object_;
2101
2102   // The register to use as a stack pointer for stack operations.
2103   Register sp_;
2104
2105   // Scratch registers available for use by the MacroAssembler.
2106   CPURegList tmp_list_;
2107   CPURegList fptmp_list_;
2108
2109   void InitializeNewString(Register string,
2110                            Register length,
2111                            Heap::RootListIndex map_index,
2112                            Register scratch1,
2113                            Register scratch2);
2114
2115  public:
2116   // Far branches resolving.
2117   //
2118   // The various classes of branch instructions with immediate offsets have
2119   // different ranges. While the Assembler will fail to assemble a branch
2120   // exceeding its range, the MacroAssembler offers a mechanism to resolve
2121   // branches to too distant targets, either by tweaking the generated code to
2122   // use branch instructions with wider ranges or generating veneers.
2123   //
2124   // Currently branches to distant targets are resolved using unconditional
2125   // branch isntructions with a range of +-128MB. If that becomes too little
2126   // (!), the mechanism can be extended to generate special veneers for really
2127   // far targets.
2128
2129   // Helps resolve branching to labels potentially out of range.
2130   // If the label is not bound, it registers the information necessary to later
2131   // be able to emit a veneer for this branch if necessary.
2132   // If the label is bound, it returns true if the label (or the previous link
2133   // in the label chain) is out of range. In that case the caller is responsible
2134   // for generating appropriate code.
2135   // Otherwise it returns false.
2136   // This function also checks wether veneers need to be emitted.
2137   bool NeedExtraInstructionsOrRegisterBranch(Label *label,
2138                                              ImmBranchType branch_type);
2139 };
2140
2141
2142 // Use this scope when you need a one-to-one mapping bewteen methods and
2143 // instructions. This scope prevents the MacroAssembler from being called and
2144 // literal pools from being emitted. It also asserts the number of instructions
2145 // emitted is what you specified when creating the scope.
2146 class InstructionAccurateScope BASE_EMBEDDED {
2147  public:
2148   explicit InstructionAccurateScope(MacroAssembler* masm, size_t count = 0)
2149       : masm_(masm)
2150 #ifdef DEBUG
2151         ,
2152         size_(count * kInstructionSize)
2153 #endif
2154   {
2155     // Before blocking the const pool, see if it needs to be emitted.
2156     masm_->CheckConstPool(false, true);
2157     masm_->CheckVeneerPool(false, true);
2158
2159     masm_->StartBlockPools();
2160 #ifdef DEBUG
2161     if (count != 0) {
2162       masm_->bind(&start_);
2163     }
2164     previous_allow_macro_instructions_ = masm_->allow_macro_instructions();
2165     masm_->set_allow_macro_instructions(false);
2166 #endif
2167   }
2168
2169   ~InstructionAccurateScope() {
2170     masm_->EndBlockPools();
2171 #ifdef DEBUG
2172     if (start_.is_bound()) {
2173       DCHECK(masm_->SizeOfCodeGeneratedSince(&start_) == size_);
2174     }
2175     masm_->set_allow_macro_instructions(previous_allow_macro_instructions_);
2176 #endif
2177   }
2178
2179  private:
2180   MacroAssembler* masm_;
2181 #ifdef DEBUG
2182   size_t size_;
2183   Label start_;
2184   bool previous_allow_macro_instructions_;
2185 #endif
2186 };
2187
2188
2189 // This scope utility allows scratch registers to be managed safely. The
2190 // MacroAssembler's TmpList() (and FPTmpList()) is used as a pool of scratch
2191 // registers. These registers can be allocated on demand, and will be returned
2192 // at the end of the scope.
2193 //
2194 // When the scope ends, the MacroAssembler's lists will be restored to their
2195 // original state, even if the lists were modified by some other means.
2196 class UseScratchRegisterScope {
2197  public:
2198   explicit UseScratchRegisterScope(MacroAssembler* masm)
2199       : available_(masm->TmpList()),
2200         availablefp_(masm->FPTmpList()),
2201         old_available_(available_->list()),
2202         old_availablefp_(availablefp_->list()) {
2203     DCHECK(available_->type() == CPURegister::kRegister);
2204     DCHECK(availablefp_->type() == CPURegister::kFPRegister);
2205   }
2206
2207   ~UseScratchRegisterScope();
2208
2209   // Take a register from the appropriate temps list. It will be returned
2210   // automatically when the scope ends.
2211   Register AcquireW() { return AcquireNextAvailable(available_).W(); }
2212   Register AcquireX() { return AcquireNextAvailable(available_).X(); }
2213   FPRegister AcquireS() { return AcquireNextAvailable(availablefp_).S(); }
2214   FPRegister AcquireD() { return AcquireNextAvailable(availablefp_).D(); }
2215
2216   Register UnsafeAcquire(const Register& reg) {
2217     return Register(UnsafeAcquire(available_, reg));
2218   }
2219
2220   Register AcquireSameSizeAs(const Register& reg);
2221   FPRegister AcquireSameSizeAs(const FPRegister& reg);
2222
2223  private:
2224   static CPURegister AcquireNextAvailable(CPURegList* available);
2225   static CPURegister UnsafeAcquire(CPURegList* available,
2226                                    const CPURegister& reg);
2227
2228   // Available scratch registers.
2229   CPURegList* available_;     // kRegister
2230   CPURegList* availablefp_;   // kFPRegister
2231
2232   // The state of the available lists at the start of this scope.
2233   RegList old_available_;     // kRegister
2234   RegList old_availablefp_;   // kFPRegister
2235 };
2236
2237
2238 inline MemOperand ContextMemOperand(Register context, int index) {
2239   return MemOperand(context, Context::SlotOffset(index));
2240 }
2241
2242 inline MemOperand GlobalObjectMemOperand() {
2243   return ContextMemOperand(cp, Context::GLOBAL_OBJECT_INDEX);
2244 }
2245
2246
2247 // Encode and decode information about patchable inline SMI checks.
2248 class InlineSmiCheckInfo {
2249  public:
2250   explicit InlineSmiCheckInfo(Address info);
2251
2252   bool HasSmiCheck() const {
2253     return smi_check_ != NULL;
2254   }
2255
2256   const Register& SmiRegister() const {
2257     return reg_;
2258   }
2259
2260   Instruction* SmiCheck() const {
2261     return smi_check_;
2262   }
2263
2264   // Use MacroAssembler::InlineData to emit information about patchable inline
2265   // SMI checks. The caller may specify 'reg' as NoReg and an unbound 'site' to
2266   // indicate that there is no inline SMI check. Note that 'reg' cannot be csp.
2267   //
2268   // The generated patch information can be read using the InlineSMICheckInfo
2269   // class.
2270   static void Emit(MacroAssembler* masm, const Register& reg,
2271                    const Label* smi_check);
2272
2273   // Emit information to indicate that there is no inline SMI check.
2274   static void EmitNotInlined(MacroAssembler* masm) {
2275     Label unbound;
2276     Emit(masm, NoReg, &unbound);
2277   }
2278
2279  private:
2280   Register reg_;
2281   Instruction* smi_check_;
2282
2283   // Fields in the data encoded by InlineData.
2284
2285   // A width of 5 (Rd_width) for the SMI register preclues the use of csp,
2286   // since kSPRegInternalCode is 63. However, csp should never hold a SMI or be
2287   // used in a patchable check. The Emit() method checks this.
2288   //
2289   // Note that the total size of the fields is restricted by the underlying
2290   // storage size handled by the BitField class, which is a uint32_t.
2291   class RegisterBits : public BitField<unsigned, 0, 5> {};
2292   class DeltaBits : public BitField<uint32_t, 5, 32-5> {};
2293 };
2294
2295 } }  // namespace v8::internal
2296
2297 #ifdef GENERATED_CODE_COVERAGE
2298 #error "Unsupported option"
2299 #define CODE_COVERAGE_STRINGIFY(x) #x
2300 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
2301 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
2302 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
2303 #else
2304 #define ACCESS_MASM(masm) masm->
2305 #endif
2306
2307 #endif  // V8_ARM64_MACRO_ASSEMBLER_ARM64_H_