Skip to content

Commit edd3312

Browse files
committed
Use rand_core#utils branch
1 parent f87954d commit edd3312

File tree

9 files changed

+23
-30
lines changed

9 files changed

+23
-30
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ serde_json = "1.0.140"
8888

8989
[patch.crates-io.rand_core]
9090
git = "https://github.com/rust-random/rand_core.git"
91-
branch = "reduce-block-code"
91+
branch = "utils"
9292
# rev = "5d19070a"

benches/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ name = "weighted"
5858
harness = false
5959

6060
[patch.crates-io]
61-
rand_core = { git = "https://github.com/rust-random/rand_core.git", branch = "reduce-block-code" }
61+
rand_core = { git = "https://github.com/rust-random/rand_core.git", branch = "utils" }

rand_pcg/src/pcg128.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
const MULTIPLIER: u128 = 0x2360_ED05_1FC6_5DA4_4385_DF64_9FCC_F645;
1515

1616
use core::fmt;
17-
use rand_core::{RngCore, SeedableRng, le};
17+
use rand_core::{RngCore, SeedableRng, utils};
1818
#[cfg(feature = "serde")]
1919
use serde::{Deserialize, Serialize};
2020

@@ -126,8 +126,7 @@ impl SeedableRng for Lcg128Xsl64 {
126126
/// We use a single 255-bit seed to initialise the state and select a stream.
127127
/// One `seed` bit (lowest bit of `seed[8]`) is ignored.
128128
fn from_seed(seed: Self::Seed) -> Self {
129-
let mut seed_u64 = [0u64; 4];
130-
le::read_u64_into(&seed, &mut seed_u64);
129+
let seed_u64: [u64; 4] = utils::read_words(&seed);
131130
let state = u128::from(seed_u64[0]) | (u128::from(seed_u64[1]) << 64);
132131
let incr = u128::from(seed_u64[2]) | (u128::from(seed_u64[3]) << 64);
133132

@@ -150,7 +149,7 @@ impl RngCore for Lcg128Xsl64 {
150149

151150
#[inline]
152151
fn fill_bytes(&mut self, dest: &mut [u8]) {
153-
le::fill_bytes_via_next(self, dest)
152+
utils::fill_bytes_via_next_word(dest, || self.next_u64());
154153
}
155154
}
156155

@@ -232,8 +231,7 @@ impl SeedableRng for Mcg128Xsl64 {
232231

233232
fn from_seed(seed: Self::Seed) -> Self {
234233
// Read as if a little-endian u128 value:
235-
let mut seed_u64 = [0u64; 2];
236-
le::read_u64_into(&seed, &mut seed_u64);
234+
let seed_u64: [u64; 2] = utils::read_words(&seed);
237235
let state = u128::from(seed_u64[0]) | (u128::from(seed_u64[1]) << 64);
238236
Mcg128Xsl64::new(state)
239237
}
@@ -253,7 +251,7 @@ impl RngCore for Mcg128Xsl64 {
253251

254252
#[inline]
255253
fn fill_bytes(&mut self, dest: &mut [u8]) {
256-
le::fill_bytes_via_next(self, dest)
254+
utils::fill_bytes_via_next_word(dest, || self.next_u64());
257255
}
258256
}
259257

rand_pcg/src/pcg128cm.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
const MULTIPLIER: u64 = 15750249268501108917;
1515

1616
use core::fmt;
17-
use rand_core::{RngCore, SeedableRng, le};
17+
use rand_core::{RngCore, SeedableRng, utils};
1818
#[cfg(feature = "serde")]
1919
use serde::{Deserialize, Serialize};
2020

@@ -131,8 +131,7 @@ impl SeedableRng for Lcg128CmDxsm64 {
131131
/// We use a single 255-bit seed to initialise the state and select a stream.
132132
/// One `seed` bit (lowest bit of `seed[8]`) is ignored.
133133
fn from_seed(seed: Self::Seed) -> Self {
134-
let mut seed_u64 = [0u64; 4];
135-
le::read_u64_into(&seed, &mut seed_u64);
134+
let seed_u64: [u64; 4] = utils::read_words(&seed);
136135
let state = u128::from(seed_u64[0]) | (u128::from(seed_u64[1]) << 64);
137136
let incr = u128::from(seed_u64[2]) | (u128::from(seed_u64[3]) << 64);
138137

@@ -156,7 +155,7 @@ impl RngCore for Lcg128CmDxsm64 {
156155

157156
#[inline]
158157
fn fill_bytes(&mut self, dest: &mut [u8]) {
159-
le::fill_bytes_via_next(self, dest)
158+
utils::fill_bytes_via_next_word(dest, || self.next_u64());
160159
}
161160
}
162161

rand_pcg/src/pcg64.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! PCG random number generators
1212
1313
use core::fmt;
14-
use rand_core::{RngCore, SeedableRng, le};
14+
use rand_core::{RngCore, SeedableRng, utils};
1515
#[cfg(feature = "serde")]
1616
use serde::{Deserialize, Serialize};
1717

@@ -127,8 +127,7 @@ impl SeedableRng for Lcg64Xsh32 {
127127
/// We use a single 127-bit seed to initialise the state and select a stream.
128128
/// One `seed` bit (lowest bit of `seed[8]`) is ignored.
129129
fn from_seed(seed: Self::Seed) -> Self {
130-
let mut seed_u64 = [0u64; 2];
131-
le::read_u64_into(&seed, &mut seed_u64);
130+
let seed_u64: [u64; 2] = utils::read_words(&seed);
132131

133132
// The increment must be odd, hence we discard one bit:
134133
Lcg64Xsh32::from_state_incr(seed_u64[0], seed_u64[1] | 1)
@@ -154,11 +153,11 @@ impl RngCore for Lcg64Xsh32 {
154153

155154
#[inline]
156155
fn next_u64(&mut self) -> u64 {
157-
le::next_u64_via_u32(self)
156+
utils::next_u64_via_u32(self)
158157
}
159158

160159
#[inline]
161160
fn fill_bytes(&mut self, dest: &mut [u8]) {
162-
le::fill_bytes_via_next(self, dest)
161+
utils::fill_bytes_via_next_word(dest, || self.next_u32());
163162
}
164163
}

src/distr/integer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ impl Distribution<__m128i> for StandardUniform {
112112
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> __m128i {
113113
// NOTE: It's tempting to use the u128 impl here, but confusingly this
114114
// results in different code (return via rdx, r10 instead of rax, rdx
115-
// with u128 impl) and is much slower (+130 time). This version calls
116-
// le::fill_bytes_via_next but performs well.
115+
// with u128 impl) and is much slower (+130 time).
117116

118117
let mut buf = [0_u8; core::mem::size_of::<__m128i>()];
119118
rng.fill_bytes(&mut buf);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ mod test {
367367
}
368368

369369
fn fill_bytes(&mut self, dst: &mut [u8]) {
370-
rand_core::le::fill_bytes_via_next(self, dst)
370+
rand_core::utils::fill_bytes_via_next_word(dst, || self.next_u64());
371371
}
372372
}
373373

src/rngs/xoshiro128plusplus.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use rand_core::{RngCore, SeedableRng, le};
9+
use rand_core::{RngCore, SeedableRng, utils};
1010
#[cfg(feature = "serde")]
1111
use serde::{Deserialize, Serialize};
1212

@@ -31,8 +31,7 @@ impl SeedableRng for Xoshiro128PlusPlus {
3131
/// mapped to a different seed.
3232
#[inline]
3333
fn from_seed(seed: [u8; 16]) -> Xoshiro128PlusPlus {
34-
let mut state = [0; 4];
35-
le::read_u32_into(&seed, &mut state);
34+
let state = utils::read_words(&seed);
3635
// Check for zero on aligned integers for better code generation.
3736
// Furtermore, seed_from_u64(0) will expand to a constant when optimized.
3837
if state.iter().all(|&x| x == 0) {
@@ -88,12 +87,12 @@ impl RngCore for Xoshiro128PlusPlus {
8887

8988
#[inline]
9089
fn next_u64(&mut self) -> u64 {
91-
le::next_u64_via_u32(self)
90+
utils::next_u64_via_u32(self)
9291
}
9392

9493
#[inline]
9594
fn fill_bytes(&mut self, dst: &mut [u8]) {
96-
le::fill_bytes_via_next(self, dst)
95+
utils::fill_bytes_via_next_word(dst, || self.next_u32());
9796
}
9897
}
9998

src/rngs/xoshiro256plusplus.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use rand_core::{RngCore, SeedableRng, le};
9+
use rand_core::{RngCore, SeedableRng, utils};
1010
#[cfg(feature = "serde")]
1111
use serde::{Deserialize, Serialize};
1212

@@ -31,8 +31,7 @@ impl SeedableRng for Xoshiro256PlusPlus {
3131
/// mapped to a different seed.
3232
#[inline]
3333
fn from_seed(seed: [u8; 32]) -> Xoshiro256PlusPlus {
34-
let mut state = [0; 4];
35-
le::read_u64_into(&seed, &mut state);
34+
let state = utils::read_words(&seed);
3635
// Check for zero on aligned integers for better code generation.
3736
// Furtermore, seed_from_u64(0) will expand to a constant when optimized.
3837
if state.iter().all(|&x| x == 0) {
@@ -95,7 +94,7 @@ impl RngCore for Xoshiro256PlusPlus {
9594

9695
#[inline]
9796
fn fill_bytes(&mut self, dst: &mut [u8]) {
98-
le::fill_bytes_via_next(self, dst)
97+
utils::fill_bytes_via_next_word(dst, || self.next_u64());
9998
}
10099
}
101100

0 commit comments

Comments
 (0)