Name |
Description |
bitmask_subset
template<typename T> bool bitmask_subset(T m1, T m2);
|
Determines if one bitmask is a subset of another. Returns true if the bits set in the first argument form a subset of the bits set in the second argument. |
countClear
template<typename T> size_t countClear(T val);
|
Counts how many bits are clear (zero). |
countSet
template<typename T> size_t countSet(T val);
|
Counts how many bits are set (one). |
extract
template< size_t lobit, size_t hibit, typename T> T extract(T bits);
|
Extract bits from a value. Bits lobit through hibit, inclusive, are right shifted into the result and higher‐order bits of the result are cleared. |
extract2
template<typename T> T extract2(size_t lobit, size_t hibit, T bits);
|
|
genMask
template<typename T> T genMask(size_t n);
|
genMask overloads
|
isPowerOfTwo
template<typename T> bool isPowerOfTwo(T value);
|
Returns true if the value is a power of two. Zero is considered a power of two. |
log2
template<typename T> T log2(T a);
|
|
log2max
template<typename T> T log2max(T value);
|
Returns the base‐2 logorithm of value. If value is not a power of two then the return value is rounded up to the next integer. The value is treated as an unsigned value. Returns zero if value is zero. |
msb_set
template<typename T> std::optional<size_t> msb_set(T val);
|
Optionally returns the zero‐origin position of the most significant set bit. Returns nothing if no bits are set. |
rotateLeft
template< size_t NBits, typename T> T rotateLeft(T value, size_t count);
|
Rotate the bits of the value left by count bits. |
rotateLeft2
template<typename T> T rotateLeft2(T value, size_t count, size_t width = 8 * sizeof(T));
|
|
rotateRight
template< size_t NBits, typename T> T rotateRight(T value, size_t count);
|
Rotate bits of the value right by count bits. |
rotateRight2
template<typename T> T rotateRight2(T value, size_t count, size_t width = 8 * sizeof(T));
|
|
shiftLeft
template< size_t NBits, typename T> T shiftLeft(T value, size_t count);
|
Shifts bits of value left by count bits. |
shiftLeft2
template<typename T> T shiftLeft2(T value, size_t count, size_t width = 8 * sizeof(T));
|
|
shiftRightArithmetic
template< size_t NBits, typename T> T shiftRightArithmetic(T value, size_t count);
|
Shifts bits of value right by count bits with sign extension. |
shiftRightArithmetic2
template<typename T> T shiftRightArithmetic2(T value, size_t count, size_t width = 8 * sizeof(T));
|
|
shiftRightLogical
template< size_t NBits, typename T> T shiftRightLogical(T value, size_t count);
|
Shifts bits of value right by count bits without sign extension. |
shiftRightLogical2
template<typename T> T shiftRightLogical2(T value, size_t count, size_t width = 8 * sizeof(T));
|
|
shift_to
template< size_t lobit, size_t hibit, typename T> T shift_to(T value);
|
Create a shifted value. The return value is created by shifting value to the specified position in the result. Other bits of the return value are clear. The hibit is specified so that we can check at run‐time that a valid value was specified (i.e., the value isn't too wide). |
shift_to2
template<typename T> T shift_to2(size_t lobit, size_t hibit, T value);
|
|
shl1
template<typename T> T shl1(size_t n);
|
Bitmask with bit n set. Handles the case where n is greater than the width of type T. |
signBit
template< size_t NBits, typename T> bool signBit(T value);
|
Returns true if the sign bit is set, false if clear. |
signBit2
template<typename T> bool signBit2(T value, size_t width = 8 * sizeof(T));
|
|
signExtend
template< size_t FromBits, size_t ToBits, typename T> T signExtend(T value);
|
Sign extend value. If the bit FromBits‐1 is set set for value, then the result will have bits FromBits through ToBits‐1 also set (other bits are unchanged). If ToBits is less than or equal to FromBits then nothing happens. |
signExtend2
template<typename T> T signExtend2(T value, size_t from_width, size_t to_width);
|
|