Skip to content

Commit 4571723

Browse files
committed
Depend on packed_simd
1 parent d162a5e commit 4571723

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ nightly = ["i128_support", "simd_support"] # enables all features requiring nigh
2323
std = ["rand_core/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-zircon"]
2424
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
2525
i128_support = [] # enables i128 and u128 support
26-
simd_support = [] # enables SIMD support
26+
simd_support = ["packed_simd"] # enables SIMD support
2727
serde1 = ["serde", "serde_derive", "rand_core/serde1"] # enables serialization for PRNGs
2828

2929
[workspace]
@@ -34,6 +34,7 @@ rand_core = { path = "rand_core", version = "0.2", default-features = false }
3434
# only for deprecations and benches:
3535
rand_isaac = { path = "rand_isaac", version = "0.1", default-features = false }
3636
log = { version = "0.4", optional = true }
37+
packed_simd = { git = "https://github.com/gnzlbg/packed_simd", optional = true, features = ["into_bits"] }
3738
serde = { version = "1", optional = true }
3839
serde_derive = { version = "1", optional = true }
3940

src/distributions/float.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use Rng;
1515
use distributions::{Distribution, Standard};
1616
use distributions::utils::FloatSIMDUtils;
1717
#[cfg(feature="simd_support")]
18-
use core::simd::*;
18+
use packed_simd::*;
1919

2020
/// A distribution to sample floating point numbers uniformly in the half-open
2121
/// interval `(0, 1]`, i.e. including 1 but not 0.
@@ -106,7 +106,7 @@ macro_rules! float_impls {
106106
// Multiply-based method; 24/53 random bits; [0, 1) interval.
107107
// We use the most significant bits because for simple RNGs
108108
// those are usually more random.
109-
let float_size = mem::size_of::<$f_scalar>() * 8;
109+
let float_size = mem::size_of::<$f_scalar>() as u32 * 8;
110110
let precision = $fraction_bits + 1;
111111
let scale = 1.0 / ((1 as $u_scalar << precision) as $f_scalar);
112112

@@ -121,7 +121,7 @@ macro_rules! float_impls {
121121
// Multiply-based method; 24/53 random bits; (0, 1] interval.
122122
// We use the most significant bits because for simple RNGs
123123
// those are usually more random.
124-
let float_size = mem::size_of::<$f_scalar>() * 8;
124+
let float_size = mem::size_of::<$f_scalar>() as u32 * 8;
125125
let precision = $fraction_bits + 1;
126126
let scale = 1.0 / ((1 as $u_scalar << precision) as $f_scalar);
127127

@@ -138,7 +138,7 @@ macro_rules! float_impls {
138138
// We use the most significant bits because for simple RNGs
139139
// those are usually more random.
140140
use core::$f_scalar::EPSILON;
141-
let float_size = mem::size_of::<$f_scalar>() * 8;
141+
let float_size = mem::size_of::<$f_scalar>() as u32 * 8;
142142

143143
let value: $uty = rng.gen();
144144
let fraction = value >> (float_size - $fraction_bits);

src/distributions/integer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use {Rng};
1414
use distributions::{Distribution, Standard};
1515
#[cfg(feature="simd_support")]
16-
use core::simd::*;
16+
use packed_simd::*;
1717

1818
impl Distribution<u8> for Standard {
1919
#[inline]

src/distributions/uniform.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ use distributions::utils::Float;
124124

125125

126126
#[cfg(feature="simd_support")]
127-
use core::simd::*;
127+
use packed_simd::*;
128128

129129
/// Sample values uniformly between two bounds.
130130
///
@@ -571,7 +571,7 @@ macro_rules! uniform_float_impl {
571571

572572
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
573573
// Generate a value in the range [1, 2)
574-
let value1_2 = (rng.gen::<$uty>() >> $bits_to_discard as u8)
574+
let value1_2 = (rng.gen::<$uty>() >> $bits_to_discard)
575575
.into_float_with_exponent(0);
576576

577577
// Get a value in the range [0, 1) in order to avoid
@@ -600,7 +600,7 @@ macro_rules! uniform_float_impl {
600600

601601
loop {
602602
// Generate a value in the range [1, 2)
603-
let value1_2 = (rng.gen::<$uty>() >> $bits_to_discard as u32)
603+
let value1_2 = (rng.gen::<$uty>() >> $bits_to_discard)
604604
.into_float_with_exponent(0);
605605

606606
// Get a value in the range [0, 1) in order to avoid

src/distributions/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! Math helper functions
1212
1313
#[cfg(feature="simd_support")]
14-
use core::simd::*;
14+
use packed_simd::*;
1515
#[cfg(feature="std")]
1616
use distributions::ziggurat_tables;
1717
#[cfg(feature="std")]
@@ -271,10 +271,10 @@ macro_rules! simd_impl {
271271
#[cfg(feature="simd_support")] simd_impl! { f32x2, f32, m32x2, u32x2 }
272272
#[cfg(feature="simd_support")] simd_impl! { f32x4, f32, m32x4, u32x4 }
273273
#[cfg(feature="simd_support")] simd_impl! { f32x8, f32, m32x8, u32x8 }
274-
#[cfg(feature="simd_support")] simd_impl! { f32x16, f32, m1x16, u32x16 }
274+
#[cfg(feature="simd_support")] simd_impl! { f32x16, f32, m32x16, u32x16 }
275275
#[cfg(feature="simd_support")] simd_impl! { f64x2, f64, m64x2, u64x2 }
276276
#[cfg(feature="simd_support")] simd_impl! { f64x4, f64, m64x4, u64x4 }
277-
#[cfg(feature="simd_support")] simd_impl! { f64x8, f64, m1x8, u64x8 }
277+
#[cfg(feature="simd_support")] simd_impl! { f64x8, f64, m64x8, u64x8 }
278278

279279
/// Calculates ln(gamma(x)) (natural logarithm of the gamma
280280
/// function) using the Lanczos approximation.

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@
236236
#[cfg(feature="std")] extern crate std as core;
237237
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc;
238238

239+
#[cfg(feature="simd_support")] extern crate packed_simd;
240+
239241
#[cfg(test)] #[cfg(feature="serde1")] extern crate bincode;
240242
#[cfg(feature="serde1")] extern crate serde;
241243
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;

0 commit comments

Comments
 (0)