diff --git a/crates/core_simd/src/intrinsics.rs b/crates/core_simd/src/intrinsics.rs index fafeed6a62a..4f89d00deb2 100644 --- a/crates/core_simd/src/intrinsics.rs +++ b/crates/core_simd/src/intrinsics.rs @@ -40,6 +40,9 @@ extern "platform-intrinsic" { /// fptoui/fptosi/uitofp/sitofp pub(crate) fn simd_cast(x: T) -> U; + /// neg/fneg + pub(crate) fn simd_neg(x: T) -> T; + // floor #[cfg(feature = "std")] pub(crate) fn simd_floor(x: T) -> T; diff --git a/crates/core_simd/src/ops.rs b/crates/core_simd/src/ops.rs index 12d675a0640..513eeb423d9 100644 --- a/crates/core_simd/src/ops.rs +++ b/crates/core_simd/src/ops.rs @@ -185,25 +185,7 @@ macro_rules! impl_op { { type Output = Self; fn neg(self) -> Self::Output { - Self::splat(0) - self - } - } - } - }; - - { impl Neg for $type:ident, $scalar:ty, @float } => { - impl_ref_ops! { - impl core::ops::Neg for crate::$type - where - crate::$type: LanesAtMost32, - crate::SimdU32: LanesAtMost32, - crate::SimdU64: LanesAtMost32, - { - type Output = Self; - fn neg(self) -> Self::Output { - // FIXME: Replace this with fneg intrinsic once available. - // https://github.com/rust-lang/stdsimd/issues/32 - Self::from_bits(Self::splat(-0.0).to_bits() ^ self.to_bits()) + unsafe { crate::intrinsics::simd_neg(self) } } } } @@ -318,7 +300,7 @@ macro_rules! impl_float_ops { impl_op! { impl Mul for $vector, $scalar } impl_op! { impl Div for $vector, $scalar } impl_op! { impl Rem for $vector, $scalar } - impl_op! { impl Neg for $vector, $scalar, @float } + impl_op! { impl Neg for $vector, $scalar } impl_op! { impl Index for $vector, $scalar } )* )*