Rust: Tracking issue for reversing the bit pattern in an integer

Created on 6 Mar 2018  路  9Comments  路  Source: rust-lang/rust

Tracking issue for the reverse_bits method implemented in #48573.

impl {integer} {
    pub fn reverse_bits(self) -> Self;
}
B-unstable C-tracking-issue T-libs disposition-merge finished-final-comment-period

Most helpful comment

Motivation from https://github.com/rust-lang/rust/pull/32798#issuecomment-207086053

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

All 9 comments

Motivation from https://github.com/rust-lang/rust/pull/32798#issuecomment-207086053

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

I'm a user that would benefit from this being stabilized. No worries if I have to wait until an LLVM requirement version bump, though. We would benefit from it, but aren't in a position to contribute support, so we are happy to wait/offer testing or documentation help.

Just to add to this, these intrinsics are useful for formatting data that is represented bit reversed, such as the IEEE standard for bit-reversed MACs, token ring addresses, etc.

I'd really like to make use of this in my chess engine. What's the status on this?

This thread or https://github.com/rust-lang/rust/pull/48573 do not show a serious issue as far as I can tell.

@rfcbot fcp merge

Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members:

  • [x] @Amanieu
  • [ ] @Kimundi
  • [x] @SimonSapin
  • [x] @alexcrichton
  • [x] @dtolnay
  • [x] @sfackler
  • [ ] @withoutboats

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

https://github.com/rust-lang/rust/pull/48573#issuecomment-372971821 says

keep in mind that the performance of LLVM's generic bitreverse solution can vary greatly depending on the types involved, your target architecture, and what the rest of your code does around it: https://bugs.llvm.org/show_bug.cgi?id=31810

If your target has a bit reverse instruction (only ARMv8 as far as I know) then everything should be fine.

The linked bug has some discussion about changing the code emitted when there is not a dedicated instruction. That has not yet lead to an LLVM change, but it doesn鈥檛 seem serious enough to me that we shouldn鈥檛 expose this at all.


Since we also have a [T]::reserve(&mut self) that works in place, it鈥檚 possible that someone assumes reverse_bits does the same. So it could be good to add #[must_use] to these methods. @nvzqz, do you want to send a PR to do that?

:bell: This is now entering its final comment period, as per the review above. :bell:

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

Was this page helpful?
0 / 5 - 0 ratings