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

Add functions for reversing the bit pattern in an integer #32798

Closed
wants to merge 2 commits into from

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Apr 7, 2016

This adds the bitreverse intrinsic and adds a reverse_bits function to all integer types.

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

Thanks for the PR! Could you elaborate on the motivation for this a bit as well? Looking at the assembly of LLVM for x86_64 it doesn't seem to be doing much special beyond what one could write in Rust anyway?

@Amanieu
Copy link
Member Author

Amanieu commented Apr 7, 2016

On ARM, there are dedicated instructions for reversing bits. The intrinsic would lower to a single RBIT instruction.

@Amanieu
Copy link
Member Author

Amanieu commented Apr 7, 2016

It seems this intrinsic is only supported on LLVM 3.8+. Since Rust currently supports LLVM 3.6+, should I add a software fallback implementation for older LLVM versions?

@alexcrichton
Copy link
Member

Is there motivation beyond just exporting this because we probably should? Adding a fallback is probably pretty complicated and perhaps not worth it at this time, so it may be best to just wait until we bump the required LLVM version if it's just a nice-to-have.

@Amanieu
Copy link
Member Author

Amanieu commented Apr 8, 2016

I just thought it would be nice to expose these intrinsics to Rust, I don't have a particularly urgent reason to use them myself.

@alexcrichton
Copy link
Member

Ah ok, in that case I'm going to close this for now as we're still trying to remain compatible with LLVM 3.6. If you'd like to draft up a PR to support this even on 3.6 (with a fallback), feel free to send a PR though!

kennytm added a commit to kennytm/rust that referenced this pull request Mar 6, 2018
Add functions for reversing the bit pattern in an integer

I'm reviving PR rust-lang#32798 now that the LLVM issues have been resolved.

> This adds the bitreverse intrinsic and adds a reverse_bits function to all integer types.
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.

3 participants