bits-extras-0.1.0: Efficient atomic and non-atomic bit operations not found in Data.Bits

Data.Bits.Extras

Description

Extended bit operations, implemented using GCC builtins (see http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Other-Builtins.html).

Synopsis

Documentation

class Bits x => ExtraBits x whereSource

Instances provided: Word, Word8, Word16, Word32, Word64, Int, Int8, Int16, Int32, Int64

Methods

lowestBitPlus1 :: x -> Word32Source

Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero.

leadingZeros :: x -> Word32Source

Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.

trailingZeros :: x -> Word32Source

Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.

populationCount :: x -> Word32Source

Returns the number of 1-bits in x.

parity :: x -> Word32Source

Returns the parity of x, i.e. the number of 1-bits in x modulo 2.

byteSwap :: x -> xSource

Returns x with the order of the bytes reversed; for example, 0xaabbccdd becomes 0xddccbbaa. Byte here always means exactly 8 bits.