Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e73985f

Browse files
Merge pull request rust-lang#89 from rust-lang/intrinsic-neg
Use neg intrinsics
2 parents 1c3d957 + 87b7207 commit e73985f

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

crates/core_simd/src/intrinsics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ extern "platform-intrinsic" {
4040
/// fptoui/fptosi/uitofp/sitofp
4141
pub(crate) fn simd_cast<T, U>(x: T) -> U;
4242

43+
/// neg/fneg
44+
pub(crate) fn simd_neg<T>(x: T) -> T;
45+
4346
// floor
4447
#[cfg(feature = "std")]
4548
pub(crate) fn simd_floor<T>(x: T) -> T;

crates/core_simd/src/ops.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,7 @@ macro_rules! impl_op {
185185
{
186186
type Output = Self;
187187
fn neg(self) -> Self::Output {
188-
Self::splat(0) - self
189-
}
190-
}
191-
}
192-
};
193-
194-
{ impl Neg for $type:ident, $scalar:ty, @float } => {
195-
impl_ref_ops! {
196-
impl<const LANES: usize> core::ops::Neg for crate::$type<LANES>
197-
where
198-
crate::$type<LANES>: LanesAtMost32,
199-
crate::SimdU32<LANES>: LanesAtMost32,
200-
crate::SimdU64<LANES>: LanesAtMost32,
201-
{
202-
type Output = Self;
203-
fn neg(self) -> Self::Output {
204-
// FIXME: Replace this with fneg intrinsic once available.
205-
// https://github.com/rust-lang/stdsimd/issues/32
206-
Self::from_bits(Self::splat(-0.0).to_bits() ^ self.to_bits())
188+
unsafe { crate::intrinsics::simd_neg(self) }
207189
}
208190
}
209191
}
@@ -318,7 +300,7 @@ macro_rules! impl_float_ops {
318300
impl_op! { impl Mul for $vector, $scalar }
319301
impl_op! { impl Div for $vector, $scalar }
320302
impl_op! { impl Rem for $vector, $scalar }
321-
impl_op! { impl Neg for $vector, $scalar, @float }
303+
impl_op! { impl Neg for $vector, $scalar }
322304
impl_op! { impl Index for $vector, $scalar }
323305
)*
324306
)*

0 commit comments

Comments
 (0)