Skip to content

Commit 57419c1

Browse files
committed
Support #[repr(simd)] types in input/output of s390x inline assembly
1 parent 5fc1014 commit 57419c1

File tree

5 files changed

+121
-9
lines changed

5 files changed

+121
-9
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,8 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
682682
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
683683
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a",
684684
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
685-
InlineAsmRegClass::S390x(
686-
S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg,
687-
) => {
685+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg) => "v",
686+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::areg) => {
688687
unreachable!("clobber-only")
689688
}
690689
InlineAsmRegClass::Err => unreachable!(),
@@ -762,7 +761,8 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
762761
S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr,
763762
) => cx.type_i32(),
764763
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
765-
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg) => {
764+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg) => cx.type_vector(cx.type_i64(), 2),
765+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::areg) => {
766766
unreachable!("clobber-only")
767767
}
768768
InlineAsmRegClass::Msp430(Msp430InlineAsmRegClass::reg) => cx.type_i16(),

compiler/rustc_codegen_llvm/src/asm.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
667667
S390x(S390xInlineAsmRegClass::reg) => "r",
668668
S390x(S390xInlineAsmRegClass::reg_addr) => "a",
669669
S390x(S390xInlineAsmRegClass::freg) => "f",
670-
S390x(S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg) => {
670+
S390x(S390xInlineAsmRegClass::vreg) => "v",
671+
S390x(S390xInlineAsmRegClass::areg) => {
671672
unreachable!("clobber-only")
672673
}
673674
Msp430(Msp430InlineAsmRegClass::reg) => "r",
@@ -828,7 +829,8 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
828829
Avr(AvrInlineAsmRegClass::reg_ptr) => cx.type_i16(),
829830
S390x(S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr) => cx.type_i32(),
830831
S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
831-
S390x(S390xInlineAsmRegClass::vreg | S390xInlineAsmRegClass::areg) => {
832+
S390x(S390xInlineAsmRegClass::vreg) => cx.type_vector(cx.type_i64(), 2),
833+
S390x(S390xInlineAsmRegClass::areg) => {
832834
unreachable!("clobber-only")
833835
}
834836
Msp430(Msp430InlineAsmRegClass::reg) => cx.type_i16(),

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,7 @@ symbols! {
21262126
vec_pop,
21272127
vec_with_capacity,
21282128
vecdeque_iter,
2129+
vector,
21292130
version,
21302131
vfp2,
21312132
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+
// FIXME: I8, I16, I32, I64, F32, F64
46+
Self::vreg => types! {
47+
vector: VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF16(8), VecF32(4), VecF64(2);
48+
},
4649
Self::areg => &[],
4750
}
4851
}

tests/assembly/asm/s390x-types.rs

+108-2
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, asm_experimental_arch)]
@@ -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");

0 commit comments

Comments
 (0)