Skip to content

Commit 51506f9

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

File tree

9 files changed

+608
-117
lines changed

9 files changed

+608
-117
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

+4-4
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

+4-2
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

+1
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

+4-1
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+
Self::vreg => types! {
46+
vector: F32, F64, F128,
47+
VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF32(4), VecF64(2);
48+
},
4649
Self::areg => &[],
4750
}
4851
}

tests/assembly/asm/s390x-types.rs

+152-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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

7-
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
9+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, f128)]
810
#![crate_type = "rlib"]
911
#![no_core]
1012
#![allow(asm_sub_register, non_camel_case_types)]
@@ -27,16 +29,38 @@ 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 {}
3552
impl Copy for i32 {}
3653
impl Copy for i64 {}
3754
impl Copy for f32 {}
3855
impl Copy for f64 {}
56+
impl Copy for f128 {}
3957
impl Copy for ptr {}
58+
impl Copy for i8x16 {}
59+
impl Copy for i16x8 {}
60+
impl Copy for i32x4 {}
61+
impl Copy for i64x2 {}
62+
impl Copy for f32x4 {}
63+
impl Copy for f64x2 {}
4064

4165
extern "C" {
4266
fn extern_func();
@@ -65,7 +89,6 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => {
6589
// CHECK: #APP
6690
// CHECK: brasl %r14, extern_func
6791
// CHECK: #NO_APP
68-
#[cfg(s390x)]
6992
#[no_mangle]
7093
pub unsafe fn sym_fn_32() {
7194
asm!("brasl %r14, {}", sym extern_func);
@@ -146,6 +169,69 @@ check!(reg_f64, f64, freg, "ldr");
146169
// CHECK: #NO_APP
147170
check!(reg_ptr, ptr, reg, "lgr");
148171

172+
// s390x_vector-LABEL: vreg_i8x16:
173+
// s390x_vector: #APP
174+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
175+
// s390x_vector: #NO_APP
176+
#[cfg(s390x_vector)]
177+
check!(vreg_i8x16, i8x16, vreg, "vlr");
178+
179+
// s390x_vector-LABEL: vreg_i16x8:
180+
// s390x_vector: #APP
181+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
182+
// s390x_vector: #NO_APP
183+
#[cfg(s390x_vector)]
184+
check!(vreg_i16x8, i16x8, vreg, "vlr");
185+
186+
// s390x_vector-LABEL: vreg_i32x4:
187+
// s390x_vector: #APP
188+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
189+
// s390x_vector: #NO_APP
190+
#[cfg(s390x_vector)]
191+
check!(vreg_i32x4, i32x4, vreg, "vlr");
192+
193+
// s390x_vector-LABEL: vreg_i64x2:
194+
// s390x_vector: #APP
195+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
196+
// s390x_vector: #NO_APP
197+
#[cfg(s390x_vector)]
198+
check!(vreg_i64x2, i64x2, vreg, "vlr");
199+
200+
// s390x_vector-LABEL: vreg_f32x4:
201+
// s390x_vector: #APP
202+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
203+
// s390x_vector: #NO_APP
204+
#[cfg(s390x_vector)]
205+
check!(vreg_f32x4, f32x4, vreg, "vlr");
206+
207+
// s390x_vector-LABEL: vreg_f64x2:
208+
// s390x_vector: #APP
209+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
210+
// s390x_vector: #NO_APP
211+
#[cfg(s390x_vector)]
212+
check!(vreg_f64x2, f64x2, vreg, "vlr");
213+
214+
// s390x_vector-LABEL: vreg_f32:
215+
// s390x_vector: #APP
216+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
217+
// s390x_vector: #NO_APP
218+
#[cfg(s390x_vector)]
219+
check!(vreg_f32, f32, vreg, "vlr");
220+
221+
// s390x_vector-LABEL: vreg_f64:
222+
// s390x_vector: #APP
223+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
224+
// s390x_vector: #NO_APP
225+
#[cfg(s390x_vector)]
226+
check!(vreg_f64, f64, vreg, "vlr");
227+
228+
// s390x_vector-LABEL: vreg_f128:
229+
// s390x_vector: #APP
230+
// s390x_vector: vlr %v{{[0-9]+}}, %v{{[0-9]+}}
231+
// s390x_vector: #NO_APP
232+
#[cfg(s390x_vector)]
233+
check!(vreg_f128, f128, vreg, "vlr");
234+
149235
// CHECK-LABEL: r0_i8:
150236
// CHECK: #APP
151237
// CHECK: lr %r0, %r0
@@ -181,3 +267,66 @@ check_reg!(f0_f32, f32, "f0", "ler");
181267
// CHECK: ldr %f0, %f0
182268
// CHECK: #NO_APP
183269
check_reg!(f0_f64, f64, "f0", "ldr");
270+
271+
// s390x_vector-LABEL: v0_i8x16:
272+
// s390x_vector: #APP
273+
// s390x_vector: vlr %v0, %v0
274+
// s390x_vector: #NO_APP
275+
#[cfg(s390x_vector)]
276+
check_reg!(v0_i8x16, i8x16, "v0", "vlr");
277+
278+
// s390x_vector-LABEL: v0_i16x8:
279+
// s390x_vector: #APP
280+
// s390x_vector: vlr %v0, %v0
281+
// s390x_vector: #NO_APP
282+
#[cfg(s390x_vector)]
283+
check_reg!(v0_i16x8, i16x8, "v0", "vlr");
284+
285+
// s390x_vector-LABEL: v0_i32x4:
286+
// s390x_vector: #APP
287+
// s390x_vector: vlr %v0, %v0
288+
// s390x_vector: #NO_APP
289+
#[cfg(s390x_vector)]
290+
check_reg!(v0_i32x4, i32x4, "v0", "vlr");
291+
292+
// s390x_vector-LABEL: v0_i64x2:
293+
// s390x_vector: #APP
294+
// s390x_vector: vlr %v0, %v0
295+
// s390x_vector: #NO_APP
296+
#[cfg(s390x_vector)]
297+
check_reg!(v0_i64x2, i64x2, "v0", "vlr");
298+
299+
// s390x_vector-LABEL: v0_f32x4:
300+
// s390x_vector: #APP
301+
// s390x_vector: vlr %v0, %v0
302+
// s390x_vector: #NO_APP
303+
#[cfg(s390x_vector)]
304+
check_reg!(v0_f32x4, f32x4, "v0", "vlr");
305+
306+
// s390x_vector-LABEL: v0_f64x2:
307+
// s390x_vector: #APP
308+
// s390x_vector: vlr %v0, %v0
309+
// s390x_vector: #NO_APP
310+
#[cfg(s390x_vector)]
311+
check_reg!(v0_f64x2, f64x2, "v0", "vlr");
312+
313+
// s390x_vector-LABEL: v0_f32:
314+
// s390x_vector: #APP
315+
// s390x_vector: vlr %v0, %v0
316+
// s390x_vector: #NO_APP
317+
#[cfg(s390x_vector)]
318+
check_reg!(v0_f32, f32, "v0", "vlr");
319+
320+
// s390x_vector-LABEL: v0_f64:
321+
// s390x_vector: #APP
322+
// s390x_vector: vlr %v0, %v0
323+
// s390x_vector: #NO_APP
324+
#[cfg(s390x_vector)]
325+
check_reg!(v0_f64, f64, "v0", "vlr");
326+
327+
// s390x_vector-LABEL: v0_f128:
328+
// s390x_vector: #APP
329+
// s390x_vector: vlr %v0, %v0
330+
// s390x_vector: #NO_APP
331+
#[cfg(s390x_vector)]
332+
check_reg!(v0_f128, f128, "v0", "vlr");

tests/auxiliary/minicore.rs

+1
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

+31-18
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)