Safe Haskell | None |
---|---|
Language | Haskell2010 |
Reverse bits
There are several algorithms performing the same thing here (reversing bits into words of different sizes). There are benchmarks for them in the "bench" directory. The fastest one for the current architecture should be selected below. If you find that another algorithm is faster on your architecture, please report it.
Synopsis
- class ReversableBits w where
- reverseBits :: w -> w
- reverseBitsGeneric :: (FiniteBits a, Integral a, ShiftableBits a, Bitwise a, KnownNat (BitSize a)) => a -> a
- reverseBitsObvious :: forall a. (FiniteBits a, ShiftableBits a, IndexableBits a, Bitwise a, KnownNat (BitSize a), Eq a) => a -> a
- reverseBits3Ops :: Word8 -> Word8
- reverseBits4Ops :: Word8 -> Word8
- reverseBitsTable :: Word8 -> Word8
- reverseBits7Ops :: Word8 -> Word8
- reverseBits5LgN :: forall a. (FiniteBits a, ShiftableBits a, Bitwise a, KnownNat (BitSize a)) => a -> a
- liftReverseBits :: (ShiftableBits a, Bitwise a, FiniteBits a, Integral a, KnownNat (BitSize a)) => (Word8 -> Word8) -> a -> a
Generic
class ReversableBits w where Source #
Data whose bits can be reversed
reverseBits :: w -> w Source #
Instances
reverseBitsGeneric :: (FiniteBits a, Integral a, ShiftableBits a, Bitwise a, KnownNat (BitSize a)) => a -> a Source #
Reverse bits in a Word
Algorithms
reverseBitsObvious :: forall a. (FiniteBits a, ShiftableBits a, IndexableBits a, Bitwise a, KnownNat (BitSize a), Eq a) => a -> a Source #
Obvious recursive version
reverseBits3Ops :: Word8 -> Word8 Source #
Reverse bits in a Word8 (3 64-bit operations, modulus division)
reverseBits4Ops :: Word8 -> Word8 Source #
Reverse bits in a Word8 (4 64-bit operations, no division)
reverseBitsTable :: Word8 -> Word8 Source #
Reverse bits using a lookup table
reverseBits7Ops :: Word8 -> Word8 Source #
Reverse bits in a Word8 (7 no 64-bit operations, no division)
reverseBits5LgN :: forall a. (FiniteBits a, ShiftableBits a, Bitwise a, KnownNat (BitSize a)) => a -> a Source #
Parallel recursive version
liftReverseBits :: (ShiftableBits a, Bitwise a, FiniteBits a, Integral a, KnownNat (BitSize a)) => (Word8 -> Word8) -> a -> a Source #
Convert a function working on Word8 to one working on any Word
The number of bits in the Word must be a multiple of 8