Skip to content

Commit 68983dc

Browse files
committed
---
yaml --- r: 188327 b: refs/heads/master c: 6189e99 h: refs/heads/master i: 188325: c7f0261 188323: 9f93191 188319: 6bc8f41 v: v3
1 parent c388b95 commit 68983dc

File tree

5 files changed

+42
-39
lines changed

5 files changed

+42
-39
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7c8edabac8030889f4a885b944c86190772953fd
2+
refs/heads/master: 6189e99c8605578aae841be6fba9e27bfbad97fc
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 3a96d6a9818fe2affc98a187fb1065120458cee9
55
refs/heads/try: 649d35e4d830b27806705dc5352c86ab6d6fd1a1

trunk/src/librand/chacha.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
use core::prelude::*;
1414
use core::num::Int;
15+
use core::num::wrapping::WrappingOps;
1516
use {Rng, SeedableRng, Rand};
1617

1718
const KEY_WORDS : uint = 8; // 8 words for the 256-bit key
@@ -43,10 +44,10 @@ static EMPTY: ChaChaRng = ChaChaRng {
4344

4445
macro_rules! quarter_round{
4546
($a: expr, $b: expr, $c: expr, $d: expr) => {{
46-
$a += $b; $d ^= $a; $d = $d.rotate_left(16);
47-
$c += $d; $b ^= $c; $b = $b.rotate_left(12);
48-
$a += $b; $d ^= $a; $d = $d.rotate_left( 8);
49-
$c += $d; $b ^= $c; $b = $b.rotate_left( 7);
47+
$a = $a.wrapping_add($b); $d = $d ^ $a; $d = $d.rotate_left(16);
48+
$c = $c.wrapping_add($d); $b = $b ^ $c; $b = $b.rotate_left(12);
49+
$a = $a.wrapping_add($b); $d = $d ^ $a; $d = $d.rotate_left( 8);
50+
$c = $c.wrapping_add($d); $b = $b ^ $c; $b = $b.rotate_left( 7);
5051
}}
5152
}
5253

@@ -74,7 +75,7 @@ fn core(output: &mut [u32; STATE_WORDS], input: &[u32; STATE_WORDS]) {
7475
}
7576

7677
for i in 0..STATE_WORDS {
77-
output[i] += input[i];
78+
output[i] = output[i].wrapping_add(input[i]);
7879
}
7980
}
8081

trunk/src/librand/distributions/range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ macro_rules! integer_impl {
123123
// be uniformly distributed)
124124
if v < r.accept_zone as $unsigned {
125125
// and return it, with some adjustments
126-
return r.low + (v % r.range as $unsigned) as $ty;
126+
return r.low.wrapping_add((v % r.range as $unsigned) as $ty);
127127
}
128128
}
129129
}

trunk/src/librand/isaac.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use core::prelude::*;
1414
use core::slice;
1515
use core::iter::{range_step, repeat};
16+
use core::num::wrapping::Wrapping;
1617

1718
use {Rng, SeedableRng, Rand};
1819

@@ -60,7 +61,7 @@ impl IsaacRng {
6061
/// of `rsl` as a seed, otherwise construct one algorithmically (not
6162
/// randomly).
6263
fn init(&mut self, use_rsl: bool) {
63-
let mut a = 0x9e3779b9;
64+
let mut a = Wrapping(0x9e3779b9);
6465
let mut b = a;
6566
let mut c = a;
6667
let mut d = a;
@@ -71,14 +72,14 @@ impl IsaacRng {
7172

7273
macro_rules! mix {
7374
() => {{
74-
a^=b<<11; d+=a; b+=c;
75-
b^=c>>2; e+=b; c+=d;
76-
c^=d<<8; f+=c; d+=e;
77-
d^=e>>16; g+=d; e+=f;
78-
e^=f<<10; h+=e; f+=g;
79-
f^=g>>4; a+=f; g+=h;
80-
g^=h<<8; b+=g; h+=a;
81-
h^=a>>9; c+=h; a+=b;
75+
a=a^(b<<11); d=d+a; b=b+c;
76+
b=b^(c>>2); e=e+b; c=c+d;
77+
c=c^(d<<8); f=f+c; d=d+e;
78+
d=d^(e>>16); g=g+d; e=e+f;
79+
e=e^(f<<10); h=h+e; f=f+g;
80+
f=f^(g>>4); a=a+f; g=g+h;
81+
g=g^(h<<8); b=b+g; h=h+a;
82+
h=h^(a>>9); c=c+h; a=a+b;
8283
}}
8384
}
8485

@@ -90,15 +91,15 @@ impl IsaacRng {
9091
macro_rules! memloop {
9192
($arr:expr) => {{
9293
for i in range_step(0, RAND_SIZE as uint, 8) {
93-
a+=$arr[i ]; b+=$arr[i+1];
94-
c+=$arr[i+2]; d+=$arr[i+3];
95-
e+=$arr[i+4]; f+=$arr[i+5];
96-
g+=$arr[i+6]; h+=$arr[i+7];
94+
a=a+Wrapping($arr[i ]); b=b+Wrapping($arr[i+1]);
95+
c=c+Wrapping($arr[i+2]); d=d+Wrapping($arr[i+3]);
96+
e=e+Wrapping($arr[i+4]); f=f+Wrapping($arr[i+5]);
97+
g=g+Wrapping($arr[i+6]); h=h+Wrapping($arr[i+7]);
9798
mix!();
98-
self.mem[i ]=a; self.mem[i+1]=b;
99-
self.mem[i+2]=c; self.mem[i+3]=d;
100-
self.mem[i+4]=e; self.mem[i+5]=f;
101-
self.mem[i+6]=g; self.mem[i+7]=h;
99+
self.mem[i ]=a.0; self.mem[i+1]=b.0;
100+
self.mem[i+2]=c.0; self.mem[i+3]=d.0;
101+
self.mem[i+4]=e.0; self.mem[i+5]=f.0;
102+
self.mem[i+6]=g.0; self.mem[i+7]=h.0;
102103
}
103104
}}
104105
}
@@ -108,10 +109,10 @@ impl IsaacRng {
108109
} else {
109110
for i in range_step(0, RAND_SIZE as uint, 8) {
110111
mix!();
111-
self.mem[i ]=a; self.mem[i+1]=b;
112-
self.mem[i+2]=c; self.mem[i+3]=d;
113-
self.mem[i+4]=e; self.mem[i+5]=f;
114-
self.mem[i+6]=g; self.mem[i+7]=h;
112+
self.mem[i ]=a.0; self.mem[i+1]=b.0;
113+
self.mem[i+2]=c.0; self.mem[i+3]=d.0;
114+
self.mem[i+4]=e.0; self.mem[i+5]=f.0;
115+
self.mem[i+6]=g.0; self.mem[i+7]=h.0;
115116
}
116117
}
117118

@@ -130,7 +131,8 @@ impl IsaacRng {
130131
static MIDPOINT: uint = (RAND_SIZE / 2) as uint;
131132

132133
macro_rules! ind {
133-
($x:expr) => ( self.mem[(($x >> 2) as uint & ((RAND_SIZE - 1) as uint))] )
134+
($x:expr) => (Wrapping( self.mem[(($x >> 2) as uint &
135+
((RAND_SIZE - 1) as uint))] ))
134136
}
135137

136138
let r = [(0, MIDPOINT), (MIDPOINT, 0)];
@@ -142,11 +144,11 @@ impl IsaacRng {
142144
let mix = a << $shift as uint;
143145

144146
let x = self.mem[base + mr_offset];
145-
a = (a ^ mix) + self.mem[base + m2_offset];
146-
let y = ind!(x) + a + b;
147-
self.mem[base + mr_offset] = y;
147+
a = (Wrapping(a ^ mix) + Wrapping(self.mem[base + m2_offset])).0;
148+
let y = ind!(x) + Wrapping(a) + Wrapping(b);
149+
self.mem[base + mr_offset] = y.0;
148150

149-
b = ind!(y >> RAND_SIZE_LEN as uint) + x;
151+
b = (ind!(y.0 >> RAND_SIZE_LEN as uint) + Wrapping(x)).0;
150152
self.rsl[base + mr_offset] = b;
151153
}}
152154
}
@@ -157,11 +159,11 @@ impl IsaacRng {
157159
let mix = a >> $shift as uint;
158160

159161
let x = self.mem[base + mr_offset];
160-
a = (a ^ mix) + self.mem[base + m2_offset];
161-
let y = ind!(x) + a + b;
162-
self.mem[base + mr_offset] = y;
162+
a = (Wrapping(a ^ mix) + Wrapping(self.mem[base + m2_offset])).0;
163+
let y = ind!(x) + Wrapping(a) + Wrapping(b);
164+
self.mem[base + mr_offset] = y.0;
163165

164-
b = ind!(y >> RAND_SIZE_LEN as uint) + x;
166+
b = (ind!(y.0 >> RAND_SIZE_LEN as uint) + Wrapping(x)).0;
165167
self.rsl[base + mr_offset] = b;
166168
}}
167169
}

trunk/src/libstd/rand/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ impl Rng for ThreadRng {
386386
/// ```
387387
/// use std::rand;
388388
///
389-
/// let x = rand::random();
390-
/// println!("{}", 2u8 * x);
389+
/// let x: u8 = rand::random();
390+
/// println!("{}", 2 * x as u16);
391391
///
392392
/// let y = rand::random::<f64>();
393393
/// println!("{}", y);

0 commit comments

Comments
 (0)