Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 509
Add basic SIMD support#523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f792e4838b9a29d80efb2209836f4dab1e35c948feFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,8 @@ | ||
| use {Rng}; | ||
| use distributions::{Distribution, Standard}; | ||
| #[cfg(feature="simd_support")] | ||
| use core::simd::*; | ||
| impl Distribution<u8> for Standard { | ||
| #[inline] | ||
| @@ -84,6 +86,39 @@ impl_int_from_uint! { i64, u64 } | ||
| #[cfg(feature = "i128_support")] impl_int_from_uint! { i128, u128 } | ||
| impl_int_from_uint! { isize, usize } | ||
| #[cfg(feature="simd_support")] | ||
| macro_rules! simd_impl { | ||
| ($bits:expr,) => {}; | ||
| ($bits:expr, $ty:ty, $($ty_more:ty,)*) => { | ||
| simd_impl!($bits, $($ty_more,)*); | ||
| impl Distribution<$ty> for Standard { | ||
| #[inline] | ||
| fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $ty { | ||
| let mut vec = Default::default(); | ||
| unsafe { | ||
| let ptr = &mut vec; | ||
| let b_ptr = &mut *(ptr as *mut $ty as *mut [u8; $bits/8]); | ||
| rng.fill_bytes(b_ptr); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look portable to me. Elsewhere we've made an effort to keep things portable; I don't think this needs to be an exception? Unfortunately it doesn't look like the SIMD types support Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that’s exactly where we’d use it | ||
| } | ||
| vec | ||
| } | ||
| } | ||
| } | ||
| } | ||
| #[cfg(feature="simd_support")] | ||
| simd_impl!(16, u8x2, i8x2,); | ||
| #[cfg(feature="simd_support")] | ||
| simd_impl!(32, u8x4, i8x4, u16x2, i16x2,); | ||
| #[cfg(feature="simd_support")] | ||
| simd_impl!(64, u8x8, i8x8, u16x4, i16x4, u32x2, i32x2,); | ||
| #[cfg(feature="simd_support")] | ||
| simd_impl!(128, u8x16, i8x16, u16x8, i16x8, u32x4, i32x4, u64x2, i64x2,); | ||
| #[cfg(feature="simd_support")] | ||
| simd_impl!(256, u8x32, i8x32, u16x16, i16x16, u32x8, i32x8, u64x4, i64x4,); | ||
| #[cfg(feature="simd_support")] | ||
| simd_impl!(512, u8x64, i8x64, u16x32, i16x32, u32x16, i32x16, u64x8, i64x8,); | ||
| #[cfg(test)] | ||
| mod tests { | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat usage of recursive macros.
But why do we need to pass
$bitshere instead of just usingmem::size_of? It seems like an unnecessary risk of underfill/overfill.