diff --git a/crates/core_arch/src/powerpc/altivec.rs b/crates/core_arch/src/powerpc/altivec.rs index 37b557c3b2..c1881da08f 100644 --- a/crates/core_arch/src/powerpc/altivec.rs +++ b/crates/core_arch/src/powerpc/altivec.rs @@ -364,15 +364,46 @@ unsafe extern "C" { fn vrfin(a: vector_float) -> vector_float; } -impl_neg! { i8x16 : 0 } -impl_neg! { i16x8 : 0 } -impl_neg! { i32x4 : 0 } -impl_neg! { f32x4 : 0f32 } - #[macro_use] mod sealed { use super::*; + #[unstable(feature = "stdarch_powerpc", issue = "111145")] + pub trait VectorNeg { + unsafe fn vec_neg(self) -> Self; + } + + macro_rules! impl_neg { + ($($v:ty)*) => { + $( + #[unstable(feature = "stdarch_powerpc", issue = "111145")] + impl VectorNeg for $v { + #[inline] + #[target_feature(enable = "altivec")] + unsafe fn vec_neg(self) -> Self { + simd_neg(self) + } + } + )* + } + } + + impl_neg! { + vector_signed_char + vector_unsigned_char + vector_bool_char + + vector_signed_short + vector_unsigned_short + vector_bool_short + + vector_signed_int + vector_unsigned_int + vector_bool_int + + vector_float + } + #[unstable(feature = "stdarch_powerpc", issue = "111145")] pub trait VectorInsert { type Scalar; @@ -1378,7 +1409,7 @@ mod sealed { #[inline] #[target_feature(enable = "altivec")] unsafe fn $name(v: s_t_l!($ty)) -> s_t_l!($ty) { - v.vec_max(-v) + v.vec_max(simd_neg(v)) } impl_vec_trait! { [VectorAbs vec_abs] $name (s_t_l!($ty)) } @@ -4030,6 +4061,14 @@ pub unsafe fn vec_mfvscr() -> vector_unsigned_short { mfvscr() } +/// Vector Negate +#[inline] +#[target_feature(enable = "altivec")] +#[unstable(feature = "stdarch_powerpc", issue = "111145")] +pub unsafe fn vec_neg(a: T) -> T { + a.vec_neg() +} + /// Vector add. #[inline] #[target_feature(enable = "altivec")] diff --git a/crates/core_arch/src/powerpc/macros.rs b/crates/core_arch/src/powerpc/macros.rs index 6097ca31ad..f697d4d257 100644 --- a/crates/core_arch/src/powerpc/macros.rs +++ b/crates/core_arch/src/powerpc/macros.rs @@ -274,20 +274,6 @@ macro_rules! t_b { }; } -macro_rules! impl_neg { - ($s: ident : $zero: expr) => { - #[unstable(feature = "stdarch_powerpc", issue = "111145")] - impl crate::ops::Neg for s_t_l!($s) { - type Output = s_t_l!($s); - #[inline] - fn neg(self) -> Self::Output { - unsafe { simd_neg(self) } - } - } - }; -} - -pub(crate) use impl_neg; pub(crate) use impl_vec_trait; pub(crate) use s_t_l; pub(crate) use t_b; diff --git a/crates/core_arch/src/s390x/macros.rs b/crates/core_arch/src/s390x/macros.rs index b72560396c..c47f242948 100644 --- a/crates/core_arch/src/s390x/macros.rs +++ b/crates/core_arch/src/s390x/macros.rs @@ -431,20 +431,6 @@ macro_rules! t_b { }; } -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); - #[inline] - fn neg(self) -> Self::Output { - unsafe { simd_neg(self) } - } - } - }; -} - -pub(crate) use impl_neg; pub(crate) use impl_vec_trait; pub(crate) use l_t_t; pub(crate) use s_t_l; diff --git a/crates/core_arch/src/s390x/vector.rs b/crates/core_arch/src/s390x/vector.rs index d63f37eeb9..97bfa32f17 100644 --- a/crates/core_arch/src/s390x/vector.rs +++ b/crates/core_arch/src/s390x/vector.rs @@ -283,13 +283,6 @@ unsafe extern "unadjusted" { #[link_name = "llvm.s390.vfenezfs"] fn vfenezfs(a: i32x4, b: i32x4) -> PackedTuple; } -impl_neg! { i8x16 : 0 } -impl_neg! { i16x8 : 0 } -impl_neg! { i32x4 : 0 } -impl_neg! { i64x2 : 0 } -impl_neg! { f32x4 : 0f32 } -impl_neg! { f64x2 : 0f64 } - #[repr(simd)] struct ShuffleMask([u32; N]); @@ -437,6 +430,43 @@ enum FindImm { mod sealed { use super::*; + #[unstable(feature = "stdarch_s390x", issue = "135681")] + pub trait VectorNeg { + unsafe fn vec_neg(self) -> Self; + } + + macro_rules! impl_neg { + ($($v:ty)*) => { + $( + #[unstable(feature = "stdarch_s390x", issue = "135681")] + impl VectorNeg for $v { + #[inline] + #[target_feature(enable = "vector")] + unsafe fn vec_neg(self) -> Self { + simd_neg(self) + } + } + )* + } + } + + impl_neg! { + vector_signed_char + vector_unsigned_char + + vector_signed_short + vector_unsigned_short + + vector_signed_int + vector_unsigned_int + + vector_signed_long_long + vector_unsigned_long_long + + vector_float + vector_double + } + #[unstable(feature = "stdarch_s390x", issue = "135681")] pub trait VectorAdd { type Result; @@ -759,7 +789,7 @@ mod sealed { #[inline] #[target_feature(enable = "vector")] unsafe fn $name(v: s_t_l!($ty)) -> s_t_l!($ty) { - v.vec_max(-v) + v.vec_max(simd_neg(v)) } impl_vec_trait! { [VectorAbs vec_abs] $name (s_t_l!($ty)) } @@ -4053,6 +4083,14 @@ unsafe fn __lcbb(ptr: *const u8) -> u32 { lcbb(ptr, const { validate_block_boundary(BLOCK_BOUNDARY) }) } +/// Vector Negate +#[inline] +#[target_feature(enable = "vector")] +#[unstable(feature = "stdarch_s390x", issue = "135681")] +pub unsafe fn vec_neg(a: T) -> T { + a.vec_neg() +} + /// Vector Add #[inline] #[target_feature(enable = "vector")]