Optimise ll::base::num_base_digits
for 2 & other powers of it.
#53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The old code would end up with an actual division when inlined into
another crate, because the
BASES
symbol isn't inlined and hence thecompiler can't tell that the division will be by a power of two. This
caused
bit_length
to be very high in the profiles of myfloat
cratewith the
div
instruction taking the majority of the time. It'sespecially unfortunate because the divison for
bit_length
is adivision by 1.
(A simple benchmark of
Int::bit_length
shows the performance droppingfrom 9 ns/iter to 1-2 ns/iter, with
div
taking ~80% of the time in theformer case.)
cc #52