next_pow2 optimized for > 2
This commit is contained in:
parent
0b6c80133c
commit
7ae7febbf6
@ -89,10 +89,6 @@ impl Xoshiro256StarRand {
|
|||||||
|
|
||||||
/// Get the next higher power of two
|
/// Get the next higher power of two
|
||||||
pub fn next_pow2(val: u64) -> u64 {
|
pub fn next_pow2(val: u64) -> u64 {
|
||||||
// Early exit so we don't have to do a wrapping subtract;
|
|
||||||
if val <= 2 {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
let mut out: u64 = val.wrapping_sub(1);
|
let mut out: u64 = val.wrapping_sub(1);
|
||||||
out |= out >> 1;
|
out |= out >> 1;
|
||||||
out |= out >> 2;
|
out |= out >> 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user