1 // AsmJit - Machine code generation for C++
2 //
3 // * Official AsmJit Home Page: https://asmjit.com
4 // * Official Github Repository: https://github.com/asmjit/asmjit
5 //
6 // Copyright (c) 2008-2020 The AsmJit Authors
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 // 2. Altered source versions must be plainly marked as such, and must not be
21 // misrepresented as being the original software.
22 // 3. This notice may not be removed or altered from any source distribution.
23
24 #ifndef ASMJIT_X86_X86INSTDB_P_H_INCLUDED
25 #define ASMJIT_X86_X86INSTDB_P_H_INCLUDED
26
27 #include "../x86/x86instdb.h"
28
ASMJIT_BEGIN_SUB_NAMESPACE(x86)29 ASMJIT_BEGIN_SUB_NAMESPACE(x86)
30
31 //! \cond INTERNAL
32 //! \addtogroup asmjit_x86
33 //! \{
34
35 namespace InstDB {
36
37 // ============================================================================
38 // [asmjit::x86::InstDB::Encoding]
39 // ============================================================================
40
41 //! Instruction encoding (X86).
42 //!
43 //! This is a specific identifier that is used by AsmJit to describe the way
44 //! each instruction is encoded. Some encodings are special only for a single
45 //! instruction as X86 instruction set contains a lot of legacy encodings, and
46 //! some encodings describe a group of instructions that share some commons,
47 //! like MMX, SSE, AVX, AVX512 instructions, etc...
48 enum EncodingId : uint32_t {
49 kEncodingNone = 0, //!< Never used.
50 kEncodingX86Op, //!< X86 [OP].
51 kEncodingX86Op_O, //!< X86 [OP] (opcode and /0-7).
52 kEncodingX86Op_O_I8, //!< X86 [OP] (opcode and /0-7 + 8-bit immediate).
53 kEncodingX86Op_xAddr, //!< X86 [OP] (implicit address in the first register operand).
54 kEncodingX86Op_xAX, //!< X86 [OP] (implicit or explicit '?AX' form).
55 kEncodingX86Op_xDX_xAX, //!< X86 [OP] (implicit or explicit '?DX, ?AX' form).
56 kEncodingX86Op_MemZAX, //!< X86 [OP] (implicit or explicit '[EAX|RAX]' form).
57 kEncodingX86I_xAX, //!< X86 [I] (implicit or explicit '?AX' form).
58 kEncodingX86M, //!< X86 [M] (handles 2|4|8-bytes size).
59 kEncodingX86M_NoSize, //!< X86 [M] (doesn't handle any size).
60 kEncodingX86M_GPB, //!< X86 [M] (handles single-byte size).
61 kEncodingX86M_GPB_MulDiv, //!< X86 [M] (like GPB, handles implicit|explicit MUL|DIV|IDIV).
62 kEncodingX86M_Only, //!< X86 [M] (restricted to memory operand of any size).
63 kEncodingX86M_Nop, //!< X86 [M] (special case of NOP instruction).
64 kEncodingX86R_Native, //!< X86 [R] (register must be either 32-bit or 64-bit depending on arch).
65 kEncodingX86Rm, //!< X86 [RM] (doesn't handle single-byte size).
66 kEncodingX86Rm_Raw66H, //!< X86 [RM] (used by LZCNT, POPCNT, and TZCNT).
67 kEncodingX86Rm_NoSize, //!< X86 [RM] (doesn't add REX.W prefix if 64-bit reg is used).
68 kEncodingX86Mr, //!< X86 [MR] (doesn't handle single-byte size).
69 kEncodingX86Mr_NoSize, //!< X86 [MR] (doesn't handle any size).
70 kEncodingX86Arith, //!< X86 adc, add, and, cmp, or, sbb, sub, xor.
71 kEncodingX86Bswap, //!< X86 bswap.
72 kEncodingX86Bt, //!< X86 bt, btc, btr, bts.
73 kEncodingX86Call, //!< X86 call.
74 kEncodingX86Cmpxchg, //!< X86 [MR] cmpxchg.
75 kEncodingX86Cmpxchg8b_16b, //!< X86 [MR] cmpxchg8b, cmpxchg16b.
76 kEncodingX86Crc, //!< X86 crc32.
77 kEncodingX86Enter, //!< X86 enter.
78 kEncodingX86Imul, //!< X86 imul.
79 kEncodingX86In, //!< X86 in.
80 kEncodingX86Ins, //!< X86 ins[b|q|d].
81 kEncodingX86IncDec, //!< X86 inc, dec.
82 kEncodingX86Int, //!< X86 int (interrupt).
83 kEncodingX86Jcc, //!< X86 jcc.
84 kEncodingX86JecxzLoop, //!< X86 jcxz, jecxz, jrcxz, loop, loope, loopne.
85 kEncodingX86Jmp, //!< X86 jmp.
86 kEncodingX86JmpRel, //!< X86 xbegin.
87 kEncodingX86Lea, //!< X86 lea.
88 kEncodingX86Mov, //!< X86 mov (all possible cases).
89 kEncodingX86MovsxMovzx, //!< X86 movsx, movzx.
90 kEncodingX86MovntiMovdiri, //!< X86 movnti/movdiri.
91 kEncodingX86EnqcmdMovdir64b, //!< X86 enqcmd/enqcmds/movdir64b.
92 kEncodingX86Out, //!< X86 out.
93 kEncodingX86Outs, //!< X86 out[b|w|d].
94 kEncodingX86Push, //!< X86 push.
95 kEncodingX86Pop, //!< X86 pop.
96 kEncodingX86Ret, //!< X86 ret.
97 kEncodingX86Rot, //!< X86 rcl, rcr, rol, ror, sal, sar, shl, shr.
98 kEncodingX86Set, //!< X86 setcc.
99 kEncodingX86ShldShrd, //!< X86 shld, shrd.
100 kEncodingX86StrRm, //!< X86 lods.
101 kEncodingX86StrMr, //!< X86 scas, stos.
102 kEncodingX86StrMm, //!< X86 cmps, movs.
103 kEncodingX86Test, //!< X86 test.
104 kEncodingX86Xadd, //!< X86 xadd.
105 kEncodingX86Xchg, //!< X86 xchg.
106 kEncodingX86Fence, //!< X86 lfence, mfence, sfence.
107 kEncodingX86Bndmov, //!< X86 [RM|MR] (used by BNDMOV).
108 kEncodingFpuOp, //!< FPU [OP].
109 kEncodingFpuArith, //!< FPU fadd, fdiv, fdivr, fmul, fsub, fsubr.
110 kEncodingFpuCom, //!< FPU fcom, fcomp.
111 kEncodingFpuFldFst, //!< FPU fld, fst, fstp.
112 kEncodingFpuM, //!< FPU fiadd, ficom, ficomp, fidiv, fidivr, fild, fimul, fist, fistp, fisttp, fisub, fisubr.
113 kEncodingFpuR, //!< FPU fcmov, fcomi, fcomip, ffree, fucom, fucomi, fucomip, fucomp, fxch.
114 kEncodingFpuRDef, //!< FPU faddp, fdivp, fdivrp, fmulp, fsubp, fsubrp.
115 kEncodingFpuStsw, //!< FPU fnstsw, Fstsw.
116 kEncodingExtRm, //!< EXT [RM].
117 kEncodingExtRm_XMM0, //!< EXT [RM<XMM0>].
118 kEncodingExtRm_ZDI, //!< EXT [RM<ZDI>].
119 kEncodingExtRm_P, //!< EXT [RM] (propagates 66H if the instruction uses XMM register).
120 kEncodingExtRm_Wx, //!< EXT [RM] (propagates REX.W if GPQ is used).
121 kEncodingExtRmRi, //!< EXT [RM|RI].
122 kEncodingExtRmRi_P, //!< EXT [RM|RI] (propagates 66H if the instruction uses XMM register).
123 kEncodingExtRmi, //!< EXT [RMI].
124 kEncodingExtRmi_P, //!< EXT [RMI] (propagates 66H if the instruction uses XMM register).
125 kEncodingExtPextrw, //!< EXT pextrw.
126 kEncodingExtExtract, //!< EXT pextrb, pextrd, pextrq, extractps.
127 kEncodingExtMov, //!< EXT mov?? - #1:[MM|XMM, MM|XMM|Mem] #2:[MM|XMM|Mem, MM|XMM].
128 kEncodingExtMovbe, //!< EXT movbe.
129 kEncodingExtMovd, //!< EXT movd.
130 kEncodingExtMovq, //!< EXT movq.
131 kEncodingExtExtrq, //!< EXT extrq (SSE4A).
132 kEncodingExtInsertq, //!< EXT insrq (SSE4A).
133 kEncodingExt3dNow, //!< EXT [RMI] (3DNOW specific).
134 kEncodingVexOp, //!< VEX [OP].
135 kEncodingVexKmov, //!< VEX [RM|MR] (used by kmov[b|w|d|q]).
136 kEncodingVexR_Wx, //!< VEX|EVEX [R] (propagatex VEX.W if GPQ used).
137 kEncodingVexM, //!< VEX|EVEX [M].
138 kEncodingVexM_VM, //!< VEX|EVEX [M] (propagates VEX|EVEX.L, VSIB support).
139 kEncodingVexMr_Lx, //!< VEX|EVEX [MR] (propagates VEX|EVEX.L if YMM used).
140 kEncodingVexMr_VM, //!< VEX|EVEX [MR] (propagates VEX|EVEX.L, VSIB support).
141 kEncodingVexMri, //!< VEX|EVEX [MRI].
142 kEncodingVexMri_Lx, //!< VEX|EVEX [MRI] (propagates VEX|EVEX.L if YMM used).
143 kEncodingVexRm, //!< VEX|EVEX [RM].
144 kEncodingVexRm_ZDI, //!< VEX|EVEX [RM<ZDI>].
145 kEncodingVexRm_Wx, //!< VEX|EVEX [RM] (propagates VEX|EVEX.W if GPQ used).
146 kEncodingVexRm_Lx, //!< VEX|EVEX [RM] (propagates VEX|EVEX.L if YMM used).
147 kEncodingVexRm_Lx_Bcst, //!< VEX|EVEX [RM] (can handle broadcast r32/r64).
148 kEncodingVexRm_VM, //!< VEX|EVEX [RM] (propagates VEX|EVEX.L, VSIB support).
149 kEncodingVexRm_T1_4X, //!< EVEX [RM] (used by NN instructions that use RM-T1_4X encoding).
150 kEncodingVexRmi, //!< VEX|EVEX [RMI].
151 kEncodingVexRmi_Wx, //!< VEX|EVEX [RMI] (propagates VEX|EVEX.W if GPQ used).
152 kEncodingVexRmi_Lx, //!< VEX|EVEX [RMI] (propagates VEX|EVEX.L if YMM used).
153 kEncodingVexRvm, //!< VEX|EVEX [RVM].
154 kEncodingVexRvm_Wx, //!< VEX|EVEX [RVM] (propagates VEX|EVEX.W if GPQ used).
155 kEncodingVexRvm_ZDX_Wx, //!< VEX|EVEX [RVM<ZDX>] (propagates VEX|EVEX.W if GPQ used).
156 kEncodingVexRvm_Lx, //!< VEX|EVEX [RVM] (propagates VEX|EVEX.L if YMM used).
157 kEncodingVexRvmr, //!< VEX|EVEX [RVMR].
158 kEncodingVexRvmr_Lx, //!< VEX|EVEX [RVMR] (propagates VEX|EVEX.L if YMM used).
159 kEncodingVexRvmi, //!< VEX|EVEX [RVMI].
160 kEncodingVexRvmi_Lx, //!< VEX|EVEX [RVMI] (propagates VEX|EVEX.L if YMM used).
161 kEncodingVexRmv, //!< VEX|EVEX [RMV].
162 kEncodingVexRmv_Wx, //!< VEX|EVEX [RMV] (propagates VEX|EVEX.W if GPQ used).
163 kEncodingVexRmv_VM, //!< VEX|EVEX [RMV] (propagates VEX|EVEX.L, VSIB support).
164 kEncodingVexRmvRm_VM, //!< VEX|EVEX [RMV|RM] (propagates VEX|EVEX.L, VSIB support).
165 kEncodingVexRmvi, //!< VEX|EVEX [RMVI].
166 kEncodingVexRmMr, //!< VEX|EVEX [RM|MR].
167 kEncodingVexRmMr_Lx, //!< VEX|EVEX [RM|MR] (propagates VEX|EVEX.L if YMM used).
168 kEncodingVexRvmRmv, //!< VEX|EVEX [RVM|RMV].
169 kEncodingVexRvmRmi, //!< VEX|EVEX [RVM|RMI].
170 kEncodingVexRvmRmi_Lx, //!< VEX|EVEX [RVM|RMI] (propagates VEX|EVEX.L if YMM used).
171 kEncodingVexRvmRmvRmi, //!< VEX|EVEX [RVM|RMV|RMI].
172 kEncodingVexRvmMr, //!< VEX|EVEX [RVM|MR].
173 kEncodingVexRvmMvr, //!< VEX|EVEX [RVM|MVR].
174 kEncodingVexRvmMvr_Lx, //!< VEX|EVEX [RVM|MVR] (propagates VEX|EVEX.L if YMM used).
175 kEncodingVexRvmVmi, //!< VEX|EVEX [RVM|VMI].
176 kEncodingVexRvmVmi_Lx, //!< VEX|EVEX [RVM|VMI] (propagates VEX|EVEX.L if YMM used).
177 kEncodingVexVm, //!< VEX|EVEX [VM].
178 kEncodingVexVm_Wx, //!< VEX|EVEX [VM] (propagates VEX|EVEX.W if GPQ used).
179 kEncodingVexVmi, //!< VEX|EVEX [VMI].
180 kEncodingVexVmi_Lx, //!< VEX|EVEX [VMI] (propagates VEX|EVEX.L if YMM used).
181 kEncodingVexVmi4_Wx, //!< VEX|EVEX [VMI] (propagates VEX|EVEX.W if GPQ used, DWORD Immediate).
182 kEncodingVexEvexVmi_Lx, //!< VEX|EVEX [VMI] (special, used by vpsrldq and vpslldq)
183 kEncodingVexRvrmRvmr, //!< VEX|EVEX [RVRM|RVMR].
184 kEncodingVexRvrmRvmr_Lx, //!< VEX|EVEX [RVRM|RVMR] (propagates VEX|EVEX.L if YMM used).
185 kEncodingVexRvrmiRvmri_Lx, //!< VEX|EVEX [RVRMI|RVMRI] (propagates VEX|EVEX.L if YMM used).
186 kEncodingVexMovdMovq, //!< VEX|EVEX vmovd, vmovq.
187 kEncodingVexMovssMovsd, //!< VEX|EVEX vmovss, vmovsd.
188 kEncodingFma4, //!< FMA4 [R, R, R/M, R/M].
189 kEncodingFma4_Lx, //!< FMA4 [R, R, R/M, R/M] (propagates AVX.L if YMM used).
190 kEncodingCount //!< Count of instruction encodings.
191 };
192
193 // ============================================================================
194 // [asmjit::x86::InstDB - CommonInfoTableB]
195 // ============================================================================
196
197 //! CPU extensions required to execute instruction.
198 struct CommonInfoTableB {
199 //! Features vector.
200 uint8_t _features[6];
201 //! Index to `_rwFlagsTable`.
202 uint8_t _rwFlagsIndex;
203 //! Reserved for future use.
204 uint8_t _reserved;
205
206 inline const uint8_t* featuresBegin() const noexcept { return _features; }
207 inline const uint8_t* featuresEnd() const noexcept { return _features + ASMJIT_ARRAY_SIZE(_features); }
208 };
209
210 // ============================================================================
211 // [asmjit::x86::InstDB - InstNameIndex]
212 // ============================================================================
213
214 // ${NameLimits:Begin}
215 // ------------------- Automatically generated, do not edit -------------------
216 enum : uint32_t { kMaxNameSize = 17 };
217 // ----------------------------------------------------------------------------
218 // ${NameLimits:End}
219
220 struct InstNameIndex {
221 uint16_t start;
222 uint16_t end;
223 };
224
225 // ============================================================================
226 // [asmjit::x86::InstDB - RWInfo]
227 // ============================================================================
228
229 struct RWInfo {
230 enum Category : uint8_t {
231 kCategoryGeneric,
232 kCategoryMov,
233 kCategoryImul,
234 kCategoryMovh64,
235 kCategoryVmaskmov,
236 kCategoryVmovddup,
237 kCategoryVmovmskpd,
238 kCategoryVmovmskps,
239 kCategoryVmov1_2,
240 kCategoryVmov1_4,
241 kCategoryVmov1_8,
242 kCategoryVmov2_1,
243 kCategoryVmov4_1,
244 kCategoryVmov8_1
245 };
246
247 uint8_t category;
248 uint8_t rmInfo;
249 uint8_t opInfoIndex[6];
250 };
251
252 struct RWInfoOp {
253 uint64_t rByteMask;
254 uint64_t wByteMask;
255 uint8_t physId;
256 uint8_t reserved[3];
257 uint32_t flags;
258 };
259
260 //! R/M information.
261 //!
262 //! This data is used to replace register operand by a memory operand reliably.
263 struct RWInfoRm {
264 enum Category : uint8_t {
265 kCategoryNone = 0,
266 kCategoryFixed,
267 kCategoryConsistent,
268 kCategoryHalf,
269 kCategoryQuarter,
270 kCategoryEighth
271 };
272
273 enum Flags : uint8_t {
274 kFlagAmbiguous = 0x01
275 };
276
277 uint8_t category;
278 uint8_t rmOpsMask;
279 uint8_t fixedSize;
280 uint8_t flags;
281 uint8_t rmFeature;
282 };
283
284 struct RWFlagsInfoTable {
285 //! CPU/FPU flags read.
286 uint32_t readFlags;
287 //! CPU/FPU flags written or undefined.
288 uint32_t writeFlags;
289 };
290
291 extern const uint8_t rwInfoIndex[Inst::_kIdCount * 2];
292 extern const RWInfo rwInfo[];
293 extern const RWInfoOp rwInfoOp[];
294 extern const RWInfoRm rwInfoRm[];
295 extern const RWFlagsInfoTable _rwFlagsInfoTable[];
296
297 // ============================================================================
298 // [asmjit::x86::InstDB::Tables]
299 // ============================================================================
300
301 extern const uint32_t _mainOpcodeTable[];
302 extern const uint32_t _altOpcodeTable[];
303
304 #ifndef ASMJIT_NO_TEXT
305 extern const char _nameData[];
306 extern const InstNameIndex instNameIndex[26];
307 #endif // !ASMJIT_NO_TEXT
308
309 extern const CommonInfoTableB _commonInfoTableB[];
310
311 } // {InstDB}
312
313 //! \}
314 //! \endcond
315
316 ASMJIT_END_SUB_NAMESPACE
317
318 #endif // ASMJIT_X86_X86INSTDB_P_H_INCLUDED
319