Skip to content

Commit 52a4264

Browse files
committed
Support #[repr(simd)] types and floats in input/output of s390x inline assembly
1 parent 75703c1 commit 52a4264

File tree

9 files changed

+564
-116
lines changed

9 files changed

+564
-116
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,8 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
683683
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
684684
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a",
685685
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
686-
InlineAsmRegClass::S390x(
687-
S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg,
688-
) => {
686+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg) => "v",
687+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::areg) => {
689688
unreachable!("clobber-only")
690689
}
691690
InlineAsmRegClass::Sparc(SparcInlineAsmRegClass::reg) => "r",
@@ -766,7 +765,8 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
766765
S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr,
767766
) => cx.type_i32(),
768767
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
769-
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg) => {
768+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg) => cx.type_vector(cx.type_i64(), 2),
769+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::areg) => {
770770
unreachable!("clobber-only")
771771
}
772772
InlineAsmRegClass::Sparc(SparcInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
678678
S390x(S390xInlineAsmRegClass::reg) => "r",
679679
S390x(S390xInlineAsmRegClass::reg_addr) => "a",
680680
S390x(S390xInlineAsmRegClass::freg) => "f",
681-
S390x(S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg) => {
681+
S390x(S390xInlineAsmRegClass::vreg) => "v",
682+
S390x(S390xInlineAsmRegClass::areg) => {
682683
unreachable!("clobber-only")
683684
}
684685
Sparc(SparcInlineAsmRegClass::reg) => "r",
@@ -844,7 +845,8 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
844845
Avr(AvrInlineAsmRegClass::reg_ptr) => cx.type_i16(),
845846
S390x(S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr) => cx.type_i32(),
846847
S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
847-
S390x(S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg) => {
848+
S390x(S390xInlineAsmRegClass::vreg) => cx.type_vector(cx.type_i64(), 2),
849+
S390x(S390xInlineAsmRegClass::areg) => {
848850
unreachable!("clobber-only")
849851
}
850852
Sparc(SparcInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,7 @@ symbols! {
21372137
vec_pop,
21382138
vec_with_capacity,
21392139
vecdeque_iter,
2140+
vector,
21402141
version,
21412142
vfp2,
21422143
vis,

compiler/rustc_target/src/asm/s390x.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ impl S390xInlineAsmRegClass {
4242
match self {
4343
Self::reg | Self::reg_addr => types! { _: I8, I16, I32, I64; },
4444
Self::freg => types! { _: F32, F64; },
45-
Self::vreg => &[],
45+
// FIXME: we can also support F32, F64, F128.
46+
Self::vreg => types! {
47+
vector: VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF32(4), VecF64(2);
48+
},
4649
Self::areg => &[],
4750
}
4851
}

tests/assembly/asm/s390x-types.rs

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
//@ revisions: s390x
1+
//@ revisions: s390x s390x_vector
22
//@ assembly-output: emit-asm
33
//@[s390x] compile-flags: --target s390x-unknown-linux-gnu
44
//@[s390x] needs-llvm-components: systemz
5+
//@[s390x_vector] compile-flags: --target s390x-unknown-linux-gnu -C target-feature=+vector
6+
//@[s390x_vector] needs-llvm-components: systemz
57
//@ compile-flags: -Zmerge-functions=disabled
68

79
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
@@ -27,8 +29,23 @@ trait Sized {}
2729
#[lang = "copy"]
2830
trait Copy {}
2931

32+
impl<T: Copy, const N: usize> Copy for [T; N] {}
33+
3034
type ptr = *const i32;
3135

36+
#[repr(simd)]
37+
pub struct i8x16([i8; 16]);
38+
#[repr(simd)]
39+
pub struct i16x8([i16; 8]);
40+
#[repr(simd)]
41+
pub struct i32x4([i32; 4]);
42+
#[repr(simd)]
43+
pub struct i64x2([i64; 2]);
44+
#[repr(simd)]
45+
pub struct f32x4([f32; 4]);
46+
#[repr(simd)]
47+
pub struct f64x2([f64; 2]);
48+
3249
impl Copy for i8 {}
3350
impl Copy for u8 {}
3451
impl Copy for i16 {}
@@ -37,6 +54,12 @@ impl Copy for i64 {}
3754
impl Copy for f32 {}
3855
impl Copy for f64 {}
3956
impl Copy for ptr {}
57+
impl Copy for i8x16 {}
58+
impl Copy for i16x8 {}
59+
impl Copy for i32x4 {}
60+
impl Copy for i64x2 {}
61+
impl Copy for f32x4 {}
62+
impl Copy for f64x2 {}
4063

4164
extern "C" {
4265
fn extern_func();
@@ -65,7 +88,6 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => {
6588
// CHECK: #APP
6689
// CHECK: brasl %r14, extern_func
6790
// CHECK: #NO_APP
68-
#[cfg(s390x)]
6991
#[no_mangle]
7092
pub unsafe fn sym_fn_32() {
7193
asm!("brasl %r14, {}", sym extern_func);
@@ -146,6 +168,48 @@ check!(reg_f64, f64, freg, "ldr");
146168
// CHECK: #NO_APP
147169
check!(reg_ptr, ptr, reg, "lgr");
148170

171+
// s390x_vector-LABEL: vreg_i8x16:
172+
// s390x_vector: #APP
173+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
174+
// s390x_vector: #NO_APP
175+
#[cfg(s390x_vector)]
176+
check!(vreg_i8x16, i8x16, vreg, "vlr");
177+
178+
// s390x_vector-LABEL: vreg_i16x8:
179+
// s390x_vector: #APP
180+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
181+
// s390x_vector: #NO_APP
182+
#[cfg(s390x_vector)]
183+
check!(vreg_i16x8, i16x8, vreg, "vlr");
184+
185+
// s390x_vector-LABEL: vreg_i32x4:
186+
// s390x_vector: #APP
187+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
188+
// s390x_vector: #NO_APP
189+
#[cfg(s390x_vector)]
190+
check!(vreg_i32x4, i32x4, vreg, "vlr");
191+
192+
// s390x_vector-LABEL: vreg_i64x2:
193+
// s390x_vector: #APP
194+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
195+
// s390x_vector: #NO_APP
196+
#[cfg(s390x_vector)]
197+
check!(vreg_i64x2, i64x2, vreg, "vlr");
198+
199+
// s390x_vector-LABEL: vreg_f32x4:
200+
// s390x_vector: #APP
201+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
202+
// s390x_vector: #NO_APP
203+
#[cfg(s390x_vector)]
204+
check!(vreg_f32x4, f32x4, vreg, "vlr");
205+
206+
// s390x_vector-LABEL: vreg_f64x2:
207+
// s390x_vector: #APP
208+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
209+
// s390x_vector: #NO_APP
210+
#[cfg(s390x_vector)]
211+
check!(vreg_f64x2, f64x2, vreg, "vlr");
212+
149213
// CHECK-LABEL: r0_i8:
150214
// CHECK: #APP
151215
// CHECK: lr %r0, %r0
@@ -181,3 +245,45 @@ check_reg!(f0_f32, f32, "f0", "ler");
181245
// CHECK: ldr %f0, %f0
182246
// CHECK: #NO_APP
183247
check_reg!(f0_f64, f64, "f0", "ldr");
248+
249+
// s390x_vector-LABEL: v0_i8x16:
250+
// s390x_vector: #APP
251+
// s390x_vector: vlr %v0, %v0
252+
// s390x_vector: #NO_APP
253+
#[cfg(s390x_vector)]
254+
check_reg!(v0_i8x16, i8x16, "v0", "vlr");
255+
256+
// s390x_vector-LABEL: v0_i16x8:
257+
// s390x_vector: #APP
258+
// s390x_vector: vlr %v0, %v0
259+
// s390x_vector: #NO_APP
260+
#[cfg(s390x_vector)]
261+
check_reg!(v0_i16x8, i16x8, "v0", "vlr");
262+
263+
// s390x_vector-LABEL: v0_i32x4:
264+
// s390x_vector: #APP
265+
// s390x_vector: vlr %v0, %v0
266+
// s390x_vector: #NO_APP
267+
#[cfg(s390x_vector)]
268+
check_reg!(v0_i32x4, i32x4, "v0", "vlr");
269+
270+
// s390x_vector-LABEL: v0_i64x2:
271+
// s390x_vector: #APP
272+
// s390x_vector: vlr %v0, %v0
273+
// s390x_vector: #NO_APP
274+
#[cfg(s390x_vector)]
275+
check_reg!(v0_i64x2, i64x2, "v0", "vlr");
276+
277+
// s390x_vector-LABEL: v0_f32x4:
278+
// s390x_vector: #APP
279+
// s390x_vector: vlr %v0, %v0
280+
// s390x_vector: #NO_APP
281+
#[cfg(s390x_vector)]
282+
check_reg!(v0_f32x4, f32x4, "v0", "vlr");
283+
284+
// s390x_vector-LABEL: v0_f64x2:
285+
// s390x_vector: #APP
286+
// s390x_vector: vlr %v0, %v0
287+
// s390x_vector: #NO_APP
288+
#[cfg(s390x_vector)]
289+
check_reg!(v0_f64x2, f64x2, "v0", "vlr");

tests/auxiliary/minicore.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl_marker_trait!(
4545
impl<'a, T: ?Sized> Copy for &'a T {}
4646
impl<T: ?Sized> Copy for *const T {}
4747
impl<T: ?Sized> Copy for *mut T {}
48+
impl<T: Copy, const N: usize> Copy for [T; N] {}
4849

4950
#[lang = "phantom_data"]
5051
pub struct PhantomData<T: ?Sized>;

tests/ui/asm/s390x/bad-reg.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
//@ add-core-stubs
22
//@ needs-asm-support
3-
//@ revisions: s390x
3+
//@ revisions: s390x s390x_vector
44
//@[s390x] compile-flags: --target s390x-unknown-linux-gnu
55
//@[s390x] needs-llvm-components: systemz
6+
//@[s390x_vector] compile-flags: --target s390x-unknown-linux-gnu -C target-feature=+vector
7+
//@[s390x_vector] needs-llvm-components: systemz
68

79
#![crate_type = "rlib"]
8-
#![feature(no_core, rustc_attrs)]
9-
#![feature(asm_experimental_arch)]
10+
#![feature(no_core, rustc_attrs, repr_simd)]
1011
#![no_core]
12+
#![allow(non_camel_case_types)]
1113

1214
extern crate minicore;
1315
use minicore::*;
1416

17+
#[repr(simd)]
18+
pub struct i64x2([i64; 2]);
19+
20+
impl Copy for i64x2 {}
21+
1522
fn f() {
1623
let mut x = 0;
24+
let mut v = i64x2([0; 2]);
1725
unsafe {
1826
// Unsupported registers
1927
asm!("", out("r11") _);
@@ -57,6 +65,26 @@ fn f() {
5765
asm!("", out("a1") _);
5866
//~^ ERROR invalid register `a1`: a0 and a1 are reserved for system use and cannot be used as operands for inline asm
5967

68+
// vreg
69+
asm!("", out("v0") _); // always ok
70+
asm!("", in("v0") v); // requires vector
71+
//[s390x]~^ ERROR register class `vreg` requires the `vector` target feature
72+
asm!("", out("v0") v); // requires vector
73+
//[s390x]~^ ERROR register class `vreg` requires the `vector` target feature
74+
asm!("", in("v0") x);
75+
//[s390x]~^ ERROR register class `vreg` requires the `vector` target feature
76+
//[s390x_vector]~^^ ERROR type `i32` cannot be used with this register class
77+
asm!("", out("v0") x);
78+
//[s390x]~^ ERROR register class `vreg` requires the `vector` target feature
79+
//[s390x_vector]~^^ ERROR type `i32` cannot be used with this register class
80+
asm!("/* {} */", in(vreg) v); // requires vector
81+
//[s390x]~^ ERROR register class `vreg` requires the `vector` target feature
82+
asm!("/* {} */", in(vreg) x);
83+
//[s390x]~^ ERROR register class `vreg` requires the `vector` target feature
84+
//[s390x_vector]~^^ ERROR type `i32` cannot be used with this register class
85+
asm!("/* {} */", out(vreg) _); // requires vector
86+
//[s390x]~^ ERROR register class `vreg` requires the `vector` target feature
87+
6088
// Clobber-only registers
6189
// areg
6290
asm!("", out("a2") _); // ok
@@ -72,21 +100,6 @@ fn f() {
72100
asm!("/* {} */", out(areg) _);
73101
//~^ ERROR can only be used as a clobber
74102

75-
// vreg
76-
asm!("", out("v0") _); // ok
77-
// FIXME: will be supported in https://github.com/rust-lang/rust/pull/131664
78-
asm!("", in("v0") x);
79-
//~^ ERROR can only be used as a clobber
80-
//~| ERROR type `i32` cannot be used with this register class
81-
asm!("", out("v0") x);
82-
//~^ ERROR can only be used as a clobber
83-
//~| ERROR type `i32` cannot be used with this register class
84-
asm!("/* {} */", in(vreg) x);
85-
//~^ ERROR can only be used as a clobber
86-
//~| ERROR type `i32` cannot be used with this register class
87-
asm!("/* {} */", out(vreg) _);
88-
//~^ ERROR can only be used as a clobber
89-
90103
// Overlapping registers
91104
// vreg/freg
92105
asm!("", out("v0") _, out("f0") _);

0 commit comments

Comments
 (0)