Use operand->extract to provide defaults for optional PowerPC operands
[external/binutils.git] / opcodes / i386-opc.h
1 /* Declarations for Intel 80386 opcode table
2    Copyright (C) 2007-2018 Free Software Foundation, Inc.
3
4    This file is part of the GNU opcodes library.
5
6    This library is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10
11    It is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14    License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GAS; see the file COPYING.  If not, write to the Free
18    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19    02110-1301, USA.  */
20
21 #include "opcode/i386.h"
22 #ifdef HAVE_LIMITS_H
23 #include <limits.h>
24 #endif
25
26 #ifndef CHAR_BIT
27 #define CHAR_BIT 8
28 #endif
29
30 /* Position of cpu flags bitfiled.  */
31
32 enum
33 {
34   /* i186 or better required */
35   Cpu186 = 0,
36   /* i286 or better required */
37   Cpu286,
38   /* i386 or better required */
39   Cpu386,
40   /* i486 or better required */
41   Cpu486,
42   /* i585 or better required */
43   Cpu586,
44   /* i686 or better required */
45   Cpu686,
46   /* CMOV Instruction support required */
47   CpuCMOV,
48   /* FXSR Instruction support required */
49   CpuFXSR,
50   /* CLFLUSH Instruction support required */
51   CpuClflush,
52   /* NOP Instruction support required */
53   CpuNop,
54   /* SYSCALL Instructions support required */
55   CpuSYSCALL,
56   /* Floating point support required */
57   Cpu8087,
58   /* i287 support required */
59   Cpu287,
60   /* i387 support required */
61   Cpu387,
62   /* i686 and floating point support required */
63   Cpu687,
64   /* SSE3 and floating point support required */
65   CpuFISTTP,
66   /* MMX support required */
67   CpuMMX,
68   /* SSE support required */
69   CpuSSE,
70   /* SSE2 support required */
71   CpuSSE2,
72   /* 3dnow! support required */
73   Cpu3dnow,
74   /* 3dnow! Extensions support required */
75   Cpu3dnowA,
76   /* SSE3 support required */
77   CpuSSE3,
78   /* VIA PadLock required */
79   CpuPadLock,
80   /* AMD Secure Virtual Machine Ext-s required */
81   CpuSVME,
82   /* VMX Instructions required */
83   CpuVMX,
84   /* SMX Instructions required */
85   CpuSMX,
86   /* SSSE3 support required */
87   CpuSSSE3,
88   /* SSE4a support required */
89   CpuSSE4a,
90   /* ABM New Instructions required */
91   CpuABM,
92   /* SSE4.1 support required */
93   CpuSSE4_1,
94   /* SSE4.2 support required */
95   CpuSSE4_2,
96   /* AVX support required */
97   CpuAVX,
98   /* AVX2 support required */
99   CpuAVX2,
100   /* Intel AVX-512 Foundation Instructions support required */
101   CpuAVX512F,
102   /* Intel AVX-512 Conflict Detection Instructions support required */
103   CpuAVX512CD,
104   /* Intel AVX-512 Exponential and Reciprocal Instructions support
105      required */
106   CpuAVX512ER,
107   /* Intel AVX-512 Prefetch Instructions support required */
108   CpuAVX512PF,
109   /* Intel AVX-512 VL Instructions support required.  */
110   CpuAVX512VL,
111   /* Intel AVX-512 DQ Instructions support required.  */
112   CpuAVX512DQ,
113   /* Intel AVX-512 BW Instructions support required.  */
114   CpuAVX512BW,
115   /* Intel L1OM support required */
116   CpuL1OM,
117   /* Intel K1OM support required */
118   CpuK1OM,
119   /* Intel IAMCU support required */
120   CpuIAMCU,
121   /* Xsave/xrstor New Instructions support required */
122   CpuXsave,
123   /* Xsaveopt New Instructions support required */
124   CpuXsaveopt,
125   /* AES support required */
126   CpuAES,
127   /* PCLMUL support required */
128   CpuPCLMUL,
129   /* FMA support required */
130   CpuFMA,
131   /* FMA4 support required */
132   CpuFMA4,
133   /* XOP support required */
134   CpuXOP,
135   /* LWP support required */
136   CpuLWP,
137   /* BMI support required */
138   CpuBMI,
139   /* TBM support required */
140   CpuTBM,
141   /* MOVBE Instruction support required */
142   CpuMovbe,
143   /* CMPXCHG16B instruction support required.  */
144   CpuCX16,
145   /* EPT Instructions required */
146   CpuEPT,
147   /* RDTSCP Instruction support required */
148   CpuRdtscp,
149   /* FSGSBASE Instructions required */
150   CpuFSGSBase,
151   /* RDRND Instructions required */
152   CpuRdRnd,
153   /* F16C Instructions required */
154   CpuF16C,
155   /* Intel BMI2 support required */
156   CpuBMI2,
157   /* LZCNT support required */
158   CpuLZCNT,
159   /* HLE support required */
160   CpuHLE,
161   /* RTM support required */
162   CpuRTM,
163   /* INVPCID Instructions required */
164   CpuINVPCID,
165   /* VMFUNC Instruction required */
166   CpuVMFUNC,
167   /* Intel MPX Instructions required  */
168   CpuMPX,
169   /* 64bit support available, used by -march= in assembler.  */
170   CpuLM,
171   /* RDRSEED instruction required.  */
172   CpuRDSEED,
173   /* Multi-presisionn add-carry instructions are required.  */
174   CpuADX,
175   /* Supports prefetchw and prefetch instructions.  */
176   CpuPRFCHW,
177   /* SMAP instructions required.  */
178   CpuSMAP,
179   /* SHA instructions required.  */
180   CpuSHA,
181   /* CLFLUSHOPT instruction required */
182   CpuClflushOpt,
183   /* XSAVES/XRSTORS instruction required */
184   CpuXSAVES,
185   /* XSAVEC instruction required */
186   CpuXSAVEC,
187   /* PREFETCHWT1 instruction required */
188   CpuPREFETCHWT1,
189   /* SE1 instruction required */
190   CpuSE1,
191   /* CLWB instruction required */
192   CpuCLWB,
193   /* Intel AVX-512 IFMA Instructions support required.  */
194   CpuAVX512IFMA,
195   /* Intel AVX-512 VBMI Instructions support required.  */
196   CpuAVX512VBMI,
197   /* Intel AVX-512 4FMAPS Instructions support required.  */
198   CpuAVX512_4FMAPS,
199   /* Intel AVX-512 4VNNIW Instructions support required.  */
200   CpuAVX512_4VNNIW,
201   /* Intel AVX-512 VPOPCNTDQ Instructions support required.  */
202   CpuAVX512_VPOPCNTDQ,
203   /* Intel AVX-512 VBMI2 Instructions support required.  */
204   CpuAVX512_VBMI2,
205   /* Intel AVX-512 VNNI Instructions support required.  */
206   CpuAVX512_VNNI,
207   /* Intel AVX-512 BITALG Instructions support required.  */
208   CpuAVX512_BITALG,
209   /* mwaitx instruction required */
210   CpuMWAITX,
211   /* Clzero instruction required */
212   CpuCLZERO,
213   /* OSPKE instruction required */
214   CpuOSPKE,
215   /* RDPID instruction required */
216   CpuRDPID,
217   /* PTWRITE instruction required */
218   CpuPTWRITE,
219   /* CET instructions support required */
220   CpuIBT,
221   CpuSHSTK,
222   /* GFNI instructions required */
223   CpuGFNI,
224   /* VAES instructions required */
225   CpuVAES,
226   /* VPCLMULQDQ instructions required */
227   CpuVPCLMULQDQ,
228   /* WBNOINVD instructions required */
229   CpuWBNOINVD,
230   /* PCONFIG instructions required */
231   CpuPCONFIG,
232   /* WAITPKG instructions required */
233   CpuWAITPKG,
234   /* CLDEMOTE instruction required */
235   CpuCLDEMOTE,
236   /* MOVDIRI instruction support required */
237   CpuMOVDIRI,
238   /* MOVDIRR64B instruction required */
239   CpuMOVDIR64B,
240   /* 64bit support required  */
241   Cpu64,
242   /* Not supported in the 64bit mode  */
243   CpuNo64,
244   /* The last bitfield in i386_cpu_flags.  */
245   CpuMax = CpuNo64
246 };
247
248 #define CpuNumOfUints \
249   (CpuMax / sizeof (unsigned int) / CHAR_BIT + 1)
250 #define CpuNumOfBits \
251   (CpuNumOfUints * sizeof (unsigned int) * CHAR_BIT)
252
253 /* If you get a compiler error for zero width of the unused field,
254    comment it out.  */
255 #define CpuUnused       (CpuMax + 1)
256
257 /* We can check if an instruction is available with array instead
258    of bitfield. */
259 typedef union i386_cpu_flags
260 {
261   struct
262     {
263       unsigned int cpui186:1;
264       unsigned int cpui286:1;
265       unsigned int cpui386:1;
266       unsigned int cpui486:1;
267       unsigned int cpui586:1;
268       unsigned int cpui686:1;
269       unsigned int cpucmov:1;
270       unsigned int cpufxsr:1;
271       unsigned int cpuclflush:1;
272       unsigned int cpunop:1;
273       unsigned int cpusyscall:1;
274       unsigned int cpu8087:1;
275       unsigned int cpu287:1;
276       unsigned int cpu387:1;
277       unsigned int cpu687:1;
278       unsigned int cpufisttp:1;
279       unsigned int cpummx:1;
280       unsigned int cpusse:1;
281       unsigned int cpusse2:1;
282       unsigned int cpua3dnow:1;
283       unsigned int cpua3dnowa:1;
284       unsigned int cpusse3:1;
285       unsigned int cpupadlock:1;
286       unsigned int cpusvme:1;
287       unsigned int cpuvmx:1;
288       unsigned int cpusmx:1;
289       unsigned int cpussse3:1;
290       unsigned int cpusse4a:1;
291       unsigned int cpuabm:1;
292       unsigned int cpusse4_1:1;
293       unsigned int cpusse4_2:1;
294       unsigned int cpuavx:1;
295       unsigned int cpuavx2:1;
296       unsigned int cpuavx512f:1;
297       unsigned int cpuavx512cd:1;
298       unsigned int cpuavx512er:1;
299       unsigned int cpuavx512pf:1;
300       unsigned int cpuavx512vl:1;
301       unsigned int cpuavx512dq:1;
302       unsigned int cpuavx512bw:1;
303       unsigned int cpul1om:1;
304       unsigned int cpuk1om:1;
305       unsigned int cpuiamcu:1;
306       unsigned int cpuxsave:1;
307       unsigned int cpuxsaveopt:1;
308       unsigned int cpuaes:1;
309       unsigned int cpupclmul:1;
310       unsigned int cpufma:1;
311       unsigned int cpufma4:1;
312       unsigned int cpuxop:1;
313       unsigned int cpulwp:1;
314       unsigned int cpubmi:1;
315       unsigned int cputbm:1;
316       unsigned int cpumovbe:1;
317       unsigned int cpucx16:1;
318       unsigned int cpuept:1;
319       unsigned int cpurdtscp:1;
320       unsigned int cpufsgsbase:1;
321       unsigned int cpurdrnd:1;
322       unsigned int cpuf16c:1;
323       unsigned int cpubmi2:1;
324       unsigned int cpulzcnt:1;
325       unsigned int cpuhle:1;
326       unsigned int cpurtm:1;
327       unsigned int cpuinvpcid:1;
328       unsigned int cpuvmfunc:1;
329       unsigned int cpumpx:1;
330       unsigned int cpulm:1;
331       unsigned int cpurdseed:1;
332       unsigned int cpuadx:1;
333       unsigned int cpuprfchw:1;
334       unsigned int cpusmap:1;
335       unsigned int cpusha:1;
336       unsigned int cpuclflushopt:1;
337       unsigned int cpuxsaves:1;
338       unsigned int cpuxsavec:1;
339       unsigned int cpuprefetchwt1:1;
340       unsigned int cpuse1:1;
341       unsigned int cpuclwb:1;
342       unsigned int cpuavx512ifma:1;
343       unsigned int cpuavx512vbmi:1;
344       unsigned int cpuavx512_4fmaps:1;
345       unsigned int cpuavx512_4vnniw:1;
346       unsigned int cpuavx512_vpopcntdq:1;
347       unsigned int cpuavx512_vbmi2:1;
348       unsigned int cpuavx512_vnni:1;
349       unsigned int cpuavx512_bitalg:1;
350       unsigned int cpumwaitx:1;
351       unsigned int cpuclzero:1;
352       unsigned int cpuospke:1;
353       unsigned int cpurdpid:1;
354       unsigned int cpuptwrite:1;
355       unsigned int cpuibt:1;
356       unsigned int cpushstk:1;
357       unsigned int cpugfni:1;
358       unsigned int cpuvaes:1;
359       unsigned int cpuvpclmulqdq:1;
360       unsigned int cpuwbnoinvd:1;
361       unsigned int cpupconfig:1;
362       unsigned int cpuwaitpkg:1;
363       unsigned int cpucldemote:1;
364       unsigned int cpumovdiri:1;
365       unsigned int cpumovdir64b:1;
366       unsigned int cpu64:1;
367       unsigned int cpuno64:1;
368 #ifdef CpuUnused
369       unsigned int unused:(CpuNumOfBits - CpuUnused);
370 #endif
371     } bitfield;
372   unsigned int array[CpuNumOfUints];
373 } i386_cpu_flags;
374
375 /* Position of opcode_modifier bits.  */
376
377 enum
378 {
379   /* has direction bit. */
380   D = 0,
381   /* set if operands can be words or dwords encoded the canonical way */
382   W,
383   /* load form instruction. Must be placed before store form.  */
384   Load,
385   /* insn has a modrm byte. */
386   Modrm,
387   /* register is in low 3 bits of opcode */
388   ShortForm,
389   /* special case for jump insns.  */
390   Jump,
391   /* call and jump */
392   JumpDword,
393   /* loop and jecxz */
394   JumpByte,
395   /* special case for intersegment leaps/calls */
396   JumpInterSegment,
397   /* FP insn memory format bit, sized by 0x4 */
398   FloatMF,
399   /* src/dest swap for floats. */
400   FloatR,
401   /* needs size prefix if in 32-bit mode */
402   Size16,
403   /* needs size prefix if in 16-bit mode */
404   Size32,
405   /* needs size prefix if in 64-bit mode */
406   Size64,
407   /* check register size.  */
408   CheckRegSize,
409   /* instruction ignores operand size prefix and in Intel mode ignores
410      mnemonic size suffix check.  */
411   IgnoreSize,
412   /* default insn size depends on mode */
413   DefaultSize,
414   /* b suffix on instruction illegal */
415   No_bSuf,
416   /* w suffix on instruction illegal */
417   No_wSuf,
418   /* l suffix on instruction illegal */
419   No_lSuf,
420   /* s suffix on instruction illegal */
421   No_sSuf,
422   /* q suffix on instruction illegal */
423   No_qSuf,
424   /* long double suffix on instruction illegal */
425   No_ldSuf,
426   /* instruction needs FWAIT */
427   FWait,
428   /* quick test for string instructions */
429   IsString,
430   /* quick test if branch instruction is MPX supported */
431   BNDPrefixOk,
432   /* quick test if NOTRACK prefix is supported */
433   NoTrackPrefixOk,
434   /* quick test for lockable instructions */
435   IsLockable,
436   /* fake an extra reg operand for clr, imul and special register
437      processing for some instructions.  */
438   RegKludge,
439   /* An implicit xmm0 as the first operand */
440   Implicit1stXmm0,
441   /* The HLE prefix is OK:
442      1. With a LOCK prefix.
443      2. With or without a LOCK prefix.
444      3. With a RELEASE (0xf3) prefix.
445    */
446 #define HLEPrefixNone           0
447 #define HLEPrefixLock           1
448 #define HLEPrefixAny            2
449 #define HLEPrefixRelease        3
450   HLEPrefixOk,
451   /* An instruction on which a "rep" prefix is acceptable.  */
452   RepPrefixOk,
453   /* Convert to DWORD */
454   ToDword,
455   /* Convert to QWORD */
456   ToQword,
457   /* Address prefix changes register operand */
458   AddrPrefixOpReg,
459   /* opcode is a prefix */
460   IsPrefix,
461   /* instruction has extension in 8 bit imm */
462   ImmExt,
463   /* instruction don't need Rex64 prefix.  */
464   NoRex64,
465   /* instruction require Rex64 prefix.  */
466   Rex64,
467   /* deprecated fp insn, gets a warning */
468   Ugh,
469   /* insn has VEX prefix:
470         1: 128bit VEX prefix (or operand dependent).
471         2: 256bit VEX prefix.
472         3: Scalar VEX prefix.
473    */
474 #define VEX128          1
475 #define VEX256          2
476 #define VEXScalar       3
477   Vex,
478   /* How to encode VEX.vvvv:
479      0: VEX.vvvv must be 1111b.
480      1: VEX.NDS.  Register-only source is encoded in VEX.vvvv where
481         the content of source registers will be preserved.
482         VEX.DDS.  The second register operand is encoded in VEX.vvvv
483         where the content of first source register will be overwritten
484         by the result.
485         VEX.NDD2.  The second destination register operand is encoded in
486         VEX.vvvv for instructions with 2 destination register operands.
487         For assembler, there are no difference between VEX.NDS, VEX.DDS
488         and VEX.NDD2.
489      2. VEX.NDD.  Register destination is encoded in VEX.vvvv for
490      instructions with 1 destination register operand.
491      3. VEX.LWP.  Register destination is encoded in VEX.vvvv and one
492         of the operands can access a memory location.
493    */
494 #define VEXXDS  1
495 #define VEXNDD  2
496 #define VEXLWP  3
497   VexVVVV,
498   /* How the VEX.W bit is used:
499      0: Set by the REX.W bit.
500      1: VEX.W0.  Should always be 0.
501      2: VEX.W1.  Should always be 1.
502    */
503 #define VEXW0   1
504 #define VEXW1   2
505   VexW,
506   /* VEX opcode prefix:
507      0: VEX 0x0F opcode prefix.
508      1: VEX 0x0F38 opcode prefix.
509      2: VEX 0x0F3A opcode prefix
510      3: XOP 0x08 opcode prefix.
511      4: XOP 0x09 opcode prefix
512      5: XOP 0x0A opcode prefix.
513    */
514 #define VEX0F           0
515 #define VEX0F38         1
516 #define VEX0F3A         2
517 #define XOP08           3
518 #define XOP09           4
519 #define XOP0A           5
520   VexOpcode,
521   /* number of VEX source operands:
522      0: <= 2 source operands.
523      1: 2 XOP source operands.
524      2: 3 source operands.
525    */
526 #define XOP2SOURCES     1
527 #define VEX3SOURCES     2
528   VexSources,
529   /* Instruction with vector SIB byte:
530         1: 128bit vector register.
531         2: 256bit vector register.
532         3: 512bit vector register.
533    */
534 #define VecSIB128       1
535 #define VecSIB256       2
536 #define VecSIB512       3
537   VecSIB,
538   /* SSE to AVX support required */
539   SSE2AVX,
540   /* No AVX equivalent */
541   NoAVX,
542
543   /* insn has EVEX prefix:
544         1: 512bit EVEX prefix.
545         2: 128bit EVEX prefix.
546         3: 256bit EVEX prefix.
547         4: Length-ignored (LIG) EVEX prefix.
548         5: Length determined from actual operands.
549    */
550 #define EVEX512                1
551 #define EVEX128                2
552 #define EVEX256                3
553 #define EVEXLIG                4
554 #define EVEXDYN                5
555   EVex,
556
557   /* AVX512 masking support:
558         1: Zeroing or merging masking depending on operands.
559         2: Merging-masking.
560         3: Both zeroing and merging masking.
561    */
562 #define DYNAMIC_MASKING 1
563 #define MERGING_MASKING 2
564 #define BOTH_MASKING    3
565   Masking,
566
567   /* AVX512 broadcast support.  The number of bytes to broadcast is
568      1 << (Broadcast - 1):
569         1: Byte broadcast.
570         2: Word broadcast.
571         3: Dword broadcast.
572         4: Qword broadcast.
573    */
574 #define BYTE_BROADCAST  1
575 #define WORD_BROADCAST  2
576 #define DWORD_BROADCAST 3
577 #define QWORD_BROADCAST 4
578   Broadcast,
579
580   /* Static rounding control is supported.  */
581   StaticRounding,
582
583   /* Supress All Exceptions is supported.  */
584   SAE,
585
586   /* Compressed Disp8*N attribute.  */
587 #define DISP8_SHIFT_VL 7
588   Disp8MemShift,
589
590   /* Default mask isn't allowed.  */
591   NoDefMask,
592
593   /* The second operand must be a vector register, {x,y,z}mmN, where N is a multiple of 4.
594      It implicitly denotes the register group of {x,y,z}mmN - {x,y,z}mm(N + 3).
595    */
596   ImplicitQuadGroup,
597
598   /* Support encoding optimization.  */
599   Optimize,
600
601   /* AT&T mnemonic.  */
602   ATTMnemonic,
603   /* AT&T syntax.  */
604   ATTSyntax,
605   /* Intel syntax.  */
606   IntelSyntax,
607   /* AMD64.  */
608   AMD64,
609   /* Intel64.  */
610   Intel64,
611   /* The last bitfield in i386_opcode_modifier.  */
612   Opcode_Modifier_Max
613 };
614
615 typedef struct i386_opcode_modifier
616 {
617   unsigned int d:1;
618   unsigned int w:1;
619   unsigned int load:1;
620   unsigned int modrm:1;
621   unsigned int shortform:1;
622   unsigned int jump:1;
623   unsigned int jumpdword:1;
624   unsigned int jumpbyte:1;
625   unsigned int jumpintersegment:1;
626   unsigned int floatmf:1;
627   unsigned int floatr:1;
628   unsigned int size16:1;
629   unsigned int size32:1;
630   unsigned int size64:1;
631   unsigned int checkregsize:1;
632   unsigned int ignoresize:1;
633   unsigned int defaultsize:1;
634   unsigned int no_bsuf:1;
635   unsigned int no_wsuf:1;
636   unsigned int no_lsuf:1;
637   unsigned int no_ssuf:1;
638   unsigned int no_qsuf:1;
639   unsigned int no_ldsuf:1;
640   unsigned int fwait:1;
641   unsigned int isstring:1;
642   unsigned int bndprefixok:1;
643   unsigned int notrackprefixok:1;
644   unsigned int islockable:1;
645   unsigned int regkludge:1;
646   unsigned int implicit1stxmm0:1;
647   unsigned int hleprefixok:2;
648   unsigned int repprefixok:1;
649   unsigned int todword:1;
650   unsigned int toqword:1;
651   unsigned int addrprefixopreg:1;
652   unsigned int isprefix:1;
653   unsigned int immext:1;
654   unsigned int norex64:1;
655   unsigned int rex64:1;
656   unsigned int ugh:1;
657   unsigned int vex:2;
658   unsigned int vexvvvv:2;
659   unsigned int vexw:2;
660   unsigned int vexopcode:3;
661   unsigned int vexsources:2;
662   unsigned int vecsib:2;
663   unsigned int sse2avx:1;
664   unsigned int noavx:1;
665   unsigned int evex:3;
666   unsigned int masking:2;
667   unsigned int broadcast:3;
668   unsigned int staticrounding:1;
669   unsigned int sae:1;
670   unsigned int disp8memshift:3;
671   unsigned int nodefmask:1;
672   unsigned int implicitquadgroup:1;
673   unsigned int optimize:1;
674   unsigned int attmnemonic:1;
675   unsigned int attsyntax:1;
676   unsigned int intelsyntax:1;
677   unsigned int amd64:1;
678   unsigned int intel64:1;
679 } i386_opcode_modifier;
680
681 /* Position of operand_type bits.  */
682
683 enum
684 {
685   /* Register (qualified by Byte, Word, etc) */
686   Reg = 0,
687   /* MMX register */
688   RegMMX,
689   /* Vector registers */
690   RegSIMD,
691   /* Vector Mask registers */
692   RegMask,
693   /* Control register */
694   Control,
695   /* Debug register */
696   Debug,
697   /* Test register */
698   Test,
699   /* 2 bit segment register */
700   SReg2,
701   /* 3 bit segment register */
702   SReg3,
703   /* 1 bit immediate */
704   Imm1,
705   /* 8 bit immediate */
706   Imm8,
707   /* 8 bit immediate sign extended */
708   Imm8S,
709   /* 16 bit immediate */
710   Imm16,
711   /* 32 bit immediate */
712   Imm32,
713   /* 32 bit immediate sign extended */
714   Imm32S,
715   /* 64 bit immediate */
716   Imm64,
717   /* 8bit/16bit/32bit displacements are used in different ways,
718      depending on the instruction.  For jumps, they specify the
719      size of the PC relative displacement, for instructions with
720      memory operand, they specify the size of the offset relative
721      to the base register, and for instructions with memory offset
722      such as `mov 1234,%al' they specify the size of the offset
723      relative to the segment base.  */
724   /* 8 bit displacement */
725   Disp8,
726   /* 16 bit displacement */
727   Disp16,
728   /* 32 bit displacement */
729   Disp32,
730   /* 32 bit signed displacement */
731   Disp32S,
732   /* 64 bit displacement */
733   Disp64,
734   /* Accumulator %al/%ax/%eax/%rax/%st(0)/%xmm0 */
735   Acc,
736   /* Register which can be used for base or index in memory operand.  */
737   BaseIndex,
738   /* Register to hold in/out port addr = dx */
739   InOutPortReg,
740   /* Register to hold shift count = cl */
741   ShiftCount,
742   /* Absolute address for jump.  */
743   JumpAbsolute,
744   /* String insn operand with fixed es segment */
745   EsSeg,
746   /* RegMem is for instructions with a modrm byte where the register
747      destination operand should be encoded in the mod and regmem fields.
748      Normally, it will be encoded in the reg field. We add a RegMem
749      flag to the destination register operand to indicate that it should
750      be encoded in the regmem field.  */
751   RegMem,
752   /* Memory.  */
753   Mem,
754   /* BYTE size. */
755   Byte,
756   /* WORD size. 2 byte */
757   Word,
758   /* DWORD size. 4 byte */
759   Dword,
760   /* FWORD size. 6 byte */
761   Fword,
762   /* QWORD size. 8 byte */
763   Qword,
764   /* TBYTE size. 10 byte */
765   Tbyte,
766   /* XMMWORD size. */
767   Xmmword,
768   /* YMMWORD size. */
769   Ymmword,
770   /* ZMMWORD size.  */
771   Zmmword,
772   /* Unspecified memory size.  */
773   Unspecified,
774   /* Any memory size.  */
775   Anysize,
776
777   /* Vector 4 bit immediate.  */
778   Vec_Imm4,
779
780   /* Bound register.  */
781   RegBND,
782
783   /* The number of bitfields in i386_operand_type.  */
784   OTNum
785 };
786
787 #define OTNumOfUints \
788   ((OTNum - 1) / sizeof (unsigned int) / CHAR_BIT + 1)
789 #define OTNumOfBits \
790   (OTNumOfUints * sizeof (unsigned int) * CHAR_BIT)
791
792 /* If you get a compiler error for zero width of the unused field,
793    comment it out.  */
794 #define OTUnused                OTNum
795
796 typedef union i386_operand_type
797 {
798   struct
799     {
800       unsigned int reg:1;
801       unsigned int regmmx:1;
802       unsigned int regsimd:1;
803       unsigned int regmask:1;
804       unsigned int control:1;
805       unsigned int debug:1;
806       unsigned int test:1;
807       unsigned int sreg2:1;
808       unsigned int sreg3:1;
809       unsigned int imm1:1;
810       unsigned int imm8:1;
811       unsigned int imm8s:1;
812       unsigned int imm16:1;
813       unsigned int imm32:1;
814       unsigned int imm32s:1;
815       unsigned int imm64:1;
816       unsigned int disp8:1;
817       unsigned int disp16:1;
818       unsigned int disp32:1;
819       unsigned int disp32s:1;
820       unsigned int disp64:1;
821       unsigned int acc:1;
822       unsigned int baseindex:1;
823       unsigned int inoutportreg:1;
824       unsigned int shiftcount:1;
825       unsigned int jumpabsolute:1;
826       unsigned int esseg:1;
827       unsigned int regmem:1;
828       unsigned int byte:1;
829       unsigned int word:1;
830       unsigned int dword:1;
831       unsigned int fword:1;
832       unsigned int qword:1;
833       unsigned int tbyte:1;
834       unsigned int xmmword:1;
835       unsigned int ymmword:1;
836       unsigned int zmmword:1;
837       unsigned int unspecified:1;
838       unsigned int anysize:1;
839       unsigned int vec_imm4:1;
840       unsigned int regbnd:1;
841 #ifdef OTUnused
842       unsigned int unused:(OTNumOfBits - OTUnused);
843 #endif
844     } bitfield;
845   unsigned int array[OTNumOfUints];
846 } i386_operand_type;
847
848 typedef struct insn_template
849 {
850   /* instruction name sans width suffix ("mov" for movl insns) */
851   char *name;
852
853   /* how many operands */
854   unsigned int operands;
855
856   /* base_opcode is the fundamental opcode byte without optional
857      prefix(es).  */
858   unsigned int base_opcode;
859 #define Opcode_D        0x2 /* Direction bit:
860                                set if Reg --> Regmem;
861                                unset if Regmem --> Reg. */
862 #define Opcode_FloatR   0x8 /* Bit to swap src/dest for float insns. */
863 #define Opcode_FloatD 0x400 /* Direction bit for float insns. */
864
865   /* extension_opcode is the 3 bit extension for group <n> insns.
866      This field is also used to store the 8-bit opcode suffix for the
867      AMD 3DNow! instructions.
868      If this template has no extension opcode (the usual case) use None
869      Instructions */
870   unsigned int extension_opcode;
871 #define None 0xffff             /* If no extension_opcode is possible.  */
872
873   /* Opcode length.  */
874   unsigned char opcode_length;
875
876   /* cpu feature flags */
877   i386_cpu_flags cpu_flags;
878
879   /* the bits in opcode_modifier are used to generate the final opcode from
880      the base_opcode.  These bits also are used to detect alternate forms of
881      the same instruction */
882   i386_opcode_modifier opcode_modifier;
883
884   /* operand_types[i] describes the type of operand i.  This is made
885      by OR'ing together all of the possible type masks.  (e.g.
886      'operand_types[i] = Reg|Imm' specifies that operand i can be
887      either a register or an immediate operand.  */
888   i386_operand_type operand_types[MAX_OPERANDS];
889 }
890 insn_template;
891
892 extern const insn_template i386_optab[];
893
894 /* these are for register name --> number & type hash lookup */
895 typedef struct
896 {
897   char *reg_name;
898   i386_operand_type reg_type;
899   unsigned char reg_flags;
900 #define RegRex      0x1  /* Extended register.  */
901 #define RegRex64    0x2  /* Extended 8 bit register.  */
902 #define RegVRex     0x4  /* Extended vector register.  */
903   unsigned char reg_num;
904 #define RegIP   ((unsigned char ) ~0)
905 /* EIZ and RIZ are fake index registers.  */
906 #define RegIZ   (RegIP - 1)
907 /* FLAT is a fake segment register (Intel mode).  */
908 #define RegFlat     ((unsigned char) ~0)
909   signed char dw2_regnum[2];
910 #define Dw2Inval (-1)
911 }
912 reg_entry;
913
914 /* Entries in i386_regtab.  */
915 #define REGNAM_AL 1
916 #define REGNAM_AX 25
917 #define REGNAM_EAX 41
918
919 extern const reg_entry i386_regtab[];
920 extern const unsigned int i386_regtab_size;
921
922 typedef struct
923 {
924   char *seg_name;
925   unsigned int seg_prefix;
926 }
927 seg_entry;
928
929 extern const seg_entry cs;
930 extern const seg_entry ds;
931 extern const seg_entry ss;
932 extern const seg_entry es;
933 extern const seg_entry fs;
934 extern const seg_entry gs;