Skip to content

Commit 13b265c

Browse files
authored
[X86][MC] Support Intel FRED and LKGS instructions. (#91909)
Spec reference: https://cdrdv2.intel.com/v1/dl/getContent/678938
1 parent 11b0591 commit 13b265c

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed

llvm/lib/Target/X86/X86InstrSystem.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def SYSENTER : I<0x34, RawFrm, (outs), (ins), "sysenter", []>, TB;
6868
def SYSEXIT : I<0x35, RawFrm, (outs), (ins), "sysexit{l}", []>, TB;
6969
def SYSEXIT64 :RI<0x35, RawFrm, (outs), (ins), "sysexitq", []>, TB,
7070
Requires<[In64BitMode]>;
71+
72+
// FRED Instructions
73+
let hasSideEffects = 1, Defs = [RSP, EFLAGS] in {
74+
def ERETS: I<0x01, MRM_CA, (outs), (ins), "erets",
75+
[]>, TB, XD, Requires<[In64BitMode]>;
76+
def ERETU: I<0x01, MRM_CA, (outs), (ins), "eretu",
77+
[]>, TB, XS, Requires<[In64BitMode]>;
78+
} // hasSideEffects = 1, Defs = [RSP, EFLAGS]
7179
} // SchedRW
7280

7381
def : Pat<(debugtrap),
@@ -212,6 +220,14 @@ def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
212220

213221
let SchedRW = [WriteSystem] in {
214222
def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
223+
// LKGS instructions
224+
let hasSideEffects = 1 in {
225+
let mayLoad = 1 in
226+
def LKGS16m : I<0x00, MRM6m, (outs), (ins i16mem:$src), "lkgs\t$src",
227+
[]>, TB, XD, Requires<[In64BitMode]>;
228+
def LKGS16r : I<0x00, MRM6r, (outs), (ins GR16:$src), "lkgs\t$src",
229+
[]>, TB, XD, Requires<[In64BitMode]>;
230+
} // hasSideEffects
215231

216232
let Defs = [EFLAGS] in {
217233
let mayLoad = 1 in
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RUN: llvm-mc --disassemble %s -triple=x86_64
2+
3+
# CHECK: erets
4+
0xf2,0x0f,0x01,0xca
5+
6+
# CHECK: eretu
7+
0xf3,0x0f,0x01,0xca
8+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
2+
# RUN: llvm-mc --disassemble %s -triple=x86_64 --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL
3+
4+
# ATT: lkgs %ax
5+
# INTEL: lkgs ax
6+
0xf2,0x0f,0x00,0xf0
7+
8+
# ATT: lkgs %r12w
9+
# INTEL: lkgs r12w
10+
0xf2,0x41,0x0f,0x00,0xf4
11+
12+
# ATT: lkgs 268435456(%rbp,%r14,8)
13+
# INTEL: lkgs word ptr [rbp + 8*r14 + 268435456]
14+
0xf2,0x42,0x0f,0x00,0xb4,0xf5,0x00,0x00,0x00,0x10
15+
16+
# ATT: lkgs 291(%r8,%rax,4)
17+
# INTEL: lkgs word ptr [r8 + 4*rax + 291]
18+
0xf2,0x41,0x0f,0x00,0xb4,0x80,0x23,0x01,0x00,0x00
19+
20+
# ATT: lkgs (%rip)
21+
# INTEL: lkgs word ptr [rip]
22+
0xf2,0x0f,0x00,0x35,0x00,0x00,0x00,0x00
23+
24+
# ATT: lkgs -64(,%rbp,2)
25+
# INTEL: lkgs word ptr [2*rbp - 64]
26+
0xf2,0x0f,0x00,0x34,0x6d,0xc0,0xff,0xff,0xff
27+
28+
# ATT: lkgs 254(%rcx)
29+
# INTEL: lkgs word ptr [rcx + 254]
30+
0xf2,0x0f,0x00,0xb1,0xfe,0x00,0x00,0x00
31+
32+
# ATT: lkgs -256(%rdx)
33+
# INTEL: lkgs word ptr [rdx - 256]
34+
0xf2,0x0f,0x00,0xb2,0x00,0xff,0xff,0xff
35+

llvm/test/MC/X86/fred-att.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
2+
// RUN: not llvm-mc -triple i386 -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR
3+
4+
// ERROR-COUNT-2: error:
5+
// ERROR-NOT: error:
6+
7+
// CHECK: erets
8+
// CHECK: encoding: [0xf2,0x0f,0x01,0xca]
9+
erets
10+
11+
// CHECK: eretu
12+
// CHECK: encoding: [0xf3,0x0f,0x01,0xca]
13+
eretu
14+

llvm/test/MC/X86/fred-intel.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
2+
3+
// CHECK: erets
4+
// CHECK: encoding: [0xf2,0x0f,0x01,0xca]
5+
erets
6+
7+
// CHECK: eretu
8+
// CHECK: encoding: [0xf3,0x0f,0x01,0xca]
9+
eretu
10+

llvm/test/MC/X86/lkgs-att.s

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
2+
// RUN: not llvm-mc -triple i386 -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR
3+
4+
// ERROR-COUNT-8: error:
5+
// ERROR-NOT: error:
6+
7+
// CHECK: lkgs %ax
8+
// CHECK: encoding: [0xf2,0x0f,0x00,0xf0]
9+
lkgs %ax
10+
11+
// CHECK: lkgs %r12w
12+
// CHECK: encoding: [0xf2,0x41,0x0f,0x00,0xf4]
13+
lkgs %r12w
14+
15+
// CHECK: lkgs 268435456(%rbp,%r14,8)
16+
// CHECK: encoding: [0xf2,0x42,0x0f,0x00,0xb4,0xf5,0x00,0x00,0x00,0x10]
17+
lkgs 268435456(%rbp,%r14,8)
18+
19+
// CHECK: lkgs 291(%r8,%rax,4)
20+
// CHECK: encoding: [0xf2,0x41,0x0f,0x00,0xb4,0x80,0x23,0x01,0x00,0x00]
21+
lkgs 291(%r8,%rax,4)
22+
23+
// CHECK: lkgs (%rip)
24+
// CHECK: encoding: [0xf2,0x0f,0x00,0x35,0x00,0x00,0x00,0x00]
25+
lkgs (%rip)
26+
27+
// CHECK: lkgs -64(,%rbp,2)
28+
// CHECK: encoding: [0xf2,0x0f,0x00,0x34,0x6d,0xc0,0xff,0xff,0xff]
29+
lkgs -64(,%rbp,2)
30+
31+
// CHECK: lkgs 254(%rcx)
32+
// CHECK: encoding: [0xf2,0x0f,0x00,0xb1,0xfe,0x00,0x00,0x00]
33+
lkgs 254(%rcx)
34+
35+
// CHECK: lkgs -256(%rdx)
36+
// CHECK: encoding: [0xf2,0x0f,0x00,0xb2,0x00,0xff,0xff,0xff]
37+
lkgs -256(%rdx)
38+

llvm/test/MC/X86/lkgs-intel.s

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
2+
3+
// CHECK: lkgs ax
4+
// CHECK: encoding: [0xf2,0x0f,0x00,0xf0]
5+
lkgs ax
6+
7+
// CHECK: lkgs r12w
8+
// CHECK: encoding: [0xf2,0x41,0x0f,0x00,0xf4]
9+
lkgs r12w
10+
11+
// CHECK: lkgs word ptr [rbp + 8*r14 + 268435456]
12+
// CHECK: encoding: [0xf2,0x42,0x0f,0x00,0xb4,0xf5,0x00,0x00,0x00,0x10]
13+
lkgs word ptr [rbp + 8*r14 + 268435456]
14+
15+
// CHECK: lkgs word ptr [r8 + 4*rax + 291]
16+
// CHECK: encoding: [0xf2,0x41,0x0f,0x00,0xb4,0x80,0x23,0x01,0x00,0x00]
17+
lkgs word ptr [r8 + 4*rax + 291]
18+
19+
// CHECK: lkgs word ptr [rip]
20+
// CHECK: encoding: [0xf2,0x0f,0x00,0x35,0x00,0x00,0x00,0x00]
21+
lkgs word ptr [rip]
22+
23+
// CHECK: lkgs word ptr [2*rbp - 64]
24+
// CHECK: encoding: [0xf2,0x0f,0x00,0x34,0x6d,0xc0,0xff,0xff,0xff]
25+
lkgs word ptr [2*rbp - 64]
26+
27+
// CHECK: lkgs word ptr [rcx + 254]
28+
// CHECK: encoding: [0xf2,0x0f,0x00,0xb1,0xfe,0x00,0x00,0x00]
29+
lkgs word ptr [rcx + 254]
30+
31+
// CHECK: lkgs word ptr [rdx - 256]
32+
// CHECK: encoding: [0xf2,0x0f,0x00,0xb2,0x00,0xff,0xff,0xff]
33+
lkgs word ptr [rdx - 256]
34+

llvm/test/TableGen/x86-fold-tables.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ static const X86FoldTableEntry Table0[] = {
426426
{X86::JMP64r, X86::JMP64m, TB_FOLDED_LOAD},
427427
{X86::JMP64r_NT, X86::JMP64m_NT, TB_FOLDED_LOAD},
428428
{X86::JMP64r_REX, X86::JMP64m_REX, TB_FOLDED_LOAD},
429+
{X86::LKGS16r, X86::LKGS16m, TB_FOLDED_LOAD},
429430
{X86::MMX_MOVD64from64rr, X86::MMX_MOVQ64mr, TB_FOLDED_STORE},
430431
{X86::MMX_MOVD64grr, X86::MMX_MOVD64mr, TB_FOLDED_STORE},
431432
{X86::MOV16ri, X86::MOV16mi, TB_FOLDED_STORE},

0 commit comments

Comments
 (0)