Closed
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).
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ChaiTRex commentedon Sep 16, 2023
@FedericoStra In case you didn't know, it seems that you closed the related pull request.
FedericoStra commentedon Sep 17, 2023
Ooops... Yes I had some troubles forking and cloning the repository (possibly slow connection) and I did something wrong. Thanks for telling me!
FedericoStra commentedon Sep 17, 2023
New PR: #115913.
I'll make sure not to accidentally close the new one this time 😬
Auto merge of rust-lang#115913 - FedericoStra:checked_ilog, r=the8472
Rollup merge of rust-lang#115913 - FedericoStra:checked_ilog, r=the8472
Unrolled build for rust-lang#115913
FedericoStra commentedon May 6, 2025
Closed by #115913.