1 //===-- X86InstrSystem.td - System Instructions ------------*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file describes the X86 instructions that are generally used in
10 // privileged modes. These are not typically used by the compiler, but are
11 // supported for the assembler and disassembler.
13 //===----------------------------------------------------------------------===//
15 let SchedRW = [WriteSystem] in {
16 let Defs = [RAX, RDX] in
17 def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", []>, TB;
19 let Defs = [RAX, RCX, RDX] in
20 def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", []>, TB;
22 // CPU flow control instructions
24 let mayLoad = 1, mayStore = 0, hasSideEffects = 1, isTrap = 1 in {
25 def TRAP : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
26 def UD2B : I<0xB9, RawFrm, (outs), (ins), "ud2b", []>, TB;
29 def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", []>;
30 def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", []>, TB;
32 // Interrupt and SysCall Instructions.
33 let Uses = [EFLAGS] in
34 def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>, Requires<[Not64BitMode]>;
36 def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3", [(int_x86_int (i8 3))]>;
39 // The long form of "int $3" turns into int3 as a size optimization.
40 // FIXME: This doesn't work because InstAlias can't match immediate constants.
41 //def : InstAlias<"int\t$3", (INT3)>;
43 let SchedRW = [WriteSystem] in {
45 def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap",
46 [(int_x86_int timm:$trap)]>;
49 def SYSCALL : I<0x05, RawFrm, (outs), (ins), "syscall", []>, TB;
50 def SYSRET : I<0x07, RawFrm, (outs), (ins), "sysret{l}", []>, TB;
51 def SYSRET64 :RI<0x07, RawFrm, (outs), (ins), "sysretq", []>, TB,
52 Requires<[In64BitMode]>;
54 def SYSENTER : I<0x34, RawFrm, (outs), (ins), "sysenter", []>, TB;
56 def SYSEXIT : I<0x35, RawFrm, (outs), (ins), "sysexit{l}", []>, TB;
57 def SYSEXIT64 :RI<0x35, RawFrm, (outs), (ins), "sysexitq", []>, TB,
58 Requires<[In64BitMode]>;
61 def : Pat<(debugtrap),
62 (INT3)>, Requires<[NotPS4]>;
63 def : Pat<(debugtrap),
64 (INT (i8 0x41))>, Requires<[IsPS4]>;
66 //===----------------------------------------------------------------------===//
67 // Input/Output Instructions.
69 let SchedRW = [WriteSystem] in {
70 let Defs = [AL], Uses = [DX] in
71 def IN8rr : I<0xEC, RawFrm, (outs), (ins), "in{b}\t{%dx, %al|al, dx}", []>;
72 let Defs = [AX], Uses = [DX] in
73 def IN16rr : I<0xED, RawFrm, (outs), (ins), "in{w}\t{%dx, %ax|ax, dx}", []>,
75 let Defs = [EAX], Uses = [DX] in
76 def IN32rr : I<0xED, RawFrm, (outs), (ins), "in{l}\t{%dx, %eax|eax, dx}", []>,
80 def IN8ri : Ii8<0xE4, RawFrm, (outs), (ins u8imm:$port),
81 "in{b}\t{$port, %al|al, $port}", []>;
83 def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
84 "in{w}\t{$port, %ax|ax, $port}", []>, OpSize16;
86 def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
87 "in{l}\t{$port, %eax|eax, $port}", []>, OpSize32;
89 let Uses = [DX, AL] in
90 def OUT8rr : I<0xEE, RawFrm, (outs), (ins), "out{b}\t{%al, %dx|dx, al}", []>;
91 let Uses = [DX, AX] in
92 def OUT16rr : I<0xEF, RawFrm, (outs), (ins), "out{w}\t{%ax, %dx|dx, ax}", []>,
94 let Uses = [DX, EAX] in
95 def OUT32rr : I<0xEF, RawFrm, (outs), (ins), "out{l}\t{%eax, %dx|dx, eax}", []>,
99 def OUT8ir : Ii8<0xE6, RawFrm, (outs), (ins u8imm:$port),
100 "out{b}\t{%al, $port|$port, al}", []>;
102 def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
103 "out{w}\t{%ax, $port|$port, ax}", []>, OpSize16;
105 def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
106 "out{l}\t{%eax, $port|$port, eax}", []>, OpSize32;
110 //===----------------------------------------------------------------------===//
111 // Moves to and from debug registers
113 let SchedRW = [WriteSystem] in {
114 def MOV32rd : I<0x21, MRMDestReg, (outs GR32:$dst), (ins DEBUG_REG:$src),
115 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
116 Requires<[Not64BitMode]>;
117 def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
118 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
119 Requires<[In64BitMode]>;
121 def MOV32dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR32:$src),
122 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
123 Requires<[Not64BitMode]>;
124 def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
125 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
126 Requires<[In64BitMode]>;
129 //===----------------------------------------------------------------------===//
130 // Moves to and from control registers
132 let SchedRW = [WriteSystem] in {
133 def MOV32rc : I<0x20, MRMDestReg, (outs GR32:$dst), (ins CONTROL_REG:$src),
134 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
135 Requires<[Not64BitMode]>;
136 def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG:$src),
137 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
138 Requires<[In64BitMode]>;
140 def MOV32cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR32:$src),
141 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB,
142 Requires<[Not64BitMode]>;
143 def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR64:$src),
144 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB,
145 Requires<[In64BitMode]>;
148 //===----------------------------------------------------------------------===//
149 // Segment override instruction prefixes
151 let SchedRW = [WriteNop] in {
152 def CS_PREFIX : I<0x2E, RawFrm, (outs), (ins), "cs", []>;
153 def SS_PREFIX : I<0x36, RawFrm, (outs), (ins), "ss", []>;
154 def DS_PREFIX : I<0x3E, RawFrm, (outs), (ins), "ds", []>;
155 def ES_PREFIX : I<0x26, RawFrm, (outs), (ins), "es", []>;
156 def FS_PREFIX : I<0x64, RawFrm, (outs), (ins), "fs", []>;
157 def GS_PREFIX : I<0x65, RawFrm, (outs), (ins), "gs", []>;
160 //===----------------------------------------------------------------------===//
161 // Moves to and from segment registers.
164 let SchedRW = [WriteMove] in {
165 def MOV16rs : I<0x8C, MRMDestReg, (outs GR16:$dst), (ins SEGMENT_REG:$src),
166 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize16;
167 def MOV32rs : I<0x8C, MRMDestReg, (outs GR32:$dst), (ins SEGMENT_REG:$src),
168 "mov{l}\t{$src, $dst|$dst, $src}", []>, OpSize32;
169 def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
170 "mov{q}\t{$src, $dst|$dst, $src}", []>;
171 let mayStore = 1 in {
172 def MOV16ms : I<0x8C, MRMDestMem, (outs), (ins i16mem:$dst, SEGMENT_REG:$src),
173 "mov{w}\t{$src, $dst|$dst, $src}", []>;
175 def MOV16sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR16:$src),
176 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize16;
177 def MOV32sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR32:$src),
178 "mov{l}\t{$src, $dst|$dst, $src}", []>, OpSize32;
179 def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
180 "mov{q}\t{$src, $dst|$dst, $src}", []>;
182 def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
183 "mov{w}\t{$src, $dst|$dst, $src}", []>;
187 //===----------------------------------------------------------------------===//
188 // Segmentation support instructions.
190 let SchedRW = [WriteSystem] in {
191 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
194 def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
195 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB,
196 OpSize16, NotMemoryFoldable;
197 def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
198 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB,
199 OpSize16, NotMemoryFoldable;
201 // i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
203 def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
204 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB,
205 OpSize32, NotMemoryFoldable;
206 def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
207 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB,
208 OpSize32, NotMemoryFoldable;
209 // i16mem operand in LAR64rm and GR32 operand in LAR64rr is not a typo.
211 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
212 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
213 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
214 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
216 // i16mem operand in LSL32rm and GR32 operand in LSL32rr is not a typo.
218 def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
219 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB,
220 OpSize16, NotMemoryFoldable;
221 def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
222 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB,
223 OpSize16, NotMemoryFoldable;
224 // i16mem operand in LSL64rm and GR32 operand in LSL64rr is not a typo.
226 def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
227 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB,
228 OpSize32, NotMemoryFoldable;
229 def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
230 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB,
231 OpSize32, NotMemoryFoldable;
233 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
234 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
235 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
236 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB, NotMemoryFoldable;
238 def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr", []>, TB;
240 def STR16r : I<0x00, MRM1r, (outs GR16:$dst), (ins),
241 "str{w}\t$dst", []>, TB, OpSize16;
242 def STR32r : I<0x00, MRM1r, (outs GR32:$dst), (ins),
243 "str{l}\t$dst", []>, TB, OpSize32;
244 def STR64r : RI<0x00, MRM1r, (outs GR64:$dst), (ins),
245 "str{q}\t$dst", []>, TB;
247 def STRm : I<0x00, MRM1m, (outs), (ins i16mem:$dst), "str{w}\t$dst", []>, TB;
249 def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src), "ltr{w}\t$src", []>, TB, NotMemoryFoldable;
251 def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src), "ltr{w}\t$src", []>, TB, NotMemoryFoldable;
253 def PUSHCS16 : I<0x0E, RawFrm, (outs), (ins), "push{w}\t{%cs|cs}", []>,
254 OpSize16, Requires<[Not64BitMode]>;
255 def PUSHCS32 : I<0x0E, RawFrm, (outs), (ins), "push{l}\t{%cs|cs}", []>,
256 OpSize32, Requires<[Not64BitMode]>;
257 def PUSHSS16 : I<0x16, RawFrm, (outs), (ins), "push{w}\t{%ss|ss}", []>,
258 OpSize16, Requires<[Not64BitMode]>;
259 def PUSHSS32 : I<0x16, RawFrm, (outs), (ins), "push{l}\t{%ss|ss}", []>,
260 OpSize32, Requires<[Not64BitMode]>;
261 def PUSHDS16 : I<0x1E, RawFrm, (outs), (ins), "push{w}\t{%ds|ds}", []>,
262 OpSize16, Requires<[Not64BitMode]>;
263 def PUSHDS32 : I<0x1E, RawFrm, (outs), (ins), "push{l}\t{%ds|ds}", []>,
264 OpSize32, Requires<[Not64BitMode]>;
265 def PUSHES16 : I<0x06, RawFrm, (outs), (ins), "push{w}\t{%es|es}", []>,
266 OpSize16, Requires<[Not64BitMode]>;
267 def PUSHES32 : I<0x06, RawFrm, (outs), (ins), "push{l}\t{%es|es}", []>,
268 OpSize32, Requires<[Not64BitMode]>;
269 def PUSHFS16 : I<0xa0, RawFrm, (outs), (ins), "push{w}\t{%fs|fs}", []>,
271 def PUSHFS32 : I<0xa0, RawFrm, (outs), (ins), "push{l}\t{%fs|fs}", []>, TB,
272 OpSize32, Requires<[Not64BitMode]>;
273 def PUSHGS16 : I<0xa8, RawFrm, (outs), (ins), "push{w}\t{%gs|gs}", []>,
275 def PUSHGS32 : I<0xa8, RawFrm, (outs), (ins), "push{l}\t{%gs|gs}", []>, TB,
276 OpSize32, Requires<[Not64BitMode]>;
277 def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins), "push{q}\t{%fs|fs}", []>, TB,
278 OpSize32, Requires<[In64BitMode]>;
279 def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins), "push{q}\t{%gs|gs}", []>, TB,
280 OpSize32, Requires<[In64BitMode]>;
282 // No "pop cs" instruction.
283 def POPSS16 : I<0x17, RawFrm, (outs), (ins), "pop{w}\t{%ss|ss}", []>,
284 OpSize16, Requires<[Not64BitMode]>;
285 def POPSS32 : I<0x17, RawFrm, (outs), (ins), "pop{l}\t{%ss|ss}", []>,
286 OpSize32, Requires<[Not64BitMode]>;
288 def POPDS16 : I<0x1F, RawFrm, (outs), (ins), "pop{w}\t{%ds|ds}", []>,
289 OpSize16, Requires<[Not64BitMode]>;
290 def POPDS32 : I<0x1F, RawFrm, (outs), (ins), "pop{l}\t{%ds|ds}", []>,
291 OpSize32, Requires<[Not64BitMode]>;
293 def POPES16 : I<0x07, RawFrm, (outs), (ins), "pop{w}\t{%es|es}", []>,
294 OpSize16, Requires<[Not64BitMode]>;
295 def POPES32 : I<0x07, RawFrm, (outs), (ins), "pop{l}\t{%es|es}", []>,
296 OpSize32, Requires<[Not64BitMode]>;
298 def POPFS16 : I<0xa1, RawFrm, (outs), (ins), "pop{w}\t{%fs|fs}", []>,
300 def POPFS32 : I<0xa1, RawFrm, (outs), (ins), "pop{l}\t{%fs|fs}", []>, TB,
301 OpSize32, Requires<[Not64BitMode]>;
302 def POPFS64 : I<0xa1, RawFrm, (outs), (ins), "pop{q}\t{%fs|fs}", []>, TB,
303 OpSize32, Requires<[In64BitMode]>;
305 def POPGS16 : I<0xa9, RawFrm, (outs), (ins), "pop{w}\t{%gs|gs}", []>,
307 def POPGS32 : I<0xa9, RawFrm, (outs), (ins), "pop{l}\t{%gs|gs}", []>, TB,
308 OpSize32, Requires<[Not64BitMode]>;
309 def POPGS64 : I<0xa9, RawFrm, (outs), (ins), "pop{q}\t{%gs|gs}", []>, TB,
310 OpSize32, Requires<[In64BitMode]>;
312 def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
313 "lds{w}\t{$src, $dst|$dst, $src}", []>, OpSize16,
314 Requires<[Not64BitMode]>;
315 def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
316 "lds{l}\t{$src, $dst|$dst, $src}", []>, OpSize32,
317 Requires<[Not64BitMode]>;
319 def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
320 "lss{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
321 def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
322 "lss{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
323 def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaquemem:$src),
324 "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
326 def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
327 "les{w}\t{$src, $dst|$dst, $src}", []>, OpSize16,
328 Requires<[Not64BitMode]>;
329 def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
330 "les{l}\t{$src, $dst|$dst, $src}", []>, OpSize32,
331 Requires<[Not64BitMode]>;
333 def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
334 "lfs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
335 def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
336 "lfs{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
337 def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaquemem:$src),
338 "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
340 def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaquemem:$src),
341 "lgs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
342 def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaquemem:$src),
343 "lgs{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
345 def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaquemem:$src),
346 "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
348 def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg), "verr\t$seg", []>, TB, NotMemoryFoldable;
349 def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg), "verw\t$seg", []>, TB, NotMemoryFoldable;
351 def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg), "verr\t$seg", []>, TB, NotMemoryFoldable;
352 def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg), "verw\t$seg", []>, TB, NotMemoryFoldable;
356 //===----------------------------------------------------------------------===//
357 // Descriptor-table support instructions
359 let SchedRW = [WriteSystem] in {
360 def SGDT16m : I<0x01, MRM0m, (outs), (ins opaquemem:$dst),
361 "sgdtw\t$dst", []>, TB, OpSize16, Requires<[Not64BitMode]>;
362 def SGDT32m : I<0x01, MRM0m, (outs), (ins opaquemem:$dst),
363 "sgdt{l|d}\t$dst", []>, OpSize32, TB, Requires <[Not64BitMode]>;
364 def SGDT64m : I<0x01, MRM0m, (outs), (ins opaquemem:$dst),
365 "sgdt{q}\t$dst", []>, TB, Requires <[In64BitMode]>;
366 def SIDT16m : I<0x01, MRM1m, (outs), (ins opaquemem:$dst),
367 "sidtw\t$dst", []>, TB, OpSize16, Requires<[Not64BitMode]>;
368 def SIDT32m : I<0x01, MRM1m, (outs), (ins opaquemem:$dst),
369 "sidt{l|d}\t$dst", []>, OpSize32, TB, Requires <[Not64BitMode]>;
370 def SIDT64m : I<0x01, MRM1m, (outs), (ins opaquemem:$dst),
371 "sidt{q}\t$dst", []>, TB, Requires <[In64BitMode]>;
372 def SLDT16r : I<0x00, MRM0r, (outs GR16:$dst), (ins),
373 "sldt{w}\t$dst", []>, TB, OpSize16;
375 def SLDT16m : I<0x00, MRM0m, (outs), (ins i16mem:$dst),
376 "sldt{w}\t$dst", []>, TB;
377 def SLDT32r : I<0x00, MRM0r, (outs GR32:$dst), (ins),
378 "sldt{l}\t$dst", []>, OpSize32, TB;
380 // LLDT is not interpreted specially in 64-bit mode because there is no sign
382 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
383 "sldt{q}\t$dst", []>, TB, Requires<[In64BitMode]>;
385 def LGDT16m : I<0x01, MRM2m, (outs), (ins opaquemem:$src),
386 "lgdtw\t$src", []>, TB, OpSize16, Requires<[Not64BitMode]>;
387 def LGDT32m : I<0x01, MRM2m, (outs), (ins opaquemem:$src),
388 "lgdt{l|d}\t$src", []>, OpSize32, TB, Requires<[Not64BitMode]>;
389 def LGDT64m : I<0x01, MRM2m, (outs), (ins opaquemem:$src),
390 "lgdt{q}\t$src", []>, TB, Requires<[In64BitMode]>;
391 def LIDT16m : I<0x01, MRM3m, (outs), (ins opaquemem:$src),
392 "lidtw\t$src", []>, TB, OpSize16, Requires<[Not64BitMode]>;
393 def LIDT32m : I<0x01, MRM3m, (outs), (ins opaquemem:$src),
394 "lidt{l|d}\t$src", []>, OpSize32, TB, Requires<[Not64BitMode]>;
395 def LIDT64m : I<0x01, MRM3m, (outs), (ins opaquemem:$src),
396 "lidt{q}\t$src", []>, TB, Requires<[In64BitMode]>;
397 def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
398 "lldt{w}\t$src", []>, TB, NotMemoryFoldable;
400 def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
401 "lldt{w}\t$src", []>, TB, NotMemoryFoldable;
404 //===----------------------------------------------------------------------===//
405 // Specialized register support
406 let SchedRW = [WriteSystem] in {
407 let Uses = [EAX, ECX, EDX] in
408 def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", []>, TB;
409 let Defs = [EAX, EDX], Uses = [ECX] in
410 def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", []>, TB;
412 let Defs = [RAX, RDX], Uses = [ECX] in
413 def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", []>, TB;
415 def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins),
416 "smsw{w}\t$dst", []>, OpSize16, TB;
417 def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins),
418 "smsw{l}\t$dst", []>, OpSize32, TB;
419 // no m form encodable; use SMSW16m
420 def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
421 "smsw{q}\t$dst", []>, TB;
423 // For memory operands, there is only a 16-bit form
424 def SMSW16m : I<0x01, MRM4m, (outs), (ins i16mem:$dst),
425 "smsw{w}\t$dst", []>, TB;
427 def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
428 "lmsw{w}\t$src", []>, TB, NotMemoryFoldable;
430 def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
431 "lmsw{w}\t$src", []>, TB, NotMemoryFoldable;
433 let Defs = [EAX, EBX, ECX, EDX], Uses = [EAX, ECX] in
434 def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", []>, TB;
437 //===----------------------------------------------------------------------===//
438 // Cache instructions
439 let SchedRW = [WriteSystem] in {
440 def INVD : I<0x08, RawFrm, (outs), (ins), "invd", []>, TB;
441 def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", [(int_x86_wbinvd)]>, TB;
443 // wbnoinvd is like wbinvd, except without invalidation
444 // encoding: like wbinvd + an 0xF3 prefix
445 def WBNOINVD : I<0x09, RawFrm, (outs), (ins), "wbnoinvd",
446 [(int_x86_wbnoinvd)]>, XS,
447 Requires<[HasWBNOINVD]>;
450 //===----------------------------------------------------------------------===//
452 // Use with caution, availability is not predicated on features.
453 let SchedRW = [WriteSystem] in {
454 let Uses = [SSP] in {
455 let Defs = [SSP] in {
456 def INCSSPD : I<0xAE, MRM5r, (outs), (ins GR32:$src), "incsspd\t$src",
457 [(int_x86_incsspd GR32:$src)]>, XS;
458 def INCSSPQ : RI<0xAE, MRM5r, (outs), (ins GR64:$src), "incsspq\t$src",
459 [(int_x86_incsspq GR64:$src)]>, XS;
462 let Constraints = "$src = $dst" in {
463 def RDSSPD : I<0x1E, MRM1r, (outs GR32:$dst), (ins GR32:$src),
465 [(set GR32:$dst, (int_x86_rdsspd GR32:$src))]>, XS;
466 def RDSSPQ : RI<0x1E, MRM1r, (outs GR64:$dst), (ins GR64:$src),
468 [(set GR64:$dst, (int_x86_rdsspq GR64:$src))]>, XS;
471 let Defs = [SSP] in {
472 def SAVEPREVSSP : I<0x01, MRM_EA, (outs), (ins), "saveprevssp",
473 [(int_x86_saveprevssp)]>, XS;
474 def RSTORSSP : I<0x01, MRM5m, (outs), (ins i32mem:$src),
476 [(int_x86_rstorssp addr:$src)]>, XS;
480 def WRSSD : I<0xF6, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
481 "wrssd\t{$src, $dst|$dst, $src}",
482 [(int_x86_wrssd GR32:$src, addr:$dst)]>, T8PS;
483 def WRSSQ : RI<0xF6, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
484 "wrssq\t{$src, $dst|$dst, $src}",
485 [(int_x86_wrssq GR64:$src, addr:$dst)]>, T8PS;
486 def WRUSSD : I<0xF5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
487 "wrussd\t{$src, $dst|$dst, $src}",
488 [(int_x86_wrussd GR32:$src, addr:$dst)]>, T8PD;
489 def WRUSSQ : RI<0xF5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
490 "wrussq\t{$src, $dst|$dst, $src}",
491 [(int_x86_wrussq GR64:$src, addr:$dst)]>, T8PD;
493 let Defs = [SSP] in {
494 let Uses = [SSP] in {
495 def SETSSBSY : I<0x01, MRM_E8, (outs), (ins), "setssbsy",
496 [(int_x86_setssbsy)]>, XS;
499 def CLRSSBSY : I<0xAE, MRM6m, (outs), (ins i32mem:$src),
501 [(int_x86_clrssbsy addr:$src)]>, XS;
505 let SchedRW = [WriteSystem] in {
506 def ENDBR64 : I<0x1E, MRM_FA, (outs), (ins), "endbr64", []>, XS;
507 def ENDBR32 : I<0x1E, MRM_FB, (outs), (ins), "endbr32", []>, XS;
510 //===----------------------------------------------------------------------===//
511 // XSAVE instructions
512 let SchedRW = [WriteSystem] in {
513 let Predicates = [HasXSAVE] in {
514 let Defs = [EDX, EAX], Uses = [ECX] in
515 def XGETBV : I<0x01, MRM_D0, (outs), (ins), "xgetbv", []>, TB;
517 let Uses = [EDX, EAX, ECX] in
518 def XSETBV : I<0x01, MRM_D1, (outs), (ins),
520 [(int_x86_xsetbv ECX, EDX, EAX)]>, TB;
524 let Uses = [EDX, EAX] in {
525 def XSAVE : I<0xAE, MRM4m, (outs), (ins opaquemem:$dst),
527 [(int_x86_xsave addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE]>;
528 def XSAVE64 : RI<0xAE, MRM4m, (outs), (ins opaquemem:$dst),
530 [(int_x86_xsave64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE, In64BitMode]>;
531 def XRSTOR : I<0xAE, MRM5m, (outs), (ins opaquemem:$dst),
533 [(int_x86_xrstor addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE]>;
534 def XRSTOR64 : RI<0xAE, MRM5m, (outs), (ins opaquemem:$dst),
536 [(int_x86_xrstor64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE, In64BitMode]>;
537 def XSAVEOPT : I<0xAE, MRM6m, (outs), (ins opaquemem:$dst),
539 [(int_x86_xsaveopt addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVEOPT]>;
540 def XSAVEOPT64 : RI<0xAE, MRM6m, (outs), (ins opaquemem:$dst),
542 [(int_x86_xsaveopt64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVEOPT, In64BitMode]>;
543 def XSAVEC : I<0xC7, MRM4m, (outs), (ins opaquemem:$dst),
545 [(int_x86_xsavec addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVEC]>;
546 def XSAVEC64 : RI<0xC7, MRM4m, (outs), (ins opaquemem:$dst),
548 [(int_x86_xsavec64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVEC, In64BitMode]>;
549 def XSAVES : I<0xC7, MRM5m, (outs), (ins opaquemem:$dst),
551 [(int_x86_xsaves addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES]>;
552 def XSAVES64 : RI<0xC7, MRM5m, (outs), (ins opaquemem:$dst),
554 [(int_x86_xsaves64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVE, In64BitMode]>;
555 def XRSTORS : I<0xC7, MRM3m, (outs), (ins opaquemem:$dst),
557 [(int_x86_xrstors addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES]>;
558 def XRSTORS64 : RI<0xC7, MRM3m, (outs), (ins opaquemem:$dst),
560 [(int_x86_xrstors64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES, In64BitMode]>;
564 //===----------------------------------------------------------------------===//
565 // VIA PadLock crypto instructions
566 let Defs = [RAX, RDI], Uses = [RDX, RDI], SchedRW = [WriteSystem] in
567 def XSTORE : I<0xa7, MRM_C0, (outs), (ins), "xstore", []>, TB;
569 def : InstAlias<"xstorerng", (XSTORE)>;
571 let SchedRW = [WriteSystem] in {
572 let Defs = [RSI, RDI], Uses = [RBX, RDX, RSI, RDI] in {
573 def XCRYPTECB : I<0xa7, MRM_C8, (outs), (ins), "xcryptecb", []>, TB;
574 def XCRYPTCBC : I<0xa7, MRM_D0, (outs), (ins), "xcryptcbc", []>, TB;
575 def XCRYPTCTR : I<0xa7, MRM_D8, (outs), (ins), "xcryptctr", []>, TB;
576 def XCRYPTCFB : I<0xa7, MRM_E0, (outs), (ins), "xcryptcfb", []>, TB;
577 def XCRYPTOFB : I<0xa7, MRM_E8, (outs), (ins), "xcryptofb", []>, TB;
580 let Defs = [RAX, RSI, RDI], Uses = [RAX, RSI, RDI] in {
581 def XSHA1 : I<0xa6, MRM_C8, (outs), (ins), "xsha1", []>, TB;
582 def XSHA256 : I<0xa6, MRM_D0, (outs), (ins), "xsha256", []>, TB;
584 let Defs = [RAX, RDX, RSI], Uses = [RAX, RSI] in
585 def MONTMUL : I<0xa6, MRM_C0, (outs), (ins), "montmul", []>, TB;
588 //==-----------------------------------------------------------------------===//
589 // PKU - enable protection key
590 let SchedRW = [WriteSystem] in {
591 let Defs = [EAX, EDX], Uses = [ECX] in
592 def RDPKRUr : I<0x01, MRM_EE, (outs), (ins), "rdpkru",
593 [(set EAX, (X86rdpkru ECX)), (implicit EDX)]>, TB;
594 let Uses = [EAX, ECX, EDX] in
595 def WRPKRUr : I<0x01, MRM_EF, (outs), (ins), "wrpkru",
596 [(X86wrpkru EAX, EDX, ECX)]>, TB;
599 //===----------------------------------------------------------------------===//
600 // FS/GS Base Instructions
601 let Predicates = [HasFSGSBase, In64BitMode], SchedRW = [WriteSystem] in {
602 def RDFSBASE : I<0xAE, MRM0r, (outs GR32:$dst), (ins),
604 [(set GR32:$dst, (int_x86_rdfsbase_32))]>, XS;
605 def RDFSBASE64 : RI<0xAE, MRM0r, (outs GR64:$dst), (ins),
607 [(set GR64:$dst, (int_x86_rdfsbase_64))]>, XS;
608 def RDGSBASE : I<0xAE, MRM1r, (outs GR32:$dst), (ins),
610 [(set GR32:$dst, (int_x86_rdgsbase_32))]>, XS;
611 def RDGSBASE64 : RI<0xAE, MRM1r, (outs GR64:$dst), (ins),
613 [(set GR64:$dst, (int_x86_rdgsbase_64))]>, XS;
614 def WRFSBASE : I<0xAE, MRM2r, (outs), (ins GR32:$src),
616 [(int_x86_wrfsbase_32 GR32:$src)]>, XS;
617 def WRFSBASE64 : RI<0xAE, MRM2r, (outs), (ins GR64:$src),
619 [(int_x86_wrfsbase_64 GR64:$src)]>, XS;
620 def WRGSBASE : I<0xAE, MRM3r, (outs), (ins GR32:$src),
622 [(int_x86_wrgsbase_32 GR32:$src)]>, XS;
623 def WRGSBASE64 : RI<0xAE, MRM3r, (outs), (ins GR64:$src),
625 [(int_x86_wrgsbase_64 GR64:$src)]>, XS;
628 //===----------------------------------------------------------------------===//
629 // INVPCID Instruction
630 let SchedRW = [WriteSystem] in {
631 def INVPCID32 : I<0x82, MRMSrcMem, (outs), (ins GR32:$src1, i128mem:$src2),
632 "invpcid\t{$src2, $src1|$src1, $src2}",
633 [(int_x86_invpcid GR32:$src1, addr:$src2)]>, T8PD,
634 Requires<[Not64BitMode, HasINVPCID]>;
635 def INVPCID64 : I<0x82, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
636 "invpcid\t{$src2, $src1|$src1, $src2}", []>, T8PD,
637 Requires<[In64BitMode, HasINVPCID]>;
640 let Predicates = [In64BitMode, HasINVPCID] in {
641 // The instruction can only use a 64 bit register as the register argument
642 // in 64 bit mode, while the intrinsic only accepts a 32 bit argument
643 // corresponding to it.
644 // The accepted values for now are 0,1,2,3 anyways (see Intel SDM -- INVCPID
645 // type),/ so it doesn't hurt us that one can't supply a 64 bit value here.
646 def : Pat<(int_x86_invpcid GR32:$src1, addr:$src2),
648 (SUBREG_TO_REG (i64 0), (MOV32rr GR32:$src1), sub_32bit),
653 //===----------------------------------------------------------------------===//
655 let Defs = [EFLAGS], SchedRW = [WriteSystem] in {
656 def CLAC : I<0x01, MRM_CA, (outs), (ins), "clac", []>, TB;
657 def STAC : I<0x01, MRM_CB, (outs), (ins), "stac", []>, TB;
660 //===----------------------------------------------------------------------===//
662 let SchedRW = [WriteSystem] in {
663 let Uses = [RAX, RBX, RCX, RDX], Defs = [RAX, RBX, RCX] in {
664 def GETSEC : I<0x37, RawFrm, (outs), (ins), "getsec", []>, TB;
668 //===----------------------------------------------------------------------===//
669 // TS flag control instruction.
670 let SchedRW = [WriteSystem] in {
671 def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
674 //===----------------------------------------------------------------------===//
675 // IF (inside EFLAGS) management instructions.
676 let SchedRW = [WriteSystem], Uses = [EFLAGS], Defs = [EFLAGS] in {
677 def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
678 def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
681 //===----------------------------------------------------------------------===//
683 let SchedRW = [WriteSystem] in {
684 def RDPID32 : I<0xC7, MRM7r, (outs GR32:$dst), (ins),
685 "rdpid\t$dst", [(set GR32:$dst, (int_x86_rdpid))]>, XS,
686 Requires<[Not64BitMode, HasRDPID]>;
687 def RDPID64 : I<0xC7, MRM7r, (outs GR64:$dst), (ins), "rdpid\t$dst", []>, XS,
688 Requires<[In64BitMode, HasRDPID]>;
691 let Predicates = [In64BitMode, HasRDPID] in {
692 // Due to silly instruction definition, we have to compensate for the
693 // instruction outputing a 64-bit register.
694 def : Pat<(int_x86_rdpid),
695 (EXTRACT_SUBREG (RDPID64), sub_32bit)>;
699 //===----------------------------------------------------------------------===//
700 // PTWRITE Instruction - Write Data to a Processor Trace Packet
701 let SchedRW = [WriteSystem] in {
702 def PTWRITEm: I<0xAE, MRM4m, (outs), (ins i32mem:$dst),
703 "ptwrite{l}\t$dst", [(int_x86_ptwrite32 (loadi32 addr:$dst))]>, XS,
704 Requires<[HasPTWRITE]>;
705 def PTWRITE64m : RI<0xAE, MRM4m, (outs), (ins i64mem:$dst),
706 "ptwrite{q}\t$dst", [(int_x86_ptwrite64 (loadi64 addr:$dst))]>, XS,
707 Requires<[In64BitMode, HasPTWRITE]>;
709 def PTWRITEr : I<0xAE, MRM4r, (outs), (ins GR32:$dst),
710 "ptwrite{l}\t$dst", [(int_x86_ptwrite32 GR32:$dst)]>, XS,
711 Requires<[HasPTWRITE]>;
712 def PTWRITE64r : RI<0xAE, MRM4r, (outs), (ins GR64:$dst),
713 "ptwrite{q}\t$dst", [(int_x86_ptwrite64 GR64:$dst)]>, XS,
714 Requires<[In64BitMode, HasPTWRITE]>;
717 //===----------------------------------------------------------------------===//
718 // Platform Configuration instruction
721 // "This instruction is used to execute functions for configuring platform
723 // EAX: Leaf function to be invoked.
724 // RBX/RCX/RDX: Leaf-specific purpose."
725 // "Successful execution of the leaf clears RAX (set to zero) and ZF, CF, PF,
726 // AF, OF, and SF are cleared. In case of failure, the failure reason is
727 // indicated in RAX with ZF set to 1 and CF, PF, AF, OF, and SF are cleared."
728 // Thus all these mentioned registers are considered clobbered.
730 let SchedRW = [WriteSystem] in {
731 let Uses = [RAX, RBX, RCX, RDX], Defs = [RAX, RBX, RCX, RDX, EFLAGS] in
732 def PCONFIG : I<0x01, MRM_C5, (outs), (ins), "pconfig", []>, TB,
733 Requires<[HasPCONFIG]>;