Skip to content

Commit

Permalink
[X86][MC] Teach disassembler to recognize apx instructions which igno…
Browse files Browse the repository at this point in the history
…res W bit (#82747)

Extended VMX instructions and 8 bit apx extended instructions don't need
W bit, they are marked as W ignored in spec.
RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
  • Loading branch information
XinWang10 committed Feb 29, 2024
1 parent f0484e0 commit ffa48f0
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 3 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86InstrSystem.td
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def INVPCID64 : I<0x82, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),

def INVPCID64_EVEX : I<0xF2, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
"invpcid\t{$src2, $src1|$src1, $src2}", []>,
EVEX, NoCD8, T_MAP4, XS, Requires<[In64BitMode]>;
EVEX, NoCD8, T_MAP4, XS, WIG, Requires<[In64BitMode]>;
} // SchedRW

let Predicates = [HasINVPCID, NoEGPR] in {
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/X86/X86InstrUtils.td
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ class ITy<bits<8> o, Format f, X86TypeInfo t, dag outs, dag ins, string m,
!strconcat(m, "{", t.InstrSuffix, "}\t", args), p>, NoCD8 {
let hasSideEffects = 0;
let hasREX_W = t.HasREX_W;
let IgnoresW = !if(!eq(t.VT, i8), 1, 0);
}

// BinOpRR - Instructions that read "reg, reg".
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/X86InstrVMX.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def INVEPT64 : I<0x80, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
Requires<[In64BitMode]>;
def INVEPT64_EVEX : I<0xF0, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
"invept\t{$src2, $src1|$src1, $src2}", []>,
EVEX, NoCD8, T_MAP4, XS, Requires<[In64BitMode]>;
EVEX, NoCD8, T_MAP4, XS, WIG, Requires<[In64BitMode]>;

// 66 0F 38 81
def INVVPID32 : I<0x81, MRMSrcMem, (outs), (ins GR32:$src1, i128mem:$src2),
Expand All @@ -35,7 +35,7 @@ def INVVPID64 : I<0x81, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
Requires<[In64BitMode]>;
def INVVPID64_EVEX : I<0xF1, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
"invvpid\t{$src2, $src1|$src1, $src2}", []>,
EVEX, NoCD8, T_MAP4, XS, Requires<[In64BitMode]>;
EVEX, NoCD8, T_MAP4, XS, WIG, Requires<[In64BitMode]>;

// 0F 01 C1
def VMCALL : I<0x01, MRM_C1, (outs), (ins), "vmcall", []>, TB;
Expand Down
118 changes: 118 additions & 0 deletions llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# 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

## invpcid

# ATT: invpcid 123(%rax,%rbx,4), %r9
# INTEL: invpcid r9, xmmword ptr [rax + 4*rbx + 123]
0x62,0x74,0xfe,0x08,0xf2,0x4c,0x98,0x7b

# ATT: invpcid 291(%r28,%r29,4), %r19
# INTEL: invpcid r19, xmmword ptr [r28 + 4*r29 + 291]
0x62,0x8c,0xfa,0x08,0xf2,0x9c,0xac,0x23,0x01,0x00,0x00

## invept

# ATT: invept 291(%r28,%r29,4), %r19
# INTEL: invept r19, xmmword ptr [r28 + 4*r29 + 291]
0x62,0x8c,0xfa,0x08,0xf0,0x9c,0xac,0x23,0x01,0x00,0x00

# ATT: invept 123(%rax,%rbx,4), %r9
# INTEL: invept r9, xmmword ptr [rax + 4*rbx + 123]
0x62,0x74,0xfe,0x08,0xf0,0x4c,0x98,0x7b

## invvpid

# ATT: invvpid 291(%r28,%r29,4), %r19
# INTEL: invvpid r19, xmmword ptr [r28 + 4*r29 + 291]
0x62,0x8c,0xfa,0x08,0xf1,0x9c,0xac,0x23,0x01,0x00,0x00

# ATT: invvpid 123(%rax,%rbx,4), %r9
# INTEL: invvpid r9, xmmword ptr [rax + 4*rbx + 123]
0x62,0x74,0xfe,0x08,0xf1,0x4c,0x98,0x7b

## adc

# ATT: {evex} adcb $123, %bl
# INTEL: {evex} adc bl, 123
0x62,0xf4,0xfc,0x08,0x80,0xd3,0x7b

# ATT: adcb $123, %bl, %cl
# INTEL: adc cl, bl, 123
0x62,0xf4,0xf4,0x18,0x80,0xd3,0x7b

# ATT: adcb $123, %r16b
# INTEL: adc r16b, 123
0xd5,0x18,0x80,0xd0,0x7b

## add

# ATT: {evex} addb $123, %bl
# INTEL: {evex} add bl, 123
0x62,0xf4,0xfc,0x08,0x80,0xc3,0x7b

# ATT: {nf} addb $123, %bl
# INTEL: {nf} add bl, 123
0x62,0xf4,0xfc,0x0c,0x80,0xc3,0x7b

# ATT: addb $123, %bl, %cl
# INTEL: add cl, bl, 123
0x62,0xf4,0xf4,0x18,0x80,0xc3,0x7b

# ATT: {nf} addb $123, %bl, %cl
# INTEL: {nf} add cl, bl, 123
0x62,0xf4,0xf4,0x1c,0x80,0xc3,0x7b

# ATT: addb $123, %r16b
# INTEL: add r16b, 123
0xd5,0x18,0x80,0xc0,0x7b

## inc

# ATT: {evex} incb %bl
# INTEL: {evex} inc bl
0x62,0xf4,0xfc,0x08,0xfe,0xc3

# ATT: {nf} incb %bl
# INTEL: {nf} inc bl
0x62,0xf4,0xfc,0x0c,0xfe,0xc3

# ATT: incb %bl, %bl
# INTEL: inc bl, bl
0x62,0xf4,0xe4,0x18,0xfe,0xc3

# ATT: {nf} incb %bl, %bl
# INTEL: {nf} inc bl, bl
0x62,0xf4,0xe4,0x1c,0xfe,0xc3

# ATT: incb %r16b
# INTEL: inc r16b
0xd5,0x18,0xfe,0xc0

## mul

# ATT: {evex} mulb %bl
# INTEL: {evex} mul bl
0x62,0xf4,0xfc,0x08,0xf6,0xe3

# ATT: {nf} mulb %bl
# INTEL: {nf} mul bl
0x62,0xf4,0xfc,0x0c,0xf6,0xe3

# ATT: mulb %r16b
# INTEL: mul r16b
0xd5,0x18,0xf6,0xe0

## imul

# ATT: {evex} imulb %bl
# INTEL: {evex} imul bl
0x62,0xf4,0xfc,0x08,0xf6,0xeb

# ATT: {nf} imulb %bl
# INTEL: {nf} imul bl
0x62,0xf4,0xfc,0x0c,0xf6,0xeb

# ATT: imulb %r16b
# INTEL: imul r16b
0xd5,0x18,0xf6,0xe8
2 changes: 2 additions & 0 deletions llvm/utils/TableGen/X86DisassemblerTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ static inline bool inheritsFrom(InstructionContext child,
case IC_EVEX_L2_W_OPSIZE_KZ_B:
return false;
case IC_EVEX_NF:
return WIG && inheritsFrom(child, IC_EVEX_W_NF);
case IC_EVEX_B_NF:
return WIG && inheritsFrom(child, IC_EVEX_W_B_NF);
case IC_EVEX_OPSIZE_NF:
case IC_EVEX_OPSIZE_B_NF:
case IC_EVEX_W_NF:
Expand Down

0 comments on commit ffa48f0

Please sign in to comment.