Skip to main content

magic_eval

Function magic_eval 

Source
pub fn magic_eval(x: i64, magic: u64, more: u8, mul_back: i64) -> i64
Expand description

Evaluate the magic reciprocal: x / c when mul_back == 0, else x % c (mul_back == c). x is the dividend reinterpreted as u64 — sound because the op is emitted ONLY for a proven non-negative x, where the i64 bit pattern equals the mathematical value and the unsigned quotient/remainder equal the signed truncating ones. The remainder is x - q*c computed in wrapping i64 (the low 64 bits agree with the u64 difference), bit-exact with the kernel’s wrapping_rem for non-negative x.