Open
Description
Currently checked_ilog
is implemented with iterated divisions:
rust/library/core/src/num/int_macros.rs
Lines 2475 to 2495 in e7f9f48
It's pretty straightforward to convert it to iterated multiplications:
fn checked_int_log(self, base:Self) -> Option<u32> {
if self <= 0 || base <= 1 {
None
} else {
let mut n = 0;
let mut r = 1;
// Optimization for 128 bit wide integers.
if Self::BITS == 128 {
let b = Self::ilog2(self) / (Self::ilog2(base) + 1);
n += b;
r *= base.pow(b);
}
while r <= self / base {
n += 1;
r *= base;
}
Some(n)
}
}
and this results in some decent speedups (1.5x - 7x).