Skip to content

s390x: add more intrinsics #1728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions crates/core_arch/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ macro_rules! types {
// a simd type with exactly one element.
unsafe { simd_shuffle!(one, one, [0; $len]) }
}

/// Returns an array reference containing the entire SIMD vector.
$v const fn as_array(&self) -> &[$elem_type; $len] {
// SAFETY: this type is just an overaligned `[T; N]` with
// potential padding at the end, so pointer casting to a
// `&[T; N]` is safe.
//
// NOTE: This deliberately doesn't just use `&self.0` because it may soon be banned
// see https://github.com/rust-lang/compiler-team/issues/838
unsafe { &*(self as *const Self as *const [$elem_type; $len]) }

}

/// Returns a mutable array reference containing the entire SIMD vector.
#[inline]
$v fn as_mut_array(&mut self) -> &mut [$elem_type; $len] {
// SAFETY: this type is just an overaligned `[T; N]` with
// potential padding at the end, so pointer casting to a
// `&mut [T; N]` is safe.
//
// NOTE: This deliberately doesn't just use `&mut self.0` because it may soon be banned
// see https://github.com/rust-lang/compiler-team/issues/838
unsafe { &mut *(self as *mut Self as *mut [$elem_type; $len]) }
}
}

$(#[$stability])+
Expand Down
51 changes: 48 additions & 3 deletions crates/core_arch/src/s390x/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ macro_rules! impl_vec_trait {
}
}
};
([$Trait:ident $m:ident]+ $fun:ident ($a:ty)) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl $Trait for $a {
#[inline]
#[target_feature(enable = "vector")]
unsafe fn $m(self) -> Self {
transmute($fun(transmute(self)))
}
}
};
([$Trait:ident $m:ident] $fun:ident ($a:ty) -> $r:ty) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl $Trait for $a {
Expand Down Expand Up @@ -213,6 +223,41 @@ macro_rules! s_t_l {
};
}

macro_rules! l_t_t {
(vector_signed_long_long) => {
i64
};
(vector_signed_int) => {
i32
};
(vector_signed_short) => {
i16
};
(vector_signed_char) => {
i8
};

(vector_unsigned_long_long ) => {
u64
};
(vector_unsigned_int ) => {
u32
};
(vector_unsigned_short ) => {
u16
};
(vector_unsigned_char ) => {
u8
};

(vector_float) => {
f32
};
(vector_double) => {
f64
};
}

macro_rules! t_t_l {
(i64) => {
vector_signed_long_long
Expand Down Expand Up @@ -315,7 +360,7 @@ macro_rules! t_u {
vector_unsigned_int
};
(vector_signed_long_long) => {
vector_signed_long_long
vector_unsigned_long_long
};
(vector_float) => {
vector_unsigned_int
Expand Down Expand Up @@ -391,8 +436,7 @@ macro_rules! impl_neg {
impl crate::ops::Neg for s_t_l!($s) {
type Output = s_t_l!($s);
fn neg(self) -> Self::Output {
let zero = $s::splat($zero);
unsafe { transmute(simd_sub(zero, transmute(self))) }
unsafe { simd_neg(self) }
}
}
};
Expand All @@ -401,6 +445,7 @@ macro_rules! impl_neg {
pub(crate) use impl_from;
pub(crate) use impl_neg;
pub(crate) use impl_vec_trait;
pub(crate) use l_t_t;
pub(crate) use s_t_l;
pub(crate) use t_b;
pub(crate) use t_t_l;
Expand Down
Loading