Update 64-bit mixer to use better constants.
This commit is contained in:
parent
62138fd9a4
commit
12886bc5eb
23
src/lib.rs
23
src/lib.rs
|
@ -25,23 +25,24 @@ pub fn mix32_inv(mut n: u32) -> u32 {
|
|||
/// 64-bit bijective bit mixer.
|
||||
///
|
||||
/// http://zimbry.blogspot.ch/2011/09/better-bit-mixing-improving-on.html
|
||||
/// (variant "Mix13")
|
||||
pub fn mix64(mut n: u64) -> u64 {
|
||||
n ^= n >> 31;
|
||||
n = n.wrapping_mul(0x7fb5d329728ea185);
|
||||
n ^= n >> 30;
|
||||
n = n.wrapping_mul(0xbf58476d1ce4e5b9);
|
||||
n ^= n >> 27;
|
||||
n = n.wrapping_mul(0x81dadef4bc2dd44d);
|
||||
n ^= n >> 33;
|
||||
n = n.wrapping_mul(0x94d049bb133111eb);
|
||||
n ^= n >> 31;
|
||||
|
||||
n
|
||||
}
|
||||
|
||||
/// Inverse of `mix64()`.
|
||||
pub fn mix64_inv(mut n: u64) -> u64 {
|
||||
n ^= n >> 33;
|
||||
n = n.wrapping_mul(0x4d6dff26c61d8485);
|
||||
n ^= (n >> 27) ^ (n >> 54);
|
||||
n = n.wrapping_mul(0x4c5ff4596f4a2f4d);
|
||||
n ^= (n >> 31) ^ (n >> 62);
|
||||
n = n.wrapping_mul(0x319642b2d24d8ec3);
|
||||
n ^= (n >> 27) ^ (n >> 54);
|
||||
n = n.wrapping_mul(0x96de1b173f119089);
|
||||
n ^= (n >> 30) ^ (n >> 60);
|
||||
|
||||
n
|
||||
}
|
||||
|
@ -77,8 +78,10 @@ mod tests {
|
|||
// #[test]
|
||||
// fn get_inverse() {
|
||||
// // Panic, to print the result.
|
||||
// panic!("0x{:x}", compute_multiplicative_inverse_32(0x21f0aaad));
|
||||
// panic!("0x{:x}", compute_multiplicative_inverse_32(0xd35a2d97));
|
||||
// panic!(
|
||||
// "0x{:x}",
|
||||
// compute_multiplicative_inverse_64(0x94d049bb133111eb)
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue
Block a user