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

More efficient reverse_bits implementation. #40

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

More efficient reverse_bits implementation. #40

Parakleta opened this issue Jun 20, 2016 · 0 comments
Labels
Important high value feature or optimization
Milestone

Comments

@Parakleta
Copy link

In general the reverse_bits function should be generalised to work on whatever word type the BitVec object is using and then be applied to accumulator directly instead of each byte (assuming the bytes are reversed while assembling the accumulator value). Additionally bit switching should be cheaper than shifting. Consider:

fn reverse_bits<B: BitBlock>(block: B) -> B {
    let mut result = B::zero();
    result = ((block >> 1) & (!B::zero() / 3)) | ((block & (!B::zero() / 3)) << 1);
    result = ((block >> 2) & (!B::zero() / 5)) | ((block & (!B::zero() / 5)) << 2);
    result = ((block >> 4) & (!B::zero() / 17)) | ((block & (!B::zero() / 17)) << 4);
    result
}

I'm assuming !B::zero() / 3 etc. become compile time constants.

@pczarn pczarn added the Important high value feature or optimization label Jul 1, 2024
@pczarn pczarn added this to the version 1.0 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Important high value feature or optimization
Projects
None yet
Development

No branches or pull requests

2 participants