Skip to content

Commit

Permalink
[X86][MC] Support instructions of MSR_IMM (llvm#113524)
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddyLeaf authored Oct 28, 2024
1 parent 99b2fea commit d3f70db
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 1 deletion.
2 changes: 2 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ Changes to the X86 Backend

* Supported ISA of `SM4(EVEX)`.

* Supported ISA of `MSR_IMM`.

Changes to the OCaml bindings
-----------------------------

Expand Down
8 changes: 7 additions & 1 deletion llvm/lib/Target/X86/X86InstrSystem.td
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ multiclass Urdwrmsr<Map rrmap, string suffix> {
"urdmsr\t{$imm, $dst|$dst, $imm}",
[(set GR64:$dst, (int_x86_urdmsr i64immSExt32_su:$imm))]>,
T_MAP7, VEX, XD, NoCD8;
}
def RDMSRri#suffix : Ii32<0xf6, MRM0r, (outs GR64:$dst), (ins i64i32imm:$imm),
"rdmsr\t{$imm, $dst|$dst, $imm}", []>,
T_MAP7, VEX, XD, NoCD8;
}
let mayStore = 1 in {
let OpMap = rrmap in
def UWRMSRrr#suffix : I<0xf8, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
Expand All @@ -476,6 +479,9 @@ multiclass Urdwrmsr<Map rrmap, string suffix> {
"uwrmsr\t{$src, $imm|$imm, $src}",
[(int_x86_uwrmsr i64immSExt32_su:$imm, GR64:$src)]>,
T_MAP7, VEX, XS, NoCD8;
def WRMSRNSir#suffix : Ii32<0xf6, MRM0r, (outs), (ins GR64:$src, i64i32imm:$imm),
"wrmsrns\t{$src, $imm|$imm, $src}",
[]>, T_MAP7, VEX, XS, NoCD8;
}
}

Expand Down
18 changes: 18 additions & 0 deletions llvm/test/MC/Disassembler/X86/apx/msr-imm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
# RUN: llvm-mc --disassemble %s -triple=x86_64 -x86-asm-syntax=intel --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL

# ATT: rdmsr $123, %r9
# INTEL: rdmsr r9, 123
0x62,0xd7,0x7f,0x08,0xf6,0xc1,0x7b,0x00,0x00,0x00

# ATT: rdmsr $123, %r19
# INTEL: rdmsr r19, 123
0x62,0xff,0x7f,0x08,0xf6,0xc3,0x7b,0x00,0x00,0x00

# ATT: wrmsrns %r9, $123
# INTEL: wrmsrns 123, r9
0x62,0xd7,0x7e,0x08,0xf6,0xc1,0x7b,0x00,0x00,0x00

# ATT: wrmsrns %r19, $123
# INTEL: wrmsrns 123, r19
0x62,0xff,0x7e,0x08,0xf6,0xc3,0x7b,0x00,0x00,0x00
10 changes: 10 additions & 0 deletions llvm/test/MC/Disassembler/X86/msrimm-64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
# RUN: llvm-mc --disassemble %s -triple=x86_64 -x86-asm-syntax=intel --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL

# ATT: rdmsr $123, %r9
# INTEL: rdmsr r9, 123
0xc4,0xc7,0x7b,0xf6,0xc1,0x7b,0x00,0x00,0x00

# ATT: wrmsrns %r9, $123
# INTEL: wrmsrns 123, r9
0xc4,0xc7,0x7a,0xf6,0xc1,0x7b,0x00,0x00,0x00
25 changes: 25 additions & 0 deletions llvm/test/MC/X86/apx/msrimm-att.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
# RUN: not llvm-mc -triple i386 -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR

# ERROR-COUNT-4: error:
# ERROR-NOT: error:

## rdmsr

// CHECK: {evex} rdmsr $123, %r9
// CHECK: encoding: [0x62,0xd7,0x7f,0x08,0xf6,0xc1,0x7b,0x00,0x00,0x00]
{evex} rdmsr $123, %r9

// CHECK: rdmsr $123, %r19
// CHECK: encoding: [0x62,0xff,0x7f,0x08,0xf6,0xc3,0x7b,0x00,0x00,0x00]
rdmsr $123, %r19

## wrmsrns

# CHECK: {evex} wrmsrns %r9, $123
# CHECK: encoding: [0x62,0xd7,0x7e,0x08,0xf6,0xc1,0x7b,0x00,0x00,0x00]
{evex} wrmsrns %r9, $123

# CHECK: wrmsrns %r19, $123
# CHECK: encoding: [0x62,0xff,0x7e,0x08,0xf6,0xc3,0x7b,0x00,0x00,0x00]
wrmsrns %r19, $123
21 changes: 21 additions & 0 deletions llvm/test/MC/X86/apx/msrimm-intel.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s

## urdmsr

# CHECK: {evex} rdmsr r9, 123
# CHECK: encoding: [0x62,0xd7,0x7f,0x08,0xf6,0xc1,0x7b,0x00,0x00,0x00]
{evex} rdmsr r9, 123

# CHECK: rdmsr r19, 123
# CHECK: encoding: [0x62,0xff,0x7f,0x08,0xf6,0xc3,0x7b,0x00,0x00,0x00]
rdmsr r19, 123

## uwrmsr

# CHECK: {evex} wrmsrns 123, r9
# CHECK: encoding: [0x62,0xd7,0x7e,0x08,0xf6,0xc1,0x7b,0x00,0x00,0x00]
{evex} wrmsrns 123, r9

# CHECK: wrmsrns 123, r19
# CHECK: encoding: [0x62,0xff,0x7e,0x08,0xf6,0xc3,0x7b,0x00,0x00,0x00]
wrmsrns 123, r19
14 changes: 14 additions & 0 deletions llvm/test/MC/X86/msrimm-64-att.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
// RUN: not llvm-mc -triple i386 -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR

// ERROR-COUNT-2: error:
// ERROR-NOT: error:

// CHECK: rdmsr $123, %r9
// CHECK: encoding: [0xc4,0xc7,0x7b,0xf6,0xc1,0x7b,0x00,0x00,0x00]
rdmsr $123, %r9

// CHECK: wrmsrns %r9, $123
// CHECK: encoding: [0xc4,0xc7,0x7a,0xf6,0xc1,0x7b,0x00,0x00,0x00]
wrmsrns %r9, $123

10 changes: 10 additions & 0 deletions llvm/test/MC/X86/msrimm-64-intel.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s

// CHECK: rdmsr r9, 123
// CHECK: encoding: [0xc4,0xc7,0x7b,0xf6,0xc1,0x7b,0x00,0x00,0x00]
rdmsr r9, 123

// CHECK: wrmsrns 123, r9
// CHECK: encoding: [0xc4,0xc7,0x7a,0xf6,0xc1,0x7b,0x00,0x00,0x00]
wrmsrns 123, r9

0 comments on commit d3f70db

Please sign in to comment.