1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // - Redistribution in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // - Neither the name of Sun Microsystems or the names of contributors may
16 // be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // The original source code covered by the above license above has been
32 // modified significantly by Google Inc.
33 // Copyright 2011 the V8 project authors. All rights reserved.
34 
35 // A light-weight IA32 Assembler.
36 
37 #ifndef V8_IA32_ASSEMBLER_IA32_H_
38 #define V8_IA32_ASSEMBLER_IA32_H_
39 
40 #include <deque>
41 
42 #include "src/assembler.h"
43 #include "src/isolate.h"
44 #include "src/utils.h"
45 
46 namespace v8 {
47 namespace internal {
48 
49 #define GENERAL_REGISTERS(V) \
50   V(eax)                     \
51   V(ecx)                     \
52   V(edx)                     \
53   V(ebx)                     \
54   V(esp)                     \
55   V(ebp)                     \
56   V(esi)                     \
57   V(edi)
58 
59 #define ALLOCATABLE_GENERAL_REGISTERS(V) \
60   V(eax)                                 \
61   V(ecx)                                 \
62   V(edx)                                 \
63   V(ebx)                                 \
64   V(esi)                                 \
65   V(edi)
66 
67 #define DOUBLE_REGISTERS(V) \
68   V(xmm0)                   \
69   V(xmm1)                   \
70   V(xmm2)                   \
71   V(xmm3)                   \
72   V(xmm4)                   \
73   V(xmm5)                   \
74   V(xmm6)                   \
75   V(xmm7)
76 
77 #define ALLOCATABLE_DOUBLE_REGISTERS(V) \
78   V(xmm1)                               \
79   V(xmm2)                               \
80   V(xmm3)                               \
81   V(xmm4)                               \
82   V(xmm5)                               \
83   V(xmm6)                               \
84   V(xmm7)
85 
86 // CPU Registers.
87 //
88 // 1) We would prefer to use an enum, but enum values are assignment-
89 // compatible with int, which has caused code-generation bugs.
90 //
91 // 2) We would prefer to use a class instead of a struct but we don't like
92 // the register initialization to depend on the particular initialization
93 // order (which appears to be different on OS X, Linux, and Windows for the
94 // installed versions of C++ we tried). Using a struct permits C-style
95 // "initialization". Also, the Register objects cannot be const as this
96 // forces initialization stubs in MSVC, making us dependent on initialization
97 // order.
98 //
99 // 3) By not using an enum, we are possibly preventing the compiler from
100 // doing certain constant folds, which may significantly reduce the
101 // code generated for some assembly instructions (because they boil down
102 // to a few constants). If this is a problem, we could change the code
103 // such that we use an enum in optimized mode, and the struct in debug
104 // mode. This way we get the compile-time error checking in debug mode
105 // and best performance in optimized code.
106 //
107 struct Register {
108   enum Code {
109 #define REGISTER_CODE(R) kCode_##R,
110     GENERAL_REGISTERS(REGISTER_CODE)
111 #undef REGISTER_CODE
112         kAfterLast,
113     kCode_no_reg = -1
114   };
115 
116   static const int kNumRegisters = Code::kAfterLast;
117 
from_codeRegister118   static Register from_code(int code) {
119     DCHECK(code >= 0);
120     DCHECK(code < kNumRegisters);
121     Register r = {code};
122     return r;
123   }
124   const char* ToString();
125   bool IsAllocatable() const;
is_validRegister126   bool is_valid() const { return 0 <= reg_code && reg_code < kNumRegisters; }
isRegister127   bool is(Register reg) const { return reg_code == reg.reg_code; }
codeRegister128   int code() const {
129     DCHECK(is_valid());
130     return reg_code;
131   }
bitRegister132   int bit() const {
133     DCHECK(is_valid());
134     return 1 << reg_code;
135   }
136 
is_byte_registerRegister137   bool is_byte_register() const { return reg_code <= 3; }
138 
139   // Unfortunately we can't make this private in a struct.
140   int reg_code;
141 };
142 
143 
144 #define DECLARE_REGISTER(R) const Register R = {Register::kCode_##R};
145 GENERAL_REGISTERS(DECLARE_REGISTER)
146 #undef DECLARE_REGISTER
147 const Register no_reg = {Register::kCode_no_reg};
148 
149 
150 struct DoubleRegister {
151   enum Code {
152 #define REGISTER_CODE(R) kCode_##R,
153     DOUBLE_REGISTERS(REGISTER_CODE)
154 #undef REGISTER_CODE
155         kAfterLast,
156     kCode_no_reg = -1
157   };
158 
159   static const int kMaxNumRegisters = Code::kAfterLast;
160 
from_codeDoubleRegister161   static DoubleRegister from_code(int code) {
162     DoubleRegister result = {code};
163     return result;
164   }
165 
166   bool IsAllocatable() const;
is_validDoubleRegister167   bool is_valid() const { return 0 <= reg_code && reg_code < kMaxNumRegisters; }
168 
codeDoubleRegister169   int code() const {
170     DCHECK(is_valid());
171     return reg_code;
172   }
173 
isDoubleRegister174   bool is(DoubleRegister reg) const { return reg_code == reg.reg_code; }
175 
176   const char* ToString();
177 
178   int reg_code;
179 };
180 
181 #define DECLARE_REGISTER(R) \
182   const DoubleRegister R = {DoubleRegister::kCode_##R};
183 DOUBLE_REGISTERS(DECLARE_REGISTER)
184 #undef DECLARE_REGISTER
185 const DoubleRegister no_double_reg = {DoubleRegister::kCode_no_reg};
186 
187 typedef DoubleRegister XMMRegister;
188 
189 enum Condition {
190   // any value < 0 is considered no_condition
191   no_condition  = -1,
192 
193   overflow      =  0,
194   no_overflow   =  1,
195   below         =  2,
196   above_equal   =  3,
197   equal         =  4,
198   not_equal     =  5,
199   below_equal   =  6,
200   above         =  7,
201   negative      =  8,
202   positive      =  9,
203   parity_even   = 10,
204   parity_odd    = 11,
205   less          = 12,
206   greater_equal = 13,
207   less_equal    = 14,
208   greater       = 15,
209 
210   // aliases
211   carry         = below,
212   not_carry     = above_equal,
213   zero          = equal,
214   not_zero      = not_equal,
215   sign          = negative,
216   not_sign      = positive
217 };
218 
219 
220 // Returns the equivalent of !cc.
221 // Negation of the default no_condition (-1) results in a non-default
222 // no_condition value (-2). As long as tests for no_condition check
223 // for condition < 0, this will work as expected.
NegateCondition(Condition cc)224 inline Condition NegateCondition(Condition cc) {
225   return static_cast<Condition>(cc ^ 1);
226 }
227 
228 
229 // Commute a condition such that {a cond b == b cond' a}.
CommuteCondition(Condition cc)230 inline Condition CommuteCondition(Condition cc) {
231   switch (cc) {
232     case below:
233       return above;
234     case above:
235       return below;
236     case above_equal:
237       return below_equal;
238     case below_equal:
239       return above_equal;
240     case less:
241       return greater;
242     case greater:
243       return less;
244     case greater_equal:
245       return less_equal;
246     case less_equal:
247       return greater_equal;
248     default:
249       return cc;
250   }
251 }
252 
253 
254 enum RoundingMode {
255   kRoundToNearest = 0x0,
256   kRoundDown = 0x1,
257   kRoundUp = 0x2,
258   kRoundToZero = 0x3
259 };
260 
261 
262 // -----------------------------------------------------------------------------
263 // Machine instruction Immediates
264 
265 class Immediate BASE_EMBEDDED {
266  public:
267   inline explicit Immediate(int x);
268   inline explicit Immediate(const ExternalReference& ext);
269   inline explicit Immediate(Handle<Object> handle);
270   inline explicit Immediate(Smi* value);
271   inline explicit Immediate(Address addr);
272 
CodeRelativeOffset(Label * label)273   static Immediate CodeRelativeOffset(Label* label) {
274     return Immediate(label);
275   }
276 
is_zero()277   bool is_zero() const { return x_ == 0 && RelocInfo::IsNone(rmode_); }
is_int8()278   bool is_int8() const {
279     return -128 <= x_ && x_ < 128 && RelocInfo::IsNone(rmode_);
280   }
is_int16()281   bool is_int16() const {
282     return -32768 <= x_ && x_ < 32768 && RelocInfo::IsNone(rmode_);
283   }
284 
285  private:
286   inline explicit Immediate(Label* value);
287 
288   int x_;
289   RelocInfo::Mode rmode_;
290 
291   friend class Operand;
292   friend class Assembler;
293   friend class MacroAssembler;
294 };
295 
296 
297 // -----------------------------------------------------------------------------
298 // Machine instruction Operands
299 
300 enum ScaleFactor {
301   times_1 = 0,
302   times_2 = 1,
303   times_4 = 2,
304   times_8 = 3,
305   times_int_size = times_4,
306   times_half_pointer_size = times_2,
307   times_pointer_size = times_4,
308   times_twice_pointer_size = times_8
309 };
310 
311 
312 class Operand BASE_EMBEDDED {
313  public:
314   // reg
315   INLINE(explicit Operand(Register reg));
316 
317   // XMM reg
318   INLINE(explicit Operand(XMMRegister xmm_reg));
319 
320   // [disp/r]
321   INLINE(explicit Operand(int32_t disp, RelocInfo::Mode rmode));
322 
323   // [disp/r]
324   INLINE(explicit Operand(Immediate imm));
325 
326   // [base + disp/r]
327   explicit Operand(Register base, int32_t disp,
328                    RelocInfo::Mode rmode = RelocInfo::NONE32);
329 
330   // [base + index*scale + disp/r]
331   explicit Operand(Register base,
332                    Register index,
333                    ScaleFactor scale,
334                    int32_t disp,
335                    RelocInfo::Mode rmode = RelocInfo::NONE32);
336 
337   // [index*scale + disp/r]
338   explicit Operand(Register index,
339                    ScaleFactor scale,
340                    int32_t disp,
341                    RelocInfo::Mode rmode = RelocInfo::NONE32);
342 
JumpTable(Register index,ScaleFactor scale,Label * table)343   static Operand JumpTable(Register index, ScaleFactor scale, Label* table) {
344     return Operand(index, scale, reinterpret_cast<int32_t>(table),
345                    RelocInfo::INTERNAL_REFERENCE);
346   }
347 
StaticVariable(const ExternalReference & ext)348   static Operand StaticVariable(const ExternalReference& ext) {
349     return Operand(reinterpret_cast<int32_t>(ext.address()),
350                    RelocInfo::EXTERNAL_REFERENCE);
351   }
352 
StaticArray(Register index,ScaleFactor scale,const ExternalReference & arr)353   static Operand StaticArray(Register index,
354                              ScaleFactor scale,
355                              const ExternalReference& arr) {
356     return Operand(index, scale, reinterpret_cast<int32_t>(arr.address()),
357                    RelocInfo::EXTERNAL_REFERENCE);
358   }
359 
ForCell(Handle<Cell> cell)360   static Operand ForCell(Handle<Cell> cell) {
361     AllowDeferredHandleDereference embedding_raw_address;
362     return Operand(reinterpret_cast<int32_t>(cell.location()),
363                    RelocInfo::CELL);
364   }
365 
ForRegisterPlusImmediate(Register base,Immediate imm)366   static Operand ForRegisterPlusImmediate(Register base, Immediate imm) {
367     return Operand(base, imm.x_, imm.rmode_);
368   }
369 
370   // Returns true if this Operand is a wrapper for the specified register.
371   bool is_reg(Register reg) const;
372 
373   // Returns true if this Operand is a wrapper for one register.
374   bool is_reg_only() const;
375 
376   // Asserts that this Operand is a wrapper for one register and returns the
377   // register.
378   Register reg() const;
379 
380  private:
381   // Set the ModRM byte without an encoded 'reg' register. The
382   // register is encoded later as part of the emit_operand operation.
383   inline void set_modrm(int mod, Register rm);
384 
385   inline void set_sib(ScaleFactor scale, Register index, Register base);
386   inline void set_disp8(int8_t disp);
387   inline void set_dispr(int32_t disp, RelocInfo::Mode rmode);
388 
389   byte buf_[6];
390   // The number of bytes in buf_.
391   unsigned int len_;
392   // Only valid if len_ > 4.
393   RelocInfo::Mode rmode_;
394 
395   friend class Assembler;
396   friend class MacroAssembler;
397 };
398 
399 
400 // -----------------------------------------------------------------------------
401 // A Displacement describes the 32bit immediate field of an instruction which
402 // may be used together with a Label in order to refer to a yet unknown code
403 // position. Displacements stored in the instruction stream are used to describe
404 // the instruction and to chain a list of instructions using the same Label.
405 // A Displacement contains 2 different fields:
406 //
407 // next field: position of next displacement in the chain (0 = end of list)
408 // type field: instruction type
409 //
410 // A next value of null (0) indicates the end of a chain (note that there can
411 // be no displacement at position zero, because there is always at least one
412 // instruction byte before the displacement).
413 //
414 // Displacement _data field layout
415 //
416 // |31.....2|1......0|
417 // [  next  |  type  |
418 
419 class Displacement BASE_EMBEDDED {
420  public:
421   enum Type { UNCONDITIONAL_JUMP, CODE_RELATIVE, OTHER, CODE_ABSOLUTE };
422 
data()423   int data() const { return data_; }
type()424   Type type() const { return TypeField::decode(data_); }
next(Label * L)425   void next(Label* L) const {
426     int n = NextField::decode(data_);
427     n > 0 ? L->link_to(n) : L->Unuse();
428   }
link_to(Label * L)429   void link_to(Label* L) { init(L, type()); }
430 
Displacement(int data)431   explicit Displacement(int data) { data_ = data; }
432 
Displacement(Label * L,Type type)433   Displacement(Label* L, Type type) { init(L, type); }
434 
print()435   void print() {
436     PrintF("%s (%x) ", (type() == UNCONDITIONAL_JUMP ? "jmp" : "[other]"),
437                        NextField::decode(data_));
438   }
439 
440  private:
441   int data_;
442 
443   class TypeField: public BitField<Type, 0, 2> {};
444   class NextField: public BitField<int,  2, 32-2> {};
445 
446   void init(Label* L, Type type);
447 };
448 
449 
450 class Assembler : public AssemblerBase {
451  private:
452   // We check before assembling an instruction that there is sufficient
453   // space to write an instruction and its relocation information.
454   // The relocation writer's position must be kGap bytes above the end of
455   // the generated instructions. This leaves enough space for the
456   // longest possible ia32 instruction, 15 bytes, and the longest possible
457   // relocation information encoding, RelocInfoWriter::kMaxLength == 16.
458   // (There is a 15 byte limit on ia32 instruction length that rules out some
459   // otherwise valid instructions.)
460   // This allows for a single, fast space check per instruction.
461   static const int kGap = 32;
462 
463  public:
464   // Create an assembler. Instructions and relocation information are emitted
465   // into a buffer, with the instructions starting from the beginning and the
466   // relocation information starting from the end of the buffer. See CodeDesc
467   // for a detailed comment on the layout (globals.h).
468   //
469   // If the provided buffer is NULL, the assembler allocates and grows its own
470   // buffer, and buffer_size determines the initial buffer size. The buffer is
471   // owned by the assembler and deallocated upon destruction of the assembler.
472   //
473   // If the provided buffer is not NULL, the assembler uses the provided buffer
474   // for code generation and assumes its size to be buffer_size. If the buffer
475   // is too small, a fatal error occurs. No deallocation of the buffer is done
476   // upon destruction of the assembler.
477   // TODO(vitalyr): the assembler does not need an isolate.
478   Assembler(Isolate* isolate, void* buffer, int buffer_size);
~Assembler()479   virtual ~Assembler() { }
480 
481   // GetCode emits any pending (non-emitted) code and fills the descriptor
482   // desc. GetCode() is idempotent; it returns the same result if no other
483   // Assembler functions are invoked in between GetCode() calls.
484   void GetCode(CodeDesc* desc);
485 
486   // Read/Modify the code target in the branch/call instruction at pc.
487   inline static Address target_address_at(Address pc, Address constant_pool);
488   inline static void set_target_address_at(
489       Isolate* isolate, Address pc, Address constant_pool, Address target,
490       ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
target_address_at(Address pc,Code * code)491   static inline Address target_address_at(Address pc, Code* code) {
492     Address constant_pool = code ? code->constant_pool() : NULL;
493     return target_address_at(pc, constant_pool);
494   }
495   static inline void set_target_address_at(
496       Isolate* isolate, Address pc, Code* code, Address target,
497       ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED) {
498     Address constant_pool = code ? code->constant_pool() : NULL;
499     set_target_address_at(isolate, pc, constant_pool, target);
500   }
501 
502   // Return the code target address at a call site from the return address
503   // of that call in the instruction stream.
504   inline static Address target_address_from_return_address(Address pc);
505 
506   // This sets the branch destination (which is in the instruction on x86).
507   // This is for calls and branches within generated code.
deserialization_set_special_target_at(Isolate * isolate,Address instruction_payload,Code * code,Address target)508   inline static void deserialization_set_special_target_at(
509       Isolate* isolate, Address instruction_payload, Code* code,
510       Address target) {
511     set_target_address_at(isolate, instruction_payload, code, target);
512   }
513 
514   // This sets the internal reference at the pc.
515   inline static void deserialization_set_target_internal_reference_at(
516       Isolate* isolate, Address pc, Address target,
517       RelocInfo::Mode mode = RelocInfo::INTERNAL_REFERENCE);
518 
519   static const int kSpecialTargetSize = kPointerSize;
520 
521   // Distance between the address of the code target in the call instruction
522   // and the return address
523   static const int kCallTargetAddressOffset = kPointerSize;
524 
525   static const int kCallInstructionLength = 5;
526 
527   // The debug break slot must be able to contain a call instruction.
528   static const int kDebugBreakSlotLength = kCallInstructionLength;
529 
530   // Distance between start of patched debug break slot and the emitted address
531   // to jump to.
532   static const int kPatchDebugBreakSlotAddressOffset = 1;  // JMP imm32.
533 
534   // One byte opcode for test al, 0xXX.
535   static const byte kTestAlByte = 0xA8;
536   // One byte opcode for nop.
537   static const byte kNopByte = 0x90;
538 
539   // One byte opcode for a short unconditional jump.
540   static const byte kJmpShortOpcode = 0xEB;
541   // One byte prefix for a short conditional jump.
542   static const byte kJccShortPrefix = 0x70;
543   static const byte kJncShortOpcode = kJccShortPrefix | not_carry;
544   static const byte kJcShortOpcode = kJccShortPrefix | carry;
545   static const byte kJnzShortOpcode = kJccShortPrefix | not_zero;
546   static const byte kJzShortOpcode = kJccShortPrefix | zero;
547 
548 
549   // ---------------------------------------------------------------------------
550   // Code generation
551   //
552   // - function names correspond one-to-one to ia32 instruction mnemonics
553   // - unless specified otherwise, instructions operate on 32bit operands
554   // - instructions on 8bit (byte) operands/registers have a trailing '_b'
555   // - instructions on 16bit (word) operands/registers have a trailing '_w'
556   // - naming conflicts with C++ keywords are resolved via a trailing '_'
557 
558   // NOTE ON INTERFACE: Currently, the interface is not very consistent
559   // in the sense that some operations (e.g. mov()) can be called in more
560   // the one way to generate the same instruction: The Register argument
561   // can in some cases be replaced with an Operand(Register) argument.
562   // This should be cleaned up and made more orthogonal. The questions
563   // is: should we always use Operands instead of Registers where an
564   // Operand is possible, or should we have a Register (overloaded) form
565   // instead? We must be careful to make sure that the selected instruction
566   // is obvious from the parameters to avoid hard-to-find code generation
567   // bugs.
568 
569   // Insert the smallest number of nop instructions
570   // possible to align the pc offset to a multiple
571   // of m. m must be a power of 2.
572   void Align(int m);
573   // Insert the smallest number of zero bytes possible to align the pc offset
574   // to a mulitple of m. m must be a power of 2 (>= 2).
575   void DataAlign(int m);
576   void Nop(int bytes = 1);
577   // Aligns code to something that's optimal for a jump target for the platform.
578   void CodeTargetAlign();
579 
580   // Stack
581   void pushad();
582   void popad();
583 
584   void pushfd();
585   void popfd();
586 
587   void push(const Immediate& x);
588   void push_imm32(int32_t imm32);
589   void push(Register src);
590   void push(const Operand& src);
591 
592   void pop(Register dst);
593   void pop(const Operand& dst);
594 
595   void enter(const Immediate& size);
596   void leave();
597 
598   // Moves
mov_b(Register dst,Register src)599   void mov_b(Register dst, Register src) { mov_b(dst, Operand(src)); }
600   void mov_b(Register dst, const Operand& src);
mov_b(Register dst,int8_t imm8)601   void mov_b(Register dst, int8_t imm8) { mov_b(Operand(dst), imm8); }
mov_b(const Operand & dst,int8_t src)602   void mov_b(const Operand& dst, int8_t src) { mov_b(dst, Immediate(src)); }
603   void mov_b(const Operand& dst, const Immediate& src);
604   void mov_b(const Operand& dst, Register src);
605 
606   void mov_w(Register dst, const Operand& src);
mov_w(const Operand & dst,int16_t src)607   void mov_w(const Operand& dst, int16_t src) { mov_w(dst, Immediate(src)); }
608   void mov_w(const Operand& dst, const Immediate& src);
609   void mov_w(const Operand& dst, Register src);
610 
611   void mov(Register dst, int32_t imm32);
612   void mov(Register dst, const Immediate& x);
613   void mov(Register dst, Handle<Object> handle);
614   void mov(Register dst, const Operand& src);
615   void mov(Register dst, Register src);
616   void mov(const Operand& dst, const Immediate& x);
617   void mov(const Operand& dst, Handle<Object> handle);
618   void mov(const Operand& dst, Register src);
619 
movsx_b(Register dst,Register src)620   void movsx_b(Register dst, Register src) { movsx_b(dst, Operand(src)); }
621   void movsx_b(Register dst, const Operand& src);
622 
movsx_w(Register dst,Register src)623   void movsx_w(Register dst, Register src) { movsx_w(dst, Operand(src)); }
624   void movsx_w(Register dst, const Operand& src);
625 
movzx_b(Register dst,Register src)626   void movzx_b(Register dst, Register src) { movzx_b(dst, Operand(src)); }
627   void movzx_b(Register dst, const Operand& src);
628 
movzx_w(Register dst,Register src)629   void movzx_w(Register dst, Register src) { movzx_w(dst, Operand(src)); }
630   void movzx_w(Register dst, const Operand& src);
631 
632   // Conditional moves
cmov(Condition cc,Register dst,Register src)633   void cmov(Condition cc, Register dst, Register src) {
634     cmov(cc, dst, Operand(src));
635   }
636   void cmov(Condition cc, Register dst, const Operand& src);
637 
638   // Flag management.
639   void cld();
640 
641   // Repetitive string instructions.
642   void rep_movs();
643   void rep_stos();
644   void stos();
645 
646   // Exchange
647   void xchg(Register dst, Register src);
648   void xchg(Register dst, const Operand& src);
649 
650   // Arithmetics
651   void adc(Register dst, int32_t imm32);
652   void adc(Register dst, const Operand& src);
653 
add(Register dst,Register src)654   void add(Register dst, Register src) { add(dst, Operand(src)); }
655   void add(Register dst, const Operand& src);
656   void add(const Operand& dst, Register src);
add(Register dst,const Immediate & imm)657   void add(Register dst, const Immediate& imm) { add(Operand(dst), imm); }
658   void add(const Operand& dst, const Immediate& x);
659 
660   void and_(Register dst, int32_t imm32);
661   void and_(Register dst, const Immediate& x);
and_(Register dst,Register src)662   void and_(Register dst, Register src) { and_(dst, Operand(src)); }
663   void and_(Register dst, const Operand& src);
664   void and_(const Operand& dst, Register src);
665   void and_(const Operand& dst, const Immediate& x);
666 
cmpb(Register reg,int8_t imm8)667   void cmpb(Register reg, int8_t imm8) { cmpb(Operand(reg), imm8); }
668   void cmpb(const Operand& op, int8_t imm8);
669   void cmpb(Register reg, const Operand& op);
670   void cmpb(const Operand& op, Register reg);
671   void cmpb_al(const Operand& op);
672   void cmpw_ax(const Operand& op);
673   void cmpw(const Operand& op, Immediate imm16);
674   void cmp(Register reg, int32_t imm32);
675   void cmp(Register reg, Handle<Object> handle);
cmp(Register reg0,Register reg1)676   void cmp(Register reg0, Register reg1) { cmp(reg0, Operand(reg1)); }
677   void cmp(Register reg, const Operand& op);
cmp(Register reg,const Immediate & imm)678   void cmp(Register reg, const Immediate& imm) { cmp(Operand(reg), imm); }
679   void cmp(const Operand& op, const Immediate& imm);
680   void cmp(const Operand& op, Handle<Object> handle);
681 
682   void dec_b(Register dst);
683   void dec_b(const Operand& dst);
684 
685   void dec(Register dst);
686   void dec(const Operand& dst);
687 
688   void cdq();
689 
idiv(Register src)690   void idiv(Register src) { idiv(Operand(src)); }
691   void idiv(const Operand& src);
div(Register src)692   void div(Register src) { div(Operand(src)); }
693   void div(const Operand& src);
694 
695   // Signed multiply instructions.
696   void imul(Register src);                               // edx:eax = eax * src.
imul(Register dst,Register src)697   void imul(Register dst, Register src) { imul(dst, Operand(src)); }
698   void imul(Register dst, const Operand& src);           // dst = dst * src.
699   void imul(Register dst, Register src, int32_t imm32);  // dst = src * imm32.
700   void imul(Register dst, const Operand& src, int32_t imm32);
701 
702   void inc(Register dst);
703   void inc(const Operand& dst);
704 
705   void lea(Register dst, const Operand& src);
706 
707   // Unsigned multiply instruction.
708   void mul(Register src);                                // edx:eax = eax * reg.
709 
710   void neg(Register dst);
711   void neg(const Operand& dst);
712 
713   void not_(Register dst);
714   void not_(const Operand& dst);
715 
716   void or_(Register dst, int32_t imm32);
or_(Register dst,Register src)717   void or_(Register dst, Register src) { or_(dst, Operand(src)); }
718   void or_(Register dst, const Operand& src);
719   void or_(const Operand& dst, Register src);
or_(Register dst,const Immediate & imm)720   void or_(Register dst, const Immediate& imm) { or_(Operand(dst), imm); }
721   void or_(const Operand& dst, const Immediate& x);
722 
723   void rcl(Register dst, uint8_t imm8);
724   void rcr(Register dst, uint8_t imm8);
725 
ror(Register dst,uint8_t imm8)726   void ror(Register dst, uint8_t imm8) { ror(Operand(dst), imm8); }
727   void ror(const Operand& dst, uint8_t imm8);
ror_cl(Register dst)728   void ror_cl(Register dst) { ror_cl(Operand(dst)); }
729   void ror_cl(const Operand& dst);
730 
sar(Register dst,uint8_t imm8)731   void sar(Register dst, uint8_t imm8) { sar(Operand(dst), imm8); }
732   void sar(const Operand& dst, uint8_t imm8);
sar_cl(Register dst)733   void sar_cl(Register dst) { sar_cl(Operand(dst)); }
734   void sar_cl(const Operand& dst);
735 
736   void sbb(Register dst, const Operand& src);
737 
shld(Register dst,Register src)738   void shld(Register dst, Register src) { shld(dst, Operand(src)); }
739   void shld(Register dst, const Operand& src);
740 
shl(Register dst,uint8_t imm8)741   void shl(Register dst, uint8_t imm8) { shl(Operand(dst), imm8); }
742   void shl(const Operand& dst, uint8_t imm8);
shl_cl(Register dst)743   void shl_cl(Register dst) { shl_cl(Operand(dst)); }
744   void shl_cl(const Operand& dst);
745 
shrd(Register dst,Register src)746   void shrd(Register dst, Register src) { shrd(dst, Operand(src)); }
747   void shrd(Register dst, const Operand& src);
748 
shr(Register dst,uint8_t imm8)749   void shr(Register dst, uint8_t imm8) { shr(Operand(dst), imm8); }
750   void shr(const Operand& dst, uint8_t imm8);
shr_cl(Register dst)751   void shr_cl(Register dst) { shr_cl(Operand(dst)); }
752   void shr_cl(const Operand& dst);
753 
sub(Register dst,const Immediate & imm)754   void sub(Register dst, const Immediate& imm) { sub(Operand(dst), imm); }
755   void sub(const Operand& dst, const Immediate& x);
sub(Register dst,Register src)756   void sub(Register dst, Register src) { sub(dst, Operand(src)); }
757   void sub(Register dst, const Operand& src);
758   void sub(const Operand& dst, Register src);
759 
760   void test(Register reg, const Immediate& imm);
test(Register reg0,Register reg1)761   void test(Register reg0, Register reg1) { test(reg0, Operand(reg1)); }
762   void test(Register reg, const Operand& op);
763   void test_b(Register reg, const Operand& op);
764   void test(const Operand& op, const Immediate& imm);
765   void test_b(Register reg, uint8_t imm8);
766   void test_b(const Operand& op, uint8_t imm8);
767 
768   void xor_(Register dst, int32_t imm32);
xor_(Register dst,Register src)769   void xor_(Register dst, Register src) { xor_(dst, Operand(src)); }
770   void xor_(Register dst, const Operand& src);
771   void xor_(const Operand& dst, Register src);
xor_(Register dst,const Immediate & imm)772   void xor_(Register dst, const Immediate& imm) { xor_(Operand(dst), imm); }
773   void xor_(const Operand& dst, const Immediate& x);
774 
775   // Bit operations.
776   void bt(const Operand& dst, Register src);
bts(Register dst,Register src)777   void bts(Register dst, Register src) { bts(Operand(dst), src); }
778   void bts(const Operand& dst, Register src);
bsr(Register dst,Register src)779   void bsr(Register dst, Register src) { bsr(dst, Operand(src)); }
780   void bsr(Register dst, const Operand& src);
bsf(Register dst,Register src)781   void bsf(Register dst, Register src) { bsf(dst, Operand(src)); }
782   void bsf(Register dst, const Operand& src);
783 
784   // Miscellaneous
785   void hlt();
786   void int3();
787   void nop();
788   void ret(int imm16);
789   void ud2();
790 
791   // Label operations & relative jumps (PPUM Appendix D)
792   //
793   // Takes a branch opcode (cc) and a label (L) and generates
794   // either a backward branch or a forward branch and links it
795   // to the label fixup chain. Usage:
796   //
797   // Label L;    // unbound label
798   // j(cc, &L);  // forward branch to unbound label
799   // bind(&L);   // bind label to the current pc
800   // j(cc, &L);  // backward branch to bound label
801   // bind(&L);   // illegal: a label may be bound only once
802   //
803   // Note: The same Label can be used for forward and backward branches
804   // but it may be bound only once.
805 
806   void bind(Label* L);  // binds an unbound label L to the current code position
807 
808   // Calls
809   void call(Label* L);
810   void call(byte* entry, RelocInfo::Mode rmode);
811   int CallSize(const Operand& adr);
call(Register reg)812   void call(Register reg) { call(Operand(reg)); }
813   void call(const Operand& adr);
814   int CallSize(Handle<Code> code, RelocInfo::Mode mode);
815   void call(Handle<Code> code,
816             RelocInfo::Mode rmode,
817             TypeFeedbackId id = TypeFeedbackId::None());
818 
819   // Jumps
820   // unconditional jump to L
821   void jmp(Label* L, Label::Distance distance = Label::kFar);
822   void jmp(byte* entry, RelocInfo::Mode rmode);
jmp(Register reg)823   void jmp(Register reg) { jmp(Operand(reg)); }
824   void jmp(const Operand& adr);
825   void jmp(Handle<Code> code, RelocInfo::Mode rmode);
826 
827   // Conditional jumps
828   void j(Condition cc,
829          Label* L,
830          Label::Distance distance = Label::kFar);
831   void j(Condition cc, byte* entry, RelocInfo::Mode rmode);
832   void j(Condition cc, Handle<Code> code,
833          RelocInfo::Mode rmode = RelocInfo::CODE_TARGET);
834 
835   // Floating-point operations
836   void fld(int i);
837   void fstp(int i);
838 
839   void fld1();
840   void fldz();
841   void fldpi();
842   void fldln2();
843 
844   void fld_s(const Operand& adr);
845   void fld_d(const Operand& adr);
846 
847   void fstp_s(const Operand& adr);
848   void fst_s(const Operand& adr);
849   void fstp_d(const Operand& adr);
850   void fst_d(const Operand& adr);
851 
852   void fild_s(const Operand& adr);
853   void fild_d(const Operand& adr);
854 
855   void fist_s(const Operand& adr);
856 
857   void fistp_s(const Operand& adr);
858   void fistp_d(const Operand& adr);
859 
860   // The fisttp instructions require SSE3.
861   void fisttp_s(const Operand& adr);
862   void fisttp_d(const Operand& adr);
863 
864   void fabs();
865   void fchs();
866   void fcos();
867   void fsin();
868   void fptan();
869   void fyl2x();
870   void f2xm1();
871   void fscale();
872   void fninit();
873 
874   void fadd(int i);
875   void fadd_i(int i);
876   void fsub(int i);
877   void fsub_i(int i);
878   void fmul(int i);
879   void fmul_i(int i);
880   void fdiv(int i);
881   void fdiv_i(int i);
882 
883   void fisub_s(const Operand& adr);
884 
885   void faddp(int i = 1);
886   void fsubp(int i = 1);
887   void fsubrp(int i = 1);
888   void fmulp(int i = 1);
889   void fdivp(int i = 1);
890   void fprem();
891   void fprem1();
892 
893   void fxch(int i = 1);
894   void fincstp();
895   void ffree(int i = 0);
896 
897   void ftst();
898   void fucomp(int i);
899   void fucompp();
900   void fucomi(int i);
901   void fucomip();
902   void fcompp();
903   void fnstsw_ax();
904   void fwait();
905   void fnclex();
906 
907   void frndint();
908 
909   void sahf();
910   void setcc(Condition cc, Register reg);
911 
912   void cpuid();
913 
914   // SSE instructions
addss(XMMRegister dst,XMMRegister src)915   void addss(XMMRegister dst, XMMRegister src) { addss(dst, Operand(src)); }
916   void addss(XMMRegister dst, const Operand& src);
subss(XMMRegister dst,XMMRegister src)917   void subss(XMMRegister dst, XMMRegister src) { subss(dst, Operand(src)); }
918   void subss(XMMRegister dst, const Operand& src);
mulss(XMMRegister dst,XMMRegister src)919   void mulss(XMMRegister dst, XMMRegister src) { mulss(dst, Operand(src)); }
920   void mulss(XMMRegister dst, const Operand& src);
divss(XMMRegister dst,XMMRegister src)921   void divss(XMMRegister dst, XMMRegister src) { divss(dst, Operand(src)); }
922   void divss(XMMRegister dst, const Operand& src);
sqrtss(XMMRegister dst,XMMRegister src)923   void sqrtss(XMMRegister dst, XMMRegister src) { sqrtss(dst, Operand(src)); }
924   void sqrtss(XMMRegister dst, const Operand& src);
925 
ucomiss(XMMRegister dst,XMMRegister src)926   void ucomiss(XMMRegister dst, XMMRegister src) { ucomiss(dst, Operand(src)); }
927   void ucomiss(XMMRegister dst, const Operand& src);
928   void movaps(XMMRegister dst, XMMRegister src);
929   void shufps(XMMRegister dst, XMMRegister src, byte imm8);
930 
maxss(XMMRegister dst,XMMRegister src)931   void maxss(XMMRegister dst, XMMRegister src) { maxss(dst, Operand(src)); }
932   void maxss(XMMRegister dst, const Operand& src);
minss(XMMRegister dst,XMMRegister src)933   void minss(XMMRegister dst, XMMRegister src) { minss(dst, Operand(src)); }
934   void minss(XMMRegister dst, const Operand& src);
935 
936   void andps(XMMRegister dst, const Operand& src);
andps(XMMRegister dst,XMMRegister src)937   void andps(XMMRegister dst, XMMRegister src) { andps(dst, Operand(src)); }
938   void xorps(XMMRegister dst, const Operand& src);
xorps(XMMRegister dst,XMMRegister src)939   void xorps(XMMRegister dst, XMMRegister src) { xorps(dst, Operand(src)); }
940   void orps(XMMRegister dst, const Operand& src);
orps(XMMRegister dst,XMMRegister src)941   void orps(XMMRegister dst, XMMRegister src) { orps(dst, Operand(src)); }
942 
943   void addps(XMMRegister dst, const Operand& src);
addps(XMMRegister dst,XMMRegister src)944   void addps(XMMRegister dst, XMMRegister src) { addps(dst, Operand(src)); }
945   void subps(XMMRegister dst, const Operand& src);
subps(XMMRegister dst,XMMRegister src)946   void subps(XMMRegister dst, XMMRegister src) { subps(dst, Operand(src)); }
947   void mulps(XMMRegister dst, const Operand& src);
mulps(XMMRegister dst,XMMRegister src)948   void mulps(XMMRegister dst, XMMRegister src) { mulps(dst, Operand(src)); }
949   void divps(XMMRegister dst, const Operand& src);
divps(XMMRegister dst,XMMRegister src)950   void divps(XMMRegister dst, XMMRegister src) { divps(dst, Operand(src)); }
951 
952   // SSE2 instructions
953   void cvttss2si(Register dst, const Operand& src);
cvttss2si(Register dst,XMMRegister src)954   void cvttss2si(Register dst, XMMRegister src) {
955     cvttss2si(dst, Operand(src));
956   }
957   void cvttsd2si(Register dst, const Operand& src);
cvttsd2si(Register dst,XMMRegister src)958   void cvttsd2si(Register dst, XMMRegister src) {
959     cvttsd2si(dst, Operand(src));
960   }
961   void cvtsd2si(Register dst, XMMRegister src);
962 
cvtsi2sd(XMMRegister dst,Register src)963   void cvtsi2sd(XMMRegister dst, Register src) { cvtsi2sd(dst, Operand(src)); }
964   void cvtsi2sd(XMMRegister dst, const Operand& src);
965   void cvtss2sd(XMMRegister dst, const Operand& src);
cvtss2sd(XMMRegister dst,XMMRegister src)966   void cvtss2sd(XMMRegister dst, XMMRegister src) {
967     cvtss2sd(dst, Operand(src));
968   }
969   void cvtsd2ss(XMMRegister dst, const Operand& src);
cvtsd2ss(XMMRegister dst,XMMRegister src)970   void cvtsd2ss(XMMRegister dst, XMMRegister src) {
971     cvtsd2ss(dst, Operand(src));
972   }
addsd(XMMRegister dst,XMMRegister src)973   void addsd(XMMRegister dst, XMMRegister src) { addsd(dst, Operand(src)); }
974   void addsd(XMMRegister dst, const Operand& src);
subsd(XMMRegister dst,XMMRegister src)975   void subsd(XMMRegister dst, XMMRegister src) { subsd(dst, Operand(src)); }
976   void subsd(XMMRegister dst, const Operand& src);
mulsd(XMMRegister dst,XMMRegister src)977   void mulsd(XMMRegister dst, XMMRegister src) { mulsd(dst, Operand(src)); }
978   void mulsd(XMMRegister dst, const Operand& src);
divsd(XMMRegister dst,XMMRegister src)979   void divsd(XMMRegister dst, XMMRegister src) { divsd(dst, Operand(src)); }
980   void divsd(XMMRegister dst, const Operand& src);
981   void xorpd(XMMRegister dst, XMMRegister src);
sqrtsd(XMMRegister dst,XMMRegister src)982   void sqrtsd(XMMRegister dst, XMMRegister src) { sqrtsd(dst, Operand(src)); }
983   void sqrtsd(XMMRegister dst, const Operand& src);
984 
985   void andpd(XMMRegister dst, XMMRegister src);
986   void orpd(XMMRegister dst, XMMRegister src);
987 
ucomisd(XMMRegister dst,XMMRegister src)988   void ucomisd(XMMRegister dst, XMMRegister src) { ucomisd(dst, Operand(src)); }
989   void ucomisd(XMMRegister dst, const Operand& src);
990 
991   void roundss(XMMRegister dst, XMMRegister src, RoundingMode mode);
992   void roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
993 
994   void movmskpd(Register dst, XMMRegister src);
995   void movmskps(Register dst, XMMRegister src);
996 
997   void cmpltsd(XMMRegister dst, XMMRegister src);
998   void pcmpeqd(XMMRegister dst, XMMRegister src);
999 
1000   void punpckldq(XMMRegister dst, XMMRegister src);
1001   void punpckhdq(XMMRegister dst, XMMRegister src);
1002 
maxsd(XMMRegister dst,XMMRegister src)1003   void maxsd(XMMRegister dst, XMMRegister src) { maxsd(dst, Operand(src)); }
1004   void maxsd(XMMRegister dst, const Operand& src);
minsd(XMMRegister dst,XMMRegister src)1005   void minsd(XMMRegister dst, XMMRegister src) { minsd(dst, Operand(src)); }
1006   void minsd(XMMRegister dst, const Operand& src);
1007 
1008   void movdqa(XMMRegister dst, const Operand& src);
1009   void movdqa(const Operand& dst, XMMRegister src);
1010   void movdqu(XMMRegister dst, const Operand& src);
1011   void movdqu(const Operand& dst, XMMRegister src);
movdq(bool aligned,XMMRegister dst,const Operand & src)1012   void movdq(bool aligned, XMMRegister dst, const Operand& src) {
1013     if (aligned) {
1014       movdqa(dst, src);
1015     } else {
1016       movdqu(dst, src);
1017     }
1018   }
1019 
movd(XMMRegister dst,Register src)1020   void movd(XMMRegister dst, Register src) { movd(dst, Operand(src)); }
1021   void movd(XMMRegister dst, const Operand& src);
movd(Register dst,XMMRegister src)1022   void movd(Register dst, XMMRegister src) { movd(Operand(dst), src); }
1023   void movd(const Operand& dst, XMMRegister src);
movsd(XMMRegister dst,XMMRegister src)1024   void movsd(XMMRegister dst, XMMRegister src) { movsd(dst, Operand(src)); }
1025   void movsd(XMMRegister dst, const Operand& src);
1026   void movsd(const Operand& dst, XMMRegister src);
1027 
1028 
1029   void movss(XMMRegister dst, const Operand& src);
1030   void movss(const Operand& dst, XMMRegister src);
movss(XMMRegister dst,XMMRegister src)1031   void movss(XMMRegister dst, XMMRegister src) { movss(dst, Operand(src)); }
1032   void extractps(Register dst, XMMRegister src, byte imm8);
1033 
1034   void pand(XMMRegister dst, XMMRegister src);
1035   void pxor(XMMRegister dst, XMMRegister src);
1036   void por(XMMRegister dst, XMMRegister src);
1037   void ptest(XMMRegister dst, XMMRegister src);
1038 
1039   void pslld(XMMRegister reg, int8_t shift);
1040   void psrld(XMMRegister reg, int8_t shift);
1041   void psllq(XMMRegister reg, int8_t shift);
1042   void psllq(XMMRegister dst, XMMRegister src);
1043   void psrlq(XMMRegister reg, int8_t shift);
1044   void psrlq(XMMRegister dst, XMMRegister src);
1045   void pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle);
pextrd(Register dst,XMMRegister src,int8_t offset)1046   void pextrd(Register dst, XMMRegister src, int8_t offset) {
1047     pextrd(Operand(dst), src, offset);
1048   }
1049   void pextrd(const Operand& dst, XMMRegister src, int8_t offset);
pinsrd(XMMRegister dst,Register src,int8_t offset)1050   void pinsrd(XMMRegister dst, Register src, int8_t offset) {
1051     pinsrd(dst, Operand(src), offset);
1052   }
1053   void pinsrd(XMMRegister dst, const Operand& src, int8_t offset);
1054 
1055   // AVX instructions
vfmadd132sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1056   void vfmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1057     vfmadd132sd(dst, src1, Operand(src2));
1058   }
vfmadd213sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1059   void vfmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1060     vfmadd213sd(dst, src1, Operand(src2));
1061   }
vfmadd231sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1062   void vfmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1063     vfmadd231sd(dst, src1, Operand(src2));
1064   }
vfmadd132sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1065   void vfmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1066     vfmasd(0x99, dst, src1, src2);
1067   }
vfmadd213sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1068   void vfmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1069     vfmasd(0xa9, dst, src1, src2);
1070   }
vfmadd231sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1071   void vfmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1072     vfmasd(0xb9, dst, src1, src2);
1073   }
vfmsub132sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1074   void vfmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1075     vfmsub132sd(dst, src1, Operand(src2));
1076   }
vfmsub213sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1077   void vfmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1078     vfmsub213sd(dst, src1, Operand(src2));
1079   }
vfmsub231sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1080   void vfmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1081     vfmsub231sd(dst, src1, Operand(src2));
1082   }
vfmsub132sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1083   void vfmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1084     vfmasd(0x9b, dst, src1, src2);
1085   }
vfmsub213sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1086   void vfmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1087     vfmasd(0xab, dst, src1, src2);
1088   }
vfmsub231sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1089   void vfmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1090     vfmasd(0xbb, dst, src1, src2);
1091   }
vfnmadd132sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1092   void vfnmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1093     vfnmadd132sd(dst, src1, Operand(src2));
1094   }
vfnmadd213sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1095   void vfnmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1096     vfnmadd213sd(dst, src1, Operand(src2));
1097   }
vfnmadd231sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1098   void vfnmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1099     vfnmadd231sd(dst, src1, Operand(src2));
1100   }
vfnmadd132sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1101   void vfnmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1102     vfmasd(0x9d, dst, src1, src2);
1103   }
vfnmadd213sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1104   void vfnmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1105     vfmasd(0xad, dst, src1, src2);
1106   }
vfnmadd231sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1107   void vfnmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1108     vfmasd(0xbd, dst, src1, src2);
1109   }
vfnmsub132sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1110   void vfnmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1111     vfnmsub132sd(dst, src1, Operand(src2));
1112   }
vfnmsub213sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1113   void vfnmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1114     vfnmsub213sd(dst, src1, Operand(src2));
1115   }
vfnmsub231sd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1116   void vfnmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1117     vfnmsub231sd(dst, src1, Operand(src2));
1118   }
vfnmsub132sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1119   void vfnmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1120     vfmasd(0x9f, dst, src1, src2);
1121   }
vfnmsub213sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1122   void vfnmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1123     vfmasd(0xaf, dst, src1, src2);
1124   }
vfnmsub231sd(XMMRegister dst,XMMRegister src1,const Operand & src2)1125   void vfnmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1126     vfmasd(0xbf, dst, src1, src2);
1127   }
1128   void vfmasd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1129 
vfmadd132ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1130   void vfmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1131     vfmadd132ss(dst, src1, Operand(src2));
1132   }
vfmadd213ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1133   void vfmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1134     vfmadd213ss(dst, src1, Operand(src2));
1135   }
vfmadd231ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1136   void vfmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1137     vfmadd231ss(dst, src1, Operand(src2));
1138   }
vfmadd132ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1139   void vfmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1140     vfmass(0x99, dst, src1, src2);
1141   }
vfmadd213ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1142   void vfmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1143     vfmass(0xa9, dst, src1, src2);
1144   }
vfmadd231ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1145   void vfmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1146     vfmass(0xb9, dst, src1, src2);
1147   }
vfmsub132ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1148   void vfmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1149     vfmsub132ss(dst, src1, Operand(src2));
1150   }
vfmsub213ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1151   void vfmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1152     vfmsub213ss(dst, src1, Operand(src2));
1153   }
vfmsub231ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1154   void vfmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1155     vfmsub231ss(dst, src1, Operand(src2));
1156   }
vfmsub132ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1157   void vfmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1158     vfmass(0x9b, dst, src1, src2);
1159   }
vfmsub213ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1160   void vfmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1161     vfmass(0xab, dst, src1, src2);
1162   }
vfmsub231ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1163   void vfmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1164     vfmass(0xbb, dst, src1, src2);
1165   }
vfnmadd132ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1166   void vfnmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1167     vfnmadd132ss(dst, src1, Operand(src2));
1168   }
vfnmadd213ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1169   void vfnmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1170     vfnmadd213ss(dst, src1, Operand(src2));
1171   }
vfnmadd231ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1172   void vfnmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1173     vfnmadd231ss(dst, src1, Operand(src2));
1174   }
vfnmadd132ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1175   void vfnmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1176     vfmass(0x9d, dst, src1, src2);
1177   }
vfnmadd213ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1178   void vfnmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1179     vfmass(0xad, dst, src1, src2);
1180   }
vfnmadd231ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1181   void vfnmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1182     vfmass(0xbd, dst, src1, src2);
1183   }
vfnmsub132ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1184   void vfnmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1185     vfnmsub132ss(dst, src1, Operand(src2));
1186   }
vfnmsub213ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1187   void vfnmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1188     vfnmsub213ss(dst, src1, Operand(src2));
1189   }
vfnmsub231ss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1190   void vfnmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1191     vfnmsub231ss(dst, src1, Operand(src2));
1192   }
vfnmsub132ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1193   void vfnmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1194     vfmass(0x9f, dst, src1, src2);
1195   }
vfnmsub213ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1196   void vfnmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1197     vfmass(0xaf, dst, src1, src2);
1198   }
vfnmsub231ss(XMMRegister dst,XMMRegister src1,const Operand & src2)1199   void vfnmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1200     vfmass(0xbf, dst, src1, src2);
1201   }
1202   void vfmass(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1203 
vaddsd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1204   void vaddsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1205     vaddsd(dst, src1, Operand(src2));
1206   }
vaddsd(XMMRegister dst,XMMRegister src1,const Operand & src2)1207   void vaddsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1208     vsd(0x58, dst, src1, src2);
1209   }
vsubsd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1210   void vsubsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1211     vsubsd(dst, src1, Operand(src2));
1212   }
vsubsd(XMMRegister dst,XMMRegister src1,const Operand & src2)1213   void vsubsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1214     vsd(0x5c, dst, src1, src2);
1215   }
vmulsd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1216   void vmulsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1217     vmulsd(dst, src1, Operand(src2));
1218   }
vmulsd(XMMRegister dst,XMMRegister src1,const Operand & src2)1219   void vmulsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1220     vsd(0x59, dst, src1, src2);
1221   }
vdivsd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1222   void vdivsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1223     vdivsd(dst, src1, Operand(src2));
1224   }
vdivsd(XMMRegister dst,XMMRegister src1,const Operand & src2)1225   void vdivsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1226     vsd(0x5e, dst, src1, src2);
1227   }
vmaxsd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1228   void vmaxsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1229     vmaxsd(dst, src1, Operand(src2));
1230   }
vmaxsd(XMMRegister dst,XMMRegister src1,const Operand & src2)1231   void vmaxsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1232     vsd(0x5f, dst, src1, src2);
1233   }
vminsd(XMMRegister dst,XMMRegister src1,XMMRegister src2)1234   void vminsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1235     vminsd(dst, src1, Operand(src2));
1236   }
vminsd(XMMRegister dst,XMMRegister src1,const Operand & src2)1237   void vminsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1238     vsd(0x5d, dst, src1, src2);
1239   }
1240   void vsd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1241 
vaddss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1242   void vaddss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1243     vaddss(dst, src1, Operand(src2));
1244   }
vaddss(XMMRegister dst,XMMRegister src1,const Operand & src2)1245   void vaddss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1246     vss(0x58, dst, src1, src2);
1247   }
vsubss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1248   void vsubss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1249     vsubss(dst, src1, Operand(src2));
1250   }
vsubss(XMMRegister dst,XMMRegister src1,const Operand & src2)1251   void vsubss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1252     vss(0x5c, dst, src1, src2);
1253   }
vmulss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1254   void vmulss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1255     vmulss(dst, src1, Operand(src2));
1256   }
vmulss(XMMRegister dst,XMMRegister src1,const Operand & src2)1257   void vmulss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1258     vss(0x59, dst, src1, src2);
1259   }
vdivss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1260   void vdivss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1261     vdivss(dst, src1, Operand(src2));
1262   }
vdivss(XMMRegister dst,XMMRegister src1,const Operand & src2)1263   void vdivss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1264     vss(0x5e, dst, src1, src2);
1265   }
vmaxss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1266   void vmaxss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1267     vmaxss(dst, src1, Operand(src2));
1268   }
vmaxss(XMMRegister dst,XMMRegister src1,const Operand & src2)1269   void vmaxss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1270     vss(0x5f, dst, src1, src2);
1271   }
vminss(XMMRegister dst,XMMRegister src1,XMMRegister src2)1272   void vminss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1273     vminss(dst, src1, Operand(src2));
1274   }
vminss(XMMRegister dst,XMMRegister src1,const Operand & src2)1275   void vminss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1276     vss(0x5d, dst, src1, src2);
1277   }
1278   void vss(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1279 
1280   // BMI instruction
andn(Register dst,Register src1,Register src2)1281   void andn(Register dst, Register src1, Register src2) {
1282     andn(dst, src1, Operand(src2));
1283   }
andn(Register dst,Register src1,const Operand & src2)1284   void andn(Register dst, Register src1, const Operand& src2) {
1285     bmi1(0xf2, dst, src1, src2);
1286   }
bextr(Register dst,Register src1,Register src2)1287   void bextr(Register dst, Register src1, Register src2) {
1288     bextr(dst, Operand(src1), src2);
1289   }
bextr(Register dst,const Operand & src1,Register src2)1290   void bextr(Register dst, const Operand& src1, Register src2) {
1291     bmi1(0xf7, dst, src2, src1);
1292   }
blsi(Register dst,Register src)1293   void blsi(Register dst, Register src) { blsi(dst, Operand(src)); }
blsi(Register dst,const Operand & src)1294   void blsi(Register dst, const Operand& src) {
1295     Register ireg = {3};
1296     bmi1(0xf3, ireg, dst, src);
1297   }
blsmsk(Register dst,Register src)1298   void blsmsk(Register dst, Register src) { blsmsk(dst, Operand(src)); }
blsmsk(Register dst,const Operand & src)1299   void blsmsk(Register dst, const Operand& src) {
1300     Register ireg = {2};
1301     bmi1(0xf3, ireg, dst, src);
1302   }
blsr(Register dst,Register src)1303   void blsr(Register dst, Register src) { blsr(dst, Operand(src)); }
blsr(Register dst,const Operand & src)1304   void blsr(Register dst, const Operand& src) {
1305     Register ireg = {1};
1306     bmi1(0xf3, ireg, dst, src);
1307   }
tzcnt(Register dst,Register src)1308   void tzcnt(Register dst, Register src) { tzcnt(dst, Operand(src)); }
1309   void tzcnt(Register dst, const Operand& src);
1310 
lzcnt(Register dst,Register src)1311   void lzcnt(Register dst, Register src) { lzcnt(dst, Operand(src)); }
1312   void lzcnt(Register dst, const Operand& src);
1313 
popcnt(Register dst,Register src)1314   void popcnt(Register dst, Register src) { popcnt(dst, Operand(src)); }
1315   void popcnt(Register dst, const Operand& src);
1316 
bzhi(Register dst,Register src1,Register src2)1317   void bzhi(Register dst, Register src1, Register src2) {
1318     bzhi(dst, Operand(src1), src2);
1319   }
bzhi(Register dst,const Operand & src1,Register src2)1320   void bzhi(Register dst, const Operand& src1, Register src2) {
1321     bmi2(kNone, 0xf5, dst, src2, src1);
1322   }
mulx(Register dst1,Register dst2,Register src)1323   void mulx(Register dst1, Register dst2, Register src) {
1324     mulx(dst1, dst2, Operand(src));
1325   }
mulx(Register dst1,Register dst2,const Operand & src)1326   void mulx(Register dst1, Register dst2, const Operand& src) {
1327     bmi2(kF2, 0xf6, dst1, dst2, src);
1328   }
pdep(Register dst,Register src1,Register src2)1329   void pdep(Register dst, Register src1, Register src2) {
1330     pdep(dst, src1, Operand(src2));
1331   }
pdep(Register dst,Register src1,const Operand & src2)1332   void pdep(Register dst, Register src1, const Operand& src2) {
1333     bmi2(kF2, 0xf5, dst, src1, src2);
1334   }
pext(Register dst,Register src1,Register src2)1335   void pext(Register dst, Register src1, Register src2) {
1336     pext(dst, src1, Operand(src2));
1337   }
pext(Register dst,Register src1,const Operand & src2)1338   void pext(Register dst, Register src1, const Operand& src2) {
1339     bmi2(kF3, 0xf5, dst, src1, src2);
1340   }
sarx(Register dst,Register src1,Register src2)1341   void sarx(Register dst, Register src1, Register src2) {
1342     sarx(dst, Operand(src1), src2);
1343   }
sarx(Register dst,const Operand & src1,Register src2)1344   void sarx(Register dst, const Operand& src1, Register src2) {
1345     bmi2(kF3, 0xf7, dst, src2, src1);
1346   }
shlx(Register dst,Register src1,Register src2)1347   void shlx(Register dst, Register src1, Register src2) {
1348     shlx(dst, Operand(src1), src2);
1349   }
shlx(Register dst,const Operand & src1,Register src2)1350   void shlx(Register dst, const Operand& src1, Register src2) {
1351     bmi2(k66, 0xf7, dst, src2, src1);
1352   }
shrx(Register dst,Register src1,Register src2)1353   void shrx(Register dst, Register src1, Register src2) {
1354     shrx(dst, Operand(src1), src2);
1355   }
shrx(Register dst,const Operand & src1,Register src2)1356   void shrx(Register dst, const Operand& src1, Register src2) {
1357     bmi2(kF2, 0xf7, dst, src2, src1);
1358   }
rorx(Register dst,Register src,byte imm8)1359   void rorx(Register dst, Register src, byte imm8) {
1360     rorx(dst, Operand(src), imm8);
1361   }
1362   void rorx(Register dst, const Operand& src, byte imm8);
1363 
1364 #define PACKED_OP_LIST(V) \
1365   V(and, 0x54)            \
1366   V(xor, 0x57)
1367 
1368 #define AVX_PACKED_OP_DECLARE(name, opcode)                                  \
1369   void v##name##ps(XMMRegister dst, XMMRegister src1, XMMRegister src2) {    \
1370     vps(opcode, dst, src1, Operand(src2));                                   \
1371   }                                                                          \
1372   void v##name##ps(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1373     vps(opcode, dst, src1, src2);                                            \
1374   }                                                                          \
1375   void v##name##pd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {    \
1376     vpd(opcode, dst, src1, Operand(src2));                                   \
1377   }                                                                          \
1378   void v##name##pd(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1379     vpd(opcode, dst, src1, src2);                                            \
1380   }
1381 
1382   PACKED_OP_LIST(AVX_PACKED_OP_DECLARE);
1383   void vps(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1384   void vps(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1385   void vpd(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1386   void vpd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1387 
1388   // Prefetch src position into cache level.
1389   // Level 1, 2 or 3 specifies CPU cache level. Level 0 specifies a
1390   // non-temporal
1391   void prefetch(const Operand& src, int level);
1392   // TODO(lrn): Need SFENCE for movnt?
1393 
1394   // Check the code size generated from label to here.
SizeOfCodeGeneratedSince(Label * label)1395   int SizeOfCodeGeneratedSince(Label* label) {
1396     return pc_offset() - label->pos();
1397   }
1398 
1399   // Mark generator continuation.
1400   void RecordGeneratorContinuation();
1401 
1402   // Mark address of a debug break slot.
1403   void RecordDebugBreakSlot(RelocInfo::Mode mode);
1404 
1405   // Record a comment relocation entry that can be used by a disassembler.
1406   // Use --code-comments to enable.
1407   void RecordComment(const char* msg);
1408 
1409   // Record a deoptimization reason that can be used by a log or cpu profiler.
1410   // Use --trace-deopt to enable.
1411   void RecordDeoptReason(const int reason, const SourcePosition position);
1412 
1413   // Writes a single byte or word of data in the code stream.  Used for
1414   // inline tables, e.g., jump-tables.
1415   void db(uint8_t data);
1416   void dd(uint32_t data);
1417   void dq(uint64_t data);
dp(uintptr_t data)1418   void dp(uintptr_t data) { dd(data); }
1419   void dd(Label* label);
1420 
1421   // Check if there is less than kGap bytes available in the buffer.
1422   // If this is the case, we need to grow the buffer before emitting
1423   // an instruction or relocation information.
buffer_overflow()1424   inline bool buffer_overflow() const {
1425     return pc_ >= reloc_info_writer.pos() - kGap;
1426   }
1427 
1428   // Get the number of bytes available in the buffer.
available_space()1429   inline int available_space() const { return reloc_info_writer.pos() - pc_; }
1430 
1431   static bool IsNop(Address addr);
1432 
positions_recorder()1433   PositionsRecorder* positions_recorder() { return &positions_recorder_; }
1434 
relocation_writer_size()1435   int relocation_writer_size() {
1436     return (buffer_ + buffer_size_) - reloc_info_writer.pos();
1437   }
1438 
1439   // Avoid overflows for displacements etc.
1440   static const int kMaximalBufferSize = 512*MB;
1441 
byte_at(int pos)1442   byte byte_at(int pos) { return buffer_[pos]; }
set_byte_at(int pos,byte value)1443   void set_byte_at(int pos, byte value) { buffer_[pos] = value; }
1444 
PatchConstantPoolAccessInstruction(int pc_offset,int offset,ConstantPoolEntry::Access access,ConstantPoolEntry::Type type)1445   void PatchConstantPoolAccessInstruction(int pc_offset, int offset,
1446                                           ConstantPoolEntry::Access access,
1447                                           ConstantPoolEntry::Type type) {
1448     // No embedded constant pool support.
1449     UNREACHABLE();
1450   }
1451 
1452  protected:
1453   void emit_sse_operand(XMMRegister reg, const Operand& adr);
1454   void emit_sse_operand(XMMRegister dst, XMMRegister src);
1455   void emit_sse_operand(Register dst, XMMRegister src);
1456   void emit_sse_operand(XMMRegister dst, Register src);
1457 
addr_at(int pos)1458   byte* addr_at(int pos) { return buffer_ + pos; }
1459 
1460 
1461  private:
long_at(int pos)1462   uint32_t long_at(int pos)  {
1463     return *reinterpret_cast<uint32_t*>(addr_at(pos));
1464   }
long_at_put(int pos,uint32_t x)1465   void long_at_put(int pos, uint32_t x)  {
1466     *reinterpret_cast<uint32_t*>(addr_at(pos)) = x;
1467   }
1468 
1469   // code emission
1470   void GrowBuffer();
1471   inline void emit(uint32_t x);
1472   inline void emit(Handle<Object> handle);
1473   inline void emit(uint32_t x,
1474                    RelocInfo::Mode rmode,
1475                    TypeFeedbackId id = TypeFeedbackId::None());
1476   inline void emit(Handle<Code> code,
1477                    RelocInfo::Mode rmode,
1478                    TypeFeedbackId id = TypeFeedbackId::None());
1479   inline void emit(const Immediate& x);
1480   inline void emit_w(const Immediate& x);
1481   inline void emit_q(uint64_t x);
1482 
1483   // Emit the code-object-relative offset of the label's position
1484   inline void emit_code_relative_offset(Label* label);
1485 
1486   // instruction generation
1487   void emit_arith_b(int op1, int op2, Register dst, int imm8);
1488 
1489   // Emit a basic arithmetic instruction (i.e. first byte of the family is 0x81)
1490   // with a given destination expression and an immediate operand.  It attempts
1491   // to use the shortest encoding possible.
1492   // sel specifies the /n in the modrm byte (see the Intel PRM).
1493   void emit_arith(int sel, Operand dst, const Immediate& x);
1494 
1495   void emit_operand(Register reg, const Operand& adr);
1496 
1497   void emit_label(Label* label);
1498 
1499   void emit_farith(int b1, int b2, int i);
1500 
1501   // Emit vex prefix
1502   enum SIMDPrefix { kNone = 0x0, k66 = 0x1, kF3 = 0x2, kF2 = 0x3 };
1503   enum VectorLength { kL128 = 0x0, kL256 = 0x4, kLIG = kL128, kLZ = kL128 };
1504   enum VexW { kW0 = 0x0, kW1 = 0x80, kWIG = kW0 };
1505   enum LeadingOpcode { k0F = 0x1, k0F38 = 0x2, k0F3A = 0x3 };
1506   inline void emit_vex_prefix(XMMRegister v, VectorLength l, SIMDPrefix pp,
1507                               LeadingOpcode m, VexW w);
1508   inline void emit_vex_prefix(Register v, VectorLength l, SIMDPrefix pp,
1509                               LeadingOpcode m, VexW w);
1510 
1511   // labels
1512   void print(Label* L);
1513   void bind_to(Label* L, int pos);
1514 
1515   // displacements
1516   inline Displacement disp_at(Label* L);
1517   inline void disp_at_put(Label* L, Displacement disp);
1518   inline void emit_disp(Label* L, Displacement::Type type);
1519   inline void emit_near_disp(Label* L);
1520 
1521   // Most BMI instructions are similiar.
1522   void bmi1(byte op, Register reg, Register vreg, const Operand& rm);
1523   void bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
1524             const Operand& rm);
1525 
1526   // record reloc info for current pc_
1527   void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1528 
1529   friend class CodePatcher;
1530   friend class EnsureSpace;
1531 
1532   // Internal reference positions, required for (potential) patching in
1533   // GrowBuffer(); contains only those internal references whose labels
1534   // are already bound.
1535   std::deque<int> internal_reference_positions_;
1536 
1537   // code generation
1538   RelocInfoWriter reloc_info_writer;
1539 
1540   PositionsRecorder positions_recorder_;
1541   friend class PositionsRecorder;
1542 };
1543 
1544 
1545 // Helper class that ensures that there is enough space for generating
1546 // instructions and relocation information.  The constructor makes
1547 // sure that there is enough space and (in debug mode) the destructor
1548 // checks that we did not generate too much.
1549 class EnsureSpace BASE_EMBEDDED {
1550  public:
EnsureSpace(Assembler * assembler)1551   explicit EnsureSpace(Assembler* assembler) : assembler_(assembler) {
1552     if (assembler_->buffer_overflow()) assembler_->GrowBuffer();
1553 #ifdef DEBUG
1554     space_before_ = assembler_->available_space();
1555 #endif
1556   }
1557 
1558 #ifdef DEBUG
~EnsureSpace()1559   ~EnsureSpace() {
1560     int bytes_generated = space_before_ - assembler_->available_space();
1561     DCHECK(bytes_generated < assembler_->kGap);
1562   }
1563 #endif
1564 
1565  private:
1566   Assembler* assembler_;
1567 #ifdef DEBUG
1568   int space_before_;
1569 #endif
1570 };
1571 
1572 }  // namespace internal
1573 }  // namespace v8
1574 
1575 #endif  // V8_IA32_ASSEMBLER_IA32_H_
1576