Closed Phaiax closed 8 years ago
let bits_per_digit = BASES.get_unchecked(base as usize).big_base.0 as usize;
// doing an actual division here is much slower than this
(total_bits + bits_per_digit - 1) >> bits_per_digit.trailing_zeros()
I do not get how the optimization should have worked. The .trailing_zeros() is doubled since it is done already in build.rs
// Powers of two use a different path, so re-use the big_base field to store
// the number of bits required to store a digit in the base.
if base.is_power_of_two() {
big_base = base.trailing_zeros() as usize;
}
The other thing. For base = 8, the correct math would be int(total_bits/3). I don't know if it is possible to reduce different divisions (/3, /4, /5, /6, /7 that are not just the power of two divisions /2 /4 /8 ..). into one single shift statement.
I guess the error was to think that if the base is a power of two, the divisor is also power of two.
fails with