Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 16 additions & 33 deletions tests/assembly-llvm/s390x-vector-abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ revisions: z10 z10_vector z13 z13_no_vector
//@ add-core-stubs
// ignore-tidy-linelength
//@ assembly-output: emit-asm
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled
Expand All @@ -18,24 +19,8 @@
// Cases where vector feature is disabled are rejected.
// See tests/ui/simd-abi-checks-s390x.rs for test for them.

#[lang = "pointee_sized"]
pub trait PointeeSized {}

#[lang = "meta_sized"]
pub trait MetaSized: PointeeSized {}

#[lang = "sized"]
pub trait Sized: MetaSized {}
#[lang = "copy"]
pub trait Copy {}
#[lang = "freeze"]
pub trait Freeze {}

impl<T: Copy, const N: usize> Copy for [T; N] {}

#[lang = "phantom_data"]
pub struct PhantomData<T: ?Sized>;
impl<T: ?Sized> Copy for PhantomData<T> {}
extern crate minicore;
use minicore::*;

#[repr(simd)]
pub struct i8x8([i8; 8]);
Expand All @@ -52,8 +37,6 @@ pub struct WrapperWithZst<T>(T, PhantomData<()>);
#[repr(transparent)]
pub struct TransparentWrapper<T>(T);

impl Copy for i8 {}
impl Copy for i64 {}
impl Copy for i8x8 {}
impl Copy for i8x16 {}
impl Copy for i8x32 {}
Expand Down Expand Up @@ -221,23 +204,23 @@ unsafe extern "C" fn vector_transparent_wrapper_ret_large(
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_arg_small(x: i8x8) -> i64 {
unsafe { *(&x as *const i8x8 as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_arg:
// CHECK: vlgvg %r2, %v24, 0
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_arg(x: i8x16) -> i64 {
unsafe { *(&x as *const i8x16 as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_arg_large:
// CHECK: lg %r2, 0(%r2)
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_arg_large(x: i8x32) -> i64 {
unsafe { *(&x as *const i8x32 as *const i64) }
unsafe { *(&raw const x as *const i64) }
}

// CHECK-LABEL: vector_wrapper_arg_small:
Expand All @@ -246,23 +229,23 @@ unsafe extern "C" fn vector_arg_large(x: i8x32) -> i64 {
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
unsafe { *(&x as *const Wrapper<i8x8> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_wrapper_arg:
// CHECK: vlgvg %r2, %v24, 0
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
unsafe { *(&x as *const Wrapper<i8x16> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_wrapper_arg_large:
// CHECK: lg %r2, 0(%r2)
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_wrapper_arg_large(x: Wrapper<i8x32>) -> i64 {
unsafe { *(&x as *const Wrapper<i8x32> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}

// https://github.com/rust-lang/rust/pull/131586#discussion_r1837071121
Expand All @@ -272,7 +255,7 @@ unsafe extern "C" fn vector_wrapper_arg_large(x: Wrapper<i8x32>) -> i64 {
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_wrapper_padding_arg(x: WrapperAlign16<i8x8>) -> i64 {
unsafe { *(&x as *const WrapperAlign16<i8x8> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}

// CHECK-LABEL: vector_wrapper_with_zst_arg_small:
Expand All @@ -282,23 +265,23 @@ unsafe extern "C" fn vector_wrapper_padding_arg(x: WrapperAlign16<i8x8>) -> i64
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_wrapper_with_zst_arg_small(x: WrapperWithZst<i8x8>) -> i64 {
unsafe { *(&x as *const WrapperWithZst<i8x8> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_wrapper_with_zst_arg:
// CHECK: lg %r2, 0(%r2)
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_wrapper_with_zst_arg(x: WrapperWithZst<i8x16>) -> i64 {
unsafe { *(&x as *const WrapperWithZst<i8x16> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_wrapper_with_zst_arg_large:
// CHECK: lg %r2, 0(%r2)
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_wrapper_with_zst_arg_large(x: WrapperWithZst<i8x32>) -> i64 {
unsafe { *(&x as *const WrapperWithZst<i8x32> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}

// CHECK-LABEL: vector_transparent_wrapper_arg_small:
Expand All @@ -307,21 +290,21 @@ unsafe extern "C" fn vector_wrapper_with_zst_arg_large(x: WrapperWithZst<i8x32>)
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
unsafe { *(&x as *const TransparentWrapper<i8x8> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_transparent_wrapper_arg:
// CHECK: vlgvg %r2, %v24, 0
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
unsafe { *(&x as *const TransparentWrapper<i8x16> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
// CHECK-LABEL: vector_transparent_wrapper_arg_large:
// CHECK: lg %r2, 0(%r2)
// CHECK-NEXT: br %r14
#[cfg_attr(no_vector, target_feature(enable = "vector"))]
#[no_mangle]
unsafe extern "C" fn vector_transparent_wrapper_arg_large(x: TransparentWrapper<i8x32>) -> i64 {
unsafe { *(&x as *const TransparentWrapper<i8x32> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
38 changes: 21 additions & 17 deletions tests/codegen-llvm/s390x-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#![crate_type = "rlib"]
#![feature(no_core, asm_experimental_arch)]
#![feature(s390x_target_feature, simd_ffi, link_llvm_intrinsics, repr_simd)]
#![feature(s390x_target_feature, simd_ffi, intrinsics, repr_simd)]
#![no_core]

extern crate minicore;
Expand All @@ -30,16 +30,20 @@ struct f32x4([f32; 4]);
#[repr(simd)]
struct f64x2([f64; 2]);

#[allow(improper_ctypes)]
extern "C" {
#[link_name = "llvm.smax.v16i8"]
fn vmxb(a: i8x16, b: i8x16) -> i8x16;
#[link_name = "llvm.smax.v8i16"]
fn vmxh(a: i16x8, b: i16x8) -> i16x8;
#[link_name = "llvm.smax.v4i32"]
fn vmxf(a: i32x4, b: i32x4) -> i32x4;
#[link_name = "llvm.smax.v2i64"]
fn vmxg(a: i64x2, b: i64x2) -> i64x2;
impl Copy for i8x16 {}
impl Copy for i16x8 {}
impl Copy for i32x4 {}
impl Copy for i64x2 {}

#[rustc_intrinsic]
unsafe fn simd_ge<T, U>(x: T, y: T) -> U;

#[rustc_intrinsic]
unsafe fn simd_select<M, V>(mask: M, a: V, b: V) -> V;

#[inline(always)]
unsafe fn simd_max<T: Copy>(a: T, b: T) -> T {
simd_select(simd_ge::<T, T>(a, b), a, b)
}

// CHECK-LABEL: define <16 x i8> @max_i8x16
Expand All @@ -48,7 +52,7 @@ extern "C" {
#[no_mangle]
#[target_feature(enable = "vector")]
pub unsafe extern "C" fn max_i8x16(a: i8x16, b: i8x16) -> i8x16 {
vmxb(a, b)
simd_max(a, b)
}

// CHECK-LABEL: define <8 x i16> @max_i16x8
Expand All @@ -57,7 +61,7 @@ pub unsafe extern "C" fn max_i8x16(a: i8x16, b: i8x16) -> i8x16 {
#[no_mangle]
#[target_feature(enable = "vector")]
pub unsafe extern "C" fn max_i16x8(a: i16x8, b: i16x8) -> i16x8 {
vmxh(a, b)
simd_max(a, b)
}

// CHECK-LABEL: define <4 x i32> @max_i32x4
Expand All @@ -66,7 +70,7 @@ pub unsafe extern "C" fn max_i16x8(a: i16x8, b: i16x8) -> i16x8 {
#[no_mangle]
#[target_feature(enable = "vector")]
pub unsafe extern "C" fn max_i32x4(a: i32x4, b: i32x4) -> i32x4 {
vmxf(a, b)
simd_max(a, b)
}

// CHECK-LABEL: define <2 x i64> @max_i64x2
Expand All @@ -75,7 +79,7 @@ pub unsafe extern "C" fn max_i32x4(a: i32x4, b: i32x4) -> i32x4 {
#[no_mangle]
#[target_feature(enable = "vector")]
pub unsafe extern "C" fn max_i64x2(a: i64x2, b: i64x2) -> i64x2 {
vmxg(a, b)
simd_max(a, b)
}

// CHECK-LABEL: define <4 x float> @choose_f32x4
Expand Down Expand Up @@ -108,7 +112,7 @@ pub unsafe extern "C" fn max_wrapper_i8x16(a: Wrapper<i8x16>, b: Wrapper<i8x16>)
// CHECK: call <16 x i8> @llvm.smax.v16i8
// CHECK-SAME: <16 x i8>
// CHECK-SAME: <16 x i8>
Wrapper(vmxb(a.0, b.0))
Wrapper(simd_max(a.0, b.0))
}

#[no_mangle]
Expand All @@ -122,7 +126,7 @@ pub unsafe extern "C" fn max_wrapper_i64x2(a: Wrapper<i64x2>, b: Wrapper<i64x2>)
// CHECK: call <2 x i64> @llvm.smax.v2i64
// CHECK-SAME: <2 x i64>
// CHECK-SAME: <2 x i64>
Wrapper(vmxg(a.0, b.0))
Wrapper(simd_max(a.0, b.0))
}

#[no_mangle]
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/abi/simd-abi-checks-s390x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,47 +110,47 @@ extern "C" fn vector_transparent_wrapper_ret_large(
#[no_mangle]
extern "C" fn vector_arg_small(x: i8x8) -> i64 {
//~^ ERROR requires the `vector` target feature, which is not enabled
unsafe { *(&x as *const i8x8 as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
#[no_mangle]
extern "C" fn vector_arg(x: i8x16) -> i64 {
//~^ ERROR requires the `vector` target feature, which is not enabled
unsafe { *(&x as *const i8x16 as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
#[no_mangle]
extern "C" fn vector_arg_large(x: i8x32) -> i64 {
// Ok
unsafe { *(&x as *const i8x32 as *const i64) }
unsafe { *(&raw const x as *const i64) }
}

#[no_mangle]
extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
//~^ ERROR requires the `vector` target feature, which is not enabled
unsafe { *(&x as *const Wrapper<i8x8> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
#[no_mangle]
extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
//~^ ERROR requires the `vector` target feature, which is not enabled
unsafe { *(&x as *const Wrapper<i8x16> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
#[no_mangle]
extern "C" fn vector_wrapper_arg_large(x: Wrapper<i8x32>) -> i64 {
// Ok
unsafe { *(&x as *const Wrapper<i8x32> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}

#[no_mangle]
extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
//~^ ERROR requires the `vector` target feature, which is not enabled
unsafe { *(&x as *const TransparentWrapper<i8x8> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
#[no_mangle]
extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
//~^ ERROR requires the `vector` target feature, which is not enabled
unsafe { *(&x as *const TransparentWrapper<i8x16> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
#[no_mangle]
extern "C" fn vector_transparent_wrapper_arg_large(x: TransparentWrapper<i8x32>) -> i64 {
// Ok
unsafe { *(&x as *const TransparentWrapper<i8x32> as *const i64) }
unsafe { *(&raw const x as *const i64) }
}
Loading