Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise ll::base::num_base_digits for 2 & other powers of it. #53

Merged
merged 1 commit into from
Nov 12, 2015

Conversation

huonw
Copy link
Contributor

@huonw huonw commented Nov 12, 2015

The old code would end up with an actual division when inlined into
another crate, because the BASES symbol isn't inlined and hence the
compiler 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 my float crate
with the div instruction taking the majority of the time. It's
especially unfortunate because the divison for bit_length is a
division by 1.

(A simple benchmark of Int::bit_length shows the performance dropping
from 9 ns/iter to 1-2 ns/iter, with div taking ~80% of the time in the
former case.)

cc #52

The old code would end up with an actual division when inlined into
another crate, because the `BASES` symbol isn't inlined and hence the
compiler 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 my `float` crate
with the `div` instruction taking the majority of the time. It's
especially unfortunate because the divison for `bit_length` is a
division by 1.

(A simple benchmark of `Int::bit_length` shows the performance dropping
from 9 ns/iter to 1-2 ns/iter, with `div` taking ~80% of the time in the
former case.)

cc Aatch#52
Aatch added a commit that referenced this pull request Nov 12, 2015
Optimise `ll::base::num_base_digits` for 2 & other powers of it.
@Aatch Aatch merged commit a7228cb into Aatch:master Nov 12, 2015
@huonw huonw deleted the faster-bit-length branch November 12, 2015 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants