OSDN Git Service

[X86] Introduce LLVM wbinvd intrinsic
[android-x86/external-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)]>, TB;
19
20 let Defs = [RAX, RCX, RDX] in
21   def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", [(X86rdtscp)]>, TB;
22
23 // CPU flow control instructions
24
25 let mayLoad = 1, mayStore = 0, hasSideEffects = 1 in {
26   def TRAP    : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
27   def UD2B    : I<0xB9, RawFrm, (outs), (ins), "ud2b", []>, TB;
28 }
29
30 def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", []>;
31 def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", []>, TB;
32
33 // Interrupt and SysCall Instructions.
34 let Uses = [EFLAGS] in
35   def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>, Requires<[Not64BitMode]>;
36
37 def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3", [(int_x86_int (i8 3))]>;
38 } // SchedRW
39
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)>;
43
44 let SchedRW = [WriteSystem] in {
45
46 def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap",
47               [(int_x86_int imm:$trap)]>;
48
49
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), "sysret{q}", []>, TB,
53                Requires<[In64BitMode]>;
54
55 def SYSENTER : I<0x34, RawFrm, (outs), (ins), "sysenter", []>, TB;
56
57 def SYSEXIT   : I<0x35, RawFrm, (outs), (ins), "sysexit{l}", []>, TB;
58 def SYSEXIT64 :RI<0x35, RawFrm, (outs), (ins), "sysexit{q}", []>, TB,
59                   Requires<[In64BitMode]>;
60 } // SchedRW
61
62 def : Pat<(debugtrap),
63           (INT3)>, Requires<[NotPS4]>;
64 def : Pat<(debugtrap),
65           (INT (i8 0x41))>, Requires<[IsPS4]>;
66
67 //===----------------------------------------------------------------------===//
68 //  Input/Output Instructions.
69 //
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}", []>,
75                OpSize16;
76 let Defs = [EAX], Uses = [DX] in
77 def IN32rr : I<0xED, RawFrm, (outs), (ins), "in{l}\t{%dx, %eax|eax, dx}", []>,
78                OpSize32;
79
80 let Defs = [AL] in
81 def IN8ri  : Ii8<0xE4, RawFrm, (outs), (ins u8imm:$port),
82                  "in{b}\t{$port, %al|al, $port}", []>;
83 let Defs = [AX] in
84 def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
85                  "in{w}\t{$port, %ax|ax, $port}", []>, OpSize16;
86 let Defs = [EAX] in
87 def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins u8imm:$port),
88                  "in{l}\t{$port, %eax|eax, $port}", []>, OpSize32;
89
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}", []>,
94                 OpSize16;
95 let Uses = [DX, EAX] in
96 def OUT32rr : I<0xEF, RawFrm, (outs), (ins), "out{l}\t{%eax, %dx|dx, eax}", []>,
97                 OpSize32;
98
99 let Uses = [AL] in
100 def OUT8ir  : Ii8<0xE6, RawFrm, (outs), (ins u8imm:$port),
101                    "out{b}\t{%al, $port|$port, al}", []>;
102 let Uses = [AX] in
103 def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
104                    "out{w}\t{%ax, $port|$port, ax}", []>, OpSize16;
105 let Uses = [EAX] in
106 def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins u8imm:$port),
107                   "out{l}\t{%eax, $port|$port, eax}", []>, OpSize32;
108
109 } // SchedRW
110
111 //===----------------------------------------------------------------------===//
112 // Moves to and from debug registers
113
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]>;
121
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]>;
128 } // SchedRW
129
130 //===----------------------------------------------------------------------===//
131 // Moves to and from control registers
132
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]>;
140
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]>;
147 } // SchedRW
148
149 //===----------------------------------------------------------------------===//
150 // Segment override instruction prefixes
151
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", []>;
159 } // SchedRW
160
161 //===----------------------------------------------------------------------===//
162 // Moves to and from segment registers.
163 //
164
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}", []>, OpSizeIgnore;
175 }
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}", []>;
182 let mayLoad = 1 in {
183 def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
184                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSizeIgnore;
185 }
186 } // SchedRW
187
188 //===----------------------------------------------------------------------===//
189 // Segmentation support instructions.
190
191 let SchedRW = [WriteSystem] in {
192 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
193
194 let mayLoad = 1 in
195 def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
196                 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB,
197                 OpSize16;
198 def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
199                 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB,
200                 OpSize16;
201
202 // i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
203 let mayLoad = 1 in
204 def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
205                 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB,
206                 OpSize32;
207 def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
208                 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB,
209                 OpSize32;
210 // i16mem operand in LAR64rm and GR32 operand in LAR64rr is not a typo.
211 let mayLoad = 1 in
212 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
213                  "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
214 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
215                  "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
216
217 // i16mem operand in LSL32rm and GR32 operand in LSL32rr is not a typo.
218 let mayLoad = 1 in
219 def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
220                 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB,
221                 OpSize16;
222 def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
223                 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB,
224                 OpSize16;
225 // i16mem operand in LSL64rm and GR32 operand in LSL64rr is not a typo.
226 let mayLoad = 1 in
227 def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
228                 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB,
229                 OpSize32;
230 def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
231                 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB,
232                 OpSize32;
233 let mayLoad = 1 in
234 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
235                  "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
236 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
237                  "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
238
239 def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr", []>, TB;
240
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;
247 let mayStore = 1 in
248 def STRm   : I<0x00, MRM1m, (outs), (ins i16mem:$dst), "str{w}\t$dst", []>, TB;
249
250 def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src), "ltr{w}\t$src", []>, TB;
251 let mayLoad = 1 in
252 def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src), "ltr{w}\t$src", []>, TB;
253
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}", []>,
271                  OpSize16, TB;
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}", []>,
275                  OpSize16, TB;
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]>;
282
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]>;
288
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]>;
293
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]>;
298
299 def POPFS16 : I<0xa1, RawFrm, (outs), (ins), "pop{w}\t{%fs|fs}", []>,
300                 OpSize16, TB;
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]>;
305
306 def POPGS16 : I<0xa9, RawFrm, (outs), (ins), "pop{w}\t{%gs|gs}", []>,
307                 OpSize16, TB;
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]>;
312                 
313 def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
314                 "lds{w}\t{$src, $dst|$dst, $src}", []>, OpSize16,
315                 Requires<[Not64BitMode]>;
316 def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
317                 "lds{l}\t{$src, $dst|$dst, $src}", []>, OpSize32,
318                 Requires<[Not64BitMode]>;
319
320 def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
321                 "lss{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
322 def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
323                 "lss{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
324 def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
325                  "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
326
327 def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
328                 "les{w}\t{$src, $dst|$dst, $src}", []>, OpSize16,
329                 Requires<[Not64BitMode]>;
330 def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
331                 "les{l}\t{$src, $dst|$dst, $src}", []>, OpSize32,
332                 Requires<[Not64BitMode]>;
333
334 def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
335                 "lfs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
336 def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
337                 "lfs{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
338 def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
339                  "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
340
341 def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
342                 "lgs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize16;
343 def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
344                 "lgs{l}\t{$src, $dst|$dst, $src}", []>, TB, OpSize32;
345
346 def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
347                  "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
348
349 def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg), "verr\t$seg", []>, TB;
350 def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg), "verw\t$seg", []>, TB;
351 let mayLoad = 1 in {
352 def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg), "verr\t$seg", []>, TB;
353 def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg), "verw\t$seg", []>, TB;
354 }
355 } // SchedRW
356
357 //===----------------------------------------------------------------------===//
358 // Descriptor-table support instructions
359
360 let SchedRW = [WriteSystem] in {
361 def SGDT16m : I<0x01, MRM0m, (outs), (ins opaque48mem:$dst),
362                 "sgdt{w}\t$dst", []>, TB, OpSize16, Requires<[Not64BitMode]>;
363 def SGDT32m : I<0x01, MRM0m, (outs), (ins opaque48mem:$dst),
364                 "sgdt{l}\t$dst", []>, OpSize32, TB, Requires <[Not64BitMode]>;
365 def SGDT64m : I<0x01, MRM0m, (outs), (ins opaque80mem:$dst),
366                 "sgdt{q}\t$dst", []>, TB, Requires <[In64BitMode]>;
367 def SIDT16m : I<0x01, MRM1m, (outs), (ins opaque48mem:$dst),
368                 "sidt{w}\t$dst", []>, TB, OpSize16, Requires<[Not64BitMode]>;
369 def SIDT32m : I<0x01, MRM1m, (outs), (ins opaque48mem:$dst),
370                 "sidt{l}\t$dst", []>, OpSize32, TB, Requires <[Not64BitMode]>;
371 def SIDT64m : I<0x01, MRM1m, (outs), (ins opaque80mem:$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;
375 let mayStore = 1 in
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;
380
381 // LLDT is not interpreted specially in 64-bit mode because there is no sign
382 //   extension.
383 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
384                  "sldt{q}\t$dst", []>, TB, Requires<[In64BitMode]>;
385 let mayStore = 1 in
386 def SLDT64m : RI<0x00, MRM0m, (outs), (ins i16mem:$dst),
387                  "sldt{q}\t$dst", []>, TB, Requires<[In64BitMode]>;
388
389 def LGDT16m : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
390                 "lgdt{w}\t$src", []>, TB, OpSize16, Requires<[Not64BitMode]>;
391 def LGDT32m : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
392                 "lgdt{l}\t$src", []>, OpSize32, TB, Requires<[Not64BitMode]>;
393 def LGDT64m : I<0x01, MRM2m, (outs), (ins opaque80mem:$src),
394                 "lgdt{q}\t$src", []>, TB, Requires<[In64BitMode]>;
395 def LIDT16m : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
396                 "lidt{w}\t$src", []>, TB, OpSize16, Requires<[Not64BitMode]>;
397 def LIDT32m : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
398                 "lidt{l}\t$src", []>, OpSize32, TB, Requires<[Not64BitMode]>;
399 def LIDT64m : I<0x01, MRM3m, (outs), (ins opaque80mem:$src),
400                 "lidt{q}\t$src", []>, TB, Requires<[In64BitMode]>;
401 def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
402                 "lldt{w}\t$src", []>, TB;
403 let mayLoad = 1 in
404 def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
405                 "lldt{w}\t$src", []>, TB;
406 } // SchedRW
407
408 //===----------------------------------------------------------------------===//
409 // Specialized register support
410 let SchedRW = [WriteSystem] in {
411 let Uses = [EAX, ECX, EDX] in
412 def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", []>, TB;
413 let Defs = [EAX, EDX], Uses = [ECX] in
414 def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", []>, TB;
415
416 let Defs = [RAX, RDX], Uses = [ECX] in
417   def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", [(X86rdpmc)]>, TB;
418
419 def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins),
420                 "smsw{w}\t$dst", []>, OpSize16, TB;
421 def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins),
422                 "smsw{l}\t$dst", []>, OpSize32, TB;
423 // no m form encodable; use SMSW16m
424 def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
425                  "smsw{q}\t$dst", []>, TB;
426
427 // For memory operands, there is only a 16-bit form
428 def SMSW16m : I<0x01, MRM4m, (outs), (ins i16mem:$dst),
429                 "smsw{w}\t$dst", []>, TB;
430
431 def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
432                 "lmsw{w}\t$src", []>, TB;
433 let mayLoad = 1 in
434 def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
435                 "lmsw{w}\t$src", []>, TB;
436
437 let Defs = [EAX, EBX, ECX, EDX], Uses = [EAX, ECX] in
438   def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", []>, TB;
439 } // SchedRW
440
441 //===----------------------------------------------------------------------===//
442 // Cache instructions
443 let SchedRW = [WriteSystem] in {
444 def INVD : I<0x08, RawFrm, (outs), (ins), "invd", []>, TB;
445 def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", [(int_x86_wbinvd)]>, TB;
446
447 // wbnoinvd is like wbinvd, except without invalidation
448 // encoding: like wbinvd + an 0xF3 prefix
449 def WBNOINVD : I<0x09, RawFrm, (outs), (ins), "wbnoinvd",
450                  [(int_x86_wbnoinvd)]>, XS,
451                  Requires<[HasWBNOINVD]>;
452 } // SchedRW
453
454 //===----------------------------------------------------------------------===//
455 // CET instructions
456 let SchedRW = [WriteSystem], Predicates = [HasSHSTK]  in{
457   let Uses = [SSP] in {
458     let Defs = [SSP] in {
459       def INCSSPD : I<0xAE, MRM5r, (outs), (ins GR32:$src), "incsspd\t$src",
460                        [(int_x86_incsspd GR32:$src)]>, XS;
461       def INCSSPQ : RI<0xAE, MRM5r, (outs), (ins GR64:$src), "incsspq\t$src",
462                        [(int_x86_incsspq GR64:$src)]>, XS;
463     } // Defs SSP
464
465     let Constraints = "$src = $dst" in {
466       def RDSSPD : I<0x1E, MRM1r, (outs GR32:$dst), (ins GR32:$src),
467                      "rdsspd\t$dst",
468                      [(set GR32:$dst, (int_x86_rdsspd GR32:$src))]>, XS;
469       def RDSSPQ : RI<0x1E, MRM1r, (outs GR64:$dst), (ins GR64:$src),
470                      "rdsspq\t$dst",
471                      [(set GR64:$dst, (int_x86_rdsspq GR64:$src))]>, XS;
472     }
473
474     let Defs = [SSP] in {
475       def SAVEPREVSSP : I<0x01, MRM_EA, (outs), (ins), "saveprevssp",
476                        [(int_x86_saveprevssp)]>, XS;
477       def RSTORSSP : I<0x01, MRM5m, (outs), (ins i32mem:$src),
478                        "rstorssp\t$src",
479                        [(int_x86_rstorssp addr:$src)]>, XS;
480     } // Defs SSP
481   } // Uses SSP
482
483   def WRSSD : I<0xF6, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
484                 "wrssd\t{$src, $dst|$dst, $src}",
485                 [(int_x86_wrssd GR32:$src, addr:$dst)]>, T8PS;
486   def WRSSQ : RI<0xF6, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
487                  "wrssq\t{$src, $dst|$dst, $src}",
488                  [(int_x86_wrssq GR64:$src, addr:$dst)]>, T8PS;
489   def WRUSSD : I<0xF5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
490                  "wrussd\t{$src, $dst|$dst, $src}",
491                  [(int_x86_wrussd GR32:$src, addr:$dst)]>, T8PD;
492   def WRUSSQ : RI<0xF5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
493                   "wrussq\t{$src, $dst|$dst, $src}",
494                   [(int_x86_wrussq GR64:$src, addr:$dst)]>, T8PD;
495
496   let Defs = [SSP] in {
497     let Uses = [SSP] in {
498         def SETSSBSY : I<0x01, MRM_E8, (outs), (ins), "setssbsy",
499                          [(int_x86_setssbsy)]>, XS;
500     } // Uses SSP
501
502     def CLRSSBSY : I<0xAE, MRM6m, (outs), (ins i32mem:$src),
503                      "clrssbsy\t$src",
504                      [(int_x86_clrssbsy addr:$src)]>, XS;
505   } // Defs SSP
506 } // SchedRW && HasSHSTK
507
508 let SchedRW = [WriteSystem], Predicates = [HasIBT]  in {
509     def ENDBR64 : I<0x1E, MRM_FA, (outs), (ins), "endbr64", []>, XS;
510     def ENDBR32 : I<0x1E, MRM_FB, (outs), (ins), "endbr32", []>, XS;
511 } // SchedRW && HasIBT
512
513 //===----------------------------------------------------------------------===//
514 // XSAVE instructions
515 let SchedRW = [WriteSystem] in {
516 let Predicates = [HasXSAVE] in {
517 let Defs = [EDX, EAX], Uses = [ECX] in
518   def XGETBV : I<0x01, MRM_D0, (outs), (ins), "xgetbv", []>, TB;
519
520 let Uses = [EDX, EAX, ECX] in
521   def XSETBV : I<0x01, MRM_D1, (outs), (ins),
522                 "xsetbv",
523                 [(int_x86_xsetbv ECX, EDX, EAX)]>, TB;
524
525 } // HasXSAVE
526
527 let Uses = [EDX, EAX] in {
528 def XSAVE : I<0xAE, MRM4m, (outs), (ins opaque512mem:$dst),
529               "xsave\t$dst",
530               [(int_x86_xsave addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE]>;
531 def XSAVE64 : RI<0xAE, MRM4m, (outs), (ins opaque512mem:$dst),
532                  "xsave64\t$dst",
533                  [(int_x86_xsave64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE, In64BitMode]>;
534 def XRSTOR : I<0xAE, MRM5m, (outs), (ins opaque512mem:$dst),
535                "xrstor\t$dst",
536                [(int_x86_xrstor addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE]>;
537 def XRSTOR64 : RI<0xAE, MRM5m, (outs), (ins opaque512mem:$dst),
538                   "xrstor64\t$dst",
539                   [(int_x86_xrstor64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVE, In64BitMode]>;
540 def XSAVEOPT : I<0xAE, MRM6m, (outs), (ins opaque512mem:$dst),
541                  "xsaveopt\t$dst",
542                  [(int_x86_xsaveopt addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVEOPT]>;
543 def XSAVEOPT64 : RI<0xAE, MRM6m, (outs), (ins opaque512mem:$dst),
544                     "xsaveopt64\t$dst",
545                     [(int_x86_xsaveopt64 addr:$dst, EDX, EAX)]>, PS, Requires<[HasXSAVEOPT, In64BitMode]>;
546 def XSAVEC : I<0xC7, MRM4m, (outs), (ins opaque512mem:$dst),
547                "xsavec\t$dst",
548                [(int_x86_xsavec addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVEC]>;
549 def XSAVEC64 : RI<0xC7, MRM4m, (outs), (ins opaque512mem:$dst),
550                  "xsavec64\t$dst",
551                  [(int_x86_xsavec64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVEC, In64BitMode]>;
552 def XSAVES : I<0xC7, MRM5m, (outs), (ins opaque512mem:$dst),
553                "xsaves\t$dst",
554                [(int_x86_xsaves addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES]>;
555 def XSAVES64 : RI<0xC7, MRM5m, (outs), (ins opaque512mem:$dst),
556                   "xsaves64\t$dst",
557                   [(int_x86_xsaves64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVE, In64BitMode]>;
558 def XRSTORS : I<0xC7, MRM3m, (outs), (ins opaque512mem:$dst),
559                 "xrstors\t$dst",
560                 [(int_x86_xrstors addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES]>;
561 def XRSTORS64 : RI<0xC7, MRM3m, (outs), (ins opaque512mem:$dst),
562                    "xrstors64\t$dst",
563                    [(int_x86_xrstors64 addr:$dst, EDX, EAX)]>, TB, Requires<[HasXSAVES, In64BitMode]>;
564 } // Uses
565 } // SchedRW
566
567 //===----------------------------------------------------------------------===//
568 // VIA PadLock crypto instructions
569 let Defs = [RAX, RDI], Uses = [RDX, RDI], SchedRW = [WriteSystem] in
570   def XSTORE : I<0xa7, MRM_C0, (outs), (ins), "xstore", []>, TB;
571
572 def : InstAlias<"xstorerng", (XSTORE)>;
573
574 let SchedRW = [WriteSystem] in {
575 let Defs = [RSI, RDI], Uses = [RBX, RDX, RSI, RDI] in {
576   def XCRYPTECB : I<0xa7, MRM_C8, (outs), (ins), "xcryptecb", []>, TB;
577   def XCRYPTCBC : I<0xa7, MRM_D0, (outs), (ins), "xcryptcbc", []>, TB;
578   def XCRYPTCTR : I<0xa7, MRM_D8, (outs), (ins), "xcryptctr", []>, TB;
579   def XCRYPTCFB : I<0xa7, MRM_E0, (outs), (ins), "xcryptcfb", []>, TB;
580   def XCRYPTOFB : I<0xa7, MRM_E8, (outs), (ins), "xcryptofb", []>, TB;
581 }
582
583 let Defs = [RAX, RSI, RDI], Uses = [RAX, RSI, RDI] in {
584   def XSHA1 : I<0xa6, MRM_C8, (outs), (ins), "xsha1", []>, TB;
585   def XSHA256 : I<0xa6, MRM_D0, (outs), (ins), "xsha256", []>, TB;
586 }
587 let Defs = [RAX, RDX, RSI], Uses = [RAX, RSI] in
588   def MONTMUL : I<0xa6, MRM_C0, (outs), (ins), "montmul", []>, TB;
589 } // SchedRW
590
591 //==-----------------------------------------------------------------------===//
592 // PKU  - enable protection key
593 let usesCustomInserter = 1, hasNoSchedulingInfo = 1 in {
594   def WRPKRU : PseudoI<(outs), (ins GR32:$src),
595                 [(int_x86_wrpkru GR32:$src)]>;
596   def RDPKRU : PseudoI<(outs GR32:$dst), (ins),
597                 [(set GR32:$dst, (int_x86_rdpkru))]>;
598 }
599
600 let SchedRW = [WriteSystem] in {
601 let Defs = [EAX, EDX], Uses = [ECX] in
602   def RDPKRUr : I<0x01, MRM_EE, (outs), (ins), "rdpkru", []>, TB;
603 let Uses = [EAX, ECX, EDX] in
604   def WRPKRUr : I<0x01, MRM_EF, (outs), (ins), "wrpkru", []>, TB;
605 } // SchedRW
606
607 //===----------------------------------------------------------------------===//
608 // FS/GS Base Instructions
609 let Predicates = [HasFSGSBase, In64BitMode], SchedRW = [WriteSystem] in {
610   def RDFSBASE : I<0xAE, MRM0r, (outs GR32:$dst), (ins),
611                    "rdfsbase{l}\t$dst",
612                    [(set GR32:$dst, (int_x86_rdfsbase_32))]>, XS;
613   def RDFSBASE64 : RI<0xAE, MRM0r, (outs GR64:$dst), (ins),
614                      "rdfsbase{q}\t$dst",
615                      [(set GR64:$dst, (int_x86_rdfsbase_64))]>, XS;
616   def RDGSBASE : I<0xAE, MRM1r, (outs GR32:$dst), (ins),
617                    "rdgsbase{l}\t$dst",
618                    [(set GR32:$dst, (int_x86_rdgsbase_32))]>, XS;
619   def RDGSBASE64 : RI<0xAE, MRM1r, (outs GR64:$dst), (ins),
620                      "rdgsbase{q}\t$dst",
621                      [(set GR64:$dst, (int_x86_rdgsbase_64))]>, XS;
622   def WRFSBASE : I<0xAE, MRM2r, (outs), (ins GR32:$src),
623                    "wrfsbase{l}\t$src",
624                    [(int_x86_wrfsbase_32 GR32:$src)]>, XS;
625   def WRFSBASE64 : RI<0xAE, MRM2r, (outs), (ins GR64:$src),
626                       "wrfsbase{q}\t$src",
627                       [(int_x86_wrfsbase_64 GR64:$src)]>, XS;
628   def WRGSBASE : I<0xAE, MRM3r, (outs), (ins GR32:$src),
629                    "wrgsbase{l}\t$src",
630                    [(int_x86_wrgsbase_32 GR32:$src)]>, XS;
631   def WRGSBASE64 : RI<0xAE, MRM3r, (outs), (ins GR64:$src),
632                       "wrgsbase{q}\t$src",
633                       [(int_x86_wrgsbase_64 GR64:$src)]>, XS;
634 }
635
636 //===----------------------------------------------------------------------===//
637 // INVPCID Instruction
638 let SchedRW = [WriteSystem] in {
639 def INVPCID32 : I<0x82, MRMSrcMem, (outs), (ins GR32:$src1, i128mem:$src2),
640                   "invpcid\t{$src2, $src1|$src1, $src2}", []>, T8PD,
641                   Requires<[Not64BitMode]>;
642 def INVPCID64 : I<0x82, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
643                   "invpcid\t{$src2, $src1|$src1, $src2}", []>, T8PD,
644                   Requires<[In64BitMode]>;
645 } // SchedRW
646
647 //===----------------------------------------------------------------------===//
648 // SMAP Instruction
649 let Defs = [EFLAGS], SchedRW = [WriteSystem] in {
650   def CLAC : I<0x01, MRM_CA, (outs), (ins), "clac", []>, TB;
651   def STAC : I<0x01, MRM_CB, (outs), (ins), "stac", []>, TB;
652 }
653
654 //===----------------------------------------------------------------------===//
655 // SMX Instruction
656 let SchedRW = [WriteSystem] in {
657 let Uses = [RAX, RBX, RCX, RDX], Defs = [RAX, RBX, RCX] in {
658   def GETSEC : I<0x37, RawFrm, (outs), (ins), "getsec", []>, TB;
659 } // Uses, Defs
660 } // SchedRW
661
662 //===----------------------------------------------------------------------===//
663 // TS flag control instruction.
664 let SchedRW = [WriteSystem] in {
665 def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
666 }
667
668 //===----------------------------------------------------------------------===//
669 // IF (inside EFLAGS) management instructions.
670 let SchedRW = [WriteSystem], Uses = [EFLAGS], Defs = [EFLAGS] in {
671 def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
672 def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
673 }
674
675 //===----------------------------------------------------------------------===//
676 // RDPID Instruction
677 let SchedRW = [WriteSystem] in {
678 def RDPID32 : I<0xC7, MRM7r, (outs GR32:$dst), (ins),
679                 "rdpid\t$dst", [(set GR32:$dst, (int_x86_rdpid))]>, XS,
680                 Requires<[Not64BitMode, HasRDPID]>;
681 def RDPID64 : I<0xC7, MRM7r, (outs GR64:$dst), (ins), "rdpid\t$dst", []>, XS,
682                 Requires<[In64BitMode, HasRDPID]>;
683 } // SchedRW
684
685 let Predicates = [In64BitMode, HasRDPID] in {
686   // Due to silly instruction definition, we have to compensate for the
687   // instruction outputing a 64-bit register.
688   def : Pat<(int_x86_rdpid),
689             (EXTRACT_SUBREG (RDPID64), sub_32bit)>;
690 }
691
692
693 //===----------------------------------------------------------------------===//
694 // PTWRITE Instruction
695 let SchedRW = [WriteSystem] in {
696
697 def PTWRITEm: I<0xAE, MRM4m, (outs), (ins i32mem:$dst),
698                 "ptwrite{l}\t$dst", []>, XS;
699 def PTWRITE64m : RI<0xAE, MRM4m, (outs), (ins i64mem:$dst),
700                     "ptwrite{q}\t$dst", []>, XS, Requires<[In64BitMode]>;
701
702 def PTWRITEr : I<0xAE, MRM4r, (outs), (ins GR32:$dst),
703                  "ptwrite{l}\t$dst", []>, XS;
704 def PTWRITE64r : RI<0xAE, MRM4r, (outs), (ins GR64:$dst),
705                     "ptwrite{q}\t$dst", []>, XS, Requires<[In64BitMode]>;
706 } // SchedRW