Skip to content

Commit

Permalink
implement VectorAdd for s390x
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev authored and Amanieu committed Jan 20, 2025
1 parent 6aa8f49 commit cf10e91
Show file tree
Hide file tree
Showing 5 changed files with 518 additions and 9 deletions.
4 changes: 0 additions & 4 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ case ${TARGET} in
export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+msa"
cargo_test "${PROFILE}"
;;
s390x*)
export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+vector"
cargo_test "${PROFILE}"
;;
powerpc64*)
# We don't build the ppc 32-bit targets with these - these targets
# are mostly unsupported for now.
Expand Down
2 changes: 1 addition & 1 deletion crates/core_arch/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub mod arch {
/// See the [module documentation](../index.html) for more details.
#[cfg(any(target_arch = "s390x", doc))]
#[doc(cfg(target_arch = "s390x"))]
#[unstable(feature = "stdarch_s390x", issue = "1")]
#[unstable(feature = "stdarch_s390x", issue = "135681")]
pub mod s390x {
pub use crate::core_arch::s390x::*;
}
Expand Down
354 changes: 354 additions & 0 deletions crates/core_arch/src/s390x/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
#![allow(unused_macros)] // FIXME remove when more tests are added
#![allow(unused_imports)] // FIXME remove when more tests are added

macro_rules! test_impl {
($fun:ident ($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $instr:ident]) => {
#[inline]
#[target_feature(enable = "vector")]
#[cfg_attr(test, assert_instr($instr))]
pub unsafe fn $fun ($($v : $ty),*) -> $r {
$call ($($v),*)
}
};
}

#[allow(unknown_lints, unused_macro_rules)]
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 {
$fun(transmute(self))
}
}
};
([$Trait:ident $m:ident] $fun:ident ($a:ty) -> $r:ty) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl $Trait for $a {
type Result = $r;
#[inline]
#[target_feature(enable = "vector")]
unsafe fn $m(self) -> Self::Result {
$fun(transmute(self))
}
}
};
([$Trait:ident $m:ident]+ $fun:ident ($a:ty) -> $r:ty) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl $Trait for $a {
type Result = $r;
#[inline]
#[target_feature(enable = "vector")]
unsafe fn $m(self) -> Self::Result {
transmute($fun(transmute(self)))
}
}
};
([$Trait:ident $m:ident] 1 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident, $sf: ident)) => {
impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char) -> vector_unsigned_char }
impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char) -> vector_signed_char }
impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short) -> vector_unsigned_short }
impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short) -> vector_signed_short }
impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int) -> vector_unsigned_int }
impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int) -> vector_signed_int }
impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_long_long) -> vector_unsigned_long_long }
impl_vec_trait!{ [$Trait $m] $sw (vector_signed_long_long) -> vector_signed_long_long }
impl_vec_trait!{ [$Trait $m] $sf (vector_float) -> vector_float }
impl_vec_trait!{ [$Trait $m] $sf (vector_double) -> vector_double }
};
([$Trait:ident $m:ident] $fun:ident ($a:ty, $b:ty) -> $r:ty) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl $Trait<$b> for $a {
type Result = $r;
#[inline]
#[target_feature(enable = "vector")]
unsafe fn $m(self, b: $b) -> Self::Result {
$fun(transmute(self), transmute(b))
}
}
};
([$Trait:ident $m:ident]+ $fun:ident ($a:ty, $b:ty) -> $r:ty) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl $Trait<$b> for $a {
type Result = $r;
#[inline]
#[target_feature(enable = "vector")]
unsafe fn $m(self, b: $b) -> Self::Result {
transmute($fun(transmute(self), transmute(b)))
}
}
};
([$Trait:ident $m:ident] $fun:ident ($a:ty, ~$b:ty) -> $r:ty) => {
impl_vec_trait!{ [$Trait $m] $fun ($a, $a) -> $r }
impl_vec_trait!{ [$Trait $m] $fun ($a, $b) -> $r }
impl_vec_trait!{ [$Trait $m] $fun ($b, $a) -> $r }
};
([$Trait:ident $m:ident] ~($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident)) => {
impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char, ~vector_bool_char) -> vector_unsigned_char }
impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char, ~vector_bool_char) -> vector_signed_char }
impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short, ~vector_bool_short) -> vector_unsigned_short }
impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short, ~vector_bool_short) -> vector_signed_short }
impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int, ~vector_bool_int) -> vector_unsigned_int }
impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int, ~vector_bool_int) -> vector_signed_int }
};
([$Trait:ident $m:ident] ~($fn:ident)) => {
impl_vec_trait!{ [$Trait $m] ~($fn, $fn, $fn, $fn, $fn, $fn) }
};
([$Trait:ident $m:ident] 2 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident)) => {
impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char, vector_signed_char) -> vector_signed_char }
impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short, vector_signed_short) -> vector_signed_short }
impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int, vector_signed_int) -> vector_signed_int }
};
([$Trait:ident $m:ident] 2 ($fn:ident)) => {
impl_vec_trait!{ [$Trait $m] ($fn, $fn, $fn, $fn, $fn, $fn) }
};
([$Trait:ident $m:ident]+ 2b ($b:ident, $h:ident, $w:ident)) => {
impl_vec_trait!{ [$Trait $m]+ $b (vector_bool_char, vector_bool_char) -> vector_bool_char }
impl_vec_trait!{ [$Trait $m]+ $b (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
impl_vec_trait!{ [$Trait $m]+ $b (vector_signed_char, vector_signed_char) -> vector_signed_char }
impl_vec_trait!{ [$Trait $m]+ $h (vector_bool_short, vector_bool_short) -> vector_bool_short }
impl_vec_trait!{ [$Trait $m]+ $h (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
impl_vec_trait!{ [$Trait $m]+ $h (vector_signed_short, vector_signed_short) -> vector_signed_short }
impl_vec_trait!{ [$Trait $m]+ $w (vector_bool_int, vector_bool_int) -> vector_bool_int }
impl_vec_trait!{ [$Trait $m]+ $w (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
impl_vec_trait!{ [$Trait $m]+ $w (vector_signed_int, vector_signed_int) -> vector_signed_int }
};
([$Trait:ident $m:ident]+ 2b ($fn:ident)) => {
impl_vec_trait!{ [$Trait $m]+ 2b ($fn, $fn, $fn) }
};
}

macro_rules! s_t_l {
(i64x2) => {
vector_signed_long_long
};
(i32x4) => {
vector_signed_int
};
(i16x8) => {
vector_signed_short
};
(i8x16) => {
vector_signed_char
};

(u64x2) => {
vector_unsigned_long_long
};
(u32x4) => {
vector_unsigned_int
};
(u16x8) => {
vector_unsigned_short
};
(u8x16) => {
vector_unsigned_char
};

(f32x4) => {
vector_float
};
(f64x2) => {
vector_double
};
}

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

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

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

macro_rules! t_t_s {
(i64) => {
i64x2
};
(i32) => {
i32x4
};
(i16) => {
i16x8
};
(i8) => {
i8x16
};

(u64) => {
u64x2
};
(u32) => {
u32x4
};
(u16) => {
u16x8
};
(u8) => {
u8x16
};

(f32) => {
f32x4
};
(f64) => {
f64x2
};
}

macro_rules! t_u {
(vector_bool_char) => {
vector_unsigned_char
};
(vector_bool_short) => {
vector_unsigned_short
};
(vector_bool_int) => {
vector_unsigned_int
};
(vector_unsigned_char) => {
vector_unsigned_char
};
(vector_unsigned_short) => {
vector_unsigned_short
};
(vector_unsigned_int) => {
vector_unsigned_int
};
(vector_unsigned_long_long) => {
vector_unsigned_long_long
};
(vector_signed_char) => {
vector_unsigned_char
};
(vector_signed_short) => {
vector_unsigned_short
};
(vector_signed_int) => {
vector_unsigned_int
};
(vector_signed_long_long) => {
vector_signed_long_long
};
(vector_float) => {
vector_unsigned_int
};
(vector_double) => {
vector_unsigned_long_long
};
}

macro_rules! t_b {
(vector_bool_char) => {
vector_bool_char
};
(vector_bool_short) => {
vector_bool_short
};
(vector_bool_int) => {
vector_bool_int
};
(vector_signed_char) => {
vector_bool_char
};
(vector_signed_short) => {
vector_bool_short
};
(vector_signed_int) => {
vector_bool_int
};
(vector_signed_long_long) => {
vector_bool_long_long
};
(vector_unsigned_char) => {
vector_bool_char
};
(vector_unsigned_short) => {
vector_bool_short
};
(vector_unsigned_int) => {
vector_bool_int
};
(vector_unsigned_long_long) => {
vector_bool_long_long
};
(vector_float) => {
vector_bool_int
};
(vector_double) => {
vector_bool_long_long
};
}

macro_rules! impl_from {
($s: ident) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl From<$s> for s_t_l!($s) {
fn from (v: $s) -> Self {
unsafe {
transmute(v)
}
}
}
};
($($s: ident),*) => {
$(
impl_from! { $s }
)*
};
}

macro_rules! impl_neg {
($s: ident : $zero: expr) => {
#[unstable(feature = "stdarch_s390x", issue = "135681")]
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))) }
}
}
};
}

pub(crate) use impl_from;
pub(crate) use impl_neg;
pub(crate) use impl_vec_trait;
pub(crate) use s_t_l;
pub(crate) use t_b;
pub(crate) use t_t_l;
pub(crate) use t_t_s;
pub(crate) use t_u;
pub(crate) use test_impl;
4 changes: 3 additions & 1 deletion crates/core_arch/src/s390x/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! `SystemZ` intrinsics
//! `s390x` intrinsics
pub(crate) mod macros;

mod vector;
#[unstable(feature = "stdarch_s390x", issue = "130869")]
Expand Down
Loading

0 comments on commit cf10e91

Please sign in to comment.