Skip to content

Commit

Permalink
Merge pull request #95 from crabm4n/crab/core_intrinsics
Browse files Browse the repository at this point in the history
Fix compatibility with latest nightly toolchain version
  • Loading branch information
yoanlcq authored May 13, 2024
2 parents 64d613b + 23a8a82 commit 5894cc5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 186 deletions.
8 changes: 1 addition & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#![cfg_attr(all(nightly, feature = "clippy"), plugin(clippy))]
//#![cfg_attr(all(nightly, feature="repr_simd" ), feature(cfg_target_feature))]
#![cfg_attr(all(nightly, feature = "repr_simd"), feature(repr_simd, simd_ffi))]
#![cfg_attr(all(nightly, feature = "platform_intrinsics"), feature(platform_intrinsics))]
#![cfg_attr(all(nightly, feature = "platform_intrinsics"), feature(portable_simd, core_intrinsics))]
//#![cfg_attr(feature="repr_simd", allow(improper_ctypes)]
//#![cfg_attr(feature="repr_simd", feature(link_llvm_intrinsics)]
#![cfg_attr(all(nightly, test), feature(test))]
Expand Down Expand Up @@ -72,10 +72,6 @@ pub extern crate num_traits;
#[macro_use]
pub extern crate approx;

#[cfg(feature = "platform_intrinsics")]
mod simd_llvm;
// ^ Please do not make this module public; we don't want people to use it, because it could change as the SIMD infrastructure evolves.

pub mod ops;
pub use crate::ops::*;
pub mod vec;
Expand All @@ -92,5 +88,3 @@ pub mod bezier;
pub use crate::bezier::*;
pub mod geom;
pub use crate::geom::*;
pub mod simd_traits;
pub use crate::simd_traits::*;
96 changes: 0 additions & 96 deletions src/simd_llvm.rs

This file was deleted.

57 changes: 0 additions & 57 deletions src/simd_traits.rs

This file was deleted.

61 changes: 35 additions & 26 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ use std::cmp;
use std::ops::*;
use std::slice::{self, /*SliceIndex*/}; // NOTE: Will want to use SliceIndex once it's stabilized
use std::num::Wrapping;
#[cfg(feature = "platform_intrinsics")]
use std::simd::SimdElement;
use num_traits::{Zero, One, NumCast, AsPrimitive, Signed, real::Real};
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
use crate::ops::*;
use crate::simd_traits::{SimdElement, SimdMask};

#[cfg(feature = "platform_intrinsics")]
use crate::simd_llvm;

#[cfg(feature = "bytemuck")]
use crate::bytemuck;
Expand Down Expand Up @@ -87,13 +85,24 @@ macro_rules! vec_impl_cmp {
}}
}
$(#[$attrs])*
#[cfg(feature = "platform_intrinsics")]
#[inline]
pub fn $cmp_simd(self, rhs: Self) -> $Vec<T::SimdMaskType> where T: $Bounds + SimdElement {
pub fn $cmp_simd(self, rhs: Self) -> $Vec<T::Mask>
where
T: $Bounds + SimdElement,
<T as SimdElement>::Mask: num_traits::cast::FromPrimitive {
choose!{$c_or_simd {
c => $Vec::new($(T::SimdMaskType::from_bool(self.$get $op rhs.$get)),+),
simd_llvm => unsafe { simd_llvm::$simd_cmp(self, rhs) },
c => $Vec::new($(<T::Mask as num_traits::cast::FromPrimitive>::from_u8((self.$get $op rhs.$get) as _).unwrap()),+),
simd_llvm => unsafe { std::intrinsics::simd::$simd_cmp(self, rhs) },
}}
}

$(#[$attrs])*
#[cfg(not(feature = "platform_intrinsics"))]
#[inline]
pub fn $cmp_simd(self, rhs: Self) -> $Vec<bool> where T: $Bounds {
self.$cmp(&rhs)
}
}
}

Expand Down Expand Up @@ -167,7 +176,7 @@ macro_rules! vec_impl_binop {
let rhs = rhs.into();
choose!{$c_or_simd {
c => $Vec::new($(self.$get.$op(rhs.$get)),+),
simd_llvm => unsafe { simd_llvm::$simd_op(self, rhs) },
simd_llvm => unsafe { std::intrinsics::simd::$simd_op(self, rhs) },
}}
}
}
Expand Down Expand Up @@ -273,7 +282,7 @@ macro_rules! vec_impl_reduce_bool_ops_for_primitive {
pub fn reduce_and(self) -> bool {
choose!{$c_or_simd {
c => reduce_binop!(&&, $(!self.$get.is_zero()),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_all(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_all(self) },
}}
}
/// Returns the result of logical OR (`||`) on all elements of this vector.
Expand All @@ -288,7 +297,7 @@ macro_rules! vec_impl_reduce_bool_ops_for_primitive {
pub fn reduce_or(self) -> bool {
choose!{$c_or_simd {
c => reduce_binop!(||, $(!self.$get.is_zero()),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_any(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_any(self) },
}}
}
}
Expand Down Expand Up @@ -668,7 +677,7 @@ macro_rules! vec_impl_vec {
pub fn as_<D>(self) -> $Vec<D> where T: AsPrimitive<D>, D: 'static + Copy {
choose!{$c_or_simd {
c => $Vec::new($(self.$get.as_()),+),
simd_llvm => unsafe { simd_llvm::simd_cast(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_cast(self) },
}}
}
/// Returns a memberwise-converted copy of this vector, using `NumCast`.
Expand Down Expand Up @@ -712,7 +721,7 @@ macro_rules! vec_impl_vec {
let add = add.into();
choose!{$c_or_simd {
c => $Vec::new($(self.$get.mul_add(mul.$get, add.$get)),+),
simd_llvm => unsafe { simd_llvm::simd_fma(self, mul, add) },
simd_llvm => unsafe { std::intrinsics::simd::simd_fma(self, mul, add) },
}}
}

Expand Down Expand Up @@ -803,7 +812,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_min(self) -> T where T: Ord {
choose!{$c_or_simd {
c => reduce_fn!(cmp::min, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_min(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_min(self) },
}}
}
/// Returns the element which has the highest value in this vector, using total
Expand All @@ -817,7 +826,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_max(self) -> T where T: Ord {
choose!{$c_or_simd {
c => reduce_fn!(cmp::max, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_max(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_max(self) },
}}
}

Expand All @@ -832,7 +841,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_partial_min(self) -> T where T: PartialOrd {
choose!{$c_or_simd {
c => reduce_fn!(partial_min, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_min(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_min(self) },
}}
}
/// Returns the element which has the highest value in this vector, using partial
Expand All @@ -846,7 +855,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_partial_max(self) -> T where T: PartialOrd {
choose!{$c_or_simd {
c => reduce_fn!(partial_max, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_max(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_max(self) },
}}
}

Expand All @@ -862,7 +871,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_bitand(self) -> T where T: BitAnd<T, Output=T> {
choose!{$c_or_simd {
c => reduce_binop!(&, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_and(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_and(self) },
}}
}

Expand All @@ -877,7 +886,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_bitor(self) -> T where T: BitOr<T, Output=T> {
choose!{$c_or_simd {
c => reduce_binop!(|, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_or(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_or(self) },
}}
}

Expand All @@ -892,7 +901,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_bitxor(self) -> T where T: BitXor<T, Output=T> {
choose!{$c_or_simd {
c => reduce_binop!(^, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_xor(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_xor(self) },
}}
}

Expand All @@ -912,7 +921,7 @@ macro_rules! vec_impl_vec {
pub fn product(self) -> T where T: Mul<Output=T> {
choose!{$c_or_simd {
c => reduce_binop!(*, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_mul_unordered(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_mul_unordered(self) },
}}
}
/// Returns the sum of each of this vector's elements.
Expand All @@ -925,7 +934,7 @@ macro_rules! vec_impl_vec {
pub fn sum(self) -> T where T: Add<T, Output=T> {
choose!{$c_or_simd {
c => reduce_binop!(+, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_add_unordered(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_add_unordered(self) },
}}
}
/// Returns the average of this vector's elements.
Expand Down Expand Up @@ -980,7 +989,7 @@ macro_rules! vec_impl_vec {
pub fn sqrt(self) -> Self where T: Real {
choose!{$c_or_simd {
c => Self::new($(self.$get.sqrt()),+),
simd_llvm => unsafe { simd_llvm::simd_fsqrt(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_fsqrt(self) },
}}
}

Expand Down Expand Up @@ -1022,7 +1031,7 @@ macro_rules! vec_impl_vec {
pub fn ceil(self) -> Self where T: Real {
choose!{$c_or_simd {
c => Self::new($(self.$get.ceil()),+),
simd_llvm => unsafe { simd_llvm::simd_ceil(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_ceil(self) },
}}
}
/// Returns a new vector which elements are rounded down to the nearest lower integer.
Expand All @@ -1036,7 +1045,7 @@ macro_rules! vec_impl_vec {
pub fn floor(self) -> Self where T: Real {
choose!{$c_or_simd {
c => Self::new($(self.$get.floor()),+),
simd_llvm => unsafe { simd_llvm::simd_floor(self) },
simd_llvm => unsafe { std::intrinsics::simd::simd_floor(self) },
}}
}
/// Returns a new vector which elements are rounded to the nearest integer.
Expand Down Expand Up @@ -1645,7 +1654,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_and(self) -> bool {
choose!{$c_or_simd {
c => reduce_binop!(&&, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_all(self.into_native_simd_integer_vector()) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_all(self.into_native_simd_integer_vector()) },
}}
}
/// Returns the result of logical OR (`||`) on all elements of this vector.
Expand All @@ -1659,7 +1668,7 @@ macro_rules! vec_impl_vec {
pub fn reduce_or(self) -> bool {
choose!{$c_or_simd {
c => reduce_binop!(||, $(self.$get),+),
simd_llvm => unsafe { simd_llvm::simd_reduce_any(self.into_native_simd_integer_vector()) },
simd_llvm => unsafe { std::intrinsics::simd::simd_reduce_any(self.into_native_simd_integer_vector()) },
}}
}
/// Reduces this vector using total inequality.
Expand Down

0 comments on commit 5894cc5

Please sign in to comment.