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

Would like highest_{set|zero}_bit() #103

Closed
seanyoung opened this issue Feb 3, 2021 · 2 comments
Closed

Would like highest_{set|zero}_bit() #103

seanyoung opened this issue Feb 3, 2021 · 2 comments

Comments

@seanyoung
Copy link

Using bitvec, I'm building a known bits optimization pass for my compiler. For this I need to know the highest set bit in a bitvec.

This can be implemented using u64::trailing_zeros(). Maybe it should be called: {leading|trailing}_{zeros|ones}().

@myrrlyn
Copy link
Collaborator

myrrlyn commented Feb 13, 2021

Thank you for this request!

I have created the methods {first,last}_{one,zero} which report the index of the first or last bit in the bit-slice set to the requested value, returning None on empty bit-slices.

I have also created the methods {leading,trailing}_{ones,zeros}, which report the length of the run of the requested bit at the corresponding end of the bit-slice, returning 0 on empty bit-slices.

Please let me know if these have the behavior you expect.

They will be included in the 0.21 released published before the end of the month.

@seanyoung
Copy link
Author

@myrrlyn fantastic news, thank you very much!
They look exactly like what I need, let me test them and get back to you.
I will be using them here https://github.com/hyperledger-labs/solang/blob/main/src/codegen/strength_reduce.rs

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

2 participants