ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/compiler/codegen_x86.h
Revision: 1.5
Committed: 2003-03-18T13:12:56Z (21 years, 6 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.4: +59 -2 lines
Log Message:
Add CMOV and BSF/BSR instructions

File Contents

# User Rev Content
1 gbeauche 1.2 /******************** -*- mode: C; tab-width: 8 -*- ********************
2 gbeauche 1.1 *
3     * Run-time assembler for i386 and x86-64
4     *
5     ***********************************************************************/
6    
7    
8     /***********************************************************************
9     *
10     * This file is derived from GNU lightning.
11     *
12     * Copyright 1999, 2000, 2001, 2002, 2003 Ian Piumarta
13     *
14     * Adaptations and enhancements for x86-64 support, Copyright 2003
15     * Gwenole Beauchesne
16     *
17     * Basilisk II (C) 1997-2003 Christian Bauer
18     *
19     * This program is free software; you can redistribute it and/or modify
20     * it under the terms of the GNU General Public License as published by
21     * the Free Software Foundation; either version 2 of the License, or
22     * (at your option) any later version.
23     *
24     * This program is distributed in the hope that it will be useful,
25     * but WITHOUT ANY WARRANTY; without even the implied warranty of
26     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27     * GNU General Public License for more details.
28     *
29     * You should have received a copy of the GNU General Public License
30     * along with this program; if not, write to the Free Software
31     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32     *
33     ***********************************************************************/
34    
35     #ifndef X86_RTASM_H
36     #define X86_RTASM_H
37    
38     /* NOTES
39     *
40     * o Best viewed on a 1024x768 screen with fixed-6x10 font ;-)
41     *
42     * TODO
43     *
44     * o Fix FIXMEs
45     * o i387 FPU instructions
46     * o SSE instructions
47     * o Optimize for cases where register numbers are not integral constants
48     */
49    
50     /* --- Configuration ------------------------------------------------------- */
51    
52     /* Define to settle a "flat" register set, i.e. different regno for
53     each size variant. */
54     #ifndef X86_FLAT_REGISTERS
55     #define X86_FLAT_REGISTERS 1
56     #endif
57    
58     /* Define to generate x86-64 code. */
59     #ifndef X86_TARGET_64BIT
60     #define X86_TARGET_64BIT 0
61     #endif
62    
63     /* Define to optimize ALU instructions. */
64     #ifndef X86_OPTIMIZE_ALU
65     #define X86_OPTIMIZE_ALU 1
66     #endif
67    
68     /* Define to optimize rotate/shift instructions. */
69     #ifndef X86_OPTIMIZE_ROTSHI
70     #define X86_OPTIMIZE_ROTSHI 1
71     #endif
72    
73    
74     /* --- Macros -------------------------------------------------------------- */
75    
76     /* Functions used to emit code.
77     *
78     * x86_emit_byte(B)
79     * x86_emit_word(W)
80     * x86_emit_long(L)
81     */
82    
83     /* Get pointer to current code
84     *
85     * x86_get_target()
86     */
87    
88     /* Abort assembler, fatal failure.
89     *
90     * x86_emit_failure(MSG)
91     */
92    
93    
94     /* --- Register set -------------------------------------------------------- */
95    
96 gbeauche 1.2 enum {
97 gbeauche 1.4 X86_RIP = -2,
98 gbeauche 1.1 #if X86_FLAT_REGISTERS
99 gbeauche 1.3 X86_NOREG = 0,
100     X86_Reg8L_Base = 0x10,
101     X86_Reg8H_Base = 0x20,
102     X86_Reg16_Base = 0x30,
103     X86_Reg32_Base = 0x40,
104     X86_Reg64_Base = 0x50,
105     X86_RegMMX_Base = 0x60,
106     X86_RegXMM_Base = 0x70,
107 gbeauche 1.1 #else
108 gbeauche 1.3 X86_NOREG = -1,
109     X86_Reg8L_Base = 0,
110     X86_Reg8H_Base = 16,
111     X86_Reg16_Base = 0,
112     X86_Reg32_Base = 0,
113     X86_Reg64_Base = 0,
114     X86_RegMMX_Base = 0,
115     X86_RegXMM_Base = 0,
116 gbeauche 1.1 #endif
117 gbeauche 1.2 };
118 gbeauche 1.1
119 gbeauche 1.2 enum {
120 gbeauche 1.1 X86_AL = X86_Reg8L_Base,
121     X86_CL, X86_DL, X86_BL,
122     X86_AH, X86_CH, X86_DH, X86_BH,
123     X86_R8B, X86_R9B, X86_R10B, X86_R11B,
124     X86_R12B, X86_R13B, X86_R14B, X86_R15B,
125     X86_SPL = X86_Reg8H_Base + 4,
126     X86_BPL, X86_SIL, X86_DIL
127 gbeauche 1.2 };
128 gbeauche 1.1
129 gbeauche 1.2 enum {
130 gbeauche 1.1 X86_AX = X86_Reg16_Base,
131     X86_CX, X86_DX, X86_BX,
132     X86_SP, X86_BP, X86_SI, X86_DI,
133     X86_R8W, X86_R9W, X86_R10W, X86_R11W,
134     X86_R12W, X86_R13W, X86_R14W, X86_R15W
135 gbeauche 1.2 };
136 gbeauche 1.1
137 gbeauche 1.2 enum {
138 gbeauche 1.1 X86_EAX = X86_Reg32_Base,
139     X86_ECX, X86_EDX, X86_EBX,
140     X86_ESP, X86_EBP, X86_ESI, X86_EDI,
141     X86_R8D, X86_R9D, X86_R10D, X86_R11D,
142     X86_R12D, X86_R13D, X86_R14D, X86_R15D
143 gbeauche 1.2 };
144 gbeauche 1.1
145 gbeauche 1.2 enum {
146 gbeauche 1.1 X86_RAX = X86_Reg64_Base,
147     X86_RCX, X86_RDX, X86_RBX,
148     X86_RSP, X86_RBP, X86_RSI, X86_RDI,
149     X86_R8, X86_R9, X86_R10, X86_R11,
150     X86_R12, X86_R13, X86_R14, X86_R15
151 gbeauche 1.2 };
152 gbeauche 1.1
153 gbeauche 1.3 enum {
154     X86_MM0 = X86_RegMMX_Base,
155     X86_MM1, X86_MM2, X86_MM3,
156     X86_MM4, X86_MM5, X86_MM6, X86_MM7,
157     };
158    
159     enum {
160     X86_XMM0 = X86_RegXMM_Base,
161     X86_XMM1, X86_XMM2, X86_XMM3,
162     X86_XMM4, X86_XMM5, X86_XMM6, X86_XMM7,
163     X86_XMM8, X86_XMM9, X86_XMM10, X86_XMM11,
164     X86_XMM12, X86_XMM13, X86_XMM14, X86_XMM15
165     };
166    
167 gbeauche 1.1 /* Register control and access
168     *
169 gbeauche 1.3 * _r0P(R) Null register?
170 gbeauche 1.4 * _rIP(R) RIP register?
171 gbeauche 1.3 * _rXP(R) Extended register?
172 gbeauche 1.1 *
173 gbeauche 1.3 * _rC(R) Class of register (only valid if X86_FLAT_REGISTERS)
174 gbeauche 1.1 * _rR(R) Full register number
175     * _rN(R) Short register number for encoding
176     *
177     * _r1(R) 8-bit register ID
178     * _r2(R) 16-bit register ID
179     * _r4(R) 32-bit register ID
180     * _r8(R) 64-bit register ID
181 gbeauche 1.3 * _rM(R) MMX register ID
182     * _rX(R) XMM register ID
183     * _rA(R) Address register ID used for EA calculation
184 gbeauche 1.1 */
185    
186 gbeauche 1.3 #define _r0P(R) ((R) == X86_NOREG)
187 gbeauche 1.4 #define _rIP(R) ((R) == X86_RIP)
188 gbeauche 1.1
189 gbeauche 1.3 #define _rC(R) ((R) & 0xf0)
190     #define _rR(R) ((R) & 0x0f)
191     #define _rN(R) ((R) & 0x07)
192     #define _rXP(R) (_rR(R) > 7)
193 gbeauche 1.1
194 gbeauche 1.3 #if !defined(_ASM_SAFETY) || ! X86_FLAT_REGISTERS
195 gbeauche 1.1 #define _r1(R) _rN(R)
196     #define _r2(R) _rN(R)
197     #define _r4(R) _rN(R)
198     #define _r8(R) _rN(R)
199 gbeauche 1.3 #define _rA(R) _rN(R)
200     #define _rM(R) _rN(R)
201     #define _rX(R) _rN(R)
202 gbeauche 1.1 #else
203 gbeauche 1.3 #define _r1(R) ( ((_rC(R) & (X86_Reg8L_Base | X86_Reg8H_Base)) != 0) ? _rN(R) : x86_emit_failure( "8-bit register required"))
204     #define _r2(R) ( (_rC(R) == X86_Reg16_Base) ? _rN(R) : x86_emit_failure("16-bit register required"))
205     #define _r4(R) ( (_rC(R) == X86_Reg32_Base) ? _rN(R) : x86_emit_failure("32-bit register required"))
206     #define _r8(R) ( (_rC(R) == X86_Reg64_Base) ? _rN(R) : x86_emit_failure("64-bit register required"))
207     #define _rA(R) ( X86_TARGET_64BIT ? \
208     ( (_rC(R) == X86_Reg64_Base) ? _rN(R) : x86_emit_failure("not a valid 64-bit base/index expression")) : \
209     ( (_rC(R) == X86_Reg32_Base) ? _rN(R) : x86_emit_failure("not a valid 32-bit base/index expression")) )
210     #define _rM(R) ( (_rC(R) == X86_RegMMX_Base) ? _rN(R) : x86_emit_failure("MMX register required"))
211     #define _rX(R) ( (_rC(R) == X86_RegXMM_Base) ? _rN(R) : x86_emit_failure("SSE register required"))
212 gbeauche 1.1 #endif
213    
214 gbeauche 1.3 #define _rSP() (X86_TARGET_64BIT ? X86_RSP : X86_ESP)
215     #define _rbpP(R) (_rR(R) == _rR(X86_RBP))
216     #define _rspP(R) (_rR(R) == _rR(X86_RSP))
217     #define _rsp12P(R) (_rN(R) == _rN(X86_RSP))
218 gbeauche 1.1
219    
220     /* ========================================================================= */
221     /* --- UTILITY ------------------------------------------------------------- */
222     /* ========================================================================= */
223    
224     typedef char _sc;
225     typedef unsigned char _uc;
226     typedef unsigned short _us;
227     typedef int _sl;
228     typedef unsigned int _ul;
229    
230     #define _UC(X) ((_uc )(X))
231     #define _US(X) ((_us )(X))
232     #define _SL(X) ((_sl )(X))
233     #define _UL(X) ((_ul )(X))
234    
235     # define _PUC(X) ((_uc *)(X))
236     # define _PUS(X) ((_us *)(X))
237     # define _PSL(X) ((_sl *)(X))
238     # define _PUL(X) ((_ul *)(X))
239    
240     #define _B(B) x86_emit_byte((B))
241     #define _W(W) x86_emit_word((W))
242     #define _L(L) x86_emit_long((L))
243    
244     #define _MASK(N) ((unsigned)((1<<(N)))-1)
245     #define _siP(N,I) (!((((unsigned)(I))^(((unsigned)(I))<<1))&~_MASK(N)))
246     #define _uiP(N,I) (!(((unsigned)(I))&~_MASK(N)))
247     #define _suiP(N,I) (_siP(N,I) | _uiP(N,I))
248    
249     #ifndef _ASM_SAFETY
250     #define _ck_s(W,I) (_UL(I) & _MASK(W))
251     #define _ck_u(W,I) (_UL(I) & _MASK(W))
252     #define _ck_su(W,I) (_UL(I) & _MASK(W))
253     #define _ck_d(W,I) (_UL(I) & _MASK(W))
254     #else
255     #define _ck_s(W,I) (_siP(W,I) ? (_UL(I) & _MASK(W)) : x86_emit_failure( "signed integer `"#I"' too large for "#W"-bit field"))
256     #define _ck_u(W,I) (_uiP(W,I) ? (_UL(I) & _MASK(W)) : x86_emit_failure("unsigned integer `"#I"' too large for "#W"-bit field"))
257     #define _ck_su(W,I) (_suiP(W,I) ? (_UL(I) & _MASK(W)) : x86_emit_failure( "integer `"#I"' too large for "#W"-bit field"))
258     #define _ck_d(W,I) (_siP(W,I) ? (_UL(I) & _MASK(W)) : x86_emit_failure( "displacement `"#I"' too large for "#W"-bit field"))
259     #endif
260    
261     #define _s0P(I) ((I)==0)
262     #define _s8P(I) _siP(8,I)
263     #define _s16P(I) _siP(16,I)
264     #define _u8P(I) _uiP(8,I)
265     #define _u16P(I) _uiP(16,I)
266    
267     #define _su8(I) _ck_su(8,I)
268     #define _su16(I) _ck_su(16,I)
269    
270     #define _s1(I) _ck_s( 1,I)
271     #define _s2(I) _ck_s( 2,I)
272     #define _s3(I) _ck_s( 3,I)
273     #define _s4(I) _ck_s( 4,I)
274     #define _s5(I) _ck_s( 5,I)
275     #define _s6(I) _ck_s( 6,I)
276     #define _s7(I) _ck_s( 7,I)
277     #define _s8(I) _ck_s( 8,I)
278     #define _s9(I) _ck_s( 9,I)
279     #define _s10(I) _ck_s(10,I)
280     #define _s11(I) _ck_s(11,I)
281     #define _s12(I) _ck_s(12,I)
282     #define _s13(I) _ck_s(13,I)
283     #define _s14(I) _ck_s(14,I)
284     #define _s15(I) _ck_s(15,I)
285     #define _s16(I) _ck_s(16,I)
286     #define _s17(I) _ck_s(17,I)
287     #define _s18(I) _ck_s(18,I)
288     #define _s19(I) _ck_s(19,I)
289     #define _s20(I) _ck_s(20,I)
290     #define _s21(I) _ck_s(21,I)
291     #define _s22(I) _ck_s(22,I)
292     #define _s23(I) _ck_s(23,I)
293     #define _s24(I) _ck_s(24,I)
294     #define _s25(I) _ck_s(25,I)
295     #define _s26(I) _ck_s(26,I)
296     #define _s27(I) _ck_s(27,I)
297     #define _s28(I) _ck_s(28,I)
298     #define _s29(I) _ck_s(29,I)
299     #define _s30(I) _ck_s(30,I)
300     #define _s31(I) _ck_s(31,I)
301     #define _u1(I) _ck_u( 1,I)
302     #define _u2(I) _ck_u( 2,I)
303     #define _u3(I) _ck_u( 3,I)
304     #define _u4(I) _ck_u( 4,I)
305     #define _u5(I) _ck_u( 5,I)
306     #define _u6(I) _ck_u( 6,I)
307     #define _u7(I) _ck_u( 7,I)
308     #define _u8(I) _ck_u( 8,I)
309     #define _u9(I) _ck_u( 9,I)
310     #define _u10(I) _ck_u(10,I)
311     #define _u11(I) _ck_u(11,I)
312     #define _u12(I) _ck_u(12,I)
313     #define _u13(I) _ck_u(13,I)
314     #define _u14(I) _ck_u(14,I)
315     #define _u15(I) _ck_u(15,I)
316     #define _u16(I) _ck_u(16,I)
317     #define _u17(I) _ck_u(17,I)
318     #define _u18(I) _ck_u(18,I)
319     #define _u19(I) _ck_u(19,I)
320     #define _u20(I) _ck_u(20,I)
321     #define _u21(I) _ck_u(21,I)
322     #define _u22(I) _ck_u(22,I)
323     #define _u23(I) _ck_u(23,I)
324     #define _u24(I) _ck_u(24,I)
325     #define _u25(I) _ck_u(25,I)
326     #define _u26(I) _ck_u(26,I)
327     #define _u27(I) _ck_u(27,I)
328     #define _u28(I) _ck_u(28,I)
329     #define _u29(I) _ck_u(29,I)
330     #define _u30(I) _ck_u(30,I)
331     #define _u31(I) _ck_u(31,I)
332    
333     /* ========================================================================= */
334     /* --- ASSEMBLER ----------------------------------------------------------- */
335     /* ========================================================================= */
336    
337     #define _b00 0
338     #define _b01 1
339     #define _b10 2
340     #define _b11 3
341    
342     #define _b000 0
343     #define _b001 1
344     #define _b010 2
345     #define _b011 3
346     #define _b100 4
347     #define _b101 5
348     #define _b110 6
349     #define _b111 7
350    
351     #define _OFF4(D) (_UL(D) - _UL(x86_get_target()))
352     #define _CKD8(D) _ck_d(8, ((_uc) _OFF4(D)) )
353    
354     #define _D8(D) (_B(0), ((*(_PUC(x86_get_target())-1))= _CKD8(D)))
355     #define _D32(D) (_L(0), ((*(_PUL(x86_get_target())-1))= _OFF4(D)))
356    
357     #ifndef _ASM_SAFETY
358     # define _M(M) (M)
359     # define _r(R) (R)
360     # define _m(M) (M)
361     # define _s(S) (S)
362     # define _i(I) (I)
363     # define _b(B) (B)
364     #else
365     # define _M(M) (((M)>3) ? x86_emit_failure("internal error: mod = " #M) : (M))
366     # define _r(R) (((R)>7) ? x86_emit_failure("internal error: reg = " #R) : (R))
367     # define _m(M) (((M)>7) ? x86_emit_failure("internal error: r/m = " #M) : (M))
368     # define _s(S) (((S)>3) ? x86_emit_failure("internal error: memory scale = " #S) : (S))
369     # define _i(I) (((I)>7) ? x86_emit_failure("internal error: memory index = " #I) : (I))
370     # define _b(B) (((B)>7) ? x86_emit_failure("internal error: memory base = " #B) : (B))
371     #endif
372    
373     #define _Mrm(Md,R,M) _B((_M(Md)<<6)|(_r(R)<<3)|_m(M))
374     #define _SIB(Sc,I, B) _B((_s(Sc)<<6)|(_i(I)<<3)|_b(B))
375    
376     #define _SCL(S) ((((S)==1) ? _b00 : \
377     (((S)==2) ? _b01 : \
378     (((S)==4) ? _b10 : \
379     (((S)==8) ? _b11 : x86_emit_failure("illegal scale: " #S))))))
380    
381    
382     /* --- Memory subformats - urgh! ------------------------------------------- */
383    
384 gbeauche 1.4 /* _r_D() is RIP addressing mode if X86_TARGET_64BIT, use _r_DSIB() instead */
385 gbeauche 1.3 #define _r_D( R, D ) (_Mrm(_b00,_rN(R),_b101 ) ,_L((long)(D)))
386 gbeauche 1.4 #define _r_DSIB(R, D ) (_Mrm(_b00,_rN(R),_b100 ),_SIB(_SCL(1),_b100 ,_b101 ),_L((long)(D)))
387 gbeauche 1.3 #define _r_0B( R, B ) (_Mrm(_b00,_rN(R),_rA(B)) )
388     #define _r_0BIS(R, B,I,S) (_Mrm(_b00,_rN(R),_b100 ),_SIB(_SCL(S),_rA(I),_rA(B)) )
389     #define _r_1B( R, D,B ) (_Mrm(_b01,_rN(R),_rA(B)) ,_B((long)(D)))
390     #define _r_1BIS(R, D,B,I,S) (_Mrm(_b01,_rN(R),_b100 ),_SIB(_SCL(S),_rA(I),_rA(B)),_B((long)(D)))
391     #define _r_4B( R, D,B ) (_Mrm(_b10,_rN(R),_rA(B)) ,_L((long)(D)))
392     #define _r_4IS( R, D,I,S) (_Mrm(_b00,_rN(R),_b100 ),_SIB(_SCL(S),_rA(I),_b101 ),_L((long)(D)))
393     #define _r_4BIS(R, D,B,I,S) (_Mrm(_b10,_rN(R),_b100 ),_SIB(_SCL(S),_rA(I),_rA(B)),_L((long)(D)))
394    
395     #define _r_DB( R, D,B ) ((_s0P(D) && (!_rbpP(B)) ? _r_0B (R, B ) : (_s8P(D) ? _r_1B( R,D,B ) : _r_4B( R,D,B ))))
396     #define _r_DBIS(R, D,B,I,S) ((_s0P(D) ? _r_0BIS(R, B,I,S) : (_s8P(D) ? _r_1BIS(R,D,B,I,S) : _r_4BIS(R,D,B,I,S))))
397    
398     #define _r_X( R, D,B,I,S) (_r0P(I) ? (_r0P(B) ? _r_D (R,D ) : \
399 gbeauche 1.4 (_rIP(B) ? _r_DSIB(R,D ) : \
400 gbeauche 1.3 (_rsp12P(B) ? _r_DBIS(R,D,_rSP(),_rSP(),1) : \
401 gbeauche 1.4 _r_DB (R,D, B )))) : \
402 gbeauche 1.3 (_r0P(B) ? _r_4IS (R,D, I,S) : \
403     (!_rspP(I) ? _r_DBIS(R,D, B, I,S) : \
404     x86_emit_failure("illegal index register: %esp"))))
405 gbeauche 1.1
406    
407     /* --- Instruction formats ------------------------------------------------- */
408    
409     #define _m32only(X) (! X86_TARGET_64BIT ? X : x86_emit_failure("invalid instruction in 64-bit mode"))
410     #define _m64only(X) ( X86_TARGET_64BIT ? X : x86_emit_failure("invalid instruction in 32-bit mode"))
411     #define _m64(X) ( X86_TARGET_64BIT ? X : ((void)0) )
412    
413     /* _format Opcd ModR/M dN(rB,rI,Sc) imm... */
414    
415     #define _d16() ( _B(0x66 ) )
416     #define _O( OP ) ( _B( OP ) )
417     #define _Or( OP,R ) ( _B( (OP)|_r(R)) )
418     #define _OO( OP ) ( _B((OP)>>8), _B( (OP) ) )
419     #define _OOr( OP,R ) ( _B((OP)>>8), _B( (OP)|_r(R)) )
420     #define _Os( OP,B ) ( _s8P(B) ? _B(((OP)|_b10)) : _B(OP) )
421     #define _sW( W ) ( _s8P(W) ? _B(W):_W(W) )
422     #define _sL( L ) ( _s8P(L) ? _B(L):_L(L) )
423     #define _O_B( OP ,B ) ( _O ( OP ) ,_B(B) )
424     #define _O_W( OP ,W ) ( _O ( OP ) ,_W(W) )
425     #define _O_L( OP ,L ) ( _O ( OP ) ,_L(L) )
426     #define _O_D8( OP ,D ) ( _O ( OP ) ,_D8(D) )
427     #define _O_D32( OP ,D ) ( _O ( OP ) ,_D32(D) )
428     #define _OO_D32( OP ,D ) ( _OO ( OP ) ,_D32(D) )
429     #define _Os_sW( OP ,W ) ( _Os ( OP,W) ,_sW(W) )
430     #define _Os_sL( OP ,L ) ( _Os ( OP,L) ,_sL(L) )
431     #define _O_W_B( OP ,W,B) ( _O ( OP ) ,_W(W),_B(B))
432     #define _Or_B( OP,R ,B ) ( _Or ( OP,R) ,_B(B) )
433     #define _Or_W( OP,R ,W ) ( _Or ( OP,R) ,_W(W) )
434     #define _Or_L( OP,R ,L ) ( _Or ( OP,R) ,_L(L) )
435     #define _O_Mrm( OP ,MO,R,M ) ( _O ( OP ),_Mrm(MO,R,M ) )
436     #define _OO_Mrm( OP ,MO,R,M ) ( _OO ( OP ),_Mrm(MO,R,M ) )
437     #define _O_Mrm_B( OP ,MO,R,M ,B ) ( _O ( OP ),_Mrm(MO,R,M ) ,_B(B) )
438     #define _O_Mrm_W( OP ,MO,R,M ,W ) ( _O ( OP ),_Mrm(MO,R,M ) ,_W(W) )
439     #define _O_Mrm_L( OP ,MO,R,M ,L ) ( _O ( OP ),_Mrm(MO,R,M ) ,_L(L) )
440     #define _OO_Mrm_B( OP ,MO,R,M ,B ) ( _OO ( OP ),_Mrm(MO,R,M ) ,_B(B) )
441     #define _Os_Mrm_sW(OP ,MO,R,M ,W ) ( _Os ( OP,W),_Mrm(MO,R,M ),_sW(W) )
442     #define _Os_Mrm_sL(OP ,MO,R,M ,L ) ( _Os ( OP,L),_Mrm(MO,R,M ),_sL(L) )
443     #define _O_r_X( OP ,R ,MD,MB,MI,MS ) ( _O ( OP ),_r_X( R ,MD,MB,MI,MS) )
444     #define _OO_r_X( OP ,R ,MD,MB,MI,MS ) ( _OO ( OP ),_r_X( R ,MD,MB,MI,MS) )
445     #define _O_r_X_B( OP ,R ,MD,MB,MI,MS,B ) ( _O ( OP ),_r_X( R ,MD,MB,MI,MS) ,_B(B) )
446     #define _O_r_X_W( OP ,R ,MD,MB,MI,MS,W ) ( _O ( OP ),_r_X( R ,MD,MB,MI,MS) ,_W(W) )
447     #define _O_r_X_L( OP ,R ,MD,MB,MI,MS,L ) ( _O ( OP ),_r_X( R ,MD,MB,MI,MS) ,_L(L) )
448     #define _OO_r_X_B( OP ,R ,MD,MB,MI,MS,B ) ( _OO ( OP ),_r_X( R ,MD,MB,MI,MS) ,_B(B) )
449     #define _Os_r_X_sW(OP ,R ,MD,MB,MI,MS,W ) ( _Os ( OP,W),_r_X( R ,MD,MB,MI,MS),_sW(W) )
450     #define _Os_r_X_sL(OP ,R ,MD,MB,MI,MS,L ) ( _Os ( OP,L),_r_X( R ,MD,MB,MI,MS),_sL(L) )
451     #define _O_X_B( OP ,MD,MB,MI,MS,B ) ( _O_r_X_B( OP ,0 ,MD,MB,MI,MS ,B) )
452     #define _O_X_W( OP ,MD,MB,MI,MS,W ) ( _O_r_X_W( OP ,0 ,MD,MB,MI,MS ,W) )
453     #define _O_X_L( OP ,MD,MB,MI,MS,L ) ( _O_r_X_L( OP ,0 ,MD,MB,MI,MS ,L) )
454    
455    
456     /* --- REX prefixes -------------------------------------------------------- */
457    
458     #define _VOID() ((void)0)
459     #define _BIT(X) (!!(X))
460     #define _d64(W,R,X,B) (_B(0x40|(W)<<3|(R)<<2|(X)<<1|(B)))
461    
462     #define __REXwrxb(L,W,R,X,B) ((W|R|X|B) || (L) ? _d64(W,R,X,B) : _VOID())
463 gbeauche 1.4 #define __REXwrx_(L,W,R,X,MR) (__REXwrxb(L,W,R,X,_BIT(_rIP(MR)?0:_rXP(MR))))
464 gbeauche 1.1 #define __REXw_x_(L,W,R,X,MR) (__REXwrx_(L,W,_BIT(_rXP(R)),X,MR))
465    
466     // FIXME: can't mix new (SPL,BPL,SIL,DIL) with (AH,BH,CH,DH)
467     #define _REXBrr(RR,MR) _m64(__REXw_x_(((RR)|(MR))>=X86_SPL,0,RR,0,MR))
468     #define _REXBmr(MB,MI,RD) _m64(__REXw_x_(((RR)|(MR))>=X86_SPL,0,RD,_BIT(_rXP(MI)),MB))
469     #define _REXBrm(RS,MB,MI) _REXBmr(MB,MI,RS)
470    
471     #define _REXLrr(RR,MR) _m64(__REXw_x_(0,0,RR,0,MR))
472     #define _REXLmr(MB,MI,RD) _m64(__REXw_x_(0,0,RD,_BIT(_rXP(MI)),MB))
473     #define _REXLrm(RS,MB,MI) _REXLmr(MB,MI,RS)
474    
475     #define _REXQrr(RR,MR) _m64only(__REXw_x_(0,1,RR,0,MR))
476     #define _REXQmr(MB,MI,RD) _m64only(__REXw_x_(0,1,RD,_BIT(_rXP(MI)),MB))
477     #define _REXQrm(RS,MB,MI) _REXQmr(MB,MI,RS)
478    
479    
480     /* ========================================================================= */
481     /* --- Fully-qualified intrinsic instructions ------------------------------ */
482     /* ========================================================================= */
483    
484     /* OPCODE + i = immediate operand
485     * + r = register operand
486     * + m = memory operand (disp,base,index,scale)
487     * + sr/sm = a star preceding a register or memory
488 gbeauche 1.2 * + 0 = top of stack register (for FPU instructions)
489 gbeauche 1.4 *
490     * NOTE in x86-64 mode: a memory operand with only a valid
491     * displacement value will lead to the expect absolute mode. If
492     * RIP addressing is necessary, X86_RIP shall be used as the base
493     * register argument.
494 gbeauche 1.1 */
495    
496     /* --- ALU instructions ---------------------------------------------------- */
497    
498 gbeauche 1.2 enum {
499 gbeauche 1.1 X86_ADD = 0,
500     X86_OR = 1,
501     X86_ADC = 2,
502     X86_SBB = 3,
503     X86_AND = 4,
504     X86_SUB = 5,
505     X86_XOR = 6,
506     X86_CMP = 7,
507 gbeauche 1.2 };
508 gbeauche 1.1
509     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
510    
511     #define _ALUBrr(OP,RS, RD) (_REXBrr(RS, RD), _O_Mrm (((OP) << 3) ,_b11,_r1(RS),_r1(RD) ))
512     #define _ALUBmr(OP, MD, MB, MI, MS, RD) (_REXBmr(MB, MI, RD), _O_r_X (((OP) << 3) + 2,_r1(RD) ,MD,MB,MI,MS ))
513     #define _ALUBrm(OP, RS, MD, MB, MI, MS) (_REXBrm(RS, MB, MI), _O_r_X (((OP) << 3) , ,_r1(RS) ,MD,MB,MI,MS ))
514     #define _ALUBir(OP, IM, RD) (X86_OPTIMIZE_ALU && ((RD) == X86_AL) ? \
515     (_REXBrr(0, RD), _O_B (((OP) << 3) + 4 ,_su8(IM))) : \
516     (_REXBrr(0, RD), _O_Mrm_B (0x80 ,_b11,OP ,_r1(RD) ,_su8(IM))) )
517     #define _ALUBim(OP, IM, MD, MB, MI, MS) (_REXBrm(0, MB, MI), _O_r_X_B (0x80 ,OP ,MD,MB,MI,MS ,_su8(IM)))
518    
519     #define _ALUWrr(OP, RS, RD) (_d16(), _REXLrr(RS, RD), _O_Mrm (((OP) << 3) + 1,_b11,_r2(RS),_r2(RD) ))
520     #define _ALUWmr(OP, MD, MB, MI, MS, RD) (_d16(), _REXLmr(MD, MI, RD), _O_r_X (((OP) << 3) + 3 ,_r2(RD) ,MD,MB,MI,MS ))
521     #define _ALUWrm(OP, RS, MD, MB, MI, MS) (_d16(), _REXLrm(RS, MD, MI), _O_r_X (((OP) << 3) + 1 ,_r2(RS) ,MD,MB,MI,MS ))
522     #define _ALUWir(OP, IM, RD) (X86_OPTIMIZE_ALU && ((RD) == X86_AX) ? \
523     (_d16(), _REXLrr(0, RD), _O_W (((OP) << 3) + 5 ,_su16(IM))) : \
524     (_d16(), _REXLrr(0, RD), _Os_Mrm_sW (0x81 ,_b11,OP ,_r2(RD) ,_su16(IM))) )
525     #define _ALUWim(OP, IM, MD, MB, MI, MS) (_d16(), _REXLrm(0, MD, MI), _Os_r_X_sW (0x81 ,OP ,MD,MB,MI,MS ,_su16(IM)))
526    
527     #define _ALULrr(OP, RS, RD) (_REXLrr(RS, RD), _O_Mrm (((OP) << 3) + 1,_b11,_r4(RS),_r4(RD) ))
528     #define _ALULmr(OP, MD, MB, MI, MS, RD) (_REXLmr(MB, MI, RD), _O_r_X (((OP) << 3) + 3 ,_r4(RD) ,MD,MB,MI,MS ))
529     #define _ALULrm(OP, RS, MD, MB, MI, MS) (_REXLrm(RS, MB, MI), _O_r_X (((OP) << 3) + 1 ,_r4(RS) ,MD,MB,MI,MS ))
530     #define _ALULir(OP, IM, RD) (X86_OPTIMIZE_ALU && ((RD) == X86_EAX) ? \
531     (_REXLrr(0, RD), _O_L (((OP) << 3) + 5 ,IM )) : \
532     (_REXLrr(0, RD), _Os_Mrm_sL (0x81 ,_b11,OP ,_r4(RD) ,IM )) )
533     #define _ALULim(OP, IM, MD, MB, MI, MS) (_REXLrm(0, MB, MI), _Os_r_X_sL (0x81 ,OP ,MD,MB,MI,MS ,IM ))
534    
535     #define _ALUQrr(OP, RS, RD) (_REXQrr(RS, RD), _O_Mrm (((OP) << 3) + 1,_b11,_r8(RS),_r8(RD) ))
536     #define _ALUQmr(OP, MD, MB, MI, MS, RD) (_REXQmr(MB, MI, RD), _O_r_X (((OP) << 3) + 3 ,_r8(RD) ,MD,MB,MI,MS ))
537     #define _ALUQrm(OP, RS, MD, MB, MI, MS) (_REXQrm(RS, MB, MI), _O_r_X (((OP) << 3) + 1 ,_r8(RS) ,MD,MB,MI,MS ))
538     #define _ALUQir(OP, IM, RD) (X86_OPTIMIZE_ALU && ((RD) == X86_RAX) ? \
539     (_REXQrr(0, RD), _O_L (((OP) << 3) + 5 ,IM )) : \
540     (_REXQrr(0, RD), _Os_Mrm_sL (0x81 ,_b11,OP ,_r8(RD) ,IM )) )
541     #define _ALUQim(OP, IM, MD, MB, MI, MS) (_REXQrm(0, MB, MI), _Os_r_X_sL (0x81 ,OP ,MD,MB,MI,MS ,IM ))
542    
543     #define ADCBrr(RS, RD) _ALUBrr(X86_ADC, RS, RD)
544     #define ADCBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_ADC, MD, MB, MI, MS, RD)
545     #define ADCBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_ADC, RS, MD, MB, MI, MS)
546     #define ADCBir(IM, RD) _ALUBir(X86_ADC, IM, RD)
547     #define ADCBim(IM, MD, MB, MI, MS) _ALUBim(X86_ADC, IM, MD, MB, MI, MS)
548    
549     #define ADCWrr(RS, RD) _ALUWrr(X86_ADC, RS, RD)
550     #define ADCWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_ADC, MD, MB, MI, MS, RD)
551     #define ADCWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_ADC, RS, MD, MB, MI, MS)
552     #define ADCWir(IM, RD) _ALUWir(X86_ADC, IM, RD)
553     #define ADCWim(IM, MD, MB, MI, MS) _ALUWim(X86_ADC, IM, MD, MB, MI, MS)
554    
555     #define ADCLrr(RS, RD) _ALULrr(X86_ADC, RS, RD)
556     #define ADCLmr(MD, MB, MI, MS, RD) _ALULmr(X86_ADC, MD, MB, MI, MS, RD)
557     #define ADCLrm(RS, MD, MB, MI, MS) _ALULrm(X86_ADC, RS, MD, MB, MI, MS)
558     #define ADCLir(IM, RD) _ALULir(X86_ADC, IM, RD)
559     #define ADCLim(IM, MD, MB, MI, MS) _ALULim(X86_ADC, IM, MD, MB, MI, MS)
560    
561     #define ADCQrr(RS, RD) _ALUQrr(X86_ADC, RS, RD)
562     #define ADCQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_ADC, MD, MB, MI, MS, RD)
563     #define ADCQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_ADC, RS, MD, MB, MI, MS)
564     #define ADCQir(IM, RD) _ALUQir(X86_ADC, IM, RD)
565     #define ADCQim(IM, MD, MB, MI, MS) _ALUQim(X86_ADC, IM, MD, MB, MI, MS)
566    
567     #define ADDBrr(RS, RD) _ALUBrr(X86_ADD, RS, RD)
568     #define ADDBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_ADD, MD, MB, MI, MS, RD)
569     #define ADDBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_ADD, RS, MD, MB, MI, MS)
570     #define ADDBir(IM, RD) _ALUBir(X86_ADD, IM, RD)
571     #define ADDBim(IM, MD, MB, MI, MS) _ALUBim(X86_ADD, IM, MD, MB, MI, MS)
572    
573     #define ADDWrr(RS, RD) _ALUWrr(X86_ADD, RS, RD)
574     #define ADDWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_ADD, MD, MB, MI, MS, RD)
575     #define ADDWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_ADD, RS, MD, MB, MI, MS)
576     #define ADDWir(IM, RD) _ALUWir(X86_ADD, IM, RD)
577     #define ADDWim(IM, MD, MB, MI, MS) _ALUWim(X86_ADD, IM, MD, MB, MI, MS)
578    
579     #define ADDLrr(RS, RD) _ALULrr(X86_ADD, RS, RD)
580     #define ADDLmr(MD, MB, MI, MS, RD) _ALULmr(X86_ADD, MD, MB, MI, MS, RD)
581     #define ADDLrm(RS, MD, MB, MI, MS) _ALULrm(X86_ADD, RS, MD, MB, MI, MS)
582     #define ADDLir(IM, RD) _ALULir(X86_ADD, IM, RD)
583     #define ADDLim(IM, MD, MB, MI, MS) _ALULim(X86_ADD, IM, MD, MB, MI, MS)
584    
585     #define ADDQrr(RS, RD) _ALUQrr(X86_ADD, RS, RD)
586     #define ADDQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_ADD, MD, MB, MI, MS, RD)
587     #define ADDQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_ADD, RS, MD, MB, MI, MS)
588     #define ADDQir(IM, RD) _ALUQir(X86_ADD, IM, RD)
589     #define ADDQim(IM, MD, MB, MI, MS) _ALUQim(X86_ADD, IM, MD, MB, MI, MS)
590    
591     #define ANDBrr(RS, RD) _ALUBrr(X86_AND, RS, RD)
592     #define ANDBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_AND, MD, MB, MI, MS, RD)
593     #define ANDBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_AND, RS, MD, MB, MI, MS)
594     #define ANDBir(IM, RD) _ALUBir(X86_AND, IM, RD)
595     #define ANDBim(IM, MD, MB, MI, MS) _ALUBim(X86_AND, IM, MD, MB, MI, MS)
596    
597     #define ANDWrr(RS, RD) _ALUWrr(X86_AND, RS, RD)
598     #define ANDWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_AND, MD, MB, MI, MS, RD)
599     #define ANDWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_AND, RS, MD, MB, MI, MS)
600     #define ANDWir(IM, RD) _ALUWir(X86_AND, IM, RD)
601     #define ANDWim(IM, MD, MB, MI, MS) _ALUWim(X86_AND, IM, MD, MB, MI, MS)
602    
603     #define ANDLrr(RS, RD) _ALULrr(X86_AND, RS, RD)
604     #define ANDLmr(MD, MB, MI, MS, RD) _ALULmr(X86_AND, MD, MB, MI, MS, RD)
605     #define ANDLrm(RS, MD, MB, MI, MS) _ALULrm(X86_AND, RS, MD, MB, MI, MS)
606     #define ANDLir(IM, RD) _ALULir(X86_AND, IM, RD)
607     #define ANDLim(IM, MD, MB, MI, MS) _ALULim(X86_AND, IM, MD, MB, MI, MS)
608    
609     #define ANDQrr(RS, RD) _ALUQrr(X86_AND, RS, RD)
610     #define ANDQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_AND, MD, MB, MI, MS, RD)
611     #define ANDQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_AND, RS, MD, MB, MI, MS)
612     #define ANDQir(IM, RD) _ALUQir(X86_AND, IM, RD)
613     #define ANDQim(IM, MD, MB, MI, MS) _ALUQim(X86_AND, IM, MD, MB, MI, MS)
614    
615     #define CMPBrr(RS, RD) _ALUBrr(X86_CMP, RS, RD)
616     #define CMPBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_CMP, MD, MB, MI, MS, RD)
617     #define CMPBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_CMP, RS, MD, MB, MI, MS)
618     #define CMPBir(IM, RD) _ALUBir(X86_CMP, IM, RD)
619     #define CMPBim(IM, MD, MB, MI, MS) _ALUBim(X86_CMP, IM, MD, MB, MI, MS)
620    
621     #define CMPWrr(RS, RD) _ALUWrr(X86_CMP, RS, RD)
622     #define CMPWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_CMP, MD, MB, MI, MS, RD)
623     #define CMPWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_CMP, RS, MD, MB, MI, MS)
624     #define CMPWir(IM, RD) _ALUWir(X86_CMP, IM, RD)
625     #define CMPWim(IM, MD, MB, MI, MS) _ALUWim(X86_CMP, IM, MD, MB, MI, MS)
626    
627     #define CMPLrr(RS, RD) _ALULrr(X86_CMP, RS, RD)
628     #define CMPLmr(MD, MB, MI, MS, RD) _ALULmr(X86_CMP, MD, MB, MI, MS, RD)
629     #define CMPLrm(RS, MD, MB, MI, MS) _ALULrm(X86_CMP, RS, MD, MB, MI, MS)
630     #define CMPLir(IM, RD) _ALULir(X86_CMP, IM, RD)
631     #define CMPLim(IM, MD, MB, MI, MS) _ALULim(X86_CMP, IM, MD, MB, MI, MS)
632    
633     #define CMPQrr(RS, RD) _ALUQrr(X86_CMP, RS, RD)
634     #define CMPQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_CMP, MD, MB, MI, MS, RD)
635     #define CMPQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_CMP, RS, MD, MB, MI, MS)
636     #define CMPQir(IM, RD) _ALUQir(X86_CMP, IM, RD)
637     #define CMPQim(IM, MD, MB, MI, MS) _ALUQim(X86_CMP, IM, MD, MB, MI, MS)
638    
639     #define ORBrr(RS, RD) _ALUBrr(X86_OR, RS, RD)
640     #define ORBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_OR, MD, MB, MI, MS, RD)
641     #define ORBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_OR, RS, MD, MB, MI, MS)
642     #define ORBir(IM, RD) _ALUBir(X86_OR, IM, RD)
643     #define ORBim(IM, MD, MB, MI, MS) _ALUBim(X86_OR, IM, MD, MB, MI, MS)
644    
645     #define ORWrr(RS, RD) _ALUWrr(X86_OR, RS, RD)
646     #define ORWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_OR, MD, MB, MI, MS, RD)
647     #define ORWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_OR, RS, MD, MB, MI, MS)
648     #define ORWir(IM, RD) _ALUWir(X86_OR, IM, RD)
649     #define ORWim(IM, MD, MB, MI, MS) _ALUWim(X86_OR, IM, MD, MB, MI, MS)
650    
651     #define ORLrr(RS, RD) _ALULrr(X86_OR, RS, RD)
652     #define ORLmr(MD, MB, MI, MS, RD) _ALULmr(X86_OR, MD, MB, MI, MS, RD)
653     #define ORLrm(RS, MD, MB, MI, MS) _ALULrm(X86_OR, RS, MD, MB, MI, MS)
654     #define ORLir(IM, RD) _ALULir(X86_OR, IM, RD)
655     #define ORLim(IM, MD, MB, MI, MS) _ALULim(X86_OR, IM, MD, MB, MI, MS)
656    
657     #define ORQrr(RS, RD) _ALUQrr(X86_OR, RS, RD)
658     #define ORQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_OR, MD, MB, MI, MS, RD)
659     #define ORQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_OR, RS, MD, MB, MI, MS)
660     #define ORQir(IM, RD) _ALUQir(X86_OR, IM, RD)
661     #define ORQim(IM, MD, MB, MI, MS) _ALUQim(X86_OR, IM, MD, MB, MI, MS)
662    
663     #define SBBBrr(RS, RD) _ALUBrr(X86_SBB, RS, RD)
664     #define SBBBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_SBB, MD, MB, MI, MS, RD)
665     #define SBBBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_SBB, RS, MD, MB, MI, MS)
666     #define SBBBir(IM, RD) _ALUBir(X86_SBB, IM, RD)
667     #define SBBBim(IM, MD, MB, MI, MS) _ALUBim(X86_SBB, IM, MD, MB, MI, MS)
668    
669     #define SBBWrr(RS, RD) _ALUWrr(X86_SBB, RS, RD)
670     #define SBBWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_SBB, MD, MB, MI, MS, RD)
671     #define SBBWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_SBB, RS, MD, MB, MI, MS)
672     #define SBBWir(IM, RD) _ALUWir(X86_SBB, IM, RD)
673     #define SBBWim(IM, MD, MB, MI, MS) _ALUWim(X86_SBB, IM, MD, MB, MI, MS)
674    
675     #define SBBLrr(RS, RD) _ALULrr(X86_SBB, RS, RD)
676     #define SBBLmr(MD, MB, MI, MS, RD) _ALULmr(X86_SBB, MD, MB, MI, MS, RD)
677     #define SBBLrm(RS, MD, MB, MI, MS) _ALULrm(X86_SBB, RS, MD, MB, MI, MS)
678     #define SBBLir(IM, RD) _ALULir(X86_SBB, IM, RD)
679     #define SBBLim(IM, MD, MB, MI, MS) _ALULim(X86_SBB, IM, MD, MB, MI, MS)
680    
681     #define SBBQrr(RS, RD) _ALUQrr(X86_SBB, RS, RD)
682     #define SBBQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_SBB, MD, MB, MI, MS, RD)
683     #define SBBQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_SBB, RS, MD, MB, MI, MS)
684     #define SBBQir(IM, RD) _ALUQir(X86_SBB, IM, RD)
685     #define SBBQim(IM, MD, MB, MI, MS) _ALUQim(X86_SBB, IM, MD, MB, MI, MS)
686    
687     #define SUBBrr(RS, RD) _ALUBrr(X86_SUB, RS, RD)
688     #define SUBBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_SUB, MD, MB, MI, MS, RD)
689     #define SUBBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_SUB, RS, MD, MB, MI, MS)
690     #define SUBBir(IM, RD) _ALUBir(X86_SUB, IM, RD)
691     #define SUBBim(IM, MD, MB, MI, MS) _ALUBim(X86_SUB, IM, MD, MB, MI, MS)
692    
693     #define SUBWrr(RS, RD) _ALUWrr(X86_SUB, RS, RD)
694     #define SUBWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_SUB, MD, MB, MI, MS, RD)
695     #define SUBWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_SUB, RS, MD, MB, MI, MS)
696     #define SUBWir(IM, RD) _ALUWir(X86_SUB, IM, RD)
697     #define SUBWim(IM, MD, MB, MI, MS) _ALUWim(X86_SUB, IM, MD, MB, MI, MS)
698    
699     #define SUBLrr(RS, RD) _ALULrr(X86_SUB, RS, RD)
700     #define SUBLmr(MD, MB, MI, MS, RD) _ALULmr(X86_SUB, MD, MB, MI, MS, RD)
701     #define SUBLrm(RS, MD, MB, MI, MS) _ALULrm(X86_SUB, RS, MD, MB, MI, MS)
702     #define SUBLir(IM, RD) _ALULir(X86_SUB, IM, RD)
703     #define SUBLim(IM, MD, MB, MI, MS) _ALULim(X86_SUB, IM, MD, MB, MI, MS)
704    
705     #define SUBQrr(RS, RD) _ALUQrr(X86_SUB, RS, RD)
706     #define SUBQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_SUB, MD, MB, MI, MS, RD)
707     #define SUBQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_SUB, RS, MD, MB, MI, MS)
708     #define SUBQir(IM, RD) _ALUQir(X86_SUB, IM, RD)
709     #define SUBQim(IM, MD, MB, MI, MS) _ALUQim(X86_SUB, IM, MD, MB, MI, MS)
710    
711     #define XORBrr(RS, RD) _ALUBrr(X86_XOR, RS, RD)
712     #define XORBmr(MD, MB, MI, MS, RD) _ALUBmr(X86_XOR, MD, MB, MI, MS, RD)
713     #define XORBrm(RS, MD, MB, MI, MS) _ALUBrm(X86_XOR, RS, MD, MB, MI, MS)
714     #define XORBir(IM, RD) _ALUBir(X86_XOR, IM, RD)
715     #define XORBim(IM, MD, MB, MI, MS) _ALUBim(X86_XOR, IM, MD, MB, MI, MS)
716    
717     #define XORWrr(RS, RD) _ALUWrr(X86_XOR, RS, RD)
718     #define XORWmr(MD, MB, MI, MS, RD) _ALUWmr(X86_XOR, MD, MB, MI, MS, RD)
719     #define XORWrm(RS, MD, MB, MI, MS) _ALUWrm(X86_XOR, RS, MD, MB, MI, MS)
720     #define XORWir(IM, RD) _ALUWir(X86_XOR, IM, RD)
721     #define XORWim(IM, MD, MB, MI, MS) _ALUWim(X86_XOR, IM, MD, MB, MI, MS)
722    
723     #define XORLrr(RS, RD) _ALULrr(X86_XOR, RS, RD)
724     #define XORLmr(MD, MB, MI, MS, RD) _ALULmr(X86_XOR, MD, MB, MI, MS, RD)
725     #define XORLrm(RS, MD, MB, MI, MS) _ALULrm(X86_XOR, RS, MD, MB, MI, MS)
726     #define XORLir(IM, RD) _ALULir(X86_XOR, IM, RD)
727     #define XORLim(IM, MD, MB, MI, MS) _ALULim(X86_XOR, IM, MD, MB, MI, MS)
728    
729     #define XORQrr(RS, RD) _ALUQrr(X86_XOR, RS, RD)
730     #define XORQmr(MD, MB, MI, MS, RD) _ALUQmr(X86_XOR, MD, MB, MI, MS, RD)
731     #define XORQrm(RS, MD, MB, MI, MS) _ALUQrm(X86_XOR, RS, MD, MB, MI, MS)
732     #define XORQir(IM, RD) _ALUQir(X86_XOR, IM, RD)
733     #define XORQim(IM, MD, MB, MI, MS) _ALUQim(X86_XOR, IM, MD, MB, MI, MS)
734    
735    
736     /* --- Shift/Rotate instructions ------------------------------------------- */
737    
738 gbeauche 1.2 enum {
739 gbeauche 1.1 X86_ROL = 0,
740     X86_ROR = 1,
741     X86_RCL = 2,
742     X86_RCR = 3,
743     X86_SHL = 4,
744     X86_SHR = 5,
745     X86_SAR = 7,
746 gbeauche 1.2 };
747 gbeauche 1.1
748     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
749    
750     #define _ROTSHIBir(OP,IM,RD) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
751     (_REXBrr(0, RD), _O_Mrm (0xd0 ,_b11,OP,_r1(RD) )) : \
752     (_REXBrr(0, RD), _O_Mrm_B (0xc0 ,_b11,OP,_r1(RD) ,_u8(IM))) )
753     #define _ROTSHIBim(OP,IM,MD,MB,MI,MS) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
754     (_REXBrm(0, MB, MI), _O_r_X (0xd0 ,OP ,MD,MB,MI,MS )) : \
755     (_REXBrm(0, MB, MI), _O_r_X_B (0xc0 ,OP ,MD,MB,MI,MS ,_u8(IM))) )
756     #define _ROTSHIBrr(OP,RS,RD) (((RS) == X86_CL) ? \
757     (_REXBrr(RS, RD), _O_Mrm (0xd2 ,_b11,OP,_r1(RD) )) : \
758     x86_emit_failure("source register must be CL" ) )
759     #define _ROTSHIBrm(OP,RS,MD,MB,MI,MS) (((RS) == X86_CL) ? \
760     (_REXBrm(RS, MB, MI), _O_r_X (0xd2 ,OP ,MD,MB,MI,MS )) : \
761     x86_emit_failure("source register must be CL" ) )
762    
763     #define _ROTSHIWir(OP,IM,RD) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
764     (_d16(), _REXLrr(0, RD), _O_Mrm (0xd1 ,_b11,OP,_r2(RD) )) : \
765     (_d16(), _REXLrr(0, RD), _O_Mrm_B (0xc1 ,_b11,OP,_r2(RD) ,_u8(IM))) )
766     #define _ROTSHIWim(OP,IM,MD,MB,MI,MS) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
767     (_d16(), _REXLrm(0, MB, MI), _O_r_X (0xd1 ,OP ,MD,MB,MI,MS )) : \
768     (_d16(), _REXLrm(0, MB, MI), _O_r_X_B (0xc1 ,OP ,MD,MB,MI,MS ,_u8(IM))) )
769     #define _ROTSHIWrr(OP,RS,RD) (((RS) == X86_CL) ? \
770     (_d16(), _REXLrr(RS, RD), _O_Mrm (0xd3 ,_b11,OP,_r2(RD) )) : \
771     x86_emit_failure("source register must be CL" ) )
772     #define _ROTSHIWrm(OP,RS,MD,MB,MI,MS) (((RS) == X86_CL) ? \
773     (_d16(), _REXLrm(RS, MB, MI), _O_r_X (0xd3 ,OP ,MD,MB,MI,MS )) : \
774     x86_emit_failure("source register must be CL" ) )
775    
776     #define _ROTSHILir(OP,IM,RD) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
777     (_REXLrr(0, RD), _O_Mrm (0xd1 ,_b11,OP,_r4(RD) )) : \
778     (_REXLrr(0, RD), _O_Mrm_B (0xc1 ,_b11,OP,_r4(RD) ,_u8(IM))) )
779     #define _ROTSHILim(OP,IM,MD,MB,MI,MS) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
780     (_REXLrm(0, MB, MI), _O_r_X (0xd1 ,OP ,MD,MB,MI,MS )) : \
781     (_REXLrm(0, MB, MI), _O_r_X_B (0xc1 ,OP ,MD,MB,MI,MS ,_u8(IM))) )
782     #define _ROTSHILrr(OP,RS,RD) (((RS) == X86_CL) ? \
783     (_REXLrr(RS, RD), _O_Mrm (0xd3 ,_b11,OP,_r4(RD) )) : \
784     x86_emit_failure("source register must be CL" ) )
785     #define _ROTSHILrm(OP,RS,MD,MB,MI,MS) (((RS) == X86_CL) ? \
786     (_REXLrm(RS, MB, MI), _O_r_X (0xd3 ,OP ,MD,MB,MI,MS )) : \
787     x86_emit_failure("source register must be CL" ) )
788    
789     #define _ROTSHIQir(OP,IM,RD) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
790     (_REXQrr(0, RD), _O_Mrm (0xd1 ,_b11,OP,_r8(RD) )) : \
791     (_REXQrr(0, RD), _O_Mrm_B (0xc1 ,_b11,OP,_r8(RD) ,_u8(IM))) )
792     #define _ROTSHIQim(OP,IM,MD,MB,MI,MS) (X86_OPTIMIZE_ROTSHI && ((IM) == 1) ? \
793     (_REXQrm(0, MB, MI), _O_r_X (0xd1 ,OP ,MD,MB,MI,MS )) : \
794     (_REXQrm(0, MB, MI), _O_r_X_B (0xc1 ,OP ,MD,MB,MI,MS ,_u8(IM))) )
795     #define _ROTSHIQrr(OP,RS,RD) (((RS) == X86_CL) ? \
796     (_REXQrr(RS, RD), _O_Mrm (0xd3 ,_b11,OP,_r8(RD) )) : \
797     x86_emit_failure("source register must be CL" ) )
798     #define _ROTSHIQrm(OP,RS,MD,MB,MI,MS) (((RS) == X86_CL) ? \
799     (_REXQrm(RS, MB, MI), _O_r_X (0xd3 ,OP ,MD,MB,MI,MS )) : \
800     x86_emit_failure("source register must be CL" ) )
801    
802     #define ROLBir(IM, RD) _ROTSHIBir(X86_ROL, IM, RD)
803     #define ROLBim(IM, MD, MB, MI, MS) _ROTSHIBim(X86_ROL, IM, MD, MB, MI, MS)
804     #define ROLBrr(RS, RD) _ROTSHIBrr(X86_ROL, RS, RD)
805     #define ROLBrm(RS, MD, MB, MI, MS) _ROTSHIBrm(X86_ROL, RS, MD, MB, MI, MS)
806    
807     #define ROLWir(IM, RD) _ROTSHIWir(X86_ROL, IM, RD)
808     #define ROLWim(IM, MD, MB, MI, MS) _ROTSHIWim(X86_ROL, IM, MD, MB, MI, MS)
809     #define ROLWrr(RS, RD) _ROTSHIWrr(X86_ROL, RS, RD)
810     #define ROLWrm(RS, MD, MB, MI, MS) _ROTSHIWrm(X86_ROL, RS, MD, MB, MI, MS)
811    
812     #define ROLLir(IM, RD) _ROTSHILir(X86_ROL, IM, RD)
813     #define ROLLim(IM, MD, MB, MI, MS) _ROTSHILim(X86_ROL, IM, MD, MB, MI, MS)
814     #define ROLLrr(RS, RD) _ROTSHILrr(X86_ROL, RS, RD)
815     #define ROLLrm(RS, MD, MB, MI, MS) _ROTSHILrm(X86_ROL, RS, MD, MB, MI, MS)
816    
817     #define ROLQir(IM, RD) _ROTSHIQir(X86_ROL, IM, RD)
818     #define ROLQim(IM, MD, MB, MI, MS) _ROTSHIQim(X86_ROL, IM, MD, MB, MI, MS)
819     #define ROLQrr(RS, RD) _ROTSHIQrr(X86_ROL, RS, RD)
820     #define ROLQrm(RS, MD, MB, MI, MS) _ROTSHIQrm(X86_ROL, RS, MD, MB, MI, MS)
821    
822     #define RORBir(IM, RD) _ROTSHIBir(X86_ROR, IM, RD)
823     #define RORBim(IM, MD, MB, MI, MS) _ROTSHIBim(X86_ROR, IM, MD, MB, MI, MS)
824     #define RORBrr(RS, RD) _ROTSHIBrr(X86_ROR, RS, RD)
825     #define RORBrm(RS, MD, MB, MI, MS) _ROTSHIBrm(X86_ROR, RS, MD, MB, MI, MS)
826    
827     #define RORWir(IM, RD) _ROTSHIWir(X86_ROR, IM, RD)
828     #define RORWim(IM, MD, MB, MI, MS) _ROTSHIWim(X86_ROR, IM, MD, MB, MI, MS)
829     #define RORWrr(RS, RD) _ROTSHIWrr(X86_ROR, RS, RD)
830     #define RORWrm(RS, MD, MB, MI, MS) _ROTSHIWrm(X86_ROR, RS, MD, MB, MI, MS)
831    
832     #define RORLir(IM, RD) _ROTSHILir(X86_ROR, IM, RD)
833     #define RORLim(IM, MD, MB, MI, MS) _ROTSHILim(X86_ROR, IM, MD, MB, MI, MS)
834     #define RORLrr(RS, RD) _ROTSHILrr(X86_ROR, RS, RD)
835     #define RORLrm(RS, MD, MB, MI, MS) _ROTSHILrm(X86_ROR, RS, MD, MB, MI, MS)
836    
837     #define RORQir(IM, RD) _ROTSHIQir(X86_ROR, IM, RD)
838     #define RORQim(IM, MD, MB, MI, MS) _ROTSHIQim(X86_ROR, IM, MD, MB, MI, MS)
839     #define RORQrr(RS, RD) _ROTSHIQrr(X86_ROR, RS, RD)
840     #define RORQrm(RS, MD, MB, MI, MS) _ROTSHIQrm(X86_ROR, RS, MD, MB, MI, MS)
841    
842     #define RCLBir(IM, RD) _ROTSHIBir(X86_RCL, IM, RD)
843     #define RCLBim(IM, MD, MB, MI, MS) _ROTSHIBim(X86_RCL, IM, MD, MB, MI, MS)
844     #define RCLBrr(RS, RD) _ROTSHIBrr(X86_RCL, RS, RD)
845     #define RCLBrm(RS, MD, MB, MI, MS) _ROTSHIBrm(X86_RCL, RS, MD, MB, MI, MS)
846    
847     #define RCLWir(IM, RD) _ROTSHIWir(X86_RCL, IM, RD)
848     #define RCLWim(IM, MD, MB, MI, MS) _ROTSHIWim(X86_RCL, IM, MD, MB, MI, MS)
849     #define RCLWrr(RS, RD) _ROTSHIWrr(X86_RCL, RS, RD)
850     #define RCLWrm(RS, MD, MB, MI, MS) _ROTSHIWrm(X86_RCL, RS, MD, MB, MI, MS)
851    
852     #define RCLLir(IM, RD) _ROTSHILir(X86_RCL, IM, RD)
853     #define RCLLim(IM, MD, MB, MI, MS) _ROTSHILim(X86_RCL, IM, MD, MB, MI, MS)
854     #define RCLLrr(RS, RD) _ROTSHILrr(X86_RCL, RS, RD)
855     #define RCLLrm(RS, MD, MB, MI, MS) _ROTSHILrm(X86_RCL, RS, MD, MB, MI, MS)
856    
857     #define RCLQir(IM, RD) _ROTSHIQir(X86_RCL, IM, RD)
858     #define RCLQim(IM, MD, MB, MI, MS) _ROTSHIQim(X86_RCL, IM, MD, MB, MI, MS)
859     #define RCLQrr(RS, RD) _ROTSHIQrr(X86_RCL, RS, RD)
860     #define RCLQrm(RS, MD, MB, MI, MS) _ROTSHIQrm(X86_RCL, RS, MD, MB, MI, MS)
861    
862     #define RCRBir(IM, RD) _ROTSHIBir(X86_RCR, IM, RD)
863     #define RCRBim(IM, MD, MB, MI, MS) _ROTSHIBim(X86_RCR, IM, MD, MB, MI, MS)
864     #define RCRBrr(RS, RD) _ROTSHIBrr(X86_RCR, RS, RD)
865     #define RCRBrm(RS, MD, MB, MI, MS) _ROTSHIBrm(X86_RCR, RS, MD, MB, MI, MS)
866    
867     #define RCRWir(IM, RD) _ROTSHIWir(X86_RCR, IM, RD)
868     #define RCRWim(IM, MD, MB, MI, MS) _ROTSHIWim(X86_RCR, IM, MD, MB, MI, MS)
869     #define RCRWrr(RS, RD) _ROTSHIWrr(X86_RCR, RS, RD)
870     #define RCRWrm(RS, MD, MB, MI, MS) _ROTSHIWrm(X86_RCR, RS, MD, MB, MI, MS)
871    
872     #define RCRLir(IM, RD) _ROTSHILir(X86_RCR, IM, RD)
873     #define RCRLim(IM, MD, MB, MI, MS) _ROTSHILim(X86_RCR, IM, MD, MB, MI, MS)
874     #define RCRLrr(RS, RD) _ROTSHILrr(X86_RCR, RS, RD)
875     #define RCRLrm(RS, MD, MB, MI, MS) _ROTSHILrm(X86_RCR, RS, MD, MB, MI, MS)
876    
877     #define RCRQir(IM, RD) _ROTSHIQir(X86_RCR, IM, RD)
878     #define RCRQim(IM, MD, MB, MI, MS) _ROTSHIQim(X86_RCR, IM, MD, MB, MI, MS)
879     #define RCRQrr(RS, RD) _ROTSHIQrr(X86_RCR, RS, RD)
880     #define RCRQrm(RS, MD, MB, MI, MS) _ROTSHIQrm(X86_RCR, RS, MD, MB, MI, MS)
881    
882     #define SHLBir(IM, RD) _ROTSHIBir(X86_SHL, IM, RD)
883     #define SHLBim(IM, MD, MB, MI, MS) _ROTSHIBim(X86_SHL, IM, MD, MB, MI, MS)
884     #define SHLBrr(RS, RD) _ROTSHIBrr(X86_SHL, RS, RD)
885     #define SHLBrm(RS, MD, MB, MI, MS) _ROTSHIBrm(X86_SHL, RS, MD, MB, MI, MS)
886    
887     #define SHLWir(IM, RD) _ROTSHIWir(X86_SHL, IM, RD)
888     #define SHLWim(IM, MD, MB, MI, MS) _ROTSHIWim(X86_SHL, IM, MD, MB, MI, MS)
889     #define SHLWrr(RS, RD) _ROTSHIWrr(X86_SHL, RS, RD)
890     #define SHLWrm(RS, MD, MB, MI, MS) _ROTSHIWrm(X86_SHL, RS, MD, MB, MI, MS)
891    
892     #define SHLLir(IM, RD) _ROTSHILir(X86_SHL, IM, RD)
893     #define SHLLim(IM, MD, MB, MI, MS) _ROTSHILim(X86_SHL, IM, MD, MB, MI, MS)
894     #define SHLLrr(RS, RD) _ROTSHILrr(X86_SHL, RS, RD)
895     #define SHLLrm(RS, MD, MB, MI, MS) _ROTSHILrm(X86_SHL, RS, MD, MB, MI, MS)
896    
897     #define SHLQir(IM, RD) _ROTSHIQir(X86_SHL, IM, RD)
898     #define SHLQim(IM, MD, MB, MI, MS) _ROTSHIQim(X86_SHL, IM, MD, MB, MI, MS)
899     #define SHLQrr(RS, RD) _ROTSHIQrr(X86_SHL, RS, RD)
900     #define SHLQrm(RS, MD, MB, MI, MS) _ROTSHIQrm(X86_SHL, RS, MD, MB, MI, MS)
901    
902     #define SHRBir(IM, RD) _ROTSHIBir(X86_SHR, IM, RD)
903     #define SHRBim(IM, MD, MB, MI, MS) _ROTSHIBim(X86_SHR, IM, MD, MB, MI, MS)
904     #define SHRBrr(RS, RD) _ROTSHIBrr(X86_SHR, RS, RD)
905     #define SHRBrm(RS, MD, MB, MI, MS) _ROTSHIBrm(X86_SHR, RS, MD, MB, MI, MS)
906    
907     #define SHRWir(IM, RD) _ROTSHIWir(X86_SHR, IM, RD)
908     #define SHRWim(IM, MD, MB, MI, MS) _ROTSHIWim(X86_SHR, IM, MD, MB, MI, MS)
909     #define SHRWrr(RS, RD) _ROTSHIWrr(X86_SHR, RS, RD)
910     #define SHRWrm(RS, MD, MB, MI, MS) _ROTSHIWrm(X86_SHR, RS, MD, MB, MI, MS)
911    
912     #define SHRLir(IM, RD) _ROTSHILir(X86_SHR, IM, RD)
913     #define SHRLim(IM, MD, MB, MI, MS) _ROTSHILim(X86_SHR, IM, MD, MB, MI, MS)
914     #define SHRLrr(RS, RD) _ROTSHILrr(X86_SHR, RS, RD)
915     #define SHRLrm(RS, MD, MB, MI, MS) _ROTSHILrm(X86_SHR, RS, MD, MB, MI, MS)
916    
917     #define SHRQir(IM, RD) _ROTSHIQir(X86_SHR, IM, RD)
918     #define SHRQim(IM, MD, MB, MI, MS) _ROTSHIQim(X86_SHR, IM, MD, MB, MI, MS)
919     #define SHRQrr(RS, RD) _ROTSHIQrr(X86_SHR, RS, RD)
920     #define SHRQrm(RS, MD, MB, MI, MS) _ROTSHIQrm(X86_SHR, RS, MD, MB, MI, MS)
921    
922     #define SALBir SHLBir
923     #define SALBim SHLBim
924     #define SALBrr SHLBrr
925     #define SALBrm SHLBrm
926    
927     #define SALWir SHLWir
928     #define SALWim SHLWim
929     #define SALWrr SHLWrr
930     #define SALWrm SHLWrm
931    
932     #define SALLir SHLLir
933     #define SALLim SHLLim
934     #define SALLrr SHLLrr
935     #define SALLrm SHLLrm
936    
937     #define SALQir SHLQir
938     #define SALQim SHLQim
939     #define SALQrr SHLQrr
940     #define SALQrm SHLQrm
941    
942     #define SARBir(IM, RD) _ROTSHIBir(X86_SAR, IM, RD)
943     #define SARBim(IM, MD, MB, MI, MS) _ROTSHIBim(X86_SAR, IM, MD, MB, MI, MS)
944     #define SARBrr(RS, RD) _ROTSHIBrr(X86_SAR, RS, RD)
945     #define SARBrm(RS, MD, MB, MI, MS) _ROTSHIBrm(X86_SAR, RS, MD, MB, MI, MS)
946    
947     #define SARWir(IM, RD) _ROTSHIWir(X86_SAR, IM, RD)
948     #define SARWim(IM, MD, MB, MI, MS) _ROTSHIWim(X86_SAR, IM, MD, MB, MI, MS)
949     #define SARWrr(RS, RD) _ROTSHIWrr(X86_SAR, RS, RD)
950     #define SARWrm(RS, MD, MB, MI, MS) _ROTSHIWrm(X86_SAR, RS, MD, MB, MI, MS)
951    
952     #define SARLir(IM, RD) _ROTSHILir(X86_SAR, IM, RD)
953     #define SARLim(IM, MD, MB, MI, MS) _ROTSHILim(X86_SAR, IM, MD, MB, MI, MS)
954     #define SARLrr(RS, RD) _ROTSHILrr(X86_SAR, RS, RD)
955     #define SARLrm(RS, MD, MB, MI, MS) _ROTSHILrm(X86_SAR, RS, MD, MB, MI, MS)
956    
957     #define SARQir(IM, RD) _ROTSHIQir(X86_SAR, IM, RD)
958     #define SARQim(IM, MD, MB, MI, MS) _ROTSHIQim(X86_SAR, IM, MD, MB, MI, MS)
959     #define SARQrr(RS, RD) _ROTSHIQrr(X86_SAR, RS, RD)
960     #define SARQrm(RS, MD, MB, MI, MS) _ROTSHIQrm(X86_SAR, RS, MD, MB, MI, MS)
961    
962    
963     /* --- Bit test instructions ----------------------------------------------- */
964    
965 gbeauche 1.2 enum {
966 gbeauche 1.1 X86_BT = 4,
967     X86_BTS = 5,
968     X86_BTR = 6,
969     X86_BTC = 7,
970 gbeauche 1.2 };
971 gbeauche 1.1
972     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
973    
974     #define _BTWir(OP, IM, RD) (_d16(), _REXLrr(0, RD), _OO_Mrm_B (0x0fba ,_b11,OP ,_r2(RD) ,_u8(IM)))
975     #define _BTWim(OP, IM, MD, MB, MI, MS) (_d16(), _REXLrm(0, MB, MI), _OO_r_X_B (0x0fba ,OP ,MD,MB,MI,MS ,_u8(IM)))
976     #define _BTWrr(OP, RS, RD) (_d16(), _REXLrr(RS, RD), _OO_Mrm (0x0f83|((OP)<<3),_b11,_r2(RS),_r2(RD) ))
977     #define _BTWrm(OP, RS, MD, MB, MI, MS) (_d16(), _REXLrm(RS, MB, MI), _OO_r_X (0x0f83|((OP)<<3) ,_r2(RS) ,MD,MB,MI,MS ))
978    
979     #define _BTLir(OP, IM, RD) (_REXLrr(0, RD), _OO_Mrm_B (0x0fba ,_b11,OP ,_r4(RD) ,_u8(IM)))
980     #define _BTLim(OP, IM, MD, MB, MI, MS) (_REXLrm(0, MB, MI), _OO_r_X_B (0x0fba ,OP ,MD,MB,MI,MS ,_u8(IM)))
981     #define _BTLrr(OP, RS, RD) (_REXLrr(RS, RD), _OO_Mrm (0x0f83|((OP)<<3),_b11,_r4(RS),_r4(RD) ))
982     #define _BTLrm(OP, RS, MD, MB, MI, MS) (_REXLrm(RS, MB, MI), _OO_r_X (0x0f83|((OP)<<3) ,_r4(RS) ,MD,MB,MI,MS ))
983    
984     #define _BTQir(OP, IM, RD) (_REXQrr(0, RD), _OO_Mrm_B (0x0fba ,_b11,OP ,_r8(RD) ,_u8(IM)))
985     #define _BTQim(OP, IM, MD, MB, MI, MS) (_REXQrm(0, MB, MI), _OO_r_X_B (0x0fba ,OP ,MD,MB,MI,MS ,_u8(IM)))
986     #define _BTQrr(OP, RS, RD) (_REXQrr(RS, RD), _OO_Mrm (0x0f83|((OP)<<3),_b11,_r8(RS),_r8(RD) ))
987     #define _BTQrm(OP, RS, MD, MB, MI, MS) (_REXQrm(RS, MB, MI), _OO_r_X (0x0f83|((OP)<<3) ,_r8(RS) ,MD,MB,MI,MS ))
988    
989     #define BTWir(IM, RD) _BTWir(X86_BT, IM, RD)
990     #define BTWim(IM, MD, MB, MI, MS) _BTWim(X86_BT, IM, MD, MI, MS)
991     #define BTWrr(RS, RD) _BTWrr(X86_BT, RS, RD)
992     #define BTWrm(RS, MD, MB, MI, MS) _BTWrm(X86_BT, RS, MD, MB, MI, MS)
993    
994     #define BTLir(IM, RD) _BTLir(X86_BT, IM, RD)
995     #define BTLim(IM, MD, MB, MI, MS) _BTLim(X86_BT, IM, MD, MB, MI, MS)
996     #define BTLrr(RS, RD) _BTLrr(X86_BT, RS, RD)
997     #define BTLrm(RS, MD, MB, MI, MS) _BTLrm(X86_BT, RS, MD, MB, MI, MS)
998    
999     #define BTQir(IM, RD) _BTQir(X86_BT, IM, RD)
1000     #define BTQim(IM, MD, MB, MI, MS) _BTQim(X86_BT, IM, MD, MB, MI, MS)
1001     #define BTQrr(RS, RD) _BTQrr(X86_BT, RS, RD)
1002     #define BTQrm(RS, MD, MB, MI, MS) _BTQrm(X86_BT, RS, MD, MB, MI, MS)
1003    
1004     #define BTCWir(IM, RD) _BTWir(X86_BTC, IM, RD)
1005     #define BTCWim(IM, MD, MB, MI, MS) _BTWim(X86_BTC, IM, MD, MI, MS)
1006     #define BTCWrr(RS, RD) _BTWrr(X86_BTC, RS, RD)
1007     #define BTCWrm(RS, MD, MB, MI, MS) _BTWrm(X86_BTC, RS, MD, MB, MI, MS)
1008    
1009     #define BTCLir(IM, RD) _BTLir(X86_BTC, IM, RD)
1010     #define BTCLim(IM, MD, MB, MI, MS) _BTLim(X86_BTC, IM, MD, MB, MI, MS)
1011     #define BTCLrr(RS, RD) _BTLrr(X86_BTC, RS, RD)
1012     #define BTCLrm(RS, MD, MB, MI, MS) _BTLrm(X86_BTC, RS, MD, MB, MI, MS)
1013    
1014     #define BTCQir(IM, RD) _BTQir(X86_BTC, IM, RD)
1015     #define BTCQim(IM, MD, MB, MI, MS) _BTQim(X86_BTC, IM, MD, MB, MI, MS)
1016     #define BTCQrr(RS, RD) _BTQrr(X86_BTC, RS, RD)
1017     #define BTCQrm(RS, MD, MB, MI, MS) _BTQrm(X86_BTC, RS, MD, MB, MI, MS)
1018    
1019     #define BTRWir(IM, RD) _BTWir(X86_BTR, IM, RD)
1020     #define BTRWim(IM, MD, MB, MI, MS) _BTWim(X86_BTR, IM, MD, MI, MS)
1021     #define BTRWrr(RS, RD) _BTWrr(X86_BTR, RS, RD)
1022     #define BTRWrm(RS, MD, MB, MI, MS) _BTWrm(X86_BTR, RS, MD, MB, MI, MS)
1023    
1024     #define BTRLir(IM, RD) _BTLir(X86_BTR, IM, RD)
1025     #define BTRLim(IM, MD, MB, MI, MS) _BTLim(X86_BTR, IM, MD, MB, MI, MS)
1026     #define BTRLrr(RS, RD) _BTLrr(X86_BTR, RS, RD)
1027     #define BTRLrm(RS, MD, MB, MI, MS) _BTLrm(X86_BTR, RS, MD, MB, MI, MS)
1028    
1029     #define BTRQir(IM, RD) _BTQir(X86_BTR, IM, RD)
1030     #define BTRQim(IM, MD, MB, MI, MS) _BTQim(X86_BTR, IM, MD, MB, MI, MS)
1031     #define BTRQrr(RS, RD) _BTQrr(X86_BTR, RS, RD)
1032     #define BTRQrm(RS, MD, MB, MI, MS) _BTQrm(X86_BTR, RS, MD, MB, MI, MS)
1033    
1034     #define BTSWir(IM, RD) _BTWir(X86_BTS, IM, RD)
1035     #define BTSWim(IM, MD, MB, MI, MS) _BTWim(X86_BTS, IM, MD, MI, MS)
1036     #define BTSWrr(RS, RD) _BTWrr(X86_BTS, RS, RD)
1037     #define BTSWrm(RS, MD, MB, MI, MS) _BTWrm(X86_BTS, RS, MD, MB, MI, MS)
1038    
1039     #define BTSLir(IM, RD) _BTLir(X86_BTS, IM, RD)
1040     #define BTSLim(IM, MD, MB, MI, MS) _BTLim(X86_BTS, IM, MD, MB, MI, MS)
1041     #define BTSLrr(RS, RD) _BTLrr(X86_BTS, RS, RD)
1042     #define BTSLrm(RS, MD, MB, MI, MS) _BTLrm(X86_BTS, RS, MD, MB, MI, MS)
1043    
1044     #define BTSQir(IM, RD) _BTQir(X86_BTS, IM, RD)
1045     #define BTSQim(IM, MD, MB, MI, MS) _BTQim(X86_BTS, IM, MD, MB, MI, MS)
1046     #define BTSQrr(RS, RD) _BTQrr(X86_BTS, RS, RD)
1047     #define BTSQrm(RS, MD, MB, MI, MS) _BTQrm(X86_BTS, RS, MD, MB, MI, MS)
1048    
1049    
1050     /* --- Move instructions --------------------------------------------------- */
1051    
1052     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1053    
1054     #define MOVBrr(RS, RD) (_REXBrr(RS, RD), _O_Mrm (0x80 ,_b11,_r1(RS),_r1(RD) ))
1055     #define MOVBmr(MD, MB, MI, MS, RD) (_REXBmr(MB, MI, RD), _O_r_X (0x8a ,_r1(RD) ,MD,MB,MI,MS ))
1056     #define MOVBrm(RS, MD, MB, MI, MS) (_REXBrm(RS, MB, MI), _O_r_X (0x88 ,_r1(RS) ,MD,MB,MI,MS ))
1057     #define MOVBir(IM, R) (_REXBrr(0, R), _Or_B (0xb0,_r1(R) ,_su8(IM)))
1058     #define MOVBim(IM, MD, MB, MI, MS) (_REXBrm(0, MB, MI), _O_X_B (0xc6 ,MD,MB,MI,MS ,_su8(IM)))
1059    
1060     #define MOVWrr(RS, RD) (_d16(), _REXLrr(RS, RD), _O_Mrm (0x89 ,_b11,_r2(RS),_r2(RD) ))
1061     #define MOVWmr(MD, MB, MI, MS, RD) (_d16(), _REXLmr(MD, MI, RD), _O_r_X (0x8b ,_r2(RD) ,MD,MB,MI,MS ))
1062     #define MOVWrm(RS, MD, MB, MI, MS) (_d16(), _REXLrm(RS, MD, MI), _O_r_X (0x89 ,_r2(RS) ,MD,MB,MI,MS ))
1063     #define MOVWir(IM, R) (_d16(), _REXLrr(0, R), _Or_W (0xb8,_r2(R) ,_su16(IM)))
1064     #define MOVWim(IM, MD, MB, MI, MS) (_d16(), _REXLrm(0, MD, MI), _O_X_W (0xc7 ,MD,MB,MI,MS ,_su16(IM)))
1065    
1066     #define MOVLrr(RS, RD) (_REXLrr(RS, RD), _O_Mrm (0x89 ,_b11,_r4(RS),_r4(RD) ))
1067     #define MOVLmr(MD, MB, MI, MS, RD) (_REXLmr(MB, MI, RD), _O_r_X (0x8b ,_r4(RD) ,MD,MB,MI,MS ))
1068     #define MOVLrm(RS, MD, MB, MI, MS) (_REXLrm(RS, MB, MI), _O_r_X (0x89 ,_r4(RS) ,MD,MB,MI,MS ))
1069     #define MOVLir(IM, R) (_REXLrr(0, R), _Or_L (0xb8,_r4(R) ,IM ))
1070     #define MOVLim(IM, MD, MB, MI, MS) (_REXLrm(0, MB, MI), _O_X_L (0xc7 ,MD,MB,MI,MS ,IM ))
1071    
1072     #define MOVQrr(RS, RD) (_REXQrr(RS, RD), _O_Mrm (0x89 ,_b11,_r8(RS),_r8(RD) ))
1073     #define MOVQmr(MD, MB, MI, MS, RD) (_REXQmr(MB, MI, RD), _O_r_X (0x8b ,_r8(RD) ,MD,MB,MI,MS ))
1074     #define MOVQrm(RS, MD, MB, MI, MS) (_REXQrm(RS, MB, MI), _O_r_X (0x89 ,_r8(RS) ,MD,MB,MI,MS ))
1075     #define MOVQir(IM, R) (_REXQrr(0, R), _Or_L (0xb8,_r8(R) ,IM ))
1076     #define MOVQim(IM, MD, MB, MI, MS) (_REXQrm(0, MB, MI), _O_X_L (0xc7 ,MD,MB,MI,MS ,IM ))
1077    
1078    
1079     /* --- Unary and Multiply/Divide instructions ------------------------------ */
1080    
1081 gbeauche 1.2 enum {
1082 gbeauche 1.1 X86_NOT = 2,
1083     X86_NEG = 3,
1084     X86_MUL = 4,
1085     X86_IMUL = 5,
1086     X86_DIV = 6,
1087     X86_IDIV = 7,
1088 gbeauche 1.2 };
1089 gbeauche 1.1
1090     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1091    
1092     #define _UNARYBr(OP, RS) (_REXBrr(0, RS), _O_Mrm (0xf6 ,_b11,OP ,_r1(RS) ))
1093     #define _UNARYBm(OP, MD, MB, MI, MS) (_REXBrm(0, MB, MI), _O_r_X (0xf6 ,OP ,MD,MB,MI,MS ))
1094     #define _UNARYWr(OP, RS) (_d16(), _REXLrr(0, RS), _O_Mrm (0xf7 ,_b11,OP ,_r2(RS) ))
1095     #define _UNARYWm(OP, MD, MB, MI, MS) (_d16(), _REXLmr(MB, MI, 0), _O_r_X (0xf7 ,OP ,MD,MB,MI,MS ))
1096     #define _UNARYLr(OP, RS) (_REXLrr(0, RS), _O_Mrm (0xf7 ,_b11,OP ,_r4(RS) ))
1097     #define _UNARYLm(OP, MD, MB, MI, MS) (_REXLmr(MB, MI, 0), _O_r_X (0xf7 ,OP ,MD,MB,MI,MS ))
1098     #define _UNARYQr(OP, RS) (_REXQrr(0, RS), _O_Mrm (0xf7 ,_b11,OP ,_r8(RS) ))
1099     #define _UNARYQm(OP, MD, MB, MI, MS) (_REXQmr(MB, MI, 0), _O_r_X (0xf7 ,OP ,MD,MB,MI,MS ))
1100    
1101     #define NOTBr(RS) _UNARYBr(X86_NOT, RS)
1102     #define NOTBm(MD, MB, MI, MS) _UNARYBm(X86_NOT, MD, MB, MI, MS)
1103     #define NOTWr(RS) _UNARYWr(X86_NOT, RS)
1104     #define NOTWm(MD, MB, MI, MS) _UNARYWm(X86_NOT, MD, MB, MI, MS)
1105     #define NOTLr(RS) _UNARYLr(X86_NOT, RS)
1106     #define NOTLm(MD, MB, MI, MS) _UNARYLm(X86_NOT, MD, MB, MI, MS)
1107     #define NOTQr(RS) _UNARYQr(X86_NOT, RS)
1108     #define NOTQm(MD, MB, MI, MS) _UNARYQm(X86_NOT, MD, MB, MI, MS)
1109    
1110     #define NEGBr(RS) _UNARYBr(X86_NEG, RS)
1111     #define NEGBm(MD, MB, MI, MS) _UNARYBm(X86_NEG, MD, MB, MI, MS)
1112     #define NEGWr(RS) _UNARYWr(X86_NEG, RS)
1113     #define NEGWm(MD, MB, MI, MS) _UNARYWm(X86_NEG, MD, MB, MI, MS)
1114     #define NEGLr(RS) _UNARYLr(X86_NEG, RS)
1115     #define NEGLm(MD, MB, MI, MS) _UNARYLm(X86_NEG, MD, MB, MI, MS)
1116     #define NEGQr(RS) _UNARYQr(X86_NEG, RS)
1117     #define NEGQm(MD, MB, MI, MS) _UNARYQm(X86_NEG, MD, MB, MI, MS)
1118    
1119     #define MULBr(RS) _UNARYBr(X86_MUL, RS)
1120     #define MULBm(MD, MB, MI, MS) _UNARYBm(X86_MUL, MD, MB, MI, MS)
1121     #define MULWr(RS) _UNARYWr(X86_MUL, RS)
1122     #define MULWm(MD, MB, MI, MS) _UNARYWm(X86_MUL, MD, MB, MI, MS)
1123     #define MULLr(RS) _UNARYLr(X86_MUL, RS)
1124     #define MULLm(MD, MB, MI, MS) _UNARYLm(X86_MUL, MD, MB, MI, MS)
1125     #define MULQr(RS) _UNARYQr(X86_MUL, RS)
1126     #define MULQm(MD, MB, MI, MS) _UNARYQm(X86_MUL, MD, MB, MI, MS)
1127    
1128     #define IMULBr(RS) _UNARYBr(X86_IMUL, RS)
1129     #define IMULBm(MD, MB, MI, MS) _UNARYBm(X86_IMUL, MD, MB, MI, MS)
1130     #define IMULWr(RS) _UNARYWr(X86_IMUL, RS)
1131     #define IMULWm(MD, MB, MI, MS) _UNARYWm(X86_IMUL, MD, MB, MI, MS)
1132     #define IMULLr(RS) _UNARYLr(X86_IMUL, RS)
1133     #define IMULLm(MD, MB, MI, MS) _UNARYLm(X86_IMUL, MD, MB, MI, MS)
1134     #define IMULQr(RS) _UNARYQr(X86_IMUL, RS)
1135     #define IMULQm(MD, MB, MI, MS) _UNARYQm(X86_IMUL, MD, MB, MI, MS)
1136    
1137     #define DIVBr(RS) _UNARYBr(X86_DIV, RS)
1138     #define DIVBm(MD, MB, MI, MS) _UNARYBm(X86_DIV, MD, MB, MI, MS)
1139     #define DIVWr(RS) _UNARYWr(X86_DIV, RS)
1140     #define DIVWm(MD, MB, MI, MS) _UNARYWm(X86_DIV, MD, MB, MI, MS)
1141     #define DIVLr(RS) _UNARYLr(X86_DIV, RS)
1142     #define DIVLm(MD, MB, MI, MS) _UNARYLm(X86_DIV, MD, MB, MI, MS)
1143     #define DIVQr(RS) _UNARYQr(X86_DIV, RS)
1144     #define DIVQm(MD, MB, MI, MS) _UNARYQm(X86_DIV, MD, MB, MI, MS)
1145    
1146     #define IDIVBr(RS) _UNARYBr(X86_IDIV, RS)
1147     #define IDIVBm(MD, MB, MI, MS) _UNARYBm(X86_IDIV, MD, MB, MI, MS)
1148     #define IDIVWr(RS) _UNARYWr(X86_IDIV, RS)
1149     #define IDIVWm(MD, MB, MI, MS) _UNARYWm(X86_IDIV, MD, MB, MI, MS)
1150     #define IDIVLr(RS) _UNARYLr(X86_IDIV, RS)
1151     #define IDIVLm(MD, MB, MI, MS) _UNARYLm(X86_IDIV, MD, MB, MI, MS)
1152     #define IDIVQr(RS) _UNARYQr(X86_IDIV, RS)
1153     #define IDIVQm(MD, MB, MI, MS) _UNARYQm(X86_IDIV, MD, MB, MI, MS)
1154    
1155     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1156    
1157     #define IMULWrr(RS, RD) (_d16(), _REXLrr(RS, RD), _OO_Mrm (0x0faf ,_b11,_r2(RS),_r2(RD) ))
1158     #define IMULWmr(MD, MB, MI, MS, RD) (_d16(), _REXLmr(MB, MI, RD), _OO_r_X (0x0faf ,_r2(RD) ,MD,MB,MI,MS ))
1159    
1160     #define IMULWirr(IM,RS,RD) (_d16(), _REXLrr(RS, RD), _Os_Mrm_sW (0x69 ,_b11,_r2(RS),_r2(RD) ,_su16(IM) ))
1161     #define IMULWimr(IM,MD,MB,MI,MS,RD) (_d16(), _REXLmr(MB, MI, RD), _Os_r_X_sW (0x69 ,_r2(RD) ,MD,MB,MI,MS ,_su16(IM) ))
1162    
1163     #define IMULLir(IM, RD) (_REXLrr(0, RD), _Os_Mrm_sL (0x69 ,_b11,_r4(RD),_r4(RD) ,IM ))
1164     #define IMULLrr(RS, RD) (_REXLrr(RS, RD), _OO_Mrm (0x0faf ,_b11,_r4(RD),_r4(RS) ))
1165     #define IMULLmr(MD, MB, MI, MS, RD) (_REXLmr(MB, MI, RD), _OO_r_X (0x0faf ,_r4(RD) ,MD,MB,MI,MS ))
1166    
1167     #define IMULQir(IM, RD) (_REXQrr(0, RD), _Os_Mrm_sL (0x69 ,_b11,_r8(RD),_r8(RD) ,IM ))
1168     #define IMULQrr(RS, RD) (_REXQrr(RS, RD), _OO_Mrm (0x0faf ,_b11,_r8(RD),_r8(RS) ))
1169     #define IMULQmr(MD, MB, MI, MS, RD) (_REXQmr(MB, MI, RD), _OO_r_X (0x0faf ,_r8(RD) ,MD,MB,MI,MS ))
1170    
1171     #define IMULLirr(IM,RS,RD) (_REXLrr(RS, RD), _Os_Mrm_sL (0x69 ,_b11,_r4(RS),_r4(RD) ,IM ))
1172     #define IMULLimr(IM,MD,MB,MI,MS,RD) (_REXLmr(MB, MI, RD), _Os_r_X_sL (0x69 ,_r4(RD) ,MD,MB,MI,MS ,IM ))
1173    
1174     #define IMULQirr(IM,RS,RD) (_REXQrr(RS, RD), _Os_Mrm_sL (0x69 ,_b11,_r8(RS),_r8(RD) ,IM ))
1175     #define IMULQimr(IM,MD,MB,MI,MS,RD) (_REXQmr(MB, MI, RD), _Os_r_X_sL (0x69 ,_r8(RD) ,MD,MB,MI,MS ,IM ))
1176    
1177    
1178     /* --- Control Flow related instructions ----------------------------------- */
1179    
1180 gbeauche 1.5 enum {
1181     X86_CC_O = 0x0,
1182     X86_CC_NO = 0x1,
1183     X86_CC_NAE = 0x2,
1184     X86_CC_B = 0x2,
1185     X86_CC_C = 0x2,
1186     X86_CC_AE = 0x3,
1187     X86_CC_NB = 0x3,
1188     X86_CC_NC = 0x3,
1189     X86_CC_E = 0x4,
1190     X86_CC_Z = 0x4,
1191     X86_CC_NE = 0x5,
1192     X86_CC_NZ = 0x5,
1193     X86_CC_BE = 0x6,
1194     X86_CC_NA = 0x6,
1195     X86_CC_A = 0x7,
1196     X86_CC_NBE = 0x7,
1197     X86_CC_S = 0x8,
1198     X86_CC_NS = 0x9,
1199     X86_CC_P = 0xa,
1200     X86_CC_PE = 0xa,
1201     X86_CC_NP = 0xb,
1202     X86_CC_PO = 0xb,
1203     X86_CC_L = 0xc,
1204     X86_CC_NGE = 0xc,
1205     X86_CC_GE = 0xd,
1206     X86_CC_NL = 0xd,
1207     X86_CC_LE = 0xe,
1208     X86_CC_NG = 0xe,
1209     X86_CC_G = 0xf,
1210     X86_CC_NLE = 0xf,
1211     };
1212    
1213 gbeauche 1.1 /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1214    
1215     // FIXME: no prefix is availble to encode a 32-bit operand size in 64-bit mode
1216     #define CALLm(M) _O_D32 (0xe8 ,(int)(M) )
1217     #define CALLsr(R) (_REXLrr(0, R), _O_Mrm (0xff ,_b11,_b010,_r4(R) ))
1218     #define CALLQsr(R) (_REXQrr(0, R), _O_Mrm (0xff ,_b11,_b010,_r8(R) ))
1219     #define CALLsm(D,B,I,S) (_REXLrm(0, B, I), _O_r_X (0xff ,_b010 ,(int)(D),B,I,S ))
1220    
1221     // FIXME: no prefix is availble to encode a 32-bit operand size in 64-bit mode
1222     #define JMPSm(M) _O_D8 (0xeb ,(int)(D) )
1223     #define JMPm(M) _O_D32 (0xe9 ,(int)(D) )
1224     #define JMPsr(R) (_REXLrr(0, R), _O_Mrm (0xff ,_b11,_b100,_r4(R) ))
1225     #define JMPQsr(R) (_REXQrr(0, R), _O_Mrm (0xff ,_b11,_b100,_r8(R) ))
1226     #define JMPsm(D,B,I,S) (_REXLrm(0, B, I), _O_r_X (0xff ,_b100 ,(int)(D),B,I,S ))
1227    
1228     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1229     #define JCCSim(CC, D) _O_D8 (0x70|(CC) ,(int)(D) )
1230     #define JOSm(D) JCCSim(0x0, D)
1231     #define JNOSm(D) JCCSim(0x1, D)
1232     #define JBSm(D) JCCSim(0x2, D)
1233     #define JNAESm(D) JCCSim(0x2, D)
1234     #define JNBSm(D) JCCSim(0x3, D)
1235     #define JAESm(D) JCCSim(0x3, D)
1236     #define JESm(D) JCCSim(0x4, D)
1237     #define JZSm(D) JCCSim(0x4, D)
1238     #define JNESm(D) JCCSim(0x5, D)
1239     #define JNZSm(D) JCCSim(0x5, D)
1240     #define JBESm(D) JCCSim(0x6, D)
1241     #define JNASm(D) JCCSim(0x6, D)
1242     #define JNBESm(D) JCCSim(0x7, D)
1243     #define JASm(D) JCCSim(0x7, D)
1244     #define JSSm(D) JCCSim(0x8, D)
1245     #define JNSSm(D) JCCSim(0x9, D)
1246     #define JPSm(D) JCCSim(0xa, D)
1247     #define JPESm(D) JCCSim(0xa, D)
1248     #define JNPSm(D) JCCSim(0xb, D)
1249     #define JPOSm(D) JCCSim(0xb, D)
1250     #define JLSm(D) JCCSim(0xc, D)
1251     #define JNGESm(D) JCCSim(0xc, D)
1252     #define JNLSm(D) JCCSim(0xd, D)
1253     #define JGESm(D) JCCSim(0xd, D)
1254     #define JLESm(D) JCCSim(0xe, D)
1255     #define JNGSm(D) JCCSim(0xe, D)
1256     #define JNLESm(D) JCCSim(0xf, D)
1257     #define JGSm(D) JCCSim(0xf, D)
1258    
1259     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1260     #define JCCim(CC, D) _OO_D32 (0x0f80|(CC) ,(int)(D) )
1261     #define JOm(D) JCCim(0x0, D)
1262     #define JNOm(D) JCCim(0x1, D)
1263     #define JBm(D) JCCim(0x2, D)
1264     #define JNAEm(D) JCCim(0x2, D)
1265     #define JNBm(D) JCCim(0x3, D)
1266     #define JAEm(D) JCCim(0x3, D)
1267     #define JEm(D) JCCim(0x4, D)
1268     #define JZm(D) JCCim(0x4, D)
1269     #define JNEm(D) JCCim(0x5, D)
1270     #define JNZm(D) JCCim(0x5, D)
1271     #define JBEm(D) JCCim(0x6, D)
1272     #define JNAm(D) JCCim(0x6, D)
1273     #define JNBEm(D) JCCim(0x7, D)
1274     #define JAm(D) JCCim(0x7, D)
1275     #define JSm(D) JCCim(0x8, D)
1276     #define JNSm(D) JCCim(0x9, D)
1277     #define JPm(D) JCCim(0xa, D)
1278     #define JPEm(D) JCCim(0xa, D)
1279     #define JNPm(D) JCCim(0xb, D)
1280     #define JPOm(D) JCCim(0xb, D)
1281     #define JLm(D) JCCim(0xc, D)
1282     #define JNGEm(D) JCCim(0xc, D)
1283     #define JNLm(D) JCCim(0xd, D)
1284     #define JGEm(D) JCCim(0xd, D)
1285     #define JLEm(D) JCCim(0xe, D)
1286     #define JNGm(D) JCCim(0xe, D)
1287     #define JNLEm(D) JCCim(0xf, D)
1288     #define JGm(D) JCCim(0xf, D)
1289    
1290     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1291     #define SETCCir(CC, RD) (_REXBrr(0, RD), _OO_Mrm (0x0f90|(CC) ,_b11,_b000,_r1(RD) ))
1292     #define SETOr(RD) SETCCir(0x0,RD)
1293     #define SETNOr(RD) SETCCir(0x1,RD)
1294     #define SETBr(RD) SETCCir(0x2,RD)
1295     #define SETNAEr(RD) SETCCir(0x2,RD)
1296     #define SETNBr(RD) SETCCir(0x3,RD)
1297     #define SETAEr(RD) SETCCir(0x3,RD)
1298     #define SETEr(RD) SETCCir(0x4,RD)
1299     #define SETZr(RD) SETCCir(0x4,RD)
1300     #define SETNEr(RD) SETCCir(0x5,RD)
1301     #define SETNZr(RD) SETCCir(0x5,RD)
1302     #define SETBEr(RD) SETCCir(0x6,RD)
1303     #define SETNAr(RD) SETCCir(0x6,RD)
1304     #define SETNBEr(RD) SETCCir(0x7,RD)
1305     #define SETAr(RD) SETCCir(0x7,RD)
1306     #define SETSr(RD) SETCCir(0x8,RD)
1307     #define SETNSr(RD) SETCCir(0x9,RD)
1308     #define SETPr(RD) SETCCir(0xa,RD)
1309     #define SETPEr(RD) SETCCir(0xa,RD)
1310     #define SETNPr(RD) SETCCir(0xb,RD)
1311     #define SETPOr(RD) SETCCir(0xb,RD)
1312     #define SETLr(RD) SETCCir(0xc,RD)
1313     #define SETNGEr(RD) SETCCir(0xc,RD)
1314     #define SETNLr(RD) SETCCir(0xd,RD)
1315     #define SETGEr(RD) SETCCir(0xd,RD)
1316     #define SETLEr(RD) SETCCir(0xe,RD)
1317     #define SETNGr(RD) SETCCir(0xe,RD)
1318     #define SETNLEr(RD) SETCCir(0xf,RD)
1319     #define SETGr(RD) SETCCir(0xf,RD)
1320    
1321     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1322     #define SETCCim(CC,MD,MB,MI,MS) (_REXBrm(0, MB, MI), _OO_r_X (0x0f90|(CC) ,_b000 ,MD,MB,MI,MS ))
1323     #define SETOm(D, B, I, S) SETCCim(0x0, D, B, I, S)
1324     #define SETNOm(D, B, I, S) SETCCim(0x1, D, B, I, S)
1325     #define SETBm(D, B, I, S) SETCCim(0x2, D, B, I, S)
1326     #define SETNAEm(D, B, I, S) SETCCim(0x2, D, B, I, S)
1327     #define SETNBm(D, B, I, S) SETCCim(0x3, D, B, I, S)
1328     #define SETAEm(D, B, I, S) SETCCim(0x3, D, B, I, S)
1329     #define SETEm(D, B, I, S) SETCCim(0x4, D, B, I, S)
1330     #define SETZm(D, B, I, S) SETCCim(0x4, D, B, I, S)
1331     #define SETNEm(D, B, I, S) SETCCim(0x5, D, B, I, S)
1332     #define SETNZm(D, B, I, S) SETCCim(0x5, D, B, I, S)
1333     #define SETBEm(D, B, I, S) SETCCim(0x6, D, B, I, S)
1334     #define SETNAm(D, B, I, S) SETCCim(0x6, D, B, I, S)
1335     #define SETNBEm(D, B, I, S) SETCCim(0x7, D, B, I, S)
1336     #define SETAm(D, B, I, S) SETCCim(0x7, D, B, I, S)
1337     #define SETSm(D, B, I, S) SETCCim(0x8, D, B, I, S)
1338     #define SETNSm(D, B, I, S) SETCCim(0x9, D, B, I, S)
1339     #define SETPm(D, B, I, S) SETCCim(0xa, D, B, I, S)
1340     #define SETPEm(D, B, I, S) SETCCim(0xa, D, B, I, S)
1341     #define SETNPm(D, B, I, S) SETCCim(0xb, D, B, I, S)
1342     #define SETPOm(D, B, I, S) SETCCim(0xb, D, B, I, S)
1343     #define SETLm(D, B, I, S) SETCCim(0xc, D, B, I, S)
1344     #define SETNGEm(D, B, I, S) SETCCim(0xc, D, B, I, S)
1345     #define SETNLm(D, B, I, S) SETCCim(0xd, D, B, I, S)
1346     #define SETGEm(D, B, I, S) SETCCim(0xd, D, B, I, S)
1347     #define SETLEm(D, B, I, S) SETCCim(0xe, D, B, I, S)
1348     #define SETNGm(D, B, I, S) SETCCim(0xe, D, B, I, S)
1349     #define SETNLEm(D, B, I, S) SETCCim(0xf, D, B, I, S)
1350     #define SETGm(D, B, I, S) SETCCim(0xf, D, B, I, S)
1351    
1352 gbeauche 1.5 /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1353     #define CMOVWrr(CC,RS,RD) (_d16(), _REXLrr(RD, RS), _OO_Mrm (0x0f40|(CC) ,_b11,_r2(RD),_r2(RS) ))
1354     #define CMOVWmr(CC,MD,MB,MI,MS,RD) (_d16(), _REXLmr(MB, MI, RD), _OO_r_X (0x0f40|(CC) ,_r2(RD) ,MD,MB,MI,MS ))
1355     #define CMOVLrr(CC,RS,RD) (_REXLrr(RD, RS), _OO_Mrm (0x0f40|(CC) ,_b11,_r4(RD),_r4(RS) ))
1356     #define CMOVLmr(CC,MD,MB,MI,MS,RD) (_REXLmr(MB, MI, RD), _OO_r_X (0x0f40|(CC) ,_r4(RD) ,MD,MB,MI,MS ))
1357     #define CMOVQrr(CC,RS,RD) (_REXQrr(RD, RS), _OO_Mrm (0x0f40|(CC) ,_b11,_r8(RD),_r8(RS) ))
1358     #define CMOVQmr(CC,MD,MB,MI,MS,RD) (_REXQmr(MB, MI, RD), _OO_r_X (0x0f40|(CC) ,_r8(RD) ,MD,MB,MI,MS ))
1359    
1360 gbeauche 1.1
1361     /* --- Push/Pop instructions ----------------------------------------------- */
1362    
1363     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1364    
1365     #define POPWr(RD) _m32only((_d16(), _Or (0x58,_r2(RD) )))
1366     #define POPWm(MD, MB, MI, MS) _m32only((_d16(), _O_r_X (0x8f ,_b000 ,MD,MB,MI,MS )))
1367    
1368     #define POPLr(RD) _m32only( _Or (0x58,_r4(RD) ))
1369     #define POPLm(MD, MB, MI, MS) _m32only( _O_r_X (0x8f ,_b000 ,MD,MB,MI,MS ))
1370    
1371     #define POPQr(RD) _m64only( _Or (0x58,_r8(RD) ))
1372     #define POPQm(MD, MB, MI, MS) _m64only( _O_r_X (0x8f ,_b000 ,MD,MB,MI,MS ))
1373    
1374     #define PUSHWr(RS) _m32only((_d16(), _Or (0x50,_r2(RS) )))
1375     #define PUSHWm(MD, MB, MI, MS) _m32only((_d16(), _O_r_X (0xff, ,_b110 ,MD,MB,MI,MS )))
1376     #define PUSHWi(IM) _m32only((_d16(), _Os_sW (0x68 ,IM )))
1377    
1378     #define PUSHLr(RS) _m32only( _Or (0x50,_r4(RS) ))
1379     #define PUSHLm(MD, MB, MI, MS) _m32only( _O_r_X (0xff ,_b110 ,MD,MB,MI,MS ))
1380     #define PUSHLi(IM) _m32only( _Os_sL (0x68 ,IM ))
1381    
1382     #define PUSHQr(RS) _m64only( _Or (0x50,_r8(RS) ))
1383     #define PUSHQm(MD, MB, MI, MS) _m64only( _O_r_X (0xff ,_b110 ,MD,MB,MI,MS ))
1384     #define PUSHQi(IM) _m64only( _Os_sL (0x68 ,IM ))
1385    
1386     #define POPA() (_d16(), _O (0x61 ))
1387     #define POPAD() _O (0x61 )
1388    
1389     #define PUSHA() (_d16(), _O (0x60 ))
1390     #define PUSHAD() _O (0x60 )
1391    
1392     #define POPF() (_d16(), _O (0x9d ))
1393     #define POPFD() _O (0x9d )
1394    
1395     #define PUSHF() _O (0x9c )
1396     #define PUSHFD() (_d16(), _O (0x9c ))
1397    
1398    
1399     /* --- Test instructions --------------------------------------------------- */
1400    
1401     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1402    
1403     #define TESTBrr(RS, RD) (_REXBrr(RS, RD), _O_Mrm (0x84 ,_b11,_r1(RS),_r1(RD) ))
1404     #define TESTBrm(RS, MD, MB, MI, MS) (_REXBrm(RS, MB, MI), _O_r_X (0x84 ,_r1(RS) ,MD,MB,MI,MS ))
1405     #define TESTBir(IM, RD) (_REXBrr(0, RD), _O_Mrm_B (0xf6 ,_b11,_b000 ,_r1(RD) ,_u8(IM)))
1406     #define TESTBim(IM, MD, MB, MI, MS) (_REXBrm(0, MB, MI), _O_r_X_B (0xf6 ,_b000 ,MD,MB,MI,MS ,_u8(IM)))
1407    
1408     #define TESTWrr(RS, RD) (_d16(), _REXLrr(RS, RD), _O_Mrm (0x85 ,_b11,_r2(RS),_r2(RD) ))
1409     #define TESTWrm(RS, MD, MB, MI, MS) (_d16(), _REXLrm(RS, MD, MI), _O_r_X (0x85 ,_r2(RS) ,MD,MB,MI,MS ))
1410     #define TESTWir(IM, RD) (_d16(), _REXLrr(0, RD), _O_Mrm_W (0xf7 ,_b11,_b000 ,_r2(RD) ,_u16(IM)))
1411     #define TESTWim(IM, MD, MB, MI, MS) (_d16(), _REXLrm(0, MD, MI), _O_r_X_W (0xf7 ,_b000 ,MD,MB,MI,MS ,_u16(IM)))
1412    
1413     #define TESTLrr(RS, RD) (_REXLrr(RS, RD), _O_Mrm (0x85 ,_b11,_r4(RS),_r4(RD) ))
1414     #define TESTLrm(RS, MD, MB, MI, MS) (_REXLrm(RS, MB, MI), _O_r_X (0x85 ,_r4(RS) ,MD,MB,MI,MS ))
1415     #define TESTLir(IM, RD) (_REXLrr(0, RD), _O_Mrm_L (0xf7 ,_b11,_b000 ,_r4(RD) ,IM ))
1416     #define TESTLim(IM, MD, MB, MI, MS) (_REXLrm(0, MB, MI), _O_r_X_L (0xf7 ,_b000 ,MD,MB,MI,MS ,IM ))
1417    
1418     #define TESTQrr(RS, RD) (_REXQrr(RS, RD), _O_Mrm (0x85 ,_b11,_r8(RS),_r8(RD) ))
1419     #define TESTQrm(RS, MD, MB, MI, MS) (_REXQrm(RS, MB, MI), _O_r_X (0x85 ,_r8(RS) ,MD,MB,MI,MS ))
1420     #define TESTQir(IM, RD) (_REXQrr(0, RD), _O_Mrm_L (0xf7 ,_b11,_b000 ,_r8(RD) ,IM ))
1421     #define TESTQim(IM, MD, MB, MI, MS) (_REXQrm(0, MB, MI), _O_r_X_L (0xf7 ,_b000 ,MD,MB,MI,MS ,IM ))
1422    
1423    
1424     /* --- Exchange instructions ----------------------------------------------- */
1425    
1426     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1427    
1428     #define CMPXCHGBrr(RS, RD) (_REXBrr(RS, RD), _OO_Mrm (0x0fb0 ,_b11,_r1(RS),_r1(RD) ))
1429     #define CMPXCHGBrm(RS, MD, MB, MI, MS) (_REXBrm(RS, MB, MI), _OO_r_X (0x0fb0 ,_r1(RS) ,MD,MB,MI,MS ))
1430    
1431     #define CMPXCHGWrr(RS, RD) (_d16(), _REXLrr(RS, RD), _OO_Mrm (0x0fb1 ,_b11,_r2(RS),_r2(RD) ))
1432     #define CMPXCHGWrm(RS, MD, MB, MI, MS) (_d16(), _REXLrm(RS, MB, MI), _OO_r_X (0x0fb1 ,_r2(RS) ,MD,MB,MI,MS ))
1433    
1434     #define CMPXCHGLrr(RS, RD) (_REXLrr(RS, RD), _OO_Mrm (0x0fb1 ,_b11,_r4(RS),_r4(RD) ))
1435     #define CMPXCHGLrm(RS, MD, MB, MI, MS) (_REXLrm(RS, MB, MI), _OO_r_X (0x0fb1 ,_r4(RS) ,MD,MB,MI,MS ))
1436    
1437     #define CMPXCHGQrr(RS, RD) (_REXQrr(RS, RD), _OO_Mrm (0x0fb1 ,_b11,_r8(RS),_r8(RD) ))
1438     #define CMPXCHGQrm(RS, MD, MB, MI, MS) (_REXQrm(RS, MB, MI), _OO_r_X (0x0fb1 ,_r8(RS) ,MD,MB,MI,MS ))
1439    
1440     #define XADDBrr(RS, RD) (_REXBrr(RS, RD), _OO_Mrm (0x0fc0 ,_b11,_r1(RS),_r1(RD) ))
1441     #define XADDBrm(RS, MD, MB, MI, MS) (_REXBrm(RS, MB, MI), _OO_r_X (0x0fc0 ,_r1(RS) ,MD,MB,MI,MS ))
1442    
1443     #define XADDWrr(RS, RD) (_d16(), _REXLrr(RS, RD), _OO_Mrm (0x0fc1 ,_b11,_r2(RS),_r2(RD) ))
1444     #define XADDWrm(RS, MD, MB, MI, MS) (_d16(), _REXLrm(RS, MB, MI), _OO_r_X (0x0fc1 ,_r2(RS) ,MD,MB,MI,MS ))
1445    
1446     #define XADDLrr(RS, RD) (_REXLrr(RS, RD), _OO_Mrm (0x0fc1 ,_b11,_r4(RS),_r4(RD) ))
1447     #define XADDLrm(RS, MD, MB, MI, MS) (_REXLrm(RS, MB, MI), _OO_r_X (0x0fc1 ,_r4(RS) ,MD,MB,MI,MS ))
1448    
1449     #define XADDQrr(RS, RD) (_REXQrr(RS, RD), _OO_Mrm (0x0fc1 ,_b11,_r8(RS),_r8(RD) ))
1450     #define XADDQrm(RS, MD, MB, MI, MS) (_REXQrm(RS, MB, MI), _OO_r_X (0x0fc1 ,_r8(RS) ,MD,MB,MI,MS ))
1451    
1452     #define XCHGBrr(RS, RD) (_REXBrr(RS, RD), _O_Mrm (0x86 ,_b11,_r1(RS),_r1(RD) ))
1453     #define XCHGBrm(RS, MD, MB, MI, MS) (_REXBrm(RS, MB, MI), _O_r_X (0x86 ,_r1(RS) ,MD,MB,MI,MS ))
1454    
1455     #define XCHGWrr(RS, RD) (_d16(), _REXLrr(RS, RD), _O_Mrm (0x87 ,_b11,_r2(RS),_r2(RD) ))
1456     #define XCHGWrm(RS, MD, MB, MI, MS) (_d16(), _REXLrm(RS, MB, MI), _O_r_X (0x87 ,_r2(RS) ,MD,MB,MI,MS ))
1457    
1458     #define XCHGLrr(RS, RD) (_REXLrr(RS, RD), _O_Mrm (0x87 ,_b11,_r4(RS),_r4(RD) ))
1459     #define XCHGLrm(RS, MD, MB, MI, MS) (_REXLrm(RS, MB, MI), _O_r_X (0x87 ,_r4(RS) ,MD,MB,MI,MS ))
1460    
1461     #define XCHGQrr(RS, RD) (_REXQrr(RS, RD), _O_Mrm (0x87 ,_b11,_r8(RS),_r8(RD) ))
1462     #define XCHGQrm(RS, MD, MB, MI, MS) (_REXQrm(RS, MB, MI), _O_r_X (0x87 ,_r8(RS) ,MD,MB,MI,MS ))
1463    
1464    
1465     /* --- Increment/Decrement instructions ------------------------------------ */
1466    
1467     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1468    
1469     #define DECBm(MD, MB, MI, MS) (_REXBrm(0, MB, MI), _O_r_X (0xfe ,_b001 ,MD,MB,MI,MS ))
1470     #define DECBr(RD) (_REXBrr(0, RD), _O_Mrm (0xfe ,_b11,_b001 ,_r1(RD) ))
1471    
1472     #define DECWm(MD, MB, MI, MS) (_d16(), _REXLrm(0, MB, MI), _O_r_X (0xff ,_b001 ,MD,MB,MI,MS ))
1473     #define DECWr(RD) (! X86_TARGET_64BIT ? (_d16(), _Or (0x48,_r2(RD) )) : \
1474     (_d16(), _REXLrr(0, RD), _O_Mrm (0xff ,_b11,_b001 ,_r2(RD) )))
1475    
1476     #define DECLm(MD, MB, MI, MS) (_REXLrm(0, MB, MI), _O_r_X (0xff ,_b001 ,MD,MB,MI,MS ))
1477     #define DECLr(RD) (! X86_TARGET_64BIT ? _Or (0x48,_r4(RD) ) : \
1478     (_REXLrr(0, RD), _O_Mrm (0xff ,_b11,_b001 ,_r4(RD) )))
1479    
1480     #define DECQm(MD, MB, MI, MS) (_REXQrm(0, MB, MI), _O_r_X (0xff ,_b001 ,MD,MB,MI,MS ))
1481     #define DECQr(RD) (_REXQrr(0, RD), _O_Mrm (0xff ,_b11,_b001 ,_r8(RD) ))
1482    
1483     #define INCBm(MD, MB, MI, MS) (_REXBrm(0, MB, MI), _O_r_X (0xfe ,_b000 ,MD,MB,MI,MS ))
1484     #define INCBr(RD) (_REXBrr(0, RD), _O_Mrm (0xfe ,_b11,_b000 ,_r1(RD) ))
1485    
1486     #define INCWm(MD, MB, MI, MS) (_d16(), _REXLrm(0, MB, MI), _O_r_X (0xff ,_b000 ,MD,MB,MI,MS ))
1487     #define INCWr(RD) (! X86_TARGET_64BIT ? (_d16(), _Or (0x40,_r2(RD) )) : \
1488     (_d16(), _REXLrr(0, RD), _O_Mrm (0xff ,_b11,_b000 ,_r2(RD) )) )
1489    
1490     #define INCLm(MD, MB, MI, MS) (_REXLrm(0, MB, MI), _O_r_X (0xff ,_b000 ,MD,MB,MI,MS ))
1491     #define INCLr(RD) (! X86_TARGET_64BIT ? _Or (0x40,_r4(RD) ) : \
1492     (_REXLrr(0, RD), _O_Mrm (0xff ,_b11,_b000 ,_r4(RD) )))
1493    
1494     #define INCQm(MD, MB, MI, MS) (_REXQrm(0, MB, MI), _O_r_X (0xff ,_b000 ,MD,MB,MI,MS ))
1495     #define INCQr(RD) (_REXQrr(0, RD), _O_Mrm (0xff ,_b11,_b000 ,_r8(RD) ))
1496    
1497    
1498 gbeauche 1.5 /* --- Misc instructions --------------------------------------------------- */
1499    
1500     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1501    
1502     #define BSFWrr(RS, RD) (_d16(), _REXLrr(RD, RS), _OO_Mrm (0x0fbc ,_b11,_r2(RD),_r2(RS) ))
1503     #define BSFWmr(MD, MB, MI, MS, RD) (_d16(), _REXLmr(MB, MI, RD), _OO_r_X (0x0fbc ,_r2(RD) ,MD,MB,MI,MS ))
1504     #define BSRWrr(RS, RD) (_d16(), _REXLrr(RD, RS), _OO_Mrm (0x0fbd ,_b11,_r2(RD),_r2(RS) ))
1505     #define BSRWmr(MD, MB, MI, MS, RD) (_d16(), _REXLmr(MB, MI, RD), _OO_r_X (0x0fbd ,_r2(RD) ,MD,MB,MI,MS ))
1506    
1507     #define BSFLrr(RS, RD) (_REXLrr(RD, RS), _OO_Mrm (0x0fbc ,_b11,_r4(RD),_r4(RS) ))
1508     #define BSFLmr(MD, MB, MI, MS, RD) (_REXLmr(MB, MI, RD), _OO_r_X (0x0fbc ,_r4(RD) ,MD,MB,MI,MS ))
1509     #define BSRLrr(RS, RD) (_REXLrr(RD, RS), _OO_Mrm (0x0fbd ,_b11,_r4(RD),_r4(RS) ))
1510     #define BSRLmr(MD, MB, MI, MS, RD) (_REXLmr(MB, MI, RD), _OO_r_X (0x0fbd ,_r4(RD) ,MD,MB,MI,MS ))
1511    
1512     #define BSFQrr(RS, RD) (_REXQrr(RD, RS), _OO_Mrm (0x0fbc ,_b11,_r8(RD),_r8(RS) ))
1513     #define BSFQmr(MD, MB, MI, MS, RD) (_REXQmr(MB, MI, RD), _OO_r_X (0x0fbc ,_r8(RD) ,MD,MB,MI,MS ))
1514     #define BSRQrr(RS, RD) (_REXQrr(RD, RS), _OO_Mrm (0x0fbd ,_b11,_r8(RD),_r8(RS) ))
1515     #define BSRQmr(MD, MB, MI, MS, RD) (_REXQmr(MB, MI, RD), _OO_r_X (0x0fbd ,_r8(RD) ,MD,MB,MI,MS ))
1516 gbeauche 1.1
1517     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1518    
1519     #define LEALmr(MD, MB, MI, MS, RD) (_REXLmr(MB, MI, RD), _O_r_X (0x8d ,_r4(RD) ,MD,MB,MI,MS ))
1520    
1521     #define BSWAPLr(R) (_REXLrr(0, R), _OOr (0x0fc8,_r4(R) ))
1522     #define BSWAPQr(R) (_REXQrr(0, R), _OOr (0x0fc8,_r8(R) ))
1523    
1524     #define CLC() _O (0xf8 )
1525     #define STC() _O (0xf9 )
1526    
1527     #define CMC() _O (0xf5 )
1528     #define CLD() _O (0xfc )
1529     #define STD() _O (0xfd )
1530    
1531     #define CBTW() (_d16(), _O (0x98 ))
1532     #define CWTL() _O (0x98 )
1533     #define CLTQ() _m64only(_REXQrr(0, 0), _O (0x98 ))
1534    
1535     #define CBW CBTW
1536     #define CWDE CWTL
1537     #define CDQE CLTQ
1538    
1539     #define CWTD() (_d16(), _O (0x99 ))
1540     #define CLTD() _O (0x99 )
1541     #define CQTO() _m64only(_REXQrr(0, 0), _O (0x99 ))
1542    
1543     #define CWD CWTD
1544     #define CDQ CLTD
1545     #define CQO CQTO
1546    
1547     #define LAHF() _m32only( _O (0x9f ))
1548     #define SAHF() _m32only( _O (0x9e ))
1549    
1550 gbeauche 1.2 /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1551    
1552 gbeauche 1.1 #define RDTSC() _OO (0xff31 )
1553    
1554     #define ENTERii(W, B) _O_W_B (0xc8 ,_su16(W),_su8(B))
1555    
1556     #define LEAVE() _O (0xc9 )
1557     #define RET() _O (0xc3 )
1558     #define RETi(IM) _O_W (0xc2 ,_su16(IM))
1559    
1560     #define NOP() _O (0x90 )
1561 gbeauche 1.3
1562    
1563     /* --- Media 128-bit instructions ------------------------------------------ */
1564    
1565     enum {
1566     X86_SSE_CVTIS = 0x2a,
1567     X86_SSE_CVTSI = 0x2d,
1568     X86_SSE_UCOMI = 0x2e,
1569     X86_SSE_COMI = 0x2f,
1570     X86_SSE_SQRT = 0x51,
1571     X86_SSE_RSQRT = 0x52,
1572     X86_SSE_RCP = 0x53,
1573     X86_SSE_AND = 0x54,
1574     X86_SSE_ANDN = 0x55,
1575     X86_SSE_OR = 0x56,
1576     X86_SSE_XOR = 0x57,
1577     X86_SSE_ADD = 0x58,
1578     X86_SSE_MUL = 0x59,
1579     X86_SSE_CVTSD = 0x5a,
1580     X86_SSE_CVTDT = 0x5b,
1581     X86_SSE_SUB = 0x5c,
1582     X86_SSE_MIN = 0x5d,
1583     X86_SSE_DIV = 0x5e,
1584     X86_SSE_MAX = 0x5f,
1585     };
1586    
1587     /* _format Opcd ,Mod ,r ,m ,mem=dsp+sib ,imm... */
1588    
1589     #define __SSELrr(OP,RS,RSA,RD,RDA) (_REXLrr(RD, RS), _OO_Mrm (0x0f00|(OP) ,_b11,RDA(RD),RSA(RS) ))
1590     #define __SSELmr(OP,MD,MB,MI,MS,RD,RDA) (_REXLmr(MB, MI, RD), _OO_r_X (0x0f00|(OP) ,RDA(RD) ,MD,MB,MI,MS ))
1591     #define __SSELrm(OP,RS,RSA,MD,MB,MI,MS) (_REXLrm(RS, MB, MI), _OO_r_X (0x0f00|(OP) ,RSA(RS) ,MD,MB,MI,MS ))
1592    
1593     #define __SSEQrr(OP,RS,RSA,RD,RDA) (_REXQrr(RD, RS), _OO_Mrm (0x0f00|(OP) ,_b11,RDA(RD),RSA(RS) ))
1594     #define __SSEQmr(OP,MD,MB,MI,MS,RD,RDA) (_REXQmr(MB, MI, RD), _OO_r_X (0x0f00|(OP) ,RDA(RD) ,MD,MB,MI,MS ))
1595     #define __SSEQrm(OP,RS,RSA,MD,MB,MI,MS) (_REXQrm(RS, MB, MI), _OO_r_X (0x0f00|(OP) ,RSA(RS) ,MD,MB,MI,MS ))
1596    
1597     #define _SSELrr(PX,OP,RS,RSA,RD,RDA) (_B(PX), __SSELrr(OP, RS, RSA, RD, RDA))
1598     #define _SSELmr(PX,OP,MD,MB,MI,MS,RD,RDA) (_B(PX), __SSELmr(OP, MD, MB, MI, MS, RD, RDA))
1599     #define _SSELrm(PX,OP,RS,RSA,MD,MB,MI,MS) (_B(PX), __SSELrm(OP, RS, RSA, MD, MB, MI, MS))
1600    
1601     #define _SSEQrr(PX,OP,RS,RSA,RD,RDA) (_B(PX), __SSEQrr(OP, RS, RSA, RD, RDA))
1602     #define _SSEQmr(PX,OP,MD,MB,MI,MS,RD,RDA) (_B(PX), __SSEQmr(OP, MD, MB, MI, MS, RD, RDA))
1603     #define _SSEQrm(PX,OP,RS,RSA,MD,MB,MI,MS) (_B(PX), __SSEQrm(OP, RS, RSA, MD, MB, MI, MS))
1604    
1605     #define _SSEPSrr(OP,RS,RD) __SSELrr( OP, RS,_rX, RD,_rX)
1606     #define _SSEPSmr(OP,MD,MB,MI,MS,RD) __SSELmr( OP, MD, MB, MI, MS, RD,_rX)
1607     #define _SSEPSrm(OP,RS,MD,MB,MI,MS) __SSELrm( OP, RS,_rX, MD, MB, MI, MS)
1608    
1609     #define _SSEPDrr(OP,RS,RD) _SSELrr(0x66, OP, RS,_rX, RD,_rX)
1610     #define _SSEPDmr(OP,MD,MB,MI,MS,RD) _SSELmr(0x66, OP, MD, MB, MI, MS, RD,_rX)
1611     #define _SSEPDrm(OP,RS,MD,MB,MI,MS) _SSELrm(0x66, OP, RS,_rX, MD, MB, MI, MS)
1612    
1613     #define _SSESSrr(OP,RS,RD) _SSELrr(0xf3, OP, RS,_rX, RD,_rX)
1614     #define _SSESSmr(OP,MD,MB,MI,MS,RD) _SSELmr(0xf3, OP, MD, MB, MI, MS, RD,_rX)
1615     #define _SSESSrm(OP,RS,MD,MB,MI,MS) _SSELrm(0xf3, OP, RS,_rX, MD, MB, MI, MS)
1616    
1617     #define _SSESDrr(OP,RS,RD) _SSELrr(0xf2, OP, RS,_rX, RD,_rX)
1618     #define _SSESDmr(OP,MD,MB,MI,MS,RD) _SSELmr(0xf2, OP, MD, MB, MI, MS, RD,_rX)
1619     #define _SSESDrm(OP,RS,MD,MB,MI,MS) _SSELrm(0xf2, OP, RS,_rX, MD, MB, MI, MS)
1620    
1621     #define ADDPSrr(RS, RD) _SSEPSrr(X86_SSE_ADD, RS, RD)
1622     #define ADDPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_ADD, MD, MB, MI, MS, RD)
1623     #define ADDPDrr(RS, RD) _SSEPDrr(X86_SSE_ADD, RS, RD)
1624     #define ADDPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_ADD, MD, MB, MI, MS, RD)
1625    
1626     #define ADDSSrr(RS, RD) _SSESSrr(X86_SSE_ADD, RS, RD)
1627     #define ADDSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_ADD, MD, MB, MI, MS, RD)
1628     #define ADDSDrr(RS, RD) _SSESDrr(X86_SSE_ADD, RS, RD)
1629     #define ADDSDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_ADD, MD, MB, MI, MS, RD)
1630    
1631     #define ANDNPSrr(RS, RD) _SSEPSrr(X86_SSE_ANDN, RS, RD)
1632     #define ANDNPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_ANDN, MD, MB, MI, MS, RD)
1633     #define ANDNPDrr(RS, RD) _SSEPDrr(X86_SSE_ANDN, RS, RD)
1634     #define ANDNPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_ANDN, MD, MB, MI, MS, RD)
1635    
1636     #define ANDPSrr(RS, RD) _SSEPSrr(X86_SSE_AND, RS, RD)
1637     #define ANDPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_AND, MD, MB, MI, MS, RD)
1638     #define ANDPDrr(RS, RD) _SSEPDrr(X86_SSE_AND, RS, RD)
1639     #define ANDPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_AND, MD, MB, MI, MS, RD)
1640    
1641     #define DIVPSrr(RS, RD) _SSEPSrr(X86_SSE_DIV, RS, RD)
1642     #define DIVPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_DIV, MD, MB, MI, MS, RD)
1643     #define DIVPDrr(RS, RD) _SSEPDrr(X86_SSE_DIV, RS, RD)
1644     #define DIVPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_DIV, MD, MB, MI, MS, RD)
1645    
1646     #define DIVSSrr(RS, RD) _SSESSrr(X86_SSE_DIV, RS, RD)
1647     #define DIVSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_DIV, MD, MB, MI, MS, RD)
1648     #define DIVSDrr(RS, RD) _SSESDrr(X86_SSE_DIV, RS, RD)
1649     #define DIVSDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_DIV, MD, MB, MI, MS, RD)
1650    
1651     #define MAXPSrr(RS, RD) _SSEPSrr(X86_SSE_MAX, RS, RD)
1652     #define MAXPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_MAX, MD, MB, MI, MS, RD)
1653     #define MAXPDrr(RS, RD) _SSEPDrr(X86_SSE_MAX, RS, RD)
1654     #define MAXPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_MAX, MD, MB, MI, MS, RD)
1655    
1656     #define MAXSSrr(RS, RD) _SSESSrr(X86_SSE_MAX, RS, RD)
1657     #define MAXSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_MAX, MD, MB, MI, MS, RD)
1658     #define MAXSDrr(RS, RD) _SSESDrr(X86_SSE_MAX, RS, RD)
1659     #define MAXSDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_MAX, MD, MB, MI, MS, RD)
1660    
1661     #define MINPSrr(RS, RD) _SSEPSrr(X86_SSE_MIN, RS, RD)
1662     #define MINPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_MIN, MD, MB, MI, MS, RD)
1663     #define MINPDrr(RS, RD) _SSEPDrr(X86_SSE_MIN, RS, RD)
1664     #define MINPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_MIN, MD, MB, MI, MS, RD)
1665    
1666     #define MINSSrr(RS, RD) _SSESSrr(X86_SSE_MIN, RS, RD)
1667     #define MINSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_MIN, MD, MB, MI, MS, RD)
1668     #define MINSDrr(RS, RD) _SSESDrr(X86_SSE_MIN, RS, RD)
1669     #define MINSDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_MIN, MD, MB, MI, MS, RD)
1670    
1671     #define MULPSrr(RS, RD) _SSEPSrr(X86_SSE_MUL, RS, RD)
1672     #define MULPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_MUL, MD, MB, MI, MS, RD)
1673     #define MULPDrr(RS, RD) _SSEPDrr(X86_SSE_MUL, RS, RD)
1674     #define MULPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_MUL, MD, MB, MI, MS, RD)
1675    
1676     #define MULSSrr(RS, RD) _SSESSrr(X86_SSE_MUL, RS, RD)
1677     #define MULSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_MUL, MD, MB, MI, MS, RD)
1678     #define MULSDrr(RS, RD) _SSESDrr(X86_SSE_MUL, RS, RD)
1679     #define MULSDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_MUL, MD, MB, MI, MS, RD)
1680    
1681     #define ORPSrr(RS, RD) _SSEPSrr(X86_SSE_OR, RS, RD)
1682     #define ORPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_OR, MD, MB, MI, MS, RD)
1683     #define ORPDrr(RS, RD) _SSEPDrr(X86_SSE_OR, RS, RD)
1684     #define ORPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_OR, MD, MB, MI, MS, RD)
1685    
1686     #define RCPPSrr(RS, RD) _SSEPSrr(X86_SSE_RCP, RS, RD)
1687     #define RCPPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_RCP, MD, MB, MI, MS, RD)
1688     #define RCPSSrr(RS, RD) _SSESSrr(X86_SSE_RCP, RS, RD)
1689     #define RCPSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_RCP, MD, MB, MI, MS, RD)
1690    
1691     #define RSQRTPSrr(RS, RD) _SSEPSrr(X86_SSE_RSQRT, RS, RD)
1692     #define RSQRTPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_RSQRT, MD, MB, MI, MS, RD)
1693     #define RSQRTSSrr(RS, RD) _SSESSrr(X86_SSE_RSQRT, RS, RD)
1694     #define RSQRTSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_RSQRT, MD, MB, MI, MS, RD)
1695    
1696     #define SQRTPSrr(RS, RD) _SSEPSrr(X86_SSE_SQRT, RS, RD)
1697     #define SQRTPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_SQRT, MD, MB, MI, MS, RD)
1698     #define SQRTPDrr(RS, RD) _SSEPDrr(X86_SSE_SQRT, RS, RD)
1699     #define SQRTPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_SQRT, MD, MB, MI, MS, RD)
1700    
1701     #define SQRTSSrr(RS, RD) _SSESSrr(X86_SSE_SQRT, RS, RD)
1702     #define SQRTSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_SQRT, MD, MB, MI, MS, RD)
1703     #define SQRTSDrr(RS, RD) _SSESDrr(X86_SSE_SQRT, RS, RD)
1704     #define SQRTSDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_SQRT, MD, MB, MI, MS, RD)
1705    
1706     #define SUBPSrr(RS, RD) _SSEPSrr(X86_SSE_SUB, RS, RD)
1707     #define SUBPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_SUB, MD, MB, MI, MS, RD)
1708     #define SUBPDrr(RS, RD) _SSEPDrr(X86_SSE_SUB, RS, RD)
1709     #define SUBPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_SUB, MD, MB, MI, MS, RD)
1710    
1711     #define SUBSSrr(RS, RD) _SSESSrr(X86_SSE_SUB, RS, RD)
1712     #define SUBSSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_SUB, MD, MB, MI, MS, RD)
1713     #define SUBSDrr(RS, RD) _SSESDrr(X86_SSE_SUB, RS, RD)
1714     #define SUBSDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_SUB, MD, MB, MI, MS, RD)
1715    
1716     #define XORPSrr(RS, RD) _SSEPSrr(X86_SSE_XOR, RS, RD)
1717     #define XORPSmr(MD, MB, MI, MS, RD) _SSEPSmr(X86_SSE_XOR, MD, MB, MI, MS, RD)
1718     #define XORPDrr(RS, RD) _SSEPDrr(X86_SSE_XOR, RS, RD)
1719     #define XORPDmr(MD, MB, MI, MS, RD) _SSEPDmr(X86_SSE_XOR, MD, MB, MI, MS, RD)
1720    
1721     #define COMISSrr(RS, RD) _SSESSrr(X86_SSE_COMI, RS, RD)
1722     #define COMISSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_COMI, MD, MB, MI, MS, RD)
1723     #define COMISDrr(RS, RD) _SSESDrr(X86_SSE_COMI, RS, RD)
1724     #define COMISDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_COMI, MD, MB, MI, MS, RD)
1725    
1726     #define UCOMISSrr(RS, RD) _SSESSrr(X86_SSE_UCOMI, RS, RD)
1727     #define UCOMISSmr(MD, MB, MI, MS, RD) _SSESSmr(X86_SSE_UCOMI, MD, MB, MI, MS, RD)
1728     #define UCOMISDrr(RS, RD) _SSESDrr(X86_SSE_UCOMI, RS, RD)
1729     #define UCOMISDmr(MD, MB, MI, MS, RD) _SSESDmr(X86_SSE_UCOMI, MD, MB, MI, MS, RD)
1730    
1731     #define MOVAPSrr(RS, RD) _SSEPSrr(0x28, RS, RD)
1732     #define MOVAPSmr(MD, MB, MI, MS, RD) _SSEPSmr(0x28, MD, MB, MI, MS, RD)
1733     #define MOVAPSrm(RS, MD, MB, MI, MS) _SSEPSrm(0x29, RS, MD, MB, MI, MS)
1734    
1735     #define MOVAPDrr(RS, RD) _SSEPDrr(0x28, RS, RD)
1736     #define MOVAPDmr(MD, MB, MI, MS, RD) _SSEPDmr(0x28, MD, MB, MI, MS, RD)
1737     #define MOVAPDrm(RS, MD, MB, MI, MS) _SSEPDrm(0x29, RS, MD, MB, MI, MS)
1738    
1739     #define CVTPS2PIrr(RS, RD) __SSELrr( X86_SSE_CVTSI, RS,_rX, RD,_rM)
1740     #define CVTPS2PImr(MD, MB, MI, MS, RD) __SSELmr( X86_SSE_CVTSI, MD, MB, MI, MS, RD,_rM)
1741     #define CVTPD2PIrr(RS, RD) _SSELrr(0x66, X86_SSE_CVTSI, RS,_rX, RD,_rM)
1742     #define CVTPD2PImr(MD, MB, MI, MS, RD) _SSELmr(0x66, X86_SSE_CVTSI, MD, MB, MI, MS, RD,_rM)
1743    
1744     #define CVTPI2PSrr(RS, RD) __SSELrr( X86_SSE_CVTIS, RS,_rM, RD,_rX)
1745     #define CVTPI2PSmr(MD, MB, MI, MS, RD) __SSELmr( X86_SSE_CVTIS, MD, MB, MI, MS, RD,_rX)
1746     #define CVTPI2PDrr(RS, RD) _SSELrr(0x66, X86_SSE_CVTIS, RS,_rM, RD,_rX)
1747     #define CVTPI2PDmr(MD, MB, MI, MS, RD) _SSELmr(0x66, X86_SSE_CVTIS, MD, MB, MI, MS, RD,_rX)
1748    
1749     #define CVTPS2PDrr(RS, RD) __SSELrr( X86_SSE_CVTSD, RS,_rX, RD,_rX)
1750     #define CVTPS2PDmr(MD, MB, MI, MS, RD) __SSELmr( X86_SSE_CVTSD, MD, MB, MI, MS, RD,_rX)
1751     #define CVTPD2PSrr(RS, RD) _SSELrr(0x66, X86_SSE_CVTSD, RS,_rX, RD,_rX)
1752     #define CVTPD2PSmr(MD, MB, MI, MS, RD) _SSELmr(0x66, X86_SSE_CVTSD, MD, MB, MI, MS, RD,_rX)
1753    
1754     #define CVTSS2SDrr(RS, RD) _SSELrr(0xf3, X86_SSE_CVTSD, RS,_rX, RD,_rX)
1755     #define CVTSS2SDmr(MD, MB, MI, MS, RD) _SSELmr(0xf3, X86_SSE_CVTSD, MD, MB, MI, MS, RD,_rX)
1756     #define CVTSD2SSrr(RS, RD) _SSELrr(0xf2, X86_SSE_CVTSD, RS,_rX, RD,_rX)
1757     #define CVTSD2SSmr(MD, MB, MI, MS, RD) _SSELmr(0xf2, X86_SSE_CVTSD, MD, MB, MI, MS, RD,_rX)
1758    
1759     #define CVTSS2SILrr(RS, RD) _SSELrr(0xf3, X86_SSE_CVTSI, RS,_rX, RD,_r4)
1760     #define CVTSS2SILmr(MD, MB, MI, MS, RD) _SSELmr(0xf3, X86_SSE_CVTSI, MD, MB, MI, MS, RD,_r4)
1761     #define CVTSD2SILrr(RS, RD) _SSELrr(0xf2, X86_SSE_CVTSI, RS,_rX, RD,_r4)
1762     #define CVTSD2SILmr(MD, MB, MI, MS, RD) _SSELmr(0xf2, X86_SSE_CVTSI, MD, MB, MI, MS, RD,_r4)
1763    
1764     #define CVTSI2SSLrr(RS, RD) _SSELrr(0xf3, X86_SSE_CVTIS, RS,_r4, RD,_rX)
1765     #define CVTSI2SSLmr(MD, MB, MI, MS, RD) _SSELmr(0xf3, X86_SSE_CVTIS, MD, MB, MI, MS, RD,_rX)
1766     #define CVTSI2SDLrr(RS, RD) _SSELrr(0xf2, X86_SSE_CVTIS, RS,_r4, RD,_rX)
1767     #define CVTSI2SDLmr(MD, MB, MI, MS, RD) _SSELmr(0xf2, X86_SSE_CVTIS, MD, MB, MI, MS, RD,_rX)
1768    
1769     #define CVTSS2SIQrr(RS, RD) _SSEQrr(0xf3, X86_SSE_CVTSI, RS,_rX, RD,_r8)
1770     #define CVTSS2SIQmr(MD, MB, MI, MS, RD) _SSEQmr(0xf3, X86_SSE_CVTSI, MD, MB, MI, MS, RD,_r8)
1771     #define CVTSD2SIQrr(RS, RD) _SSEQrr(0xf2, X86_SSE_CVTSI, RS,_rX, RD,_r8)
1772     #define CVTSD2SIQmr(MD, MB, MI, MS, RD) _SSEQmr(0xf2, X86_SSE_CVTSI, MD, MB, MI, MS, RD,_r8)
1773    
1774     #define CVTSI2SSQrr(RS, RD) _SSEQrr(0xf3, X86_SSE_CVTIS, RS,_r8, RD,_rX)
1775     #define CVTSI2SSQmr(MD, MB, MI, MS, RD) _SSEQmr(0xf3, X86_SSE_CVTIS, MD, MB, MI, MS, RD,_rX)
1776     #define CVTSI2SDQrr(RS, RD) _SSEQrr(0xf2, X86_SSE_CVTIS, RS,_r8, RD,_rX)
1777     #define CVTSI2SDQmr(MD, MB, MI, MS, RD) _SSEQmr(0xf2, X86_SSE_CVTIS, MD, MB, MI, MS, RD,_rX)
1778    
1779     #define MOVDLXrr(RS, RD) _SSELrr(0x66, 0x6e, RS,_r4, RD,_rX)
1780     #define MOVDLXmr(MD, MB, MI, MS, RD) _SSELmr(0x66, 0x6e, MD, MB, MI, MS, RD,_rX)
1781     #define MOVDQXrr(RS, RD) _SSEQrr(0x66, 0x6e, RS,_r8, RD,_rX)
1782     #define MOVDQXmr(MD, MB, MI, MS, RD) _SSEQmr(0x66, 0x6e, MD, MB, MI, MS, RD,_rX)
1783    
1784     #define MOVDXLrr(RS, RD) _SSELrr(0x66, 0x7e, RS,_rX, RD,_r4)
1785     #define MOVDXLrm(RS, MD, MB, MI, MS) _SSELrm(0x66, 0x7e, RS,_rX, MD, MB, MI, MS)
1786     #define MOVDXQrr(RS, RD) _SSEQrr(0x66, 0x7e, RS,_rX, RD,_r8)
1787     #define MOVDXQrm(RS, MD, MB, MI, MS) _SSEQrm(0x66, 0x7e, RS,_rX, MD, MB, MI, MS)
1788    
1789     #define MOVDLMrr(RS, RD) __SSELrr( 0x6e, RS,_r4, RD,_rM)
1790     #define MOVDLMmr(MD, MB, MI, MS, RD) __SSELmr( 0x6e, MD, MB, MI, MS, RD,_rM)
1791     #define MOVDQMrr(RS, RD) __SSEQrr( 0x6e, RS,_r8, RD,_rM)
1792     #define MOVDQMmr(MD, MB, MI, MS, RD) __SSEQmr( 0x6e, MD, MB, MI, MS, RD,_rM)
1793    
1794     #define MOVDMLrr(RS, RD) __SSELrr( 0x7e, RS,_rM, RD,_r4)
1795     #define MOVDMLrm(RS, MD, MB, MI, MS) __SSELrm( 0x7e, RS,_rM, MD, MB, MI, MS)
1796     #define MOVDMQrr(RS, RD) __SSEQrr( 0x7e, RS,_rM, RD,_r8)
1797     #define MOVDMQrm(RS, MD, MB, MI, MS) __SSEQrm( 0x7e, RS,_rM, MD, MB, MI, MS)
1798    
1799     #define MOVDQ2Qrr(RS, RD) _SSELrr(0xf2, 0xd6, RS,_rX, RD,_rM)
1800     #define MOVHLPSrr(RS, RD) __SSELrr( 0x12, RS,_rX, RD,_rX)
1801     #define MOVLHPSrr(RS, RD) __SSELrr( 0x16, RS,_rX, RD,_rX)
1802    
1803     #define MOVDQArr(RS, RD) _SSELrr(0x66, 0x6f, RS,_rX, RD,_rX)
1804     #define MOVDQAmr(MD, MB, MI, MS, RD) _SSELmr(0x66, 0x6f, MD, MB, MI, MS, RD,_rX)
1805     #define MOVDQArm(RS, MD, MB, MI, MS) _SSELrm(0x66, 0x7f, RS,_rX, MD, MB, MI, MS)
1806    
1807     #define MOVDQUrr(RS, RD) _SSELrr(0xf3, 0x6f, RS,_rX, RD,_rX)
1808     #define MOVDQUmr(MD, MB, MI, MS, RD) _SSELmr(0xf3, 0x6f, MD, MB, MI, MS, RD,_rX)
1809     #define MOVDQUrm(RS, MD, MB, MI, MS) _SSELrm(0xf3, 0x7f, RS,_rX, MD, MB, MI, MS)
1810    
1811     #define MOVHPDmr(MD, MB, MI, MS, RD) _SSELmr(0x66, 0x16, MD, MB, MI, MS, RD,_rX)
1812     #define MOVHPDrm(RS, MD, MB, MI, MS) _SSELrm(0x66, 0x17, RS,_rX, MD, MB, MI, MS)
1813     #define MOVHPSmr(MD, MB, MI, MS, RD) __SSELmr( 0x16, MD, MB, MI, MS, RD,_rX)
1814     #define MOVHPSrm(RS, MD, MB, MI, MS) __SSELrm( 0x17, RS,_rX, MD, MB, MI, MS)
1815    
1816     #define MOVLPDmr(MD, MB, MI, MS, RD) _SSELmr(0x66, 0x12, MD, MB, MI, MS, RD,_rX)
1817     #define MOVLPDrm(RS, MD, MB, MI, MS) _SSELrm(0x66, 0x13, RS,_rX, MD, MB, MI, MS)
1818     #define MOVLPSmr(MD, MB, MI, MS, RD) __SSELmr( 0x12, MD, MB, MI, MS, RD,_rX)
1819     #define MOVLPSrm(RS, MD, MB, MI, MS) __SSELrm( 0x13, RS,_rX, MD, MB, MI, MS)
1820 gbeauche 1.2
1821    
1822     /* --- FLoating-Point instructions ----------------------------------------- */
1823    
1824     #define _ESCmi(D,B,I,S,OP) (_REXLrm(0,B,I), _O_r_X(0xd8|(OP & 7), (OP >> 3), D,B,I,S))
1825    
1826     #define FLDr(R) _OOr(0xd9c0,_rN(R))
1827     #define FLDLm(D,B,I,S) _ESCmi(D,B,I,S,005)
1828     #define FLDSm(D,B,I,S) _ESCmi(D,B,I,S,001)
1829     #define FLDTm(D,B,I,S) _ESCmi(D,B,I,S,053)
1830    
1831     #define FSTr(R) _OOr(0xddd0,_rN(R))
1832     #define FSTSm(D,B,I,S) _ESCmi(D,B,I,S,021)
1833     #define FSTLm(D,B,I,S) _ESCmi(D,B,I,S,025)
1834    
1835     #define FSTPr(R) _OOr(0xddd8,_rN(R))
1836     #define FSTPSm(D,B,I,S) _ESCmi(D,B,I,S,031)
1837     #define FSTPLm(D,B,I,S) _ESCmi(D,B,I,S,035)
1838     #define FSTPTm(D,B,I,S) _ESCmi(D,B,I,S,073)
1839    
1840     #define FADDr0(R) _OOr(0xd8c0,_rN(R))
1841     #define FADD0r(R) _OOr(0xdcc0,_rN(R))
1842     #define FADDP0r(R) _OOr(0xdec0,_rN(R))
1843     #define FADDSm(D,B,I,S) _ESCmi(D,B,I,S,000)
1844     #define FADDLm(D,B,I,S) _ESCmi(D,B,I,S,004)
1845    
1846     #define FSUBSm(D,B,I,S) _ESCmi(D,B,I,S,040)
1847     #define FSUBLm(D,B,I,S) _ESCmi(D,B,I,S,044)
1848     #define FSUBr0(R) _OOr(0xd8e0,_rN(R))
1849     #define FSUB0r(R) _OOr(0xdce8,_rN(R))
1850     #define FSUBP0r(R) _OOr(0xdee8,_rN(R))
1851    
1852     #define FSUBRr0(R) _OOr(0xd8e8,_rN(R))
1853     #define FSUBR0r(R) _OOr(0xdce0,_rN(R))
1854     #define FSUBRP0r(R) _OOr(0xdee0,_rN(R))
1855     #define FSUBRSm(D,B,I,S) _ESCmi(D,B,I,S,050)
1856     #define FSUBRLm(D,B,I,S) _ESCmi(D,B,I,S,054)
1857    
1858     #define FMULr0(R) _OOr(0xd8c8,_rN(R))
1859     #define FMUL0r(R) _OOr(0xdcc8,_rN(R))
1860     #define FMULP0r(R) _OOr(0xdec8,_rN(R))
1861     #define FMULSm(D,B,I,S) _ESCmi(D,B,I,S,010)
1862     #define FMULLm(D,B,I,S) _ESCmi(D,B,I,S,014)
1863    
1864     #define FDIVr0(R) _OOr(0xd8f0,_rN(R))
1865     #define FDIV0r(R) _OOr(0xdcf8,_rN(R))
1866     #define FDIVP0r(R) _OOr(0xdef8,_rN(R))
1867     #define FDIVSm(D,B,I,S) _ESCmi(D,B,I,S,060)
1868     #define FDIVLm(D,B,I,S) _ESCmi(D,B,I,S,064)
1869    
1870     #define FDIVRr0(R) _OOr(0xd8f8,_rN(R))
1871     #define FDIVR0r(R) _OOr(0xdcf0,_rN(R))
1872     #define FDIVRP0r(R) _OOr(0xdef0,_rN(R))
1873     #define FDIVRSm(D,B,I,S) _ESCmi(D,B,I,S,070)
1874     #define FDIVRLm(D,B,I,S) _ESCmi(D,B,I,S,074)
1875    
1876     #define FCMOVBr0(R) _OOr(0xdac0,_rN(R))
1877     #define FCMOVBEr0(R) _OOr(0xdad0,_rN(R))
1878     #define FCMOVEr0(R) _OOr(0xdac8,_rN(R))
1879     #define FCMOVNBr0(R) _OOr(0xdbc0,_rN(R))
1880     #define FCMOVNBEr0(R) _OOr(0xdbd0,_rN(R))
1881     #define FCMOVNEr0(R) _OOr(0xdbc8,_rN(R))
1882     #define FCMOVNUr0(R) _OOr(0xdbd8,_rN(R))
1883     #define FCMOVUr0(R) _OOr(0xdad8,_rN(R))
1884     #define FCOMIr0(R) _OOr(0xdbf0,_rN(R))
1885     #define FCOMIPr0(R) _OOr(0xdff0,_rN(R))
1886    
1887     #define FCOMr(R) _OOr(0xd8d0,_rN(R))
1888     #define FCOMSm(D,B,I,S) _ESCmi(D,B,I,S,020)
1889     #define FCOMLm(D,B,I,S) _ESCmi(D,B,I,S,024)
1890    
1891     #define FCOMPr(R) _OOr(0xd8d8,_rN(R))
1892     #define FCOMPSm(D,B,I,S) _ESCmi(D,B,I,S,030)
1893     #define FCOMPLm(D,B,I,S) _ESCmi(D,B,I,S,034)
1894    
1895     #define FUCOMIr0(R) _OOr(0xdbe8,_rN(R))
1896     #define FUCOMIPr0(R) _OOr(0xdfe8,_rN(R))
1897     #define FUCOMPr(R) _OOr(0xdde8,_rN(R))
1898     #define FUCOMr(R) _OOr(0xdde0,_rN(R))
1899    
1900     #define FIADDLm(D,B,I,S) _ESCmi(D,B,I,S,002)
1901     #define FICOMLm(D,B,I,S) _ESCmi(D,B,I,S,022)
1902     #define FICOMPLm(D,B,I,S) _ESCmi(D,B,I,S,032)
1903     #define FIDIVLm(D,B,I,S) _ESCmi(D,B,I,S,062)
1904     #define FIDIVRLm(D,B,I,S) _ESCmi(D,B,I,S,072)
1905     #define FILDLm(D,B,I,S) _ESCmi(D,B,I,S,003)
1906     #define FILDQm(D,B,I,S) _ESCmi(D,B,I,S,057)
1907     #define FIMULLm(D,B,I,S) _ESCmi(D,B,I,S,012)
1908     #define FISTLm(D,B,I,S) _ESCmi(D,B,I,S,023)
1909     #define FISTPLm(D,B,I,S) _ESCmi(D,B,I,S,033)
1910     #define FISTPQm(D,B,I,S) _ESCmi(D,B,I,S,077)
1911     #define FISUBLm(D,B,I,S) _ESCmi(D,B,I,S,042)
1912     #define FISUBRLm(D,B,I,S) _ESCmi(D,B,I,S,052)
1913    
1914     #define FREEr(R) _OOr(0xddc0,_rN(R))
1915     #define FXCHr(R) _OOr(0xd9c8,_rN(R))
1916 gbeauche 1.1
1917     #endif /* X86_RTASM_H */