1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
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.
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.
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.
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.
35 // A light-weight IA32 Assembler.
37 #ifndef V8_IA32_ASSEMBLER_IA32_H_
38 #define V8_IA32_ASSEMBLER_IA32_H_
42 #include "src/assembler.h"
43 #include "src/compiler.h"
44 #include "src/isolate.h"
51 // 1) We would prefer to use an enum, but enum values are assignment-
52 // compatible with int, which has caused code-generation bugs.
54 // 2) We would prefer to use a class instead of a struct but we don't like
55 // the register initialization to depend on the particular initialization
56 // order (which appears to be different on OS X, Linux, and Windows for the
57 // installed versions of C++ we tried). Using a struct permits C-style
58 // "initialization". Also, the Register objects cannot be const as this
59 // forces initialization stubs in MSVC, making us dependent on initialization
62 // 3) By not using an enum, we are possibly preventing the compiler from
63 // doing certain constant folds, which may significantly reduce the
64 // code generated for some assembly instructions (because they boil down
65 // to a few constants). If this is a problem, we could change the code
66 // such that we use an enum in optimized mode, and the struct in debug
67 // mode. This way we get the compile-time error checking in debug mode
68 // and best performance in optimized code.
71 static const int kMaxNumAllocatableRegisters = 6;
72 static int NumAllocatableRegisters() {
73 return kMaxNumAllocatableRegisters;
75 static const int kNumRegisters = 8;
77 static inline const char* AllocationIndexToString(int index);
79 static inline int ToAllocationIndex(Register reg);
81 static inline Register FromAllocationIndex(int index);
83 static Register from_code(int code) {
85 DCHECK(code < kNumRegisters);
86 Register r = { code };
89 bool is_valid() const { return 0 <= code_ && code_ < kNumRegisters; }
90 bool is(Register reg) const { return code_ == reg.code_; }
91 // eax, ebx, ecx and edx are byte registers, the rest are not.
92 bool is_byte_register() const { return code_ <= 3; }
102 // Unfortunately we can't make this private in a struct.
106 const int kRegister_eax_Code = 0;
107 const int kRegister_ecx_Code = 1;
108 const int kRegister_edx_Code = 2;
109 const int kRegister_ebx_Code = 3;
110 const int kRegister_esp_Code = 4;
111 const int kRegister_ebp_Code = 5;
112 const int kRegister_esi_Code = 6;
113 const int kRegister_edi_Code = 7;
114 const int kRegister_no_reg_Code = -1;
116 const Register eax = { kRegister_eax_Code };
117 const Register ecx = { kRegister_ecx_Code };
118 const Register edx = { kRegister_edx_Code };
119 const Register ebx = { kRegister_ebx_Code };
120 const Register esp = { kRegister_esp_Code };
121 const Register ebp = { kRegister_ebp_Code };
122 const Register esi = { kRegister_esi_Code };
123 const Register edi = { kRegister_edi_Code };
124 const Register no_reg = { kRegister_no_reg_Code };
127 inline const char* Register::AllocationIndexToString(int index) {
128 DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters);
129 // This is the mapping of allocation indices to registers.
130 const char* const kNames[] = { "eax", "ecx", "edx", "ebx", "esi", "edi" };
131 return kNames[index];
135 inline int Register::ToAllocationIndex(Register reg) {
136 DCHECK(reg.is_valid() && !reg.is(esp) && !reg.is(ebp));
137 return (reg.code() >= 6) ? reg.code() - 2 : reg.code();
141 inline Register Register::FromAllocationIndex(int index) {
142 DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters);
143 return (index >= 4) ? from_code(index + 2) : from_code(index);
148 static const int kMaxNumAllocatableRegisters = 7;
149 static const int kMaxNumRegisters = 8;
150 static int NumAllocatableRegisters() {
151 return kMaxNumAllocatableRegisters;
154 // TODO(turbofan): Proper support for float32.
155 static int NumAllocatableAliasedRegisters() {
156 return NumAllocatableRegisters();
159 static int ToAllocationIndex(XMMRegister reg) {
160 DCHECK(reg.code() != 0);
161 return reg.code() - 1;
164 static XMMRegister FromAllocationIndex(int index) {
165 DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters);
166 return from_code(index + 1);
169 static XMMRegister from_code(int code) {
170 XMMRegister result = { code };
174 bool is_valid() const {
175 return 0 <= code_ && code_ < kMaxNumRegisters;
183 bool is(XMMRegister reg) const { return code_ == reg.code_; }
185 static const char* AllocationIndexToString(int index) {
186 DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters);
187 const char* const names[] = {
203 typedef XMMRegister DoubleRegister;
206 const XMMRegister xmm0 = { 0 };
207 const XMMRegister xmm1 = { 1 };
208 const XMMRegister xmm2 = { 2 };
209 const XMMRegister xmm3 = { 3 };
210 const XMMRegister xmm4 = { 4 };
211 const XMMRegister xmm5 = { 5 };
212 const XMMRegister xmm6 = { 6 };
213 const XMMRegister xmm7 = { 7 };
214 const XMMRegister no_xmm_reg = { -1 };
218 // any value < 0 is considered no_condition
240 not_carry = above_equal,
242 not_zero = not_equal,
248 // Returns the equivalent of !cc.
249 // Negation of the default no_condition (-1) results in a non-default
250 // no_condition value (-2). As long as tests for no_condition check
251 // for condition < 0, this will work as expected.
252 inline Condition NegateCondition(Condition cc) {
253 return static_cast<Condition>(cc ^ 1);
257 // Commute a condition such that {a cond b == b cond' a}.
258 inline Condition CommuteCondition(Condition cc) {
275 return greater_equal;
283 kRoundToNearest = 0x0,
290 // -----------------------------------------------------------------------------
291 // Machine instruction Immediates
293 class Immediate BASE_EMBEDDED {
295 inline explicit Immediate(int x);
296 inline explicit Immediate(const ExternalReference& ext);
297 inline explicit Immediate(Handle<Object> handle);
298 inline explicit Immediate(Smi* value);
299 inline explicit Immediate(Address addr);
301 static Immediate CodeRelativeOffset(Label* label) {
302 return Immediate(label);
305 bool is_zero() const { return x_ == 0 && RelocInfo::IsNone(rmode_); }
306 bool is_int8() const {
307 return -128 <= x_ && x_ < 128 && RelocInfo::IsNone(rmode_);
309 bool is_int16() const {
310 return -32768 <= x_ && x_ < 32768 && RelocInfo::IsNone(rmode_);
314 inline explicit Immediate(Label* value);
317 RelocInfo::Mode rmode_;
319 friend class Operand;
320 friend class Assembler;
321 friend class MacroAssembler;
325 // -----------------------------------------------------------------------------
326 // Machine instruction Operands
333 times_int_size = times_4,
334 times_half_pointer_size = times_2,
335 times_pointer_size = times_4,
336 times_twice_pointer_size = times_8
340 class Operand BASE_EMBEDDED {
343 INLINE(explicit Operand(Register reg));
346 INLINE(explicit Operand(XMMRegister xmm_reg));
349 INLINE(explicit Operand(int32_t disp, RelocInfo::Mode rmode));
352 INLINE(explicit Operand(Immediate imm));
355 explicit Operand(Register base, int32_t disp,
356 RelocInfo::Mode rmode = RelocInfo::NONE32);
358 // [base + index*scale + disp/r]
359 explicit Operand(Register base,
363 RelocInfo::Mode rmode = RelocInfo::NONE32);
365 // [index*scale + disp/r]
366 explicit Operand(Register index,
369 RelocInfo::Mode rmode = RelocInfo::NONE32);
371 static Operand JumpTable(Register index, ScaleFactor scale, Label* table) {
372 return Operand(index, scale, reinterpret_cast<int32_t>(table),
373 RelocInfo::INTERNAL_REFERENCE);
376 static Operand StaticVariable(const ExternalReference& ext) {
377 return Operand(reinterpret_cast<int32_t>(ext.address()),
378 RelocInfo::EXTERNAL_REFERENCE);
381 static Operand StaticArray(Register index,
383 const ExternalReference& arr) {
384 return Operand(index, scale, reinterpret_cast<int32_t>(arr.address()),
385 RelocInfo::EXTERNAL_REFERENCE);
388 static Operand ForCell(Handle<Cell> cell) {
389 AllowDeferredHandleDereference embedding_raw_address;
390 return Operand(reinterpret_cast<int32_t>(cell.location()),
394 static Operand ForRegisterPlusImmediate(Register base, Immediate imm) {
395 return Operand(base, imm.x_, imm.rmode_);
398 // Returns true if this Operand is a wrapper for the specified register.
399 bool is_reg(Register reg) const;
401 // Returns true if this Operand is a wrapper for one register.
402 bool is_reg_only() const;
404 // Asserts that this Operand is a wrapper for one register and returns the
406 Register reg() const;
409 // Set the ModRM byte without an encoded 'reg' register. The
410 // register is encoded later as part of the emit_operand operation.
411 inline void set_modrm(int mod, Register rm);
413 inline void set_sib(ScaleFactor scale, Register index, Register base);
414 inline void set_disp8(int8_t disp);
415 inline void set_dispr(int32_t disp, RelocInfo::Mode rmode);
418 // The number of bytes in buf_.
420 // Only valid if len_ > 4.
421 RelocInfo::Mode rmode_;
423 friend class Assembler;
424 friend class MacroAssembler;
428 // -----------------------------------------------------------------------------
429 // A Displacement describes the 32bit immediate field of an instruction which
430 // may be used together with a Label in order to refer to a yet unknown code
431 // position. Displacements stored in the instruction stream are used to describe
432 // the instruction and to chain a list of instructions using the same Label.
433 // A Displacement contains 2 different fields:
435 // next field: position of next displacement in the chain (0 = end of list)
436 // type field: instruction type
438 // A next value of null (0) indicates the end of a chain (note that there can
439 // be no displacement at position zero, because there is always at least one
440 // instruction byte before the displacement).
442 // Displacement _data field layout
444 // |31.....2|1......0|
447 class Displacement BASE_EMBEDDED {
449 enum Type { UNCONDITIONAL_JUMP, CODE_RELATIVE, OTHER, CODE_ABSOLUTE };
451 int data() const { return data_; }
452 Type type() const { return TypeField::decode(data_); }
453 void next(Label* L) const {
454 int n = NextField::decode(data_);
455 n > 0 ? L->link_to(n) : L->Unuse();
457 void link_to(Label* L) { init(L, type()); }
459 explicit Displacement(int data) { data_ = data; }
461 Displacement(Label* L, Type type) { init(L, type); }
464 PrintF("%s (%x) ", (type() == UNCONDITIONAL_JUMP ? "jmp" : "[other]"),
465 NextField::decode(data_));
471 class TypeField: public BitField<Type, 0, 2> {};
472 class NextField: public BitField<int, 2, 32-2> {};
474 void init(Label* L, Type type);
478 class Assembler : public AssemblerBase {
480 // We check before assembling an instruction that there is sufficient
481 // space to write an instruction and its relocation information.
482 // The relocation writer's position must be kGap bytes above the end of
483 // the generated instructions. This leaves enough space for the
484 // longest possible ia32 instruction, 15 bytes, and the longest possible
485 // relocation information encoding, RelocInfoWriter::kMaxLength == 16.
486 // (There is a 15 byte limit on ia32 instruction length that rules out some
487 // otherwise valid instructions.)
488 // This allows for a single, fast space check per instruction.
489 static const int kGap = 32;
492 // Create an assembler. Instructions and relocation information are emitted
493 // into a buffer, with the instructions starting from the beginning and the
494 // relocation information starting from the end of the buffer. See CodeDesc
495 // for a detailed comment on the layout (globals.h).
497 // If the provided buffer is NULL, the assembler allocates and grows its own
498 // buffer, and buffer_size determines the initial buffer size. The buffer is
499 // owned by the assembler and deallocated upon destruction of the assembler.
501 // If the provided buffer is not NULL, the assembler uses the provided buffer
502 // for code generation and assumes its size to be buffer_size. If the buffer
503 // is too small, a fatal error occurs. No deallocation of the buffer is done
504 // upon destruction of the assembler.
505 // TODO(vitalyr): the assembler does not need an isolate.
506 Assembler(Isolate* isolate, void* buffer, int buffer_size);
507 virtual ~Assembler() { }
509 // GetCode emits any pending (non-emitted) code and fills the descriptor
510 // desc. GetCode() is idempotent; it returns the same result if no other
511 // Assembler functions are invoked in between GetCode() calls.
512 void GetCode(CodeDesc* desc);
514 // Read/Modify the code target in the branch/call instruction at pc.
515 inline static Address target_address_at(Address pc, Address constant_pool);
516 inline static void set_target_address_at(
517 Address pc, Address constant_pool, Address target,
518 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
519 static inline Address target_address_at(Address pc, Code* code) {
520 Address constant_pool = code ? code->constant_pool() : NULL;
521 return target_address_at(pc, constant_pool);
523 static inline void set_target_address_at(Address pc,
526 ICacheFlushMode icache_flush_mode =
527 FLUSH_ICACHE_IF_NEEDED) {
528 Address constant_pool = code ? code->constant_pool() : NULL;
529 set_target_address_at(pc, constant_pool, target);
532 // Return the code target address at a call site from the return address
533 // of that call in the instruction stream.
534 inline static Address target_address_from_return_address(Address pc);
536 // This sets the branch destination (which is in the instruction on x86).
537 // This is for calls and branches within generated code.
538 inline static void deserialization_set_special_target_at(
539 Address instruction_payload, Code* code, Address target) {
540 set_target_address_at(instruction_payload, code, target);
543 // This sets the internal reference at the pc.
544 inline static void deserialization_set_target_internal_reference_at(
545 Address pc, Address target,
546 RelocInfo::Mode mode = RelocInfo::INTERNAL_REFERENCE);
548 static const int kSpecialTargetSize = kPointerSize;
550 // Distance between the address of the code target in the call instruction
551 // and the return address
552 static const int kCallTargetAddressOffset = kPointerSize;
554 static const int kCallInstructionLength = 5;
556 // The debug break slot must be able to contain a call instruction.
557 static const int kDebugBreakSlotLength = kCallInstructionLength;
559 // Distance between start of patched debug break slot and the emitted address
561 static const int kPatchDebugBreakSlotAddressOffset = 1; // JMP imm32.
563 // One byte opcode for test al, 0xXX.
564 static const byte kTestAlByte = 0xA8;
565 // One byte opcode for nop.
566 static const byte kNopByte = 0x90;
568 // One byte opcode for a short unconditional jump.
569 static const byte kJmpShortOpcode = 0xEB;
570 // One byte prefix for a short conditional jump.
571 static const byte kJccShortPrefix = 0x70;
572 static const byte kJncShortOpcode = kJccShortPrefix | not_carry;
573 static const byte kJcShortOpcode = kJccShortPrefix | carry;
574 static const byte kJnzShortOpcode = kJccShortPrefix | not_zero;
575 static const byte kJzShortOpcode = kJccShortPrefix | zero;
578 // ---------------------------------------------------------------------------
581 // - function names correspond one-to-one to ia32 instruction mnemonics
582 // - unless specified otherwise, instructions operate on 32bit operands
583 // - instructions on 8bit (byte) operands/registers have a trailing '_b'
584 // - instructions on 16bit (word) operands/registers have a trailing '_w'
585 // - naming conflicts with C++ keywords are resolved via a trailing '_'
587 // NOTE ON INTERFACE: Currently, the interface is not very consistent
588 // in the sense that some operations (e.g. mov()) can be called in more
589 // the one way to generate the same instruction: The Register argument
590 // can in some cases be replaced with an Operand(Register) argument.
591 // This should be cleaned up and made more orthogonal. The questions
592 // is: should we always use Operands instead of Registers where an
593 // Operand is possible, or should we have a Register (overloaded) form
594 // instead? We must be careful to make sure that the selected instruction
595 // is obvious from the parameters to avoid hard-to-find code generation
598 // Insert the smallest number of nop instructions
599 // possible to align the pc offset to a multiple
600 // of m. m must be a power of 2.
602 // Insert the smallest number of zero bytes possible to align the pc offset
603 // to a mulitple of m. m must be a power of 2 (>= 2).
604 void DataAlign(int m);
605 void Nop(int bytes = 1);
606 // Aligns code to something that's optimal for a jump target for the platform.
607 void CodeTargetAlign();
616 void push(const Immediate& x);
617 void push_imm32(int32_t imm32);
618 void push(Register src);
619 void push(const Operand& src);
621 void pop(Register dst);
622 void pop(const Operand& dst);
624 void enter(const Immediate& size);
628 void mov_b(Register dst, Register src) { mov_b(dst, Operand(src)); }
629 void mov_b(Register dst, const Operand& src);
630 void mov_b(Register dst, int8_t imm8) { mov_b(Operand(dst), imm8); }
631 void mov_b(const Operand& dst, int8_t src) { mov_b(dst, Immediate(src)); }
632 void mov_b(const Operand& dst, const Immediate& src);
633 void mov_b(const Operand& dst, Register src);
635 void mov_w(Register dst, const Operand& src);
636 void mov_w(const Operand& dst, int16_t src) { mov_w(dst, Immediate(src)); }
637 void mov_w(const Operand& dst, const Immediate& src);
638 void mov_w(const Operand& dst, Register src);
640 void mov(Register dst, int32_t imm32);
641 void mov(Register dst, const Immediate& x);
642 void mov(Register dst, Handle<Object> handle);
643 void mov(Register dst, const Operand& src);
644 void mov(Register dst, Register src);
645 void mov(const Operand& dst, const Immediate& x);
646 void mov(const Operand& dst, Handle<Object> handle);
647 void mov(const Operand& dst, Register src);
649 void movsx_b(Register dst, Register src) { movsx_b(dst, Operand(src)); }
650 void movsx_b(Register dst, const Operand& src);
652 void movsx_w(Register dst, Register src) { movsx_w(dst, Operand(src)); }
653 void movsx_w(Register dst, const Operand& src);
655 void movzx_b(Register dst, Register src) { movzx_b(dst, Operand(src)); }
656 void movzx_b(Register dst, const Operand& src);
658 void movzx_w(Register dst, Register src) { movzx_w(dst, Operand(src)); }
659 void movzx_w(Register dst, const Operand& src);
662 void cmov(Condition cc, Register dst, Register src) {
663 cmov(cc, dst, Operand(src));
665 void cmov(Condition cc, Register dst, const Operand& src);
670 // Repetitive string instructions.
676 void xchg(Register dst, Register src);
677 void xchg(Register dst, const Operand& src);
680 void adc(Register dst, int32_t imm32);
681 void adc(Register dst, const Operand& src);
683 void add(Register dst, Register src) { add(dst, Operand(src)); }
684 void add(Register dst, const Operand& src);
685 void add(const Operand& dst, Register src);
686 void add(Register dst, const Immediate& imm) { add(Operand(dst), imm); }
687 void add(const Operand& dst, const Immediate& x);
689 void and_(Register dst, int32_t imm32);
690 void and_(Register dst, const Immediate& x);
691 void and_(Register dst, Register src) { and_(dst, Operand(src)); }
692 void and_(Register dst, const Operand& src);
693 void and_(const Operand& dst, Register src);
694 void and_(const Operand& dst, const Immediate& x);
696 void cmpb(Register reg, int8_t imm8) { cmpb(Operand(reg), imm8); }
697 void cmpb(const Operand& op, int8_t imm8);
698 void cmpb(Register reg, const Operand& op);
699 void cmpb(const Operand& op, Register reg);
700 void cmpb_al(const Operand& op);
701 void cmpw_ax(const Operand& op);
702 void cmpw(const Operand& op, Immediate imm16);
703 void cmp(Register reg, int32_t imm32);
704 void cmp(Register reg, Handle<Object> handle);
705 void cmp(Register reg0, Register reg1) { cmp(reg0, Operand(reg1)); }
706 void cmp(Register reg, const Operand& op);
707 void cmp(Register reg, const Immediate& imm) { cmp(Operand(reg), imm); }
708 void cmp(const Operand& op, const Immediate& imm);
709 void cmp(const Operand& op, Handle<Object> handle);
711 void dec_b(Register dst);
712 void dec_b(const Operand& dst);
714 void dec(Register dst);
715 void dec(const Operand& dst);
719 void idiv(Register src) { idiv(Operand(src)); }
720 void idiv(const Operand& src);
721 void div(Register src) { div(Operand(src)); }
722 void div(const Operand& src);
724 // Signed multiply instructions.
725 void imul(Register src); // edx:eax = eax * src.
726 void imul(Register dst, Register src) { imul(dst, Operand(src)); }
727 void imul(Register dst, const Operand& src); // dst = dst * src.
728 void imul(Register dst, Register src, int32_t imm32); // dst = src * imm32.
729 void imul(Register dst, const Operand& src, int32_t imm32);
731 void inc(Register dst);
732 void inc(const Operand& dst);
734 void lea(Register dst, const Operand& src);
736 // Unsigned multiply instruction.
737 void mul(Register src); // edx:eax = eax * reg.
739 void neg(Register dst);
740 void neg(const Operand& dst);
742 void not_(Register dst);
743 void not_(const Operand& dst);
745 void or_(Register dst, int32_t imm32);
746 void or_(Register dst, Register src) { or_(dst, Operand(src)); }
747 void or_(Register dst, const Operand& src);
748 void or_(const Operand& dst, Register src);
749 void or_(Register dst, const Immediate& imm) { or_(Operand(dst), imm); }
750 void or_(const Operand& dst, const Immediate& x);
752 void rcl(Register dst, uint8_t imm8);
753 void rcr(Register dst, uint8_t imm8);
755 void ror(Register dst, uint8_t imm8) { ror(Operand(dst), imm8); }
756 void ror(const Operand& dst, uint8_t imm8);
757 void ror_cl(Register dst) { ror_cl(Operand(dst)); }
758 void ror_cl(const Operand& dst);
760 void sar(Register dst, uint8_t imm8) { sar(Operand(dst), imm8); }
761 void sar(const Operand& dst, uint8_t imm8);
762 void sar_cl(Register dst) { sar_cl(Operand(dst)); }
763 void sar_cl(const Operand& dst);
765 void sbb(Register dst, const Operand& src);
767 void shld(Register dst, Register src) { shld(dst, Operand(src)); }
768 void shld(Register dst, const Operand& src);
770 void shl(Register dst, uint8_t imm8) { shl(Operand(dst), imm8); }
771 void shl(const Operand& dst, uint8_t imm8);
772 void shl_cl(Register dst) { shl_cl(Operand(dst)); }
773 void shl_cl(const Operand& dst);
775 void shrd(Register dst, Register src) { shrd(dst, Operand(src)); }
776 void shrd(Register dst, const Operand& src);
778 void shr(Register dst, uint8_t imm8) { shr(Operand(dst), imm8); }
779 void shr(const Operand& dst, uint8_t imm8);
780 void shr_cl(Register dst) { shr_cl(Operand(dst)); }
781 void shr_cl(const Operand& dst);
783 void sub(Register dst, const Immediate& imm) { sub(Operand(dst), imm); }
784 void sub(const Operand& dst, const Immediate& x);
785 void sub(Register dst, Register src) { sub(dst, Operand(src)); }
786 void sub(Register dst, const Operand& src);
787 void sub(const Operand& dst, Register src);
789 void test(Register reg, const Immediate& imm);
790 void test(Register reg0, Register reg1) { test(reg0, Operand(reg1)); }
791 void test(Register reg, const Operand& op);
792 void test_b(Register reg, const Operand& op);
793 void test(const Operand& op, const Immediate& imm);
794 void test_b(Register reg, uint8_t imm8);
795 void test_b(const Operand& op, uint8_t imm8);
797 void xor_(Register dst, int32_t imm32);
798 void xor_(Register dst, Register src) { xor_(dst, Operand(src)); }
799 void xor_(Register dst, const Operand& src);
800 void xor_(const Operand& dst, Register src);
801 void xor_(Register dst, const Immediate& imm) { xor_(Operand(dst), imm); }
802 void xor_(const Operand& dst, const Immediate& x);
805 void bt(const Operand& dst, Register src);
806 void bts(Register dst, Register src) { bts(Operand(dst), src); }
807 void bts(const Operand& dst, Register src);
808 void bsr(Register dst, Register src) { bsr(dst, Operand(src)); }
809 void bsr(Register dst, const Operand& src);
818 // Label operations & relative jumps (PPUM Appendix D)
820 // Takes a branch opcode (cc) and a label (L) and generates
821 // either a backward branch or a forward branch and links it
822 // to the label fixup chain. Usage:
824 // Label L; // unbound label
825 // j(cc, &L); // forward branch to unbound label
826 // bind(&L); // bind label to the current pc
827 // j(cc, &L); // backward branch to bound label
828 // bind(&L); // illegal: a label may be bound only once
830 // Note: The same Label can be used for forward and backward branches
831 // but it may be bound only once.
833 void bind(Label* L); // binds an unbound label L to the current code position
837 void call(byte* entry, RelocInfo::Mode rmode);
838 int CallSize(const Operand& adr);
839 void call(Register reg) { call(Operand(reg)); }
840 void call(const Operand& adr);
841 int CallSize(Handle<Code> code, RelocInfo::Mode mode);
842 void call(Handle<Code> code,
843 RelocInfo::Mode rmode,
844 TypeFeedbackId id = TypeFeedbackId::None());
847 // unconditional jump to L
848 void jmp(Label* L, Label::Distance distance = Label::kFar);
849 void jmp(byte* entry, RelocInfo::Mode rmode);
850 void jmp(Register reg) { jmp(Operand(reg)); }
851 void jmp(const Operand& adr);
852 void jmp(Handle<Code> code, RelocInfo::Mode rmode);
857 Label::Distance distance = Label::kFar);
858 void j(Condition cc, byte* entry, RelocInfo::Mode rmode);
859 void j(Condition cc, Handle<Code> code);
861 // Floating-point operations
870 void fld_s(const Operand& adr);
871 void fld_d(const Operand& adr);
873 void fstp_s(const Operand& adr);
874 void fst_s(const Operand& adr);
875 void fstp_d(const Operand& adr);
876 void fst_d(const Operand& adr);
878 void fild_s(const Operand& adr);
879 void fild_d(const Operand& adr);
881 void fist_s(const Operand& adr);
883 void fistp_s(const Operand& adr);
884 void fistp_d(const Operand& adr);
886 // The fisttp instructions require SSE3.
887 void fisttp_s(const Operand& adr);
888 void fisttp_d(const Operand& adr);
909 void fisub_s(const Operand& adr);
911 void faddp(int i = 1);
912 void fsubp(int i = 1);
913 void fsubrp(int i = 1);
914 void fmulp(int i = 1);
915 void fdivp(int i = 1);
919 void fxch(int i = 1);
921 void ffree(int i = 0);
936 void setcc(Condition cc, Register reg);
941 void addss(XMMRegister dst, XMMRegister src) { addss(dst, Operand(src)); }
942 void addss(XMMRegister dst, const Operand& src);
943 void subss(XMMRegister dst, XMMRegister src) { subss(dst, Operand(src)); }
944 void subss(XMMRegister dst, const Operand& src);
945 void mulss(XMMRegister dst, XMMRegister src) { mulss(dst, Operand(src)); }
946 void mulss(XMMRegister dst, const Operand& src);
947 void divss(XMMRegister dst, XMMRegister src) { divss(dst, Operand(src)); }
948 void divss(XMMRegister dst, const Operand& src);
949 void sqrtss(XMMRegister dst, XMMRegister src) { sqrtss(dst, Operand(src)); }
950 void sqrtss(XMMRegister dst, const Operand& src);
952 void ucomiss(XMMRegister dst, XMMRegister src) { ucomiss(dst, Operand(src)); }
953 void ucomiss(XMMRegister dst, const Operand& src);
954 void movaps(XMMRegister dst, XMMRegister src);
955 void shufps(XMMRegister dst, XMMRegister src, byte imm8);
957 void maxss(XMMRegister dst, XMMRegister src) { maxss(dst, Operand(src)); }
958 void maxss(XMMRegister dst, const Operand& src);
959 void minss(XMMRegister dst, XMMRegister src) { minss(dst, Operand(src)); }
960 void minss(XMMRegister dst, const Operand& src);
962 void andps(XMMRegister dst, const Operand& src);
963 void andps(XMMRegister dst, XMMRegister src) { andps(dst, Operand(src)); }
964 void xorps(XMMRegister dst, const Operand& src);
965 void xorps(XMMRegister dst, XMMRegister src) { xorps(dst, Operand(src)); }
966 void orps(XMMRegister dst, const Operand& src);
967 void orps(XMMRegister dst, XMMRegister src) { orps(dst, Operand(src)); }
969 void addps(XMMRegister dst, const Operand& src);
970 void addps(XMMRegister dst, XMMRegister src) { addps(dst, Operand(src)); }
971 void subps(XMMRegister dst, const Operand& src);
972 void subps(XMMRegister dst, XMMRegister src) { subps(dst, Operand(src)); }
973 void mulps(XMMRegister dst, const Operand& src);
974 void mulps(XMMRegister dst, XMMRegister src) { mulps(dst, Operand(src)); }
975 void divps(XMMRegister dst, const Operand& src);
976 void divps(XMMRegister dst, XMMRegister src) { divps(dst, Operand(src)); }
979 void cvttss2si(Register dst, const Operand& src);
980 void cvttss2si(Register dst, XMMRegister src) {
981 cvttss2si(dst, Operand(src));
983 void cvttsd2si(Register dst, const Operand& src);
984 void cvttsd2si(Register dst, XMMRegister src) {
985 cvttsd2si(dst, Operand(src));
987 void cvtsd2si(Register dst, XMMRegister src);
989 void cvtsi2sd(XMMRegister dst, Register src) { cvtsi2sd(dst, Operand(src)); }
990 void cvtsi2sd(XMMRegister dst, const Operand& src);
991 void cvtss2sd(XMMRegister dst, const Operand& src);
992 void cvtss2sd(XMMRegister dst, XMMRegister src) {
993 cvtss2sd(dst, Operand(src));
995 void cvtsd2ss(XMMRegister dst, const Operand& src);
996 void cvtsd2ss(XMMRegister dst, XMMRegister src) {
997 cvtsd2ss(dst, Operand(src));
999 void addsd(XMMRegister dst, XMMRegister src) { addsd(dst, Operand(src)); }
1000 void addsd(XMMRegister dst, const Operand& src);
1001 void subsd(XMMRegister dst, XMMRegister src) { subsd(dst, Operand(src)); }
1002 void subsd(XMMRegister dst, const Operand& src);
1003 void mulsd(XMMRegister dst, XMMRegister src) { mulsd(dst, Operand(src)); }
1004 void mulsd(XMMRegister dst, const Operand& src);
1005 void divsd(XMMRegister dst, XMMRegister src) { divsd(dst, Operand(src)); }
1006 void divsd(XMMRegister dst, const Operand& src);
1007 void xorpd(XMMRegister dst, XMMRegister src);
1008 void sqrtsd(XMMRegister dst, XMMRegister src) { sqrtsd(dst, Operand(src)); }
1009 void sqrtsd(XMMRegister dst, const Operand& src);
1011 void andpd(XMMRegister dst, XMMRegister src);
1012 void orpd(XMMRegister dst, XMMRegister src);
1014 void ucomisd(XMMRegister dst, XMMRegister src) { ucomisd(dst, Operand(src)); }
1015 void ucomisd(XMMRegister dst, const Operand& src);
1017 void roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
1019 void movmskpd(Register dst, XMMRegister src);
1020 void movmskps(Register dst, XMMRegister src);
1022 void cmpltsd(XMMRegister dst, XMMRegister src);
1023 void pcmpeqd(XMMRegister dst, XMMRegister src);
1025 void punpckldq(XMMRegister dst, XMMRegister src);
1026 void punpckhdq(XMMRegister dst, XMMRegister src);
1028 void maxsd(XMMRegister dst, XMMRegister src) { maxsd(dst, Operand(src)); }
1029 void maxsd(XMMRegister dst, const Operand& src);
1030 void minsd(XMMRegister dst, XMMRegister src) { minsd(dst, Operand(src)); }
1031 void minsd(XMMRegister dst, const Operand& src);
1033 void movdqa(XMMRegister dst, const Operand& src);
1034 void movdqa(const Operand& dst, XMMRegister src);
1035 void movdqu(XMMRegister dst, const Operand& src);
1036 void movdqu(const Operand& dst, XMMRegister src);
1037 void movdq(bool aligned, XMMRegister dst, const Operand& src) {
1045 void movd(XMMRegister dst, Register src) { movd(dst, Operand(src)); }
1046 void movd(XMMRegister dst, const Operand& src);
1047 void movd(Register dst, XMMRegister src) { movd(Operand(dst), src); }
1048 void movd(const Operand& dst, XMMRegister src);
1049 void movsd(XMMRegister dst, XMMRegister src) { movsd(dst, Operand(src)); }
1050 void movsd(XMMRegister dst, const Operand& src);
1051 void movsd(const Operand& dst, XMMRegister src);
1054 void movss(XMMRegister dst, const Operand& src);
1055 void movss(const Operand& dst, XMMRegister src);
1056 void movss(XMMRegister dst, XMMRegister src) { movss(dst, Operand(src)); }
1057 void extractps(Register dst, XMMRegister src, byte imm8);
1059 void pand(XMMRegister dst, XMMRegister src);
1060 void pxor(XMMRegister dst, XMMRegister src);
1061 void por(XMMRegister dst, XMMRegister src);
1062 void ptest(XMMRegister dst, XMMRegister src);
1064 void pslld(XMMRegister reg, int8_t shift);
1065 void psrld(XMMRegister reg, int8_t shift);
1066 void psllq(XMMRegister reg, int8_t shift);
1067 void psllq(XMMRegister dst, XMMRegister src);
1068 void psrlq(XMMRegister reg, int8_t shift);
1069 void psrlq(XMMRegister dst, XMMRegister src);
1070 void pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle);
1071 void pextrd(Register dst, XMMRegister src, int8_t offset) {
1072 pextrd(Operand(dst), src, offset);
1074 void pextrd(const Operand& dst, XMMRegister src, int8_t offset);
1075 void pinsrd(XMMRegister dst, Register src, int8_t offset) {
1076 pinsrd(dst, Operand(src), offset);
1078 void pinsrd(XMMRegister dst, const Operand& src, int8_t offset);
1081 void vfmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1082 vfmadd132sd(dst, src1, Operand(src2));
1084 void vfmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1085 vfmadd213sd(dst, src1, Operand(src2));
1087 void vfmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1088 vfmadd231sd(dst, src1, Operand(src2));
1090 void vfmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1091 vfmasd(0x99, dst, src1, src2);
1093 void vfmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1094 vfmasd(0xa9, dst, src1, src2);
1096 void vfmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1097 vfmasd(0xb9, dst, src1, src2);
1099 void vfmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1100 vfmsub132sd(dst, src1, Operand(src2));
1102 void vfmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1103 vfmsub213sd(dst, src1, Operand(src2));
1105 void vfmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1106 vfmsub231sd(dst, src1, Operand(src2));
1108 void vfmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1109 vfmasd(0x9b, dst, src1, src2);
1111 void vfmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1112 vfmasd(0xab, dst, src1, src2);
1114 void vfmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1115 vfmasd(0xbb, dst, src1, src2);
1117 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1118 vfnmadd132sd(dst, src1, Operand(src2));
1120 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1121 vfnmadd213sd(dst, src1, Operand(src2));
1123 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1124 vfnmadd231sd(dst, src1, Operand(src2));
1126 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1127 vfmasd(0x9d, dst, src1, src2);
1129 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1130 vfmasd(0xad, dst, src1, src2);
1132 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1133 vfmasd(0xbd, dst, src1, src2);
1135 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1136 vfnmsub132sd(dst, src1, Operand(src2));
1138 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1139 vfnmsub213sd(dst, src1, Operand(src2));
1141 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1142 vfnmsub231sd(dst, src1, Operand(src2));
1144 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1145 vfmasd(0x9f, dst, src1, src2);
1147 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1148 vfmasd(0xaf, dst, src1, src2);
1150 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1151 vfmasd(0xbf, dst, src1, src2);
1153 void vfmasd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1155 void vfmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1156 vfmadd132ss(dst, src1, Operand(src2));
1158 void vfmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1159 vfmadd213ss(dst, src1, Operand(src2));
1161 void vfmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1162 vfmadd231ss(dst, src1, Operand(src2));
1164 void vfmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1165 vfmass(0x99, dst, src1, src2);
1167 void vfmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1168 vfmass(0xa9, dst, src1, src2);
1170 void vfmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1171 vfmass(0xb9, dst, src1, src2);
1173 void vfmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1174 vfmsub132ss(dst, src1, Operand(src2));
1176 void vfmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1177 vfmsub213ss(dst, src1, Operand(src2));
1179 void vfmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1180 vfmsub231ss(dst, src1, Operand(src2));
1182 void vfmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1183 vfmass(0x9b, dst, src1, src2);
1185 void vfmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1186 vfmass(0xab, dst, src1, src2);
1188 void vfmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1189 vfmass(0xbb, dst, src1, src2);
1191 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1192 vfnmadd132ss(dst, src1, Operand(src2));
1194 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1195 vfnmadd213ss(dst, src1, Operand(src2));
1197 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1198 vfnmadd231ss(dst, src1, Operand(src2));
1200 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1201 vfmass(0x9d, dst, src1, src2);
1203 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1204 vfmass(0xad, dst, src1, src2);
1206 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1207 vfmass(0xbd, dst, src1, src2);
1209 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1210 vfnmsub132ss(dst, src1, Operand(src2));
1212 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1213 vfnmsub213ss(dst, src1, Operand(src2));
1215 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1216 vfnmsub231ss(dst, src1, Operand(src2));
1218 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1219 vfmass(0x9f, dst, src1, src2);
1221 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1222 vfmass(0xaf, dst, src1, src2);
1224 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1225 vfmass(0xbf, dst, src1, src2);
1227 void vfmass(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1229 void vaddsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1230 vaddsd(dst, src1, Operand(src2));
1232 void vaddsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1233 vsd(0x58, dst, src1, src2);
1235 void vsubsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1236 vsubsd(dst, src1, Operand(src2));
1238 void vsubsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1239 vsd(0x5c, dst, src1, src2);
1241 void vmulsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1242 vmulsd(dst, src1, Operand(src2));
1244 void vmulsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1245 vsd(0x59, dst, src1, src2);
1247 void vdivsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1248 vdivsd(dst, src1, Operand(src2));
1250 void vdivsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1251 vsd(0x5e, dst, src1, src2);
1253 void vmaxsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1254 vmaxsd(dst, src1, Operand(src2));
1256 void vmaxsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1257 vsd(0x5f, dst, src1, src2);
1259 void vminsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1260 vminsd(dst, src1, Operand(src2));
1262 void vminsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1263 vsd(0x5d, dst, src1, src2);
1265 void vsd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1267 void vaddss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1268 vaddss(dst, src1, Operand(src2));
1270 void vaddss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1271 vss(0x58, dst, src1, src2);
1273 void vsubss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1274 vsubss(dst, src1, Operand(src2));
1276 void vsubss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1277 vss(0x5c, dst, src1, src2);
1279 void vmulss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1280 vmulss(dst, src1, Operand(src2));
1282 void vmulss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1283 vss(0x59, dst, src1, src2);
1285 void vdivss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1286 vdivss(dst, src1, Operand(src2));
1288 void vdivss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1289 vss(0x5e, dst, src1, src2);
1291 void vmaxss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1292 vmaxss(dst, src1, Operand(src2));
1294 void vmaxss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1295 vss(0x5f, dst, src1, src2);
1297 void vminss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1298 vminss(dst, src1, Operand(src2));
1300 void vminss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1301 vss(0x5d, dst, src1, src2);
1303 void vss(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1306 void andn(Register dst, Register src1, Register src2) {
1307 andn(dst, src1, Operand(src2));
1309 void andn(Register dst, Register src1, const Operand& src2) {
1310 bmi1(0xf2, dst, src1, src2);
1312 void bextr(Register dst, Register src1, Register src2) {
1313 bextr(dst, Operand(src1), src2);
1315 void bextr(Register dst, const Operand& src1, Register src2) {
1316 bmi1(0xf7, dst, src2, src1);
1318 void blsi(Register dst, Register src) { blsi(dst, Operand(src)); }
1319 void blsi(Register dst, const Operand& src) {
1320 Register ireg = {3};
1321 bmi1(0xf3, ireg, dst, src);
1323 void blsmsk(Register dst, Register src) { blsmsk(dst, Operand(src)); }
1324 void blsmsk(Register dst, const Operand& src) {
1325 Register ireg = {2};
1326 bmi1(0xf3, ireg, dst, src);
1328 void blsr(Register dst, Register src) { blsr(dst, Operand(src)); }
1329 void blsr(Register dst, const Operand& src) {
1330 Register ireg = {1};
1331 bmi1(0xf3, ireg, dst, src);
1333 void tzcnt(Register dst, Register src) { tzcnt(dst, Operand(src)); }
1334 void tzcnt(Register dst, const Operand& src);
1336 void lzcnt(Register dst, Register src) { lzcnt(dst, Operand(src)); }
1337 void lzcnt(Register dst, const Operand& src);
1339 void popcnt(Register dst, Register src) { popcnt(dst, Operand(src)); }
1340 void popcnt(Register dst, const Operand& src);
1342 void bzhi(Register dst, Register src1, Register src2) {
1343 bzhi(dst, Operand(src1), src2);
1345 void bzhi(Register dst, const Operand& src1, Register src2) {
1346 bmi2(kNone, 0xf5, dst, src2, src1);
1348 void mulx(Register dst1, Register dst2, Register src) {
1349 mulx(dst1, dst2, Operand(src));
1351 void mulx(Register dst1, Register dst2, const Operand& src) {
1352 bmi2(kF2, 0xf6, dst1, dst2, src);
1354 void pdep(Register dst, Register src1, Register src2) {
1355 pdep(dst, src1, Operand(src2));
1357 void pdep(Register dst, Register src1, const Operand& src2) {
1358 bmi2(kF2, 0xf5, dst, src1, src2);
1360 void pext(Register dst, Register src1, Register src2) {
1361 pext(dst, src1, Operand(src2));
1363 void pext(Register dst, Register src1, const Operand& src2) {
1364 bmi2(kF3, 0xf5, dst, src1, src2);
1366 void sarx(Register dst, Register src1, Register src2) {
1367 sarx(dst, Operand(src1), src2);
1369 void sarx(Register dst, const Operand& src1, Register src2) {
1370 bmi2(kF3, 0xf7, dst, src2, src1);
1372 void shlx(Register dst, Register src1, Register src2) {
1373 shlx(dst, Operand(src1), src2);
1375 void shlx(Register dst, const Operand& src1, Register src2) {
1376 bmi2(k66, 0xf7, dst, src2, src1);
1378 void shrx(Register dst, Register src1, Register src2) {
1379 shrx(dst, Operand(src1), src2);
1381 void shrx(Register dst, const Operand& src1, Register src2) {
1382 bmi2(kF2, 0xf7, dst, src2, src1);
1384 void rorx(Register dst, Register src, byte imm8) {
1385 rorx(dst, Operand(src), imm8);
1387 void rorx(Register dst, const Operand& src, byte imm8);
1389 #define PACKED_OP_LIST(V) \
1393 #define AVX_PACKED_OP_DECLARE(name, opcode) \
1394 void v##name##ps(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1395 vps(opcode, dst, src1, Operand(src2)); \
1397 void v##name##ps(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1398 vps(opcode, dst, src1, src2); \
1400 void v##name##pd(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1401 vpd(opcode, dst, src1, Operand(src2)); \
1403 void v##name##pd(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1404 vpd(opcode, dst, src1, src2); \
1407 PACKED_OP_LIST(AVX_PACKED_OP_DECLARE);
1408 void vps(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1409 void vps(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1410 void vpd(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1411 void vpd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1413 // Prefetch src position into cache level.
1414 // Level 1, 2 or 3 specifies CPU cache level. Level 0 specifies a
1416 void prefetch(const Operand& src, int level);
1417 // TODO(lrn): Need SFENCE for movnt?
1419 // Check the code size generated from label to here.
1420 int SizeOfCodeGeneratedSince(Label* label) {
1421 return pc_offset() - label->pos();
1424 // Mark generator continuation.
1425 void RecordGeneratorContinuation();
1427 // Mark address of a debug break slot.
1428 void RecordDebugBreakSlot(RelocInfo::Mode mode, int argc = 0);
1430 // Record a comment relocation entry that can be used by a disassembler.
1431 // Use --code-comments to enable.
1432 void RecordComment(const char* msg);
1434 // Record a deoptimization reason that can be used by a log or cpu profiler.
1435 // Use --trace-deopt to enable.
1436 void RecordDeoptReason(const int reason, const SourcePosition position);
1438 // Writes a single byte or word of data in the code stream. Used for
1439 // inline tables, e.g., jump-tables.
1440 void db(uint8_t data);
1441 void dd(uint32_t data);
1442 void dq(uint64_t data);
1443 void dp(uintptr_t data) { dd(data); }
1444 void dd(Label* label);
1446 // Check if there is less than kGap bytes available in the buffer.
1447 // If this is the case, we need to grow the buffer before emitting
1448 // an instruction or relocation information.
1449 inline bool buffer_overflow() const {
1450 return pc_ >= reloc_info_writer.pos() - kGap;
1453 // Get the number of bytes available in the buffer.
1454 inline int available_space() const { return reloc_info_writer.pos() - pc_; }
1456 static bool IsNop(Address addr);
1458 PositionsRecorder* positions_recorder() { return &positions_recorder_; }
1460 int relocation_writer_size() {
1461 return (buffer_ + buffer_size_) - reloc_info_writer.pos();
1464 // Avoid overflows for displacements etc.
1465 static const int kMaximalBufferSize = 512*MB;
1467 byte byte_at(int pos) { return buffer_[pos]; }
1468 void set_byte_at(int pos, byte value) { buffer_[pos] = value; }
1470 void PatchConstantPoolAccessInstruction(int pc_offset, int offset,
1471 ConstantPoolEntry::Access access,
1472 ConstantPoolEntry::Type type) {
1473 // No embedded constant pool support.
1478 void emit_sse_operand(XMMRegister reg, const Operand& adr);
1479 void emit_sse_operand(XMMRegister dst, XMMRegister src);
1480 void emit_sse_operand(Register dst, XMMRegister src);
1481 void emit_sse_operand(XMMRegister dst, Register src);
1483 byte* addr_at(int pos) { return buffer_ + pos; }
1487 uint32_t long_at(int pos) {
1488 return *reinterpret_cast<uint32_t*>(addr_at(pos));
1490 void long_at_put(int pos, uint32_t x) {
1491 *reinterpret_cast<uint32_t*>(addr_at(pos)) = x;
1496 inline void emit(uint32_t x);
1497 inline void emit(Handle<Object> handle);
1498 inline void emit(uint32_t x,
1499 RelocInfo::Mode rmode,
1500 TypeFeedbackId id = TypeFeedbackId::None());
1501 inline void emit(Handle<Code> code,
1502 RelocInfo::Mode rmode,
1503 TypeFeedbackId id = TypeFeedbackId::None());
1504 inline void emit(const Immediate& x);
1505 inline void emit_w(const Immediate& x);
1506 inline void emit_q(uint64_t x);
1508 // Emit the code-object-relative offset of the label's position
1509 inline void emit_code_relative_offset(Label* label);
1511 // instruction generation
1512 void emit_arith_b(int op1, int op2, Register dst, int imm8);
1514 // Emit a basic arithmetic instruction (i.e. first byte of the family is 0x81)
1515 // with a given destination expression and an immediate operand. It attempts
1516 // to use the shortest encoding possible.
1517 // sel specifies the /n in the modrm byte (see the Intel PRM).
1518 void emit_arith(int sel, Operand dst, const Immediate& x);
1520 void emit_operand(Register reg, const Operand& adr);
1522 void emit_label(Label* label);
1524 void emit_farith(int b1, int b2, int i);
1527 enum SIMDPrefix { kNone = 0x0, k66 = 0x1, kF3 = 0x2, kF2 = 0x3 };
1528 enum VectorLength { kL128 = 0x0, kL256 = 0x4, kLIG = kL128, kLZ = kL128 };
1529 enum VexW { kW0 = 0x0, kW1 = 0x80, kWIG = kW0 };
1530 enum LeadingOpcode { k0F = 0x1, k0F38 = 0x2, k0F3A = 0x3 };
1531 inline void emit_vex_prefix(XMMRegister v, VectorLength l, SIMDPrefix pp,
1532 LeadingOpcode m, VexW w);
1533 inline void emit_vex_prefix(Register v, VectorLength l, SIMDPrefix pp,
1534 LeadingOpcode m, VexW w);
1537 void print(Label* L);
1538 void bind_to(Label* L, int pos);
1541 inline Displacement disp_at(Label* L);
1542 inline void disp_at_put(Label* L, Displacement disp);
1543 inline void emit_disp(Label* L, Displacement::Type type);
1544 inline void emit_near_disp(Label* L);
1546 // Most BMI instructions are similiar.
1547 void bmi1(byte op, Register reg, Register vreg, const Operand& rm);
1548 void bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
1551 // record reloc info for current pc_
1552 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1554 friend class CodePatcher;
1555 friend class EnsureSpace;
1557 // Internal reference positions, required for (potential) patching in
1558 // GrowBuffer(); contains only those internal references whose labels
1559 // are already bound.
1560 std::deque<int> internal_reference_positions_;
1563 RelocInfoWriter reloc_info_writer;
1565 PositionsRecorder positions_recorder_;
1566 friend class PositionsRecorder;
1570 // Helper class that ensures that there is enough space for generating
1571 // instructions and relocation information. The constructor makes
1572 // sure that there is enough space and (in debug mode) the destructor
1573 // checks that we did not generate too much.
1574 class EnsureSpace BASE_EMBEDDED {
1576 explicit EnsureSpace(Assembler* assembler) : assembler_(assembler) {
1577 if (assembler_->buffer_overflow()) assembler_->GrowBuffer();
1579 space_before_ = assembler_->available_space();
1585 int bytes_generated = space_before_ - assembler_->available_space();
1586 DCHECK(bytes_generated < assembler_->kGap);
1591 Assembler* assembler_;
1597 } } // namespace v8::internal
1599 #endif // V8_IA32_ASSEMBLER_IA32_H_