Skip to content

Commit 9c12ad3

Browse files
TheIronBornTheIronBorn
authored and
TheIronBorn
committed
impl SIMD wmul, UniformInt
1 parent 0159528 commit 9c12ad3

File tree

6 files changed

+377
-66
lines changed

6 files changed

+377
-66
lines changed

Cargo.toml

+2-1
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 = { version = "0.1", optional = true, features = ["into_bits"] }
3738
serde = { version = "1", optional = true }
3839
serde_derive = { version = "1", optional = true }
3940

src/distributions/float.rs

+5-5
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

+1-1
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]

0 commit comments

Comments
 (0)