mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
firmware: Explicitly use wrapping integer math in PRNGs
Patch by Hannah McLaughlin; apparently, the overflow actually doesn't get checked/reported without `opt-level = 2` and `lto = "thin"`.
This commit is contained in:
parent
8866ab301a
commit
e45cb217be
@ -65,8 +65,8 @@ fn memory_test(total: &mut usize, wrong: &mut usize) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
fn prng32(seed: &mut u32) -> u32 { *seed = 1664525 * *seed + 1013904223; *seed }
|
||||
fn prng16(seed: &mut u16) -> u16 { *seed = 25173 * *seed + 13849; *seed }
|
||||
fn prng32(seed: &mut u32) -> u32 { *seed = u32::wrapping_add(u32::wrapping_mul(1664525, *seed), 1013904223); *seed }
|
||||
fn prng16(seed: &mut u16) -> u16 { *seed = u16::wrapping_add(u16::wrapping_mul(25173, *seed), 13849); *seed }
|
||||
|
||||
for _ in 0..4 {
|
||||
// Test data bus
|
||||
|
@ -211,9 +211,10 @@ mod ddr {
|
||||
|
||||
// Generate pseudo-random sequence
|
||||
let mut prs = [0; DFII_NPHASES * DFII_PIX_DATA_SIZE];
|
||||
let mut prv = 42;
|
||||
let mut prv: u32 = 42;
|
||||
for b in prs.iter_mut() {
|
||||
prv = 1664525 * prv + 1013904223;
|
||||
|
||||
prv = u32::wrapping_add(u32::wrapping_mul(1664525, prv), 1013904223);
|
||||
*b = prv as u8;
|
||||
}
|
||||
|
||||
@ -296,7 +297,7 @@ mod ddr {
|
||||
let mut prs = [0; DFII_NPHASES * DFII_PIX_DATA_SIZE];
|
||||
let mut prv = 42;
|
||||
for b in prs.iter_mut() {
|
||||
prv = 1664525 * prv + 1013904223;
|
||||
prv = u32::wrapping_add(u32::wrapping_mul(1664525, prv), 1013904223);
|
||||
*b = prv as u8;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user