1 //===-- X86InstrSystem.td - System Instructions ------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 let SchedRW = [WriteSystem] in {
17 let Defs = [RAX, RDX] in
18 def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", [(X86rdtsc)]>, TB;
20 let Defs = [RAX, RCX, RDX] in
21 def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", [(X86rdtscp)]>, TB;
23 // CPU flow control instructions
25 let mayLoad = 1, mayStore = 0, hasSideEffects = 1, isTrap = 1 in {
26 def TRAP : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
27 def UD2B : I<0xB9, RawFrm, (outs), (ins), "ud2b", []>, TB;
30 def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", []>;
31 def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", []>, TB;
33 // Interrupt and SysCall Instructions.
34 let Uses = [EFLAGS] in
35 def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>, Requires<[Not64BitMode]>;
37 def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3", [(int_x86_int (i8 3))]>;
40 // The long form of "int $3" turns into int3 as a size optimization.
41 // FIXME: This doesn't work because InstAlias can't match immediate constants.
42 //def : InstAlias<"int\t$3", (INT3)>;
44 let SchedRW = [WriteSystem] in {
46 def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap",
47 [(int_x86_int imm:$trap)]>;
50 def SYSCALL : I<0x05, RawFrm, (outs), (ins), "syscall", []>, TB;
51 def SYSRET : I<0x07, RawFrm, (outs), (ins), "sysret{l}", []>, TB;
52 def SYSRET64 :RI<0x07, RawFrm, (outs), (ins), "sysretq", []>, TB,
53 Requires<[In64BitMode]>;
55 def SYSENTER : I<0x34, RawFrm, (outs), (ins), "sysenter", []>, TB;
57 def SYSEXIT : I<0x35, RawFrm, (outs), (ins), "sysexit{l}", []>, TB;
58 def SYSEXIT64 :RI<0x35, RawFrm, (outs), (ins), "sysexitq", []>, TB,
59 Requires<[In64BitMode]>;
62 def : Pat<(debugtrap),
63 (INT3)>, Requires<[NotPS4]>;
64 def : Pat<(debugtrap),
65 (INT (i8 0x41))>, Requires<[IsPS4]>;
67 //===----------------------------------------------------------------------===//
68 // Input/Output Instructions.
70 let SchedRW = [WriteSystem] in {
71 let Defs = [AL], Uses = [DX] in
72 def IN8rr : I<0xEC, RawFrm, (outs), (ins), "in{b}\t{%dx, %al|al, dx}", []>;
73 let Defs = [AX], Uses = [DX] in
74 def IN16rr : I<0xED, RawFrm, (outs), (ins), "in{w}\t{%dx, %ax|ax, dx}", []>,
76 let Defs = [EAX], Uses = [DX] in
77 def IN32rr : I<0xED, RawFrm, (outs), (ins), "in{l}\t{%dx, %eax|eax, dx}", []>,
81 def IN8ri : Ii8<0xE4, RawFrm, (outs), (ins u8imm:$port),
82 "in{b}\t{$port, %al|al, $port}", []>;
84 def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
85 "in{w}\t{$port, %ax|ax, $port}", []>, OpSize16;
87 def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
88 "in{l}\t{$port, %eax|eax, $port}", []>, OpSize32;
90 let Uses = [DX, AL] in
91 def OUT8rr : I<0xEE, RawFrm, (outs), (ins), "out{b}\t{%al, %dx|dx, al}", []>;
92 let Uses = [DX, AX] in
93 def OUT16rr : I<0xEF, RawFrm, (outs), (ins), "out{w}\t{%ax, %dx|dx, ax}", []>,
95 let Uses = [DX, EAX] in
96 def OUT32rr : I<0xEF, RawFrm, (outs), (ins), "out{l}\t{%eax, %dx|dx, eax}", []>,
100 def OUT8ir : Ii8<0xE6, RawFrm, (outs), (ins u8imm:$port),
101 "out{b}\t{%al, $port|$port, al}", []>;
103 def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
104 "out{w}\t{%ax, $port|$port, ax}", []>, OpSize16;
106 def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
107 "out{l}\t{%eax, $port|$port, eax}", []>, OpSize32;
111 //===----------------------------------------------------------------------===//
112 // Moves to and from debug registers
114 let SchedRW = [WriteSystem] in {
115 def MOV32rd : I<0x21, MRMDestReg, (outs GR32:$dst), (ins DEBUG_REG:$src),
116 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
117 Requires<[Not64BitMode]>;
118 def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
119 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
120 Requires<[In64BitMode]>;
122 def MOV32dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR32:$src),
123 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
124 Requires<[Not64BitMode]>;
125 def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
126 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
127 Requires<[In64BitMode]>;
130 //===----------------------------------------------------------------------===//
131 // Moves to and from control registers
133 let SchedRW = [WriteSystem] in {
134 def MOV32rc : I<0x20, MRMDestReg, (outs GR32:$dst), (ins CONTROL_REG:$src),
135 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
136 Requires<[Not64BitMode]>;
137 def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG:$src),
138 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
139 Requires<[In64BitMode]>;
141 def MOV32cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR32:$src),
142 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
143 Requires<[Not64BitMode]>;
144 def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR64:$src),
145 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
146 Requires<[In64BitMode]>;
149 //===----------------------------------------------------------------------===//
150 // Segment override instruction prefixes
152 let SchedRW = [WriteNop] in {
153 def CS_PREFIX : I<0x2E, RawFrm, (outs), (ins), "cs", []>;
154 def SS_PREFIX : I<0x36, RawFrm, (outs), (ins), "ss", []>;
155 def DS_PREFIX : I<0x3E, RawFrm, (outs), (ins), "ds", []>;
156 def ES_PREFIX : I<0x26, RawFrm, (outs), (ins), "es", []>;
157 def FS_PREFIX : I<0x64, RawFrm, (outs), (ins), "fs", []>;
158 def GS_PREFIX : I<0x65, RawFrm, (outs), (ins), "gs", []>;
161 //===----------------------------------------------------------------------===//
162 // Moves to and from segment registers.
165 let SchedRW = [WriteMove] in {
166 def MOV16rs : I<0x8C, MRMDestReg, (outs GR16:$dst), (ins SEGMENT_REG:$src),
167 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize16;
168 def MOV32rs : I<0x8C, MRMDestReg, (outs GR32:$dst), (ins SEGMENT_REG:$src),
169 "mov{l}\t{$src, $dst|$dst, $src}", []>, OpSize32;
170 def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
171 "mov{q}\t{$src, $dst|$dst, $src}", []>;
172 let mayStore = 1 in {
173 def MOV16ms : I<0x8C, MRMDestMem, (outs), (ins i16mem:$dst, SEGMENT_REG:$src),
174 "mov{w}\t{$src, $dst|$dst, $src}", []>;
176 def MOV16sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR16:$src),
177 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize16;
178 def MOV32sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR32:$src),
179 "mov{l}\t{$src, $dst|$dst, $src}", []>, OpSize32;
180 def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
181 "mov{q}\t{$src, $dst|$dst, $src}", []>;
183 def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
184 "mov{w}\t{$src, $dst|$dst, $src}", []>;
188 //===----------------------------------------------------------------------===//
189 // Segmentation support instructions.
191 let SchedRW = [WriteSystem] in {
192 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
195 def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
196 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB,
197 OpSize16, NotMemoryFoldable;
198 def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
199 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB,
200 OpSize16, NotMemoryFoldable;
202 // i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
204 def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
205 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB,
206 OpSize32, NotMemoryFoldable;
207 def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
208 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB,
209 OpSize32, NotMemoryFoldable;
210 // i16mem operand in LAR64rm and GR32 operand in LAR64rr is not a typo.
212 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
213 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
214 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
215 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
217 // i16mem operand in LSL32rm and GR32 operand in LSL32rr is not a typo.
219 def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
220 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB,
221 OpSize16, NotMemoryFoldable;
222 def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
223 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB,
224 OpSize16, NotMemoryFoldable;
225 // i16mem operand in LSL64rm and GR32 operand in LSL64rr is not a typo.
227 def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
228 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB,
229 OpSize32, NotMemoryFoldable;
230 def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
231 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB,
232 OpSize32, NotMemoryFoldable;
234 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
235 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
236 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
237 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
239 def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr", []>, TB;
241 def STR16r : I<0x00, MRM1r, (outs GR16:$dst), (ins),
242 "str{w}\t$dst", []>, TB, OpSize16;
243 def STR32r : I<0x00, MRM1r, (outs GR32:$dst), (ins),
244 "str{l}\t$dst", []>, TB, OpSize32;
245 def STR64r : RI<0x00, MRM1r, (outs GR64:$dst), (ins),
246 "str{q}\t$dst", []>, TB;
248 def STRm : I<0x00, MRM1m, (outs), (ins i16mem:$dst), "str{w}\t$dst", []>, TB;
250 def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src), "ltr{w}\t$src", []>, TB, NotMemoryFoldable;
252 def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src), "ltr{w}\t$src", []>, TB, NotMemoryFoldable;
254 def PUSHCS16 : I<0x0E, RawFrm, (outs), (ins), "push{w}\t{%cs|cs}", []>,
255 OpSize16, Requires<[Not64BitMode]>;
256 def PUSHCS32 : I<0x0E, RawFrm, (outs), (ins), "push{l}\t{%cs|cs}", []>,
257 OpSize32, Requires<[Not64BitMode]>;
258 def PUSHSS16 : I<0x16, RawFrm, (outs), (ins), "push{w}\t{%ss|ss}", []>,
259 OpSize16, Requires<[Not64BitMode]>;
260 def PUSHSS32 : I<0x16, RawFrm, (outs), (ins), "push{l}\t{%ss|ss}", []>,
261 OpSize32, Requires<[Not64BitMode]>;
262 def PUSHDS16 : I<0x1E, RawFrm, (outs), (ins), "push{w}\t{%ds|ds}", []>,
263 OpSize16, Requires<[Not64BitMode]>;
264 def PUSHDS32 : I<0x1E, RawFrm, (outs), (ins), "push{l}\t{%ds|ds}", []>,
265 OpSize32, Requires<[Not64BitMode]>;
266 def PUSHES16 : I<0x06, RawFrm, (outs), (ins), "push{w}\t{%es|es}", []>,
267 OpSize16, Requires<[Not64BitMode]>;
268 def PUSHES32 : I<0x06, RawFrm, (outs), (ins), "push{l}\t{%es|es}", []>,
269 OpSize32, Requires<[Not64BitMode]>;
270 def PUSHFS16 : I<0xa0, RawFrm, (outs), (ins), "push{w}\t{%fs|fs}", []>,
272 def PUSHFS32 : I<0xa0, RawFrm, (outs), (ins), "push{l}\t{%fs|fs}", []>, TB,
273 OpSize32, Requires<[Not64BitMode]>;
274 def PUSHGS16 : I<0xa8, RawFrm, (outs), (ins), "push{w}\t{%gs|gs}", []>,
276 def PUSHGS32 : I<0xa8, RawFrm, (outs), (ins), "push{l}\t{%gs|gs}", []>, TB,
277 OpSize32, Requires<[Not64BitMode]>;
278 def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins), "push{q}\t{%fs|fs}", []>, TB,
279 OpSize32, Requires<[In64BitMode]>;
280 def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins), "push{q}\t{%gs|gs}", []>, TB,
281 OpSize32, Requires<[In64BitMode]>;
283 // No "pop cs" instruction.
284 def POPSS16 : I<0x17, RawFrm, (outs), (ins), "pop{w}\t{%ss|ss}", []>,
285 OpSize16, Requires<[Not64BitMode]>;
286 def POPSS32 : I<0x17, RawFrm, (outs), (ins), "pop{l}\t{%ss|ss}", []>,
287 OpSize32, Requires<[Not64BitMode]>;
289 def POPDS16 : I<0x1F, RawFrm, (outs), (ins), "pop{w}\t{%ds|ds}", []>,
290 OpSize16, Requires<[Not64BitMode]>;
291 def POPDS32 : I<0x1F, RawFrm, (outs), (ins), "pop{l}\t{%ds|ds}", []>,
292 OpSize32, Requires<[Not64BitMode]>;
294 def POPES16 : I<0x07, RawFrm, (outs), (ins), "pop{w}\t{%es|es}", []>,
295 OpSize16, Requires<[Not64BitMode]>;
296 def POPES32 : I<0x07, RawFrm, (outs), (ins), "pop{l}\t{%es|es}", []>,
297 OpSize32, Requires<[Not64BitMode]>;
299 def POPFS16 : I<0xa1, RawFrm, (outs), (ins), "pop{w}\t{%fs|fs}", []>,
301 def POPFS32 : I<0xa1, RawFrm, (outs), (ins), "pop{l}\t{%fs|fs}", []>, TB,
302 OpSize32, Requires<[Not64BitMode]>;
303 def POPFS64 : I<0xa1, RawFrm, (outs), (ins), "pop{q}\t{%fs|fs}", []>, TB,
304 OpSize32, Requires<[In64BitMode]>;
306 def POPGS16 : I<0xa9, RawFrm, (outs), (ins), "pop{w}\t{%gs|gs}", []>,
308 def POPGS32 : I<0xa9, RawFrm, (outs), (ins), "pop{l}\t{%gs|gs}", []>, TB,
309 OpSize32, Requires<[Not64BitMode]>;
310 def POPGS64 : I<0xa9, RawFrm, (outs), (ins), "pop{q}\t{%gs|gs}", []>, TB,
311 OpSize32, Requires<[In64BitMode]>;
313 def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
314 "lds{w}\t{$src, $dst|$dst, $src}", []>, OpSize16,
315 Requires<[Not64BitMode]>;
316 def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
317 "lds{l}\t{$src, $dst|$dst, $src}", []>, OpSize32,
318 Requires<[Not64BitMode]>;
320 def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
321 "lss{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
322 def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
323 "lss{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
324 def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaquemem:$src),
325 "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
327 def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
328 "les{w}\t{$src, $dst|$dst, $src}", []>, OpSize16,
329 Requires<[Not64BitMode]>;
330 def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
331 "les{l}\t{$src, $dst|$dst, $src}", []>, OpSize32,
332 Requires<[Not64BitMode]>;
334 def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
335 "lfs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
336 def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
337 "lfs{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
338 def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaquemem:$src),
339 "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
341 def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
342 "lgs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
343 def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
344 "lgs{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
346 def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaquemem:$src),
347 "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
349 def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg), "verr\t$seg", []>, TB, NotMemoryFoldable;
350 def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg), "verw\t$seg", []>, TB, NotMemoryFoldable;
352 def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg), "verr\t$seg", []>, TB, NotMemoryFoldable;
353 def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg), "verw\t$seg", []>, TB, NotMemoryFoldable;
357 //===----------------------------------------------------------------------===//
358 // Descriptor-table support instructions
360 let SchedRW = [WriteSystem] in {
361 def SGDT16m : I<0x01, MRM0m, (outs), (ins opaquemem:$dst),
362 "sgdtw\t$dst", []>, TB, OpSize16, Requires<[Not64BitMode]>;
363 def SGDT32m : I<0x01, MRM0m, (outs), (ins opaquemem:$dst),
364 "sgdt{l|d}\t$dst", []>, OpSize32, TB, Requires <[Not64BitMode]>;
365 def SGDT64m : I<0x01, MRM0m, (outs), (ins opaquemem:$dst),
366 "sgdt{q}\t$dst", []>, TB, Requires <[In64BitMode]>;
367 def SIDT16m : I<0x01, MRM1m, (outs), (ins opaquemem:$dst),
368 "sidtw\t$dst", []>, TB, OpSize16, Requires<[Not64BitMode]>;
369 def SIDT32m : I<0x01, MRM1m, (outs), (ins opaquemem:$dst),
370 "sidt{l|d}\t$dst", []>, OpSize32, TB, Requires <[Not64BitMode]>;
371 def SIDT64m : I<0x01, MRM1m, (outs), (ins opaquemem:$dst),
372 "sidt{q}\t$dst", []>, TB, Requires <[In64BitMode]>;
373 def SLDT16r : I<0x00, MRM0r, (outs GR16:$dst), (ins),
374 "sldt{w}\t$dst", []>, TB, OpSize16;
376 def SLDT16m : I<0x00, MRM0m, (outs), (ins i16mem:$dst),
377 "sldt{w}\t$dst", []>, TB;
378 def SLDT32r : I<0x00, MRM0r, (outs GR32:$dst), (ins),
379 "sldt{l}\t$dst", []>, OpSize32, TB;
381 // LLDT is not interpreted specially in 64-bit mode because there is no sign
383 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
384 "sldt{q}\t$dst", []>, TB, Requires<[In64BitMode]>;
386 def LGDT16m : I<0x01, MRM2m, (outs), (ins opaquemem:$src),
387 "lgdtw\t$src", []>, TB, OpSize16, Requires<[Not64BitMode]>;
388 def LGDT32m : I<0x01, MRM2m, (outs), (ins opaquemem:$src),
389 "lgdt{l|d}\t$src", []>, OpSize32, TB, Requires<[Not64BitMode]>;
390 def LGDT64m : I<0x01, MRM2m, (outs), (ins opaquemem:$src),
391 "lgdt{q}\t$src", []>, TB, Requires<[In64BitMode]>;
392 def LIDT16m : I<0x01, MRM3m, (outs), (ins opaquemem:$src),
393 "lidtw\t$src", []>, TB, OpSize16, Requires<[Not64BitMode]>;
394 def LIDT32m : I<0x01, MRM3m, (outs), (ins opaquemem:$src),
395 "lidt{l|d}\t$src", []>, OpSize32, TB, Requires<[Not64BitMode]>;
396 def LIDT64m : I<0x01, MRM3m, (outs), (ins opaquemem:$src),
397 "lidt{q}\t$src", []>, TB, Requires<[In64BitMode]>;
398 def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
399 "lldt{w}\t$src", []>, TB, NotMemoryFoldable;
401 def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
402 "lldt{w}\t$src", []>, TB, NotMemoryFoldable;
405 //===----------------------------------------------------------------------===//
406 // Specialized register support
407 let SchedRW = [WriteSystem] in {
408 let Uses = [EAX, ECX, EDX] in
409 def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", []>, TB;
410 let Defs = [EAX, EDX], Uses = [ECX] in
411 def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", []>, TB;
413 let Defs = [RAX, RDX], Uses = [ECX] in
414 def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", [(X86rdpmc)]>, TB;
416 def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins),
417 "smsw{w}\t$dst", []>, OpSize16, TB;
418 def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins),
419 "smsw{l}\t$dst", []>, OpSize32, TB;
420 // no m form encodable; use SMSW16m
421 def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
422 "smsw{q}\t$dst", []>, TB;
424 // For memory operands, there is only a 16-bit form
425 def SMSW16m : I<0x01, MRM4m, (outs), (ins i16mem:$dst),
426 "smsw{w}\t$dst", []>, TB;
428 def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
429 "lmsw{w}\t$src", []>, TB, NotMemoryFoldable;
431 def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
432 "lmsw{w}\t$src", []>, TB, NotMemoryFoldable;
434 let Defs = [EAX, EBX, ECX, EDX], Uses = [EAX, ECX] in
435 def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", []>, TB;
438 //===----------------------------------------------------------------------===//
439 // Cache instructions
440 let SchedRW = [WriteSystem] in {
441 def INVD : I<0x08, RawFrm, (outs), (ins), "invd", []>, TB;
442 def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", [(int_x86_wbinvd)]>, TB;
444 // wbnoinvd is like wbinvd, except without invalidation
445 // encoding: like wbinvd + an 0xF3 prefix
446 def WBNOINVD : I<0x09, RawFrm, (outs), (ins), "wbnoinvd",
447 [(int_x86_wbnoinvd)]>, XS,
448 Requires<[HasWBNOINVD]>;
451 //===----------------------------------------------------------------------===//
453 // Use with caution, availability is not predicated on features.
454 let SchedRW = [WriteSystem] in {
455 let Uses = [SSP] in {
456 let Defs = [SSP] in {
457 def INCSSPD : I<0xAE, MRM5r, (outs), (ins GR32:$src), "incsspd\t$src",
458 [(int_x86_incsspd GR32:$src)]>, XS;
459 def INCSSPQ : RI<0xAE, MRM5r, (outs), (ins GR64:$src), "incsspq\t$src",
460 [(int_x86_incsspq GR64:$src)]>, XS;
463 let Constraints = "$src = $dst" in {
464 def RDSSPD : I<0x1E, MRM1r, (outs GR32:$dst), (ins GR32:$src),
466 [(set GR32:$dst, (int_x86_rdsspd GR32:$src))]>, XS;
467 def RDSSPQ : RI<0x1E, MRM1r, (outs GR64:$dst), (ins GR64:$src),
469 [(set GR64:$dst, (int_x86_rdsspq GR64:$src))]>, XS;
472 let Defs = [SSP] in {
473 def SAVEPREVSSP : I<0x01, MRM_EA, (outs), (ins), "saveprevssp",
474 [(int_x86_saveprevssp)]>, XS;
475 def RSTORSSP : I<0x01, MRM5m, (outs), (ins i32mem:$src),
477 [(int_x86_rstorssp addr:$src)]>, XS;
481 def WRSSD : I<0xF6, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
482 "wrssd\t{$src, $dst|$dst, $src}",
483 [(int_x86_wrssd GR32:$src, addr:$dst)]>, T8PS;
484 def WRSSQ : RI<0xF6, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
485 "wrssq\t{$src, $dst|$dst, $src}",
486 [(int_x86_wrssq GR64:$src, addr:$dst)]>, T8PS;
487 def WRUSSD : I<0xF5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
488 "wrussd\t{$src, $dst|$dst, $src}",
489 [(int_x86_wrussd GR32:$src, addr:$dst)]>, T8PD;
490 def WRUSSQ : RI<0xF5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
491 "wrussq\t{$src, $dst|$dst, $src}",
492 [(int_x86_wrussq GR64:$src, addr:$dst)]>, T8PD;
494 let Defs = [SSP] in {
495 let Uses = [SSP] in {
496 def SETSSBSY : I<0x01, MRM_E8, (outs), (ins), "setssbsy",
497 [(int_x86_setssbsy)]>, XS;
500 def CLRSSBSY : I<0xAE, MRM6m, (outs), (ins i32mem:$src),
502 [(int_x86_clrssbsy addr:$src)]>, XS;
506 let SchedRW = [WriteSystem] in {
507 def ENDBR64 : I<0x1E, MRM_FA, (outs), (ins), "endbr64", []>, XS;
508 def ENDBR32 : I<0x1E, MRM_FB, (outs), (ins), "endbr32", []>, XS;
511 //===----------------------------------------------------------------------===//
512 // XSAVE instructions
513 let SchedRW = [WriteSystem] in {
514 let Predicates = [HasXSAVE] in {
515 let Defs = [EDX, EAX], Uses = [ECX] in
516 def XGETBV : I<0x01, MRM_D0, (outs), (ins), "xgetbv", []>, TB;
518 let Uses = [EDX, EAX, ECX] in
519 def XSETBV : I<0x01, MRM_D1, (outs), (ins),
521 [(int_x86_xsetbv ECX, EDX, EAX)]>, TB;
525 let Uses = [EDX, EAX] in {
526 def XSAVE : I<0xAE, MRM4m, (outs), (ins opaquemem:$dst),
528 [(int_x86_xsave addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE]>;
529 def XSAVE64 : RI<0xAE, MRM4m, (outs), (ins opaquemem:$dst),
531 [(int_x86_xsave64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE, In64BitMode]>;
532 def XRSTOR : I<0xAE, MRM5m, (outs), (ins opaquemem:$dst),
534 [(int_x86_xrstor addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE]>;
535 def XRSTOR64 : RI<0xAE, MRM5m, (outs), (ins opaquemem:$dst),
537 [(int_x86_xrstor64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE, In64BitMode]>;
538 def XSAVEOPT : I<0xAE, MRM6m, (outs), (ins opaquemem:$dst),
540 [(int_x86_xsaveopt addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVEOPT]>;
541 def XSAVEOPT64 : RI<0xAE, MRM6m, (outs), (ins opaquemem:$dst),
543 [(int_x86_xsaveopt64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVEOPT, In64BitMode]>;
544 def XSAVEC : I<0xC7, MRM4m, (outs), (ins opaquemem:$dst),
546 [(int_x86_xsavec addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVEC]>;
547 def XSAVEC64 : RI<0xC7, MRM4m, (outs), (ins opaquemem:$dst),
549 [(int_x86_xsavec64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVEC, In64BitMode]>;
550 def XSAVES : I<0xC7, MRM5m, (outs), (ins opaquemem:$dst),
552 [(int_x86_xsaves addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES]>;
553 def XSAVES64 : RI<0xC7, MRM5m, (outs), (ins opaquemem:$dst),
555 [(int_x86_xsaves64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVE, In64BitMode]>;
556 def XRSTORS : I<0xC7, MRM3m, (outs), (ins opaquemem:$dst),
558 [(int_x86_xrstors addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES]>;
559 def XRSTORS64 : RI<0xC7, MRM3m, (outs), (ins opaquemem:$dst),
561 [(int_x86_xrstors64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES, In64BitMode]>;
565 //===----------------------------------------------------------------------===//
566 // VIA PadLock crypto instructions
567 let Defs = [RAX, RDI], Uses = [RDX, RDI], SchedRW = [WriteSystem] in
568 def XSTORE : I<0xa7, MRM_C0, (outs), (ins), "xstore", []>, TB;
570 def : InstAlias<"xstorerng", (XSTORE)>;
572 let SchedRW = [WriteSystem] in {
573 let Defs = [RSI, RDI], Uses = [RBX, RDX, RSI, RDI] in {
574 def XCRYPTECB : I<0xa7, MRM_C8, (outs), (ins), "xcryptecb", []>, TB;
575 def XCRYPTCBC : I<0xa7, MRM_D0, (outs), (ins), "xcryptcbc", []>, TB;
576 def XCRYPTCTR : I<0xa7, MRM_D8, (outs), (ins), "xcryptctr", []>, TB;
577 def XCRYPTCFB : I<0xa7, MRM_E0, (outs), (ins), "xcryptcfb", []>, TB;
578 def XCRYPTOFB : I<0xa7, MRM_E8, (outs), (ins), "xcryptofb", []>, TB;
581 let Defs = [RAX, RSI, RDI], Uses = [RAX, RSI, RDI] in {
582 def XSHA1 : I<0xa6, MRM_C8, (outs), (ins), "xsha1", []>, TB;
583 def XSHA256 : I<0xa6, MRM_D0, (outs), (ins), "xsha256", []>, TB;
585 let Defs = [RAX, RDX, RSI], Uses = [RAX, RSI] in
586 def MONTMUL : I<0xa6, MRM_C0, (outs), (ins), "montmul", []>, TB;
589 //==-----------------------------------------------------------------------===//
590 // PKU - enable protection key
591 let usesCustomInserter = 1, hasNoSchedulingInfo = 1 in {
592 def WRPKRU : PseudoI<(outs), (ins GR32:$src),
593 [(int_x86_wrpkru GR32:$src)]>;
594 def RDPKRU : PseudoI<(outs GR32:$dst), (ins),
595 [(set GR32:$dst, (int_x86_rdpkru))]>;
598 let SchedRW = [WriteSystem] in {
599 let Defs = [EAX, EDX], Uses = [ECX] in
600 def RDPKRUr : I<0x01, MRM_EE, (outs), (ins), "rdpkru", []>, TB;
601 let Uses = [EAX, ECX, EDX] in
602 def WRPKRUr : I<0x01, MRM_EF, (outs), (ins), "wrpkru", []>, TB;
605 //===----------------------------------------------------------------------===//
606 // FS/GS Base Instructions
607 let Predicates = [HasFSGSBase, In64BitMode], SchedRW = [WriteSystem] in {
608 def RDFSBASE : I<0xAE, MRM0r, (outs GR32:$dst), (ins),
610 [(set GR32:$dst, (int_x86_rdfsbase_32))]>, XS;
611 def RDFSBASE64 : RI<0xAE, MRM0r, (outs GR64:$dst), (ins),
613 [(set GR64:$dst, (int_x86_rdfsbase_64))]>, XS;
614 def RDGSBASE : I<0xAE, MRM1r, (outs GR32:$dst), (ins),
616 [(set GR32:$dst, (int_x86_rdgsbase_32))]>, XS;
617 def RDGSBASE64 : RI<0xAE, MRM1r, (outs GR64:$dst), (ins),
619 [(set GR64:$dst, (int_x86_rdgsbase_64))]>, XS;
620 def WRFSBASE : I<0xAE, MRM2r, (outs), (ins GR32:$src),
622 [(int_x86_wrfsbase_32 GR32:$src)]>, XS;
623 def WRFSBASE64 : RI<0xAE, MRM2r, (outs), (ins GR64:$src),
625 [(int_x86_wrfsbase_64 GR64:$src)]>, XS;
626 def WRGSBASE : I<0xAE, MRM3r, (outs), (ins GR32:$src),
628 [(int_x86_wrgsbase_32 GR32:$src)]>, XS;
629 def WRGSBASE64 : RI<0xAE, MRM3r, (outs), (ins GR64:$src),
631 [(int_x86_wrgsbase_64 GR64:$src)]>, XS;
634 //===----------------------------------------------------------------------===//
635 // INVPCID Instruction
636 let SchedRW = [WriteSystem] in {
637 def INVPCID32 : I<0x82, MRMSrcMem, (outs), (ins GR32:$src1, i128mem:$src2),
638 "invpcid\t{$src2, $src1|$src1, $src2}",
639 [(int_x86_invpcid GR32:$src1, addr:$src2)]>, T8PD,
640 Requires<[Not64BitMode, HasINVPCID]>;
641 def INVPCID64 : I<0x82, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
642 "invpcid\t{$src2, $src1|$src1, $src2}", []>, T8PD,
643 Requires<[In64BitMode, HasINVPCID]>;
646 let Predicates = [In64BitMode, HasINVPCID] in {
647 // The instruction can only use a 64 bit register as the register argument
648 // in 64 bit mode, while the intrinsic only accepts a 32 bit argument
649 // corresponding to it.
650 // The accepted values for now are 0,1,2,3 anyways (see Intel SDM -- INVCPID
651 // type),/ so it doesn't hurt us that one can't supply a 64 bit value here.
652 def : Pat<(int_x86_invpcid GR32:$src1, addr:$src2),
654 (SUBREG_TO_REG (i64 0), (MOV32rr GR32:$src1), sub_32bit),
659 //===----------------------------------------------------------------------===//
661 let Defs = [EFLAGS], SchedRW = [WriteSystem] in {
662 def CLAC : I<0x01, MRM_CA, (outs), (ins), "clac", []>, TB;
663 def STAC : I<0x01, MRM_CB, (outs), (ins), "stac", []>, TB;
666 //===----------------------------------------------------------------------===//
668 let SchedRW = [WriteSystem] in {
669 let Uses = [RAX, RBX, RCX, RDX], Defs = [RAX, RBX, RCX] in {
670 def GETSEC : I<0x37, RawFrm, (outs), (ins), "getsec", []>, TB;
674 //===----------------------------------------------------------------------===//
675 // TS flag control instruction.
676 let SchedRW = [WriteSystem] in {
677 def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
680 //===----------------------------------------------------------------------===//
681 // IF (inside EFLAGS) management instructions.
682 let SchedRW = [WriteSystem], Uses = [EFLAGS], Defs = [EFLAGS] in {
683 def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
684 def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
687 //===----------------------------------------------------------------------===//
689 let SchedRW = [WriteSystem] in {
690 def RDPID32 : I<0xC7, MRM7r, (outs GR32:$dst), (ins),
691 "rdpid\t$dst", [(set GR32:$dst, (int_x86_rdpid))]>, XS,
692 Requires<[Not64BitMode, HasRDPID]>;
693 def RDPID64 : I<0xC7, MRM7r, (outs GR64:$dst), (ins), "rdpid\t$dst", []>, XS,
694 Requires<[In64BitMode, HasRDPID]>;
697 let Predicates = [In64BitMode, HasRDPID] in {
698 // Due to silly instruction definition, we have to compensate for the
699 // instruction outputing a 64-bit register.
700 def : Pat<(int_x86_rdpid),
701 (EXTRACT_SUBREG (RDPID64), sub_32bit)>;
705 //===----------------------------------------------------------------------===//
706 // PTWRITE Instruction - Write Data to a Processor Trace Packet
707 let SchedRW = [WriteSystem] in {
708 def PTWRITEm: I<0xAE, MRM4m, (outs), (ins i32mem:$dst),
709 "ptwrite{l}\t$dst", [(int_x86_ptwrite32 (loadi32 addr:$dst))]>, XS,
710 Requires<[HasPTWRITE]>;
711 def PTWRITE64m : RI<0xAE, MRM4m, (outs), (ins i64mem:$dst),
712 "ptwrite{q}\t$dst", [(int_x86_ptwrite64 (loadi64 addr:$dst))]>, XS,
713 Requires<[In64BitMode, HasPTWRITE]>;
715 def PTWRITEr : I<0xAE, MRM4r, (outs), (ins GR32:$dst),
716 "ptwrite{l}\t$dst", [(int_x86_ptwrite32 GR32:$dst)]>, XS,
717 Requires<[HasPTWRITE]>;
718 def PTWRITE64r : RI<0xAE, MRM4r, (outs), (ins GR64:$dst),
719 "ptwrite{q}\t$dst", [(int_x86_ptwrite64 GR64:$dst)]>, XS,
720 Requires<[In64BitMode, HasPTWRITE]>;
723 //===----------------------------------------------------------------------===//
724 // Platform Configuration instruction
727 // "This instruction is used to execute functions for configuring platform
729 // EAX: Leaf function to be invoked.
730 // RBX/RCX/RDX: Leaf-specific purpose."
731 // "Successful execution of the leaf clears RAX (set to zero) and ZF, CF, PF,
732 // AF, OF, and SF are cleared. In case of failure, the failure reason is
733 // indicated in RAX with ZF set to 1 and CF, PF, AF, OF, and SF are cleared."
734 // Thus all these mentioned registers are considered clobbered.
736 let SchedRW = [WriteSystem] in {
737 let Uses = [RAX, RBX, RCX, RDX], Defs = [RAX, RBX, RCX, RDX, EFLAGS] in
738 def PCONFIG : I<0x01, MRM_C5, (outs), (ins), "pconfig", []>, TB,
739 Requires<[HasPCONFIG]>;