[X86] Convert to MVT instead of calling EVT functions since we already know the type...
[oota-llvm.git] / lib / Target / X86 / X86InstrSystem.td
1 //===-- X86InstrSystem.td - System Instructions ------------*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the X86 instructions that are generally used in
11 // privileged modes.  These are not typically used by the compiler, but are
12 // supported for the assembler and disassembler.
13 //
14 //===----------------------------------------------------------------------===//
15
16 let SchedRW = [WriteSystem] in {
17 let Defs = [RAX, RDX] in
18   def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", [(X86rdtsc)], IIC_RDTSC>,
19               TB;
20
21 let Defs = [RAX, RCX, RDX] in
22   def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", [(X86rdtscp)]>, TB;
23
24 // CPU flow control instructions
25
26 let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in {
27   def TRAP    : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
28   def UD2B    : I<0xB9, RawFrm, (outs), (ins), "ud2b", []>, TB;
29 }
30
31 def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", [], IIC_HLT>;
32 def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", [], IIC_RSM>, TB;
33
34 // Interrupt and SysCall Instructions.
35 let Uses = [EFLAGS] in
36   def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>;
37 def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3",
38               [(int_x86_int (i8 3))], IIC_INT3>;
39 } // SchedRW
40
41 // The long form of "int $3" turns into int3 as a size optimization.
42 // FIXME: This doesn't work because InstAlias can't match immediate constants.
43 //def : InstAlias<"int\t$3", (INT3)>;
44
45 let SchedRW = [WriteSystem] in {
46
47 def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap",
48               [(int_x86_int imm:$trap)], IIC_INT>;
49
50
51 def SYSCALL  : I<0x05, RawFrm, (outs), (ins), "syscall", [], IIC_SYSCALL>, TB;
52 def SYSRET   : I<0x07, RawFrm, (outs), (ins), "sysret{l}", [], IIC_SYSCALL>, TB;
53 def SYSRET64 :RI<0x07, RawFrm, (outs), (ins), "sysret{q}", [], IIC_SYSCALL>, TB,
54                Requires<[In64BitMode]>;
55
56 def SYSENTER : I<0x34, RawFrm, (outs), (ins), "sysenter", [],
57                  IIC_SYS_ENTER_EXIT>, TB;
58
59 def SYSEXIT   : I<0x35, RawFrm, (outs), (ins), "sysexit{l}", [],
60                  IIC_SYS_ENTER_EXIT>, TB;
61 def SYSEXIT64 :RI<0x35, RawFrm, (outs), (ins), "sysexit{q}", [],
62                  IIC_SYS_ENTER_EXIT>, TB, Requires<[In64BitMode]>;
63
64 def IRET16 : I<0xcf, RawFrm, (outs), (ins), "iret{w}", [], IIC_IRET>, OpSize16;
65 def IRET32 : I<0xcf, RawFrm, (outs), (ins), "iret{l|d}", [], IIC_IRET>,
66              OpSize32;
67 def IRET64 : RI<0xcf, RawFrm, (outs), (ins), "iretq", [], IIC_IRET>,
68              Requires<[In64BitMode]>;
69 } // SchedRW
70
71 def : Pat<(debugtrap),
72           (INT3)>, Requires<[NotPS4]>;
73 def : Pat<(debugtrap),
74           (INT (i8 0x41))>, Requires<[IsPS4]>;
75
76 //===----------------------------------------------------------------------===//
77 //  Input/Output Instructions.
78 //
79 let SchedRW = [WriteSystem] in {
80 let Defs = [AL], Uses = [DX] in
81 def IN8rr  : I<0xEC, RawFrm, (outs), (ins),
82                "in{b}\t{%dx, %al|al, dx}", [], IIC_IN_RR>;
83 let Defs = [AX], Uses = [DX] in
84 def IN16rr : I<0xED, RawFrm, (outs), (ins),
85                "in{w}\t{%dx, %ax|ax, dx}", [], IIC_IN_RR>,  OpSize16;
86 let Defs = [EAX], Uses = [DX] in
87 def IN32rr : I<0xED, RawFrm, (outs), (ins),
88                "in{l}\t{%dx, %eax|eax, dx}", [], IIC_IN_RR>, OpSize32;
89
90 let Defs = [AL] in
91 def IN8ri  : Ii8<0xE4, RawFrm, (outs), (ins u8imm:$port),
92                   "in{b}\t{$port, %al|al, $port}", [], IIC_IN_RI>;
93 let Defs = [AX] in
94 def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
95                   "in{w}\t{$port, %ax|ax, $port}", [], IIC_IN_RI>, OpSize16;
96 let Defs = [EAX] in
97 def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
98                   "in{l}\t{$port, %eax|eax, $port}", [], IIC_IN_RI>, OpSize32;
99
100 let Uses = [DX, AL] in
101 def OUT8rr  : I<0xEE, RawFrm, (outs), (ins),
102                 "out{b}\t{%al, %dx|dx, al}", [], IIC_OUT_RR>;
103 let Uses = [DX, AX] in
104 def OUT16rr : I<0xEF, RawFrm, (outs), (ins),
105                 "out{w}\t{%ax, %dx|dx, ax}", [], IIC_OUT_RR>, OpSize16;
106 let Uses = [DX, EAX] in
107 def OUT32rr : I<0xEF, RawFrm, (outs), (ins),
108                 "out{l}\t{%eax, %dx|dx, eax}", [], IIC_OUT_RR>, OpSize32;
109
110 let Uses = [AL] in
111 def OUT8ir  : Ii8<0xE6, RawFrm, (outs), (ins u8imm:$port),
112                    "out{b}\t{%al, $port|$port, al}", [], IIC_OUT_IR>;
113 let Uses = [AX] in
114 def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
115                    "out{w}\t{%ax, $port|$port, ax}", [], IIC_OUT_IR>, OpSize16;
116 let Uses = [EAX] in
117 def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
118                   "out{l}\t{%eax, $port|$port, eax}", [], IIC_OUT_IR>, OpSize32;
119
120 } // SchedRW
121
122 //===----------------------------------------------------------------------===//
123 // Moves to and from debug registers
124
125 let SchedRW = [WriteSystem] in {
126 def MOV32rd : I<0x21, MRMDestReg, (outs GR32:$dst), (ins DEBUG_REG:$src),
127                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_REG_DR>, TB,
128                 Requires<[Not64BitMode]>;
129 def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
130                 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_REG_DR>, TB,
131                 Requires<[In64BitMode]>;
132
133 def MOV32dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR32:$src),
134                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_DR_REG>, TB,
135                 Requires<[Not64BitMode]>;
136 def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
137                 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_DR_REG>, TB,
138                 Requires<[In64BitMode]>;
139 } // SchedRW
140
141 //===----------------------------------------------------------------------===//
142 // Moves to and from control registers
143
144 let SchedRW = [WriteSystem] in {
145 def MOV32rc : I<0x20, MRMDestReg, (outs GR32:$dst), (ins CONTROL_REG:$src),
146                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_REG_CR>, TB,
147                 Requires<[Not64BitMode]>;
148 def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG:$src),
149                 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_REG_CR>, TB,
150                 Requires<[In64BitMode]>;
151
152 def MOV32cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR32:$src),
153                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_CR_REG>, TB,
154                 Requires<[Not64BitMode]>;
155 def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR64:$src),
156                 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_CR_REG>, TB,
157                 Requires<[In64BitMode]>;
158 } // SchedRW
159
160 //===----------------------------------------------------------------------===//
161 // Segment override instruction prefixes
162
163 def CS_PREFIX : I<0x2E, RawFrm, (outs), (ins), "cs", []>;
164 def SS_PREFIX : I<0x36, RawFrm, (outs), (ins), "ss", []>;
165 def DS_PREFIX : I<0x3E, RawFrm, (outs), (ins), "ds", []>;
166 def ES_PREFIX : I<0x26, RawFrm, (outs), (ins), "es", []>;
167 def FS_PREFIX : I<0x64, RawFrm, (outs), (ins), "fs", []>;
168 def GS_PREFIX : I<0x65, RawFrm, (outs), (ins), "gs", []>;
169
170
171 //===----------------------------------------------------------------------===//
172 // Moves to and from segment registers.
173 //
174
175 let SchedRW = [WriteMove] in {
176 def MOV16rs : I<0x8C, MRMDestReg, (outs GR16:$dst), (ins SEGMENT_REG:$src),
177                 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV_REG_SR>, OpSize16;
178 def MOV32rs : I<0x8C, MRMDestReg, (outs GR32:$dst), (ins SEGMENT_REG:$src),
179                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_REG_SR>, OpSize32;
180 def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
181                  "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_REG_SR>;
182
183 def MOV16ms : I<0x8C, MRMDestMem, (outs i16mem:$dst), (ins SEGMENT_REG:$src),
184                 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV_MEM_SR>, OpSize16;
185 def MOV32ms : I<0x8C, MRMDestMem, (outs i32mem:$dst), (ins SEGMENT_REG:$src),
186                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_MEM_SR>, OpSize32;
187 def MOV64ms : RI<0x8C, MRMDestMem, (outs i64mem:$dst), (ins SEGMENT_REG:$src),
188                  "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_MEM_SR>;
189
190 def MOV16sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR16:$src),
191                 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV_SR_REG>, OpSize16;
192 def MOV32sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR32:$src),
193                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_SR_REG>, OpSize32;
194 def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
195                  "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_SR_REG>;
196
197 def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
198                 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV_SR_MEM>, OpSize16;
199 def MOV32sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i32mem:$src),
200                 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV_SR_MEM>, OpSize32;
201 def MOV64sm : RI<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i64mem:$src),
202                  "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV_SR_MEM>;
203 } // SchedRW
204
205 //===----------------------------------------------------------------------===//
206 // Segmentation support instructions.
207
208 let SchedRW = [WriteSystem] in {
209 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", [], IIC_SWAPGS>, TB;
210
211 def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
212                 "lar{w}\t{$src, $dst|$dst, $src}", [], IIC_LAR_RM>, TB,
213                 OpSize16;
214 def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
215                 "lar{w}\t{$src, $dst|$dst, $src}", [], IIC_LAR_RR>, TB,
216                 OpSize16;
217
218 // i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
219 def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
220                 "lar{l}\t{$src, $dst|$dst, $src}", [], IIC_LAR_RM>, TB,
221                 OpSize32;
222 def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
223                 "lar{l}\t{$src, $dst|$dst, $src}", [], IIC_LAR_RR>, TB,
224                 OpSize32;
225 // i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
226 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
227                  "lar{q}\t{$src, $dst|$dst, $src}", [], IIC_LAR_RM>, TB;
228 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
229                  "lar{q}\t{$src, $dst|$dst, $src}", [], IIC_LAR_RR>, TB;
230
231 def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
232                 "lsl{w}\t{$src, $dst|$dst, $src}", [], IIC_LSL_RM>, TB,
233                 OpSize16;
234 def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
235                 "lsl{w}\t{$src, $dst|$dst, $src}", [], IIC_LSL_RR>, TB,
236                 OpSize16;
237 def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
238                 "lsl{l}\t{$src, $dst|$dst, $src}", [], IIC_LSL_RM>, TB,
239                 OpSize32;
240 def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
241                 "lsl{l}\t{$src, $dst|$dst, $src}", [], IIC_LSL_RR>, TB,
242                 OpSize32;
243 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
244                  "lsl{q}\t{$src, $dst|$dst, $src}", [], IIC_LSL_RM>, TB;
245 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
246                  "lsl{q}\t{$src, $dst|$dst, $src}", [], IIC_LSL_RR>, TB;
247
248 def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr",
249                [], IIC_INVLPG>, TB;
250
251 def STR16r : I<0x00, MRM1r, (outs GR16:$dst), (ins),
252                "str{w}\t$dst", [], IIC_STR>, TB, OpSize16;
253 def STR32r : I<0x00, MRM1r, (outs GR32:$dst), (ins),
254                "str{l}\t$dst", [], IIC_STR>, TB, OpSize32;
255 def STR64r : RI<0x00, MRM1r, (outs GR64:$dst), (ins),
256                 "str{q}\t$dst", [], IIC_STR>, TB;
257 def STRm   : I<0x00, MRM1m, (outs i16mem:$dst), (ins),
258                "str{w}\t$dst", [], IIC_STR>, TB;
259
260 def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src),
261              "ltr{w}\t$src", [], IIC_LTR>, TB;
262 def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src),
263              "ltr{w}\t$src", [], IIC_LTR>, TB;
264
265 def PUSHCS16 : I<0x0E, RawFrm, (outs), (ins),
266                  "push{w}\t{%cs|cs}", [], IIC_PUSH_SR>,
267                  OpSize16, Requires<[Not64BitMode]>;
268 def PUSHCS32 : I<0x0E, RawFrm, (outs), (ins),
269                  "push{l}\t{%cs|cs}", [], IIC_PUSH_CS>,
270                  OpSize32, Requires<[Not64BitMode]>;
271 def PUSHSS16 : I<0x16, RawFrm, (outs), (ins),
272                  "push{w}\t{%ss|ss}", [], IIC_PUSH_SR>,
273                  OpSize16, Requires<[Not64BitMode]>;
274 def PUSHSS32 : I<0x16, RawFrm, (outs), (ins),
275                  "push{l}\t{%ss|ss}", [], IIC_PUSH_SR>,
276                  OpSize32, Requires<[Not64BitMode]>;
277 def PUSHDS16 : I<0x1E, RawFrm, (outs), (ins),
278                  "push{w}\t{%ds|ds}", [], IIC_PUSH_SR>,
279                  OpSize16, Requires<[Not64BitMode]>;
280 def PUSHDS32 : I<0x1E, RawFrm, (outs), (ins),
281                  "push{l}\t{%ds|ds}", [], IIC_PUSH_SR>,
282                  OpSize32, Requires<[Not64BitMode]>;
283 def PUSHES16 : I<0x06, RawFrm, (outs), (ins),
284                  "push{w}\t{%es|es}", [], IIC_PUSH_SR>,
285                  OpSize16, Requires<[Not64BitMode]>;
286 def PUSHES32 : I<0x06, RawFrm, (outs), (ins),
287                  "push{l}\t{%es|es}", [], IIC_PUSH_SR>,
288                  OpSize32, Requires<[Not64BitMode]>;
289 def PUSHFS16 : I<0xa0, RawFrm, (outs), (ins),
290                  "push{w}\t{%fs|fs}", [], IIC_PUSH_SR>, OpSize16, TB;
291 def PUSHFS32 : I<0xa0, RawFrm, (outs), (ins),
292                  "push{l}\t{%fs|fs}", [], IIC_PUSH_SR>, TB,
293                OpSize32, Requires<[Not64BitMode]>;
294 def PUSHGS16 : I<0xa8, RawFrm, (outs), (ins),
295                  "push{w}\t{%gs|gs}", [], IIC_PUSH_SR>, OpSize16, TB;
296 def PUSHGS32 : I<0xa8, RawFrm, (outs), (ins),
297                  "push{l}\t{%gs|gs}", [], IIC_PUSH_SR>, TB,
298                OpSize32, Requires<[Not64BitMode]>;
299 def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins),
300                  "push{q}\t{%fs|fs}", [], IIC_PUSH_SR>, TB,
301                OpSize32, Requires<[In64BitMode]>;
302 def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins),
303                  "push{q}\t{%gs|gs}", [], IIC_PUSH_SR>, TB,
304                OpSize32, Requires<[In64BitMode]>;
305
306 // No "pop cs" instruction.
307 def POPSS16 : I<0x17, RawFrm, (outs), (ins),
308                 "pop{w}\t{%ss|ss}", [], IIC_POP_SR_SS>,
309               OpSize16, Requires<[Not64BitMode]>;
310 def POPSS32 : I<0x17, RawFrm, (outs), (ins),
311                 "pop{l}\t{%ss|ss}", [], IIC_POP_SR_SS>,
312               OpSize32, Requires<[Not64BitMode]>;
313
314 def POPDS16 : I<0x1F, RawFrm, (outs), (ins),
315                 "pop{w}\t{%ds|ds}", [], IIC_POP_SR>,
316               OpSize16, Requires<[Not64BitMode]>;
317 def POPDS32 : I<0x1F, RawFrm, (outs), (ins),
318                 "pop{l}\t{%ds|ds}", [], IIC_POP_SR>,
319               OpSize32, Requires<[Not64BitMode]>;
320
321 def POPES16 : I<0x07, RawFrm, (outs), (ins),
322                 "pop{w}\t{%es|es}", [], IIC_POP_SR>,
323               OpSize16, Requires<[Not64BitMode]>;
324 def POPES32 : I<0x07, RawFrm, (outs), (ins),
325                 "pop{l}\t{%es|es}", [], IIC_POP_SR>,
326               OpSize32, Requires<[Not64BitMode]>;
327
328 def POPFS16 : I<0xa1, RawFrm, (outs), (ins),
329                 "pop{w}\t{%fs|fs}", [], IIC_POP_SR>, OpSize16, TB;
330 def POPFS32 : I<0xa1, RawFrm, (outs), (ins),
331                 "pop{l}\t{%fs|fs}", [], IIC_POP_SR>, TB,
332               OpSize32, Requires<[Not64BitMode]>;
333 def POPFS64 : I<0xa1, RawFrm, (outs), (ins),
334                 "pop{q}\t{%fs|fs}", [], IIC_POP_SR>, TB,
335               OpSize32, Requires<[In64BitMode]>;
336
337 def POPGS16 : I<0xa9, RawFrm, (outs), (ins),
338                 "pop{w}\t{%gs|gs}", [], IIC_POP_SR>, OpSize16, TB;
339 def POPGS32 : I<0xa9, RawFrm, (outs), (ins),
340                 "pop{l}\t{%gs|gs}", [], IIC_POP_SR>, TB,
341               OpSize32, Requires<[Not64BitMode]>;
342 def POPGS64 : I<0xa9, RawFrm, (outs), (ins),
343                 "pop{q}\t{%gs|gs}", [], IIC_POP_SR>, TB,
344               OpSize32, Requires<[In64BitMode]>;
345
346
347 def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
348                 "lds{w}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, OpSize16;
349 def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
350                 "lds{l}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, OpSize32;
351
352 def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
353                 "lss{w}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB, OpSize16;
354 def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
355                 "lss{l}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB, OpSize32;
356 def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
357                  "lss{q}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB;
358
359 def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
360                 "les{w}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, OpSize16;
361 def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
362                 "les{l}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, OpSize32;
363
364 def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
365                 "lfs{w}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB, OpSize16;
366 def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
367                 "lfs{l}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB, OpSize32;
368 def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
369                  "lfs{q}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB;
370
371 def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
372                 "lgs{w}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB, OpSize16;
373 def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
374                 "lgs{l}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB, OpSize32;
375
376 def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
377                  "lgs{q}\t{$src, $dst|$dst, $src}", [], IIC_LXS>, TB;
378
379
380 def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg),
381               "verr\t$seg", [], IIC_VERR>, TB;
382 def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg),
383               "verr\t$seg", [], IIC_VERR>, TB;
384 def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg),
385               "verw\t$seg", [], IIC_VERW_MEM>, TB;
386 def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg),
387               "verw\t$seg", [], IIC_VERW_REG>, TB;
388 } // SchedRW
389
390 //===----------------------------------------------------------------------===//
391 // Descriptor-table support instructions
392
393 let SchedRW = [WriteSystem] in {
394 def SGDT16m : I<0x01, MRM0m, (outs opaque48mem:$dst), (ins),
395               "sgdt{w}\t$dst", [], IIC_SGDT>, TB, OpSize16, Requires<[Not64BitMode]>;
396 def SGDT32m : I<0x01, MRM0m, (outs opaque48mem:$dst), (ins),
397               "sgdt{l}\t$dst", [], IIC_SGDT>, OpSize32, TB, Requires <[Not64BitMode]>;
398 def SGDT64m : I<0x01, MRM0m, (outs opaque80mem:$dst), (ins),
399               "sgdt{q}\t$dst", [], IIC_SGDT>, TB, Requires <[In64BitMode]>;
400 def SIDT16m : I<0x01, MRM1m, (outs opaque48mem:$dst), (ins),
401               "sidt{w}\t$dst", [], IIC_SIDT>, TB, OpSize16, Requires<[Not64BitMode]>;
402 def SIDT32m : I<0x01, MRM1m, (outs opaque48mem:$dst), (ins),
403               "sidt{l}\t$dst", []>, OpSize32, TB, Requires <[Not64BitMode]>;
404 def SIDT64m : I<0x01, MRM1m, (outs opaque80mem:$dst), (ins),
405               "sidt{q}\t$dst", []>, TB, Requires <[In64BitMode]>;
406 def SLDT16r : I<0x00, MRM0r, (outs GR16:$dst), (ins),
407                 "sldt{w}\t$dst", [], IIC_SLDT>, TB, OpSize16;
408 def SLDT16m : I<0x00, MRM0m, (outs i16mem:$dst), (ins),
409                 "sldt{w}\t$dst", [], IIC_SLDT>, TB;
410 def SLDT32r : I<0x00, MRM0r, (outs GR32:$dst), (ins),
411                 "sldt{l}\t$dst", [], IIC_SLDT>, OpSize32, TB;
412
413 // LLDT is not interpreted specially in 64-bit mode because there is no sign
414 //   extension.
415 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
416                  "sldt{q}\t$dst", [], IIC_SLDT>, TB;
417 def SLDT64m : RI<0x00, MRM0m, (outs i16mem:$dst), (ins),
418                  "sldt{q}\t$dst", [], IIC_SLDT>, TB;
419
420 def LGDT16m : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
421               "lgdt{w}\t$src", [], IIC_LGDT>, TB, OpSize16, Requires<[Not64BitMode]>;
422 def LGDT32m : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
423               "lgdt{l}\t$src", [], IIC_LGDT>, OpSize32, TB, Requires<[Not64BitMode]>;
424 def LGDT64m : I<0x01, MRM2m, (outs), (ins opaque80mem:$src),
425               "lgdt{q}\t$src", [], IIC_LGDT>, TB, Requires<[In64BitMode]>;
426 def LIDT16m : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
427               "lidt{w}\t$src", [], IIC_LIDT>, TB, OpSize16, Requires<[Not64BitMode]>;
428 def LIDT32m : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
429               "lidt{l}\t$src", [], IIC_LIDT>, OpSize32, TB, Requires<[Not64BitMode]>;
430 def LIDT64m : I<0x01, MRM3m, (outs), (ins opaque80mem:$src),
431               "lidt{q}\t$src", [], IIC_LIDT>, TB, Requires<[In64BitMode]>;
432 def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
433                 "lldt{w}\t$src", [], IIC_LLDT_REG>, TB;
434 def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
435                 "lldt{w}\t$src", [], IIC_LLDT_MEM>, TB;
436 } // SchedRW
437
438 //===----------------------------------------------------------------------===//
439 // Specialized register support
440 let SchedRW = [WriteSystem] in {
441 let Uses = [EAX, ECX, EDX] in
442 def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", [], IIC_WRMSR>, TB;
443 let Defs = [EAX, EDX], Uses = [ECX] in
444 def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", [], IIC_RDMSR>, TB;
445
446 let Defs = [RAX, RDX], Uses = [ECX] in
447   def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", [(X86rdpmc)], IIC_RDPMC>,
448               TB;
449
450 def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins),
451                 "smsw{w}\t$dst", [], IIC_SMSW>, OpSize16, TB;
452 def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins),
453                 "smsw{l}\t$dst", [], IIC_SMSW>, OpSize32, TB;
454 // no m form encodable; use SMSW16m
455 def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
456                  "smsw{q}\t$dst", [], IIC_SMSW>, TB;
457
458 // For memory operands, there is only a 16-bit form
459 def SMSW16m : I<0x01, MRM4m, (outs i16mem:$dst), (ins),
460                 "smsw{w}\t$dst", [], IIC_SMSW>, TB;
461
462 def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
463                 "lmsw{w}\t$src", [], IIC_LMSW_MEM>, TB;
464 def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
465                 "lmsw{w}\t$src", [], IIC_LMSW_REG>, TB;
466
467 let Defs = [EAX, EBX, ECX, EDX], Uses = [EAX, ECX] in
468   def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", [], IIC_CPUID>, TB;
469 } // SchedRW
470
471 //===----------------------------------------------------------------------===//
472 // Cache instructions
473 let SchedRW = [WriteSystem] in {
474 def INVD : I<0x08, RawFrm, (outs), (ins), "invd", [], IIC_INVD>, TB;
475 def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", [], IIC_INVD>, TB;
476 } // SchedRW
477
478 //===----------------------------------------------------------------------===//
479 // XSAVE instructions
480 let SchedRW = [WriteSystem] in {
481 let Predicates = [HasXSAVE] in {
482 let Defs = [EDX, EAX], Uses = [ECX] in
483   def XGETBV : I<0x01, MRM_D0, (outs), (ins), "xgetbv", []>, TB;
484
485 let Uses = [EDX, EAX, ECX] in
486   def XSETBV : I<0x01, MRM_D1, (outs), (ins), "xsetbv", []>, TB;
487 }
488
489 let Uses = [EDX, EAX] in {
490 let Predicates = [HasXSAVE] in {
491   def XSAVE : I<0xAE, MRM4m, (outs), (ins opaque512mem:$dst),
492                 "xsave\t$dst",
493                 [(int_x86_xsave addr:$dst, EDX, EAX)]>, TB;
494   def XSAVE64 : RI<0xAE, MRM4m, (outs), (ins opaque512mem:$dst),
495                    "xsave64\t$dst",
496                    [(int_x86_xsave64 addr:$dst, EDX, EAX)]>, TB, Requires<[In64BitMode]>;
497   def XRSTOR : I<0xAE, MRM5m, (outs), (ins opaque512mem:$dst),
498                  "xrstor\t$dst",
499                  [(int_x86_xrstor addr:$dst, EDX, EAX)]>, TB;
500   def XRSTOR64 : RI<0xAE, MRM5m, (outs), (ins opaque512mem:$dst),
501                     "xrstor64\t$dst",
502                     [(int_x86_xrstor64 addr:$dst, EDX, EAX)]>, TB, Requires<[In64BitMode]>;
503 }
504 let Predicates = [HasXSAVEOPT] in {
505   def XSAVEOPT : I<0xAE, MRM6m, (outs), (ins opaque512mem:$dst),
506                    "xsaveopt\t$dst",
507                    [(int_x86_xsaveopt addr:$dst, EDX, EAX)]>, TB;
508   def XSAVEOPT64 : RI<0xAE, MRM6m, (outs), (ins opaque512mem:$dst),
509                       "xsaveopt64\t$dst",
510                       [(int_x86_xsaveopt64 addr:$dst, EDX, EAX)]>, TB, Requires<[In64BitMode]>;
511 }
512 let Predicates = [HasXSAVEC] in {
513   def XSAVEC : I<0xC7, MRM4m, (outs), (ins opaque512mem:$dst),
514                  "xsavec\t$dst",
515                  [(int_x86_xsavec addr:$dst, EDX, EAX)]>, TB;
516   def XSAVEC64 : RI<0xC7, MRM4m, (outs), (ins opaque512mem:$dst),
517                    "xsavec64\t$dst",
518                    [(int_x86_xsavec64 addr:$dst, EDX, EAX)]>, TB, Requires<[In64BitMode]>;
519 }
520 let Predicates = [HasXSAVES] in {
521   def XSAVES : I<0xC7, MRM5m, (outs), (ins opaque512mem:$dst),
522                  "xsaves\t$dst",
523                  [(int_x86_xsaves addr:$dst, EDX, EAX)]>, TB;
524   def XSAVES64 : RI<0xC7, MRM5m, (outs), (ins opaque512mem:$dst),
525                     "xsaves64\t$dst",
526                     [(int_x86_xsaves64 addr:$dst, EDX, EAX)]>, TB, Requires<[In64BitMode]>;
527   def XRSTORS : I<0xC7, MRM3m, (outs), (ins opaque512mem:$dst),
528                   "xrstors\t$dst",
529                   [(int_x86_xrstors addr:$dst, EDX, EAX)]>, TB;
530   def XRSTORS64 : RI<0xC7, MRM3m, (outs), (ins opaque512mem:$dst),
531                      "xrstors64\t$dst",
532                      [(int_x86_xrstors64 addr:$dst, EDX, EAX)]>, TB, Requires<[In64BitMode]>;
533 }
534 } // Uses
535 } // SchedRW
536
537 //===----------------------------------------------------------------------===//
538 // VIA PadLock crypto instructions
539 let Defs = [RAX, RDI], Uses = [RDX, RDI] in
540   def XSTORE : I<0xa7, MRM_C0, (outs), (ins), "xstore", []>, TB;
541
542 def : InstAlias<"xstorerng", (XSTORE)>;
543
544 let Defs = [RSI, RDI], Uses = [RBX, RDX, RSI, RDI] in {
545   def XCRYPTECB : I<0xa7, MRM_C8, (outs), (ins), "xcryptecb", []>, TB;
546   def XCRYPTCBC : I<0xa7, MRM_D0, (outs), (ins), "xcryptcbc", []>, TB;
547   def XCRYPTCTR : I<0xa7, MRM_D8, (outs), (ins), "xcryptctr", []>, TB;
548   def XCRYPTCFB : I<0xa7, MRM_E0, (outs), (ins), "xcryptcfb", []>, TB;
549   def XCRYPTOFB : I<0xa7, MRM_E8, (outs), (ins), "xcryptofb", []>, TB;
550 }
551
552 let Defs = [RAX, RSI, RDI], Uses = [RAX, RSI, RDI] in {
553   def XSHA1 : I<0xa6, MRM_C8, (outs), (ins), "xsha1", []>, TB;
554   def XSHA256 : I<0xa6, MRM_D0, (outs), (ins), "xsha256", []>, TB;
555 }
556 let Defs = [RAX, RDX, RSI], Uses = [RAX, RSI] in
557   def MONTMUL : I<0xa6, MRM_C0, (outs), (ins), "montmul", []>, TB;
558
559 //===----------------------------------------------------------------------===//
560 // FS/GS Base Instructions
561 let Predicates = [HasFSGSBase, In64BitMode] in {
562   def RDFSBASE : I<0xAE, MRM0r, (outs GR32:$dst), (ins),
563                    "rdfsbase{l}\t$dst",
564                    [(set GR32:$dst, (int_x86_rdfsbase_32))]>, XS;
565   def RDFSBASE64 : RI<0xAE, MRM0r, (outs GR64:$dst), (ins),
566                      "rdfsbase{q}\t$dst",
567                      [(set GR64:$dst, (int_x86_rdfsbase_64))]>, XS;
568   def RDGSBASE : I<0xAE, MRM1r, (outs GR32:$dst), (ins),
569                    "rdgsbase{l}\t$dst",
570                    [(set GR32:$dst, (int_x86_rdgsbase_32))]>, XS;
571   def RDGSBASE64 : RI<0xAE, MRM1r, (outs GR64:$dst), (ins),
572                      "rdgsbase{q}\t$dst",
573                      [(set GR64:$dst, (int_x86_rdgsbase_64))]>, XS;
574   def WRFSBASE : I<0xAE, MRM2r, (outs), (ins GR32:$src),
575                    "wrfsbase{l}\t$src",
576                    [(int_x86_wrfsbase_32 GR32:$src)]>, XS;
577   def WRFSBASE64 : RI<0xAE, MRM2r, (outs), (ins GR64:$src),
578                       "wrfsbase{q}\t$src",
579                       [(int_x86_wrfsbase_64 GR64:$src)]>, XS;
580   def WRGSBASE : I<0xAE, MRM3r, (outs), (ins GR32:$src),
581                    "wrgsbase{l}\t$src",
582                    [(int_x86_wrgsbase_32 GR32:$src)]>, XS;
583   def WRGSBASE64 : RI<0xAE, MRM3r, (outs), (ins GR64:$src),
584                       "wrgsbase{q}\t$src",
585                       [(int_x86_wrgsbase_64 GR64:$src)]>, XS;
586 }
587
588 //===----------------------------------------------------------------------===//
589 // INVPCID Instruction
590 def INVPCID32 : I<0x82, MRMSrcMem, (outs), (ins GR32:$src1, i128mem:$src2),
591                 "invpcid\t{$src2, $src1|$src1, $src2}", []>, T8PD,
592                 Requires<[Not64BitMode]>;
593 def INVPCID64 : I<0x82, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
594                 "invpcid\t{$src2, $src1|$src1, $src2}", []>, T8PD,
595                 Requires<[In64BitMode]>;
596
597 //===----------------------------------------------------------------------===//
598 // SMAP Instruction
599 let Defs = [EFLAGS] in {
600   def CLAC : I<0x01, MRM_CA, (outs), (ins), "clac", []>, TB;
601   def STAC : I<0x01, MRM_CB, (outs), (ins), "stac", []>, TB;
602 }
603
604 //===----------------------------------------------------------------------===//
605 // SMX Instruction
606 let Uses = [RAX, RBX, RCX, RDX], Defs = [RAX, RBX, RCX] in {
607   def GETSEC : I<0x37, RawFrm, (outs), (ins), "getsec", []>, TB;
608 }