From 4c48771da2f64489426a8cbebadf9aa6aac601ed Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Sat, 22 Feb 2025 19:40:02 +0100 Subject: [PATCH] add `vec_nabs` --- .../crates/core_arch/src/s390x/macros.rs | 3 +- .../crates/core_arch/src/s390x/vector.rs | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/library/stdarch/crates/core_arch/src/s390x/macros.rs b/library/stdarch/crates/core_arch/src/s390x/macros.rs index 565465c348fe..2c40fedae24f 100644 --- a/library/stdarch/crates/core_arch/src/s390x/macros.rs +++ b/library/stdarch/crates/core_arch/src/s390x/macros.rs @@ -436,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) } } } }; diff --git a/library/stdarch/crates/core_arch/src/s390x/vector.rs b/library/stdarch/crates/core_arch/src/s390x/vector.rs index 27153ae9ae90..22e0eb5ec997 100644 --- a/library/stdarch/crates/core_arch/src/s390x/vector.rs +++ b/library/stdarch/crates/core_arch/src/s390x/vector.rs @@ -506,6 +506,31 @@ mod sealed { impl_vec_trait! { [VectorAbs vec_abs] vec_abs_f32 (vector_float) } impl_vec_trait! { [VectorAbs vec_abs] vec_abs_f64 (vector_double) } + #[unstable(feature = "stdarch_s390x", issue = "135681")] + pub trait VectorNabs { + unsafe fn vec_nabs(self) -> Self; + } + + #[inline] + #[target_feature(enable = "vector")] + #[cfg_attr( + all(test, target_feature = "vector-enhancements-1"), + assert_instr(vflnsb) + )] + unsafe fn vec_nabs_f32(a: vector_float) -> vector_float { + simd_neg(simd_fabs(a)) + } + + #[inline] + #[target_feature(enable = "vector")] + #[cfg_attr(test, assert_instr(vflndb))] + unsafe fn vec_nabs_f64(a: vector_double) -> vector_double { + simd_neg(simd_fabs(a)) + } + + impl_vec_trait! { [VectorNabs vec_nabs] vec_nabs_f32 (vector_float) } + impl_vec_trait! { [VectorNabs vec_nabs] vec_nabs_f64 (vector_double) } + #[unstable(feature = "stdarch_s390x", issue = "135681")] pub trait VectorSplats { unsafe fn vec_splats(self) -> Output; @@ -1528,6 +1553,17 @@ where a.vec_abs() } +/// Vector negative abs. +#[inline] +#[target_feature(enable = "vector")] +#[unstable(feature = "stdarch_s390x", issue = "135681")] +pub unsafe fn vec_nabs(a: T) -> T +where + T: sealed::VectorNabs, +{ + a.vec_nabs() +} + /// Vector splats. #[inline] #[target_feature(enable = "vector")] @@ -2351,6 +2387,10 @@ mod tests { test_vec_abs! { test_vec_abs_f32, f32x4, -42f32, 42f32 } test_vec_abs! { test_vec_abs_f64, f64x2, -42f64, 42f64 } + test_vec_1! { test_vec_nabs, vec_nabs, f32x4, + [core::f32::consts::PI, 1.0, 0.0, -1.0], + [-core::f32::consts::PI, -1.0, 0.0, -1.0] } + test_vec_2! { test_vec_andc, vec_andc, i32x4, [0b11001100, 0b11001100, 0b11001100, 0b11001100], [0b00110011, 0b11110011, 0b00001100, 0b10000000],