Giter VIP home page Giter VIP logo

bit_reverse's Introduction

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

128bit support

You can enable support for u128 and i128 by enabling the feature u128.

bit_reverse's People

Contributors

cr1901 avatar eugenegonzalez avatar petoknm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bit_reverse's Issues

Implement Signed Integers for LookupReverse

Right now there are no implementations for signed primitive integers in LookupReverse.
This should be done to avoid forcing the users to have to deal with integer conversions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.