Merge pull request #89 from rust-lang/intrinsic-neg

Use neg intrinsics
This commit is contained in:
Caleb Zulawski 2021-04-16 21:35:11 -04:00 committed by GitHub
commit e73985f25d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 20 deletions

View file

@ -40,6 +40,9 @@ extern "platform-intrinsic" {
/// fptoui/fptosi/uitofp/sitofp
pub(crate) fn simd_cast<T, U>(x: T) -> U;
/// neg/fneg
pub(crate) fn simd_neg<T>(x: T) -> T;
// floor
#[cfg(feature = "std")]
pub(crate) fn simd_floor<T>(x: T) -> T;

View file

@ -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<const LANES: usize> core::ops::Neg for crate::$type<LANES>
where
crate::$type<LANES>: LanesAtMost32,
crate::SimdU32<LANES>: LanesAtMost32,
crate::SimdU64<LANES>: 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 }
)*
)*