core.bitop

This module contains a collection of bit-level operations.

Types 4

private unionSplit64
Fields
ulong u64
Constructors
this(ulong u64)
Nested Templates
private aliassoftBsf(N) = softScan!(N, true)
private aliassoftBsr(N) = softScan!(N, false)
structBitRange

Range over bit set. Each element is the bit number that is set.

This is more efficient than testing each bit in a sparsely populated bit set. Note that the first bit in the bit set would be bit 0.

Fields
size_t.sizeof * 8 bitsPerWordNumber of bits in each size_t
const(size_t) *bits bits
size_t cur
size_t idx
size_t len
Methods
size_t front()Range functions
bool empty() constditto
void popFront() @systemditto
Constructors
this(const(size_t) * bitarr, size_t numBits)Construct a BitRange.

Functions 22

fnint bsf(uint v) pureScans the bits in v starting with bit 0, looking for the first set bit. Returns: The bit number of the first bit set. The return value is undefined if v is zero.
fnint bsf(ulong v) pureditto
fnint bsr(uint v) pureScans the bits in v from the most significant bit to the least significant bit, looking for the first set bit. Returns: The bit number of the first bit set. The return value is undefined if v is zero.
fnint bsr(ulong v) pureditto
private fnint softScan(N, bool forward)(N v) if (is(N == uint) || is(N == ulong)) pure
fnint bt(const scope size_t * p, size_t bitnum) pure @systemTests the bit. (No longer an intrisic - the compiler recognizes the patterns in the body.)
fnint btc(size_t * p, size_t bitnum) pure @systemTests and complements the bit.
fnint btr(size_t * p, size_t bitnum) pure @systemTests and resets (sets to 0) the bit.
fnint bts(size_t * p, size_t bitnum) pure @system Tests and sets the bit. Params: p = a non-NULL pointer to an array of sizets. bitnum = a bit number, starting with bit 0 of p[0], and progressing. It addresses bits like the expression: --- p[...
fnushort byteswap(ushort x) pureSwaps bytes in a 2 byte ushort. Params: x = value Returns: `x` with bytes swapped
fnuint bswap(uint v) pure;Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3 becomes byte 0.
fnulong bswap(ulong v) pure;Swaps bytes in an 8 byte ulong end-to-end, i.e. byte 0 becomes byte 7, byte 1 becomes byte 6, etc. This is meant to be recognized by the compiler as an intrinsic.
fnint popcnt(uint x) pureCalculates the number of set bits in an integer.
fnint popcnt(ulong x) pureditto
private fnint softPopcnt(N)(N x) if (is(N == uint) || is(N == ulong)) pure
fnuint bitswap( uint x ) pureReverses the order of bits in a 32-bit integer.
fnulong bitswap( ulong x ) pureReverses the order of bits in a 64-bit integer.
private fnN softBitswap(N)(N x) if (is(N == uint) || is(N == ulong)) pure
fnT rol(T)(const T value, const uint count) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) pureBitwise rotate `value` left (`rol`) or right (`ror`) by `count` bit positions.
fnT ror(T)(const T value, const uint count) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) pureditto
fnT rol(uint count, T)(const T value) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) pureditto
fnT ror(uint count, T)(const T value) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) pureditto