Skip to content

Commit 7361b22

Browse files
authored
Rollup merge of rust-lang#97097 - chorman0773:add_tmm_clobers, r=joshtriplett
Add tmm_reg clobbers This adds support for naming the 8 tile registers from intel AMX as clobbers from `asm!` invocations on x86_64 (only). It does not add the registers as input or output operands.
2 parents f597846 + eabe851 commit 7361b22

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
592592
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg0) => unimplemented!(),
593593
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => unimplemented!(),
594594
InlineAsmRegClass::X86(
595-
X86InlineAsmRegClass::x87_reg | X86InlineAsmRegClass::mmx_reg,
595+
X86InlineAsmRegClass::x87_reg | X86InlineAsmRegClass::mmx_reg | X86InlineAsmRegClass::tmm_reg,
596596
) => unreachable!("clobber-only"),
597597
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
598598
bug!("GCC backend does not support SPIR-V")
@@ -656,6 +656,7 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
656656
InlineAsmRegClass::X86(X86InlineAsmRegClass::x87_reg) => unimplemented!(),
657657
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg) => cx.type_i16(),
658658
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg0) => cx.type_i16(),
659+
InlineAsmRegClass::X86(X86InlineAsmRegClass::tmm_reg) => unimplemented!(),
659660
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
660661
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
661662
bug!("LLVM backend does not support SPIR-V")
@@ -787,7 +788,7 @@ fn modifier_to_gcc(arch: InlineAsmArch, reg: InlineAsmRegClass, modifier: Option
787788
},
788789
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg) => None,
789790
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg0) => None,
790-
InlineAsmRegClass::X86(X86InlineAsmRegClass::x87_reg | X86InlineAsmRegClass::mmx_reg) => {
791+
InlineAsmRegClass::X86(X86InlineAsmRegClass::x87_reg | X86InlineAsmRegClass::mmx_reg | X86InlineAsmRegClass::tmm_reg) => {
791792
unreachable!("clobber-only")
792793
}
793794
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => unimplemented!(),

compiler/rustc_codegen_llvm/src/asm.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
604604
InlineAsmRegClass::X86(
605605
X86InlineAsmRegClass::x87_reg
606606
| X86InlineAsmRegClass::mmx_reg
607-
| X86InlineAsmRegClass::kreg0,
607+
| X86InlineAsmRegClass::kreg0
608+
| X86InlineAsmRegClass::tmm_reg,
608609
) => unreachable!("clobber-only"),
609610
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
610611
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
@@ -692,7 +693,8 @@ fn modifier_to_llvm(
692693
InlineAsmRegClass::X86(
693694
X86InlineAsmRegClass::x87_reg
694695
| X86InlineAsmRegClass::mmx_reg
695-
| X86InlineAsmRegClass::kreg0,
696+
| X86InlineAsmRegClass::kreg0
697+
| X86InlineAsmRegClass::tmm_reg,
696698
) => {
697699
unreachable!("clobber-only")
698700
}
@@ -766,7 +768,8 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
766768
InlineAsmRegClass::X86(
767769
X86InlineAsmRegClass::x87_reg
768770
| X86InlineAsmRegClass::mmx_reg
769-
| X86InlineAsmRegClass::kreg0,
771+
| X86InlineAsmRegClass::kreg0
772+
| X86InlineAsmRegClass::tmm_reg,
770773
) => {
771774
unreachable!("clobber-only")
772775
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ symbols! {
14081408
thread_local_macro,
14091409
thumb2,
14101410
thumb_mode: "thumb-mode",
1411+
tmm_reg,
14111412
todo_macro,
14121413
tool_attributes,
14131414
tool_lints,

compiler/rustc_target/src/asm/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ impl InlineAsmClobberAbi {
912912

913913
mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7,
914914
st0, st1, st2, st3, st4, st5, st6, st7,
915+
tmm0, tmm1, tmm2, tmm3, tmm4, tmm5, tmm6, tmm7,
915916
}
916917
},
917918
InlineAsmClobberAbi::X86_64Win => clobbered_regs! {
@@ -931,6 +932,7 @@ impl InlineAsmClobberAbi {
931932

932933
mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7,
933934
st0, st1, st2, st3, st4, st5, st6, st7,
935+
tmm0, tmm1, tmm2, tmm3, tmm4, tmm5, tmm6, tmm7,
934936
}
935937
},
936938
InlineAsmClobberAbi::AArch64 => clobbered_regs! {

compiler/rustc_target/src/asm/x86.rs

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def_reg_class! {
1717
kreg0,
1818
mmx_reg,
1919
x87_reg,
20+
tmm_reg,
2021
}
2122
}
2223

@@ -41,6 +42,7 @@ impl X86InlineAsmRegClass {
4142
Self::xmm_reg | Self::ymm_reg | Self::zmm_reg => &['x', 'y', 'z'],
4243
Self::kreg | Self::kreg0 => &[],
4344
Self::mmx_reg | Self::x87_reg => &[],
45+
Self::tmm_reg => &[],
4446
}
4547
}
4648

@@ -80,6 +82,7 @@ impl X86InlineAsmRegClass {
8082
},
8183
Self::kreg | Self::kreg0 => None,
8284
Self::mmx_reg | Self::x87_reg => None,
85+
Self::tmm_reg => None,
8386
}
8487
}
8588

@@ -98,6 +101,7 @@ impl X86InlineAsmRegClass {
98101
Self::zmm_reg => Some(('z', "zmm0")),
99102
Self::kreg | Self::kreg0 => None,
100103
Self::mmx_reg | Self::x87_reg => None,
104+
Self::tmm_reg => None,
101105
}
102106
}
103107

@@ -135,6 +139,7 @@ impl X86InlineAsmRegClass {
135139
},
136140
Self::kreg0 => &[],
137141
Self::mmx_reg | Self::x87_reg => &[],
142+
Self::tmm_reg => &[],
138143
}
139144
}
140145
}
@@ -320,6 +325,14 @@ def_regs! {
320325
st5: x87_reg = ["st(5)"],
321326
st6: x87_reg = ["st(6)"],
322327
st7: x87_reg = ["st(7)"],
328+
tmm0: tmm_reg = ["tmm0"] % x86_64_only,
329+
tmm1: tmm_reg = ["tmm1"] % x86_64_only,
330+
tmm2: tmm_reg = ["tmm2"] % x86_64_only,
331+
tmm3: tmm_reg = ["tmm3"] % x86_64_only,
332+
tmm4: tmm_reg = ["tmm4"] % x86_64_only,
333+
tmm5: tmm_reg = ["tmm5"] % x86_64_only,
334+
tmm6: tmm_reg = ["tmm6"] % x86_64_only,
335+
tmm7: tmm_reg = ["tmm7"] % x86_64_only,
323336
#error = ["bp", "bpl", "ebp", "rbp"] =>
324337
"the frame pointer cannot be used as an operand for inline asm",
325338
#error = ["sp", "spl", "esp", "rsp"] =>

src/test/codegen/asm-clobber_abi.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@
66
use std::arch::asm;
77

88
// CHECK-LABEL: @clobber_sysv64
9-
// CHECK: ={ax},={cx},={dx},={si},={di},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{dirflag},~{fpsr},~{flags},~{memory}
9+
// CHECK: ={ax},={cx},={dx},={si},={di},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{tmm0},~{tmm1},~{tmm2},~{tmm3},~{tmm4},~{tmm5},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags},~{memory}
1010
#[no_mangle]
1111
pub unsafe fn clobber_sysv64() {
1212
asm!("", clobber_abi("sysv64"));
1313
}
1414

1515
// CHECK-LABEL: @clobber_win64
16-
// CHECK: ={ax},={cx},={dx},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{dirflag},~{fpsr},~{flags},~{memory}
16+
// CHECK: ={ax},={cx},={dx},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{tmm0},~{tmm1},~{tmm2},~{tmm3},~{tmm4},~{tmm5},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags},~{memory}
1717
#[no_mangle]
1818
pub unsafe fn clobber_win64() {
1919
asm!("", clobber_abi("win64"));
2020
}
2121

2222
// CHECK-LABEL: @clobber_sysv64
23-
// CHECK: =&{dx},={ax},={cx},={si},={di},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{dirflag},~{fpsr},~{flags},~{memory}
23+
// CHECK: =&{dx},={ax},={cx},={si},={di},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{tmm0},~{tmm1},~{tmm2},~{tmm3},~{tmm4},~{tmm5},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags},~{memory}
2424
#[no_mangle]
2525
pub unsafe fn clobber_sysv64_edx() {
2626
let foo: i32;
2727
asm!("", out("edx") foo, clobber_abi("sysv64"));
2828
}
2929

3030
// CHECK-LABEL: @clobber_win64
31-
// CHECK: =&{dx},={ax},={cx},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{dirflag},~{fpsr},~{flags},~{memory}
31+
// CHECK: =&{dx},={ax},={cx},={r8},={r9},={r10},={r11},={xmm0},={xmm1},={xmm2},={xmm3},={xmm4},={xmm5},={xmm6},={xmm7},={xmm8},={xmm9},={xmm10},={xmm11},={xmm12},={xmm13},={xmm14},={xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{k0},~{k1},~{k2},~{k3},~{k4},~{k5},~{k6},~{k7},~{st},~{st(1)},~{st(2)},~{st(3)},~{st(4)},~{st(5)},~{st(6)},~{st(7)},~{tmm0},~{tmm1},~{tmm2},~{tmm3},~{tmm4},~{tmm5},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags},~{memory}
3232
#[no_mangle]
3333
pub unsafe fn clobber_win64_edx() {
3434
let foo: i32;

src/test/codegen/asm-target-clobbers.rs

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
use std::arch::asm;
88

9+
// CHECK-LABEL: @amx_clobber
10+
// base: call void asm sideeffect inteldialect "", "~{tmm0}"()
11+
#[no_mangle]
12+
pub unsafe fn amx_clobber() {
13+
asm!("", out("tmm0") _, options(nostack, nomem, preserves_flags));
14+
}
15+
916
// CHECK-LABEL: @avx512_clobber
1017
// base: call void asm sideeffect inteldialect "", "~{xmm31}"()
1118
// avx512: call float asm sideeffect inteldialect "", "=&{xmm31}"()

0 commit comments

Comments
 (0)