Skip to content

Commit 149c8b3

Browse files
pitdickerdhardy
authored andcommitted
Depend on packed_simd for simd support
1 parent 11d6386 commit 149c8b3

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
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 = ["rand_core/serde1", "rand_isaac/serde1", "rand_xorshift/serde1"] # enables serialization for PRNGs
2828

2929
[workspace]
@@ -35,6 +35,7 @@ rand_core = { path = "rand_core", version = "0.2", default-features = false }
3535
rand_isaac = { path = "rand_isaac", version = "0.1" }
3636
rand_xorshift = { path = "rand_xorshift", version = "0.1" }
3737
log = { version = "0.4", optional = true }
38+
packed_simd = { version = "0.1", optional = true, features = ["into_bits"] }
3839

3940
[target.'cfg(unix)'.dependencies]
4041
libc = { version = "0.2", optional = true }

src/distributions/float.rs

Lines changed: 5 additions & 5 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);
@@ -174,7 +174,7 @@ mod tests {
174174
use distributions::{Open01, OpenClosed01};
175175
use rngs::mock::StepRng;
176176
#[cfg(feature="simd_support")]
177-
use core::simd::*;
177+
use packed_simd::*;
178178

179179
const EPSILON32: f32 = ::core::f32::EPSILON;
180180
const EPSILON64: f64 = ::core::f64::EPSILON;

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: 4 additions & 4 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
@@ -785,7 +785,7 @@ mod tests {
785785
use rngs::mock::StepRng;
786786
use distributions::uniform::Uniform;
787787
use distributions::utils::FloatAsSIMD;
788-
#[cfg(feature="simd_support")] use core::simd::*;
788+
#[cfg(feature="simd_support")] use packed_simd::*;
789789

790790
#[should_panic]
791791
#[test]

src/distributions/utils.rs

Lines changed: 4 additions & 4 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")]
@@ -263,18 +263,18 @@ macro_rules! simd_impl {
263263
<$ty>::from_bits(<$uty>::from_bits(self) + <$uty>::from_bits(mask))
264264
}
265265
type UInt = $uty;
266-
fn cast_from_int(i: Self::UInt) -> Self { $ty::from(i) }
266+
fn cast_from_int(i: Self::UInt) -> Self { i.cast() }
267267
}
268268
}
269269
}
270270

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 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(all(target_arch="wasm32", not(target_os="emscripten"), feature="stdweb"))]
240242
#[macro_use]
241243
extern crate stdweb;

0 commit comments

Comments
 (0)