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

'blocks_for_bits' implementation. #39

Open
Parakleta opened this issue Jun 17, 2016 · 0 comments
Open

'blocks_for_bits' implementation. #39

Parakleta opened this issue Jun 17, 2016 · 0 comments

Comments

@Parakleta
Copy link

I don't know how the function as it exists is currently optimised, but in principle you can much more simply use (without risk of over/underflow):

if bits == 0 {
    0
} else {
    (bits-1) / B::bits() + 1
}

If bits were signed (and you have a signed right shift operated that was not UB) you can just use (bits-1) >> B::bitsbits() + 1 where bitsbits() is the number of bits required to store the index into a word (i.e. 5 for 32 bit words). This is probably not practical though.

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

No branches or pull requests

1 participant