#bit #primitive-integer #reverse #swap

no-std bit_reverse

Computes the bit reversal of primitive integers

9 releases

Uses old Rust 2015

0.1.8 Jun 13, 2019
0.1.7 Jun 26, 2017
0.1.5 Sep 23, 2016

#121 in No standard library

Download history 2101/week @ 2024-07-22 1731/week @ 2024-07-29 1841/week @ 2024-08-05 1839/week @ 2024-08-12 1890/week @ 2024-08-19 1905/week @ 2024-08-26 2108/week @ 2024-09-02 2717/week @ 2024-09-09 2775/week @ 2024-09-16 2966/week @ 2024-09-23 2352/week @ 2024-09-30 2392/week @ 2024-10-07 1785/week @ 2024-10-14 2599/week @ 2024-10-21 3060/week @ 2024-10-28 2761/week @ 2024-11-04

10,275 downloads per month
Used in 17 crates (8 directly)

MIT/Apache

16KB
217 lines

bit_reverse

Crates Shield Build Shield Build status

Library Objective

This library provides a number of ways to compute the bit reversal of all primitive integers. There are currently 3 different algorithms implemented: Bitwise, Parallel, and Lookup reversal.

Example

use bit_reverse::ParallelReverse;

assert_eq!(0xA0u8.swap_bits(), 0x05u8);

This library is very simple to uses just import the crate and the algorithm you want to use. Then you can call swap_bits() on any primitive integer. If you want to try a different algorithm just change the use statement and now your program will use the algorithm instead.

YMMV Performance Comparison

BitwiseReverse may be useful in space-constrained microcontrollers when capturing data, but is typically inferior to ParallelReverse, which is a Bitwise Parallel Reverse and thus an order of magnitude faster. For small sizes, <= 16 bits, LookupReverse is the fastest but it doesn't scale as well as ParallelReverse this is because ParallelReverse does a constant number of operations for every size (assuming your cpu has a hardware byte swap instruction). LookupReverse needs more lookups, ANDs, and ORs for each size increase. Thus ParallelReverse performs a little better at 32 bits and much better at 64 bits. These runtime characteristics are based on a Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz.

Memory Consumption

BitwiseReverse and ParallelReverse both only use a couple of stack variables for their computations. BitwiseReverse takes less space than ParallelReverse (18 bytes on MSP430). LookupReverse on the other hand statically allocates 256 u8s or 256 bytes to do its computations. LookupReverse's memory cost is shared by all of the types LookupReverse supports.

no_std Compatible

To link to core instead of STD, disable default features for this library in your Cargo.toml. Cargo choosing features

No runtime deps

Features