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
bitsPerWordNumber of bits in each size_t
private const(size_t) *bits bits
private size_t cur
private size_t idx
private size_t len
Methods
size_t front() @nogc nothrow pureRange functions
bool empty() @nogc nothrow pure constditto
void popFront() @nogc nothrow pure @systemditto
Constructors
this(const(size_t) * bitarr, size_t numBits)Construct a BitRange.

Functions 22

fnint bsf(uint v) nothrow @safe @nogc 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) nothrow @safe @nogc pureditto
fnint bsr(uint v) nothrow @safe @nogc 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) nothrow @safe @nogc pureditto
private fnint softScan(N, bool forward)(N v) if (is(N == uint) || is(N == ulong)) nothrow @safe @nogc pure
fnint bt(const scope size_t * p, size_t bitnum) nothrow @safe @nogc pure @systemTests the bit. (No longer an intrisic - the compiler recognizes the patterns in the body.)
fnint btc(size_t * p, size_t bitnum) nothrow @safe @nogc pure @systemTests and complements the bit.
fnint btr(size_t * p, size_t bitnum) nothrow @safe @nogc pure @systemTests and resets (sets to 0) the bit.
fnint bts(size_t * p, size_t bitnum) nothrow @safe @nogc pure @system Tests and sets the bit. Params: p = a non-NULL pointer to an array of size_ts. bitnum = a bit number, starting with bit 0 of p[0], * and progressing. It addresses bits like the expression:
fnushort byteswap(ushort x) nothrow @safe @nogc pureSwaps bytes in a 2 byte ushort. Params: x = value Returns: `x` with bytes swapped
fnuint bswap(uint v) nothrow @safe @nogc 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) nothrow @safe @nogc 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) nothrow @safe @nogc pureCalculates the number of set bits in an integer.
fnint popcnt(ulong x) nothrow @safe @nogc pureditto
private fnint softPopcnt(N)(N x) if (is(N == uint) || is(N == ulong)) nothrow @safe @nogc pure
fnuint bitswap( uint x ) nothrow @safe @nogc pureReverses the order of bits in a 32-bit integer.
fnulong bitswap( ulong x ) nothrow @safe @nogc pureReverses the order of bits in a 64-bit integer.
private fnN softBitswap(N)(N x) if (is(N == uint) || is(N == ulong)) nothrow @safe @nogc pure
fnT rol(T)(const T value, const uint count) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) pure nothrow @safe @nogcBitwise 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)) pure nothrow @safe @nogcditto
fnT rol(uint count, T)(const T value) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) pure nothrow @safe @nogcditto
fnT ror(uint count, T)(const T value) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) pure nothrow @safe @nogcditto