data.bits ≡
Bit manipulation functions for unsigned integers.
template <typename T> inline T rotl(T value, bitindex_t<T> amount) §
Rotate the specified value left by the specified amount.
Examples
>>> rotl(0x9, 0);
0x9
>>> rotl(0x9, 1);
0x3
>>> rotl(0x9, 2);
0x6
>>> rotl(0x9, 3);
0xC
template <typename T> inline T rotr(T value, bitindex_t<T> amount) §
Rotate the specified value right by the specified amount.
Examples
>>> rotr(0x9, 0);
0x9
>>> rotr(0x9, 1);
0xC
>>> rotr(0x9, 2);
0x6
>>> rotr(0x9, 3);
0x3
template <typename T> inline optional<bitindex_t<T>> highest_one(T value) §
Find the index of the highest 1 bit in the value. The result is an
optional<bitindex_t<T>> with the
is_valid field indicating if there are any 1 bits in the
value. When is_valid is true then value is the
index of the highest 1 bit.
Examples
>>> highest_one(0);
{0x0, 0x0}
>>> highest_one(1);
{0x1, 0x0}
>>> highest_one(0x32);
{0x1, 0x5}
template <typename T> inline optional<bitindex_t<T>> lowest_one(T value) §
Find the index of the lowest 1 bit in the value. The result is an
optional<bitindex_t<T>> with the
is_valid field indicating if there are any 1 bits in the
value. When is_valid is true then value is the
index of the lowest 1 bit.
Examples
>>> lowest_one(0);
{0x0, 0x0}
>>> lowest_one(1);
{0x1, 0x0}
>>> lowest_one(0x34);
{0x1, 0x2}
template <typename T> inline bitcount_t<T> pop_count(T value) §
Return a count of the number of bits set in the value.
Examples
>>> pop_count(0);
0x0
>>> pop_count(1);
0x1
>>> pop_count(0x34);
0x3
template <typename DividendType, typename DivisorType> inline DividendType divide_and_roundup(DividendType dividend, const DivisorType divisor) §
Divide dividend by divisor and round the result up. Divisor must be an unsigned power of 2, known at compile time. Calling with (x, 32) returns the equivalent of (x + 31) / 32.
Examples
>>> divide_and_roundup(0, 0x20);
0x0
>>> divide_and_roundup(1, 0x20);
0x1
>>> divide_and_roundup(0x20, 0x20);
0x1
>>> divide_and_roundup(0x81f, 0x40);
0x21
template <typename InputType, typename OutputType> inline optional<OutputType> roundup_to_pow2(InputType input) §
Round up a value to the next larger power of two. For example, all values from 33 through 64 (inclusive) round up to 64. OutputType must be at least one bit larger than InputType.
Examples
>>> roundup_to_pow2<uint15, uint16>(0);
{0x0, 0x0}
>>> roundup_to_pow2<int7, int8>(0x1f);
{0x1, 0x20}
>>> roundup_to_pow2<uint7, uint8>(0x20);
{0x1, 0x20}
>>> roundup_to_pow2<uint15, uint16>(0x21);
{0x1, 0x40}
template <typename T> inline T reverse(T data) §
Reverse all bits and return the same input data type.
Examples
>>> reverse(0xC);
0x3
>>> reverse<optional<uint1>>({false, 0x1});
{0x1, 0x0}
>>> reverse<uint2[4]>({0, 1, 2, 3});
{0x3, 0x1, 0x2, 0x0}
template <typename T> inline T reverse_bytes(T data) §
Reverse input byte-by-byte and return as the same data type.
Examples
>>> reverse_bytes<uint8>(0xC);
0xC
>>> reverse_bytes<uint32>(0xB01DFACE);
0xCEFA1DB0
>>> reverse_bytes<uint8[4]>({0, 1, 2, 3});
{0x3, 0x2, 0x1, 0x0}
template <auto N, typename T> inline bool[N] mask_greater_equal(T arg) §
Return array bool[N] with element at i the result of i
>= arg.
Example
>>> mask_greater_equal<4>(2);
{0x0, 0x0, 0x1, 0x1}
template <auto N, typename T> inline bool[N] mask_less_than(T arg) §
Return array bool[N] with element at i the result of i
< arg.
Example
>>> mask_less_than<4>(2);
{0x1, 0x1, 0x0, 0x0}
template <auto N, typename T> inline bool[N] mask_greater_than(T arg) §
Return array bool[N] with element at i the result of i
> arg.
Example
>>> mask_greater_than<4>(2);
{0x0, 0x0, 0x0, 0x1}
template <auto N, typename T> inline bool[N] mask_less_equal(T arg) §
Return array bool[N] with element at i the result of i
<= arg.
Example
>>> mask_less_equal<4>(2);
{0x1, 0x1, 0x1, 0x0}
template <typename T> inline bool reduction((bool, bool) -> bool f, T x) §
Casts the specified scalar type to an array of booleans and applies the reduction operator to it
template <typename T> inline bool reduction_and(T x) §
Verilog style AND reduction operator
template <typename T> inline bool reduction_or(T x) §
Verilog style OR reduction operator
template <typename T> inline bool reduction_xor(T x) §
Verilog style XOR reduction operator
template <typename T> inline bool reduction_xnor(T x) §
Verilog style XNOR reduction operator
template <typename T> inline bool reduction_nand(T x) §
Verilog style NAND reduction operator
template <typename T> inline bool reduction_nor(T x) §
Verilog style NOR reduction operator
template <typename T> inline T bitwise_and(T x, T y) §
AND operator applied to the bits of an arbitrary type.
template <typename T> inline T bitwise_or(T x, T y) §
OR operator applied to the bits of an arbitrary type.
template <typename T> inline T bitwise_xor(T x, T y) §
XOR operator applied to the bits of an arbitrary type.
template <typename T> inline T bitwise_nand(T x, T y) §
NAND operator applied to the bits of an arbitrary type.
template <typename T> inline T bitwise_nor(T x, T y) §
NOR operator applied to the bits of an arbitrary type.
template <typename T> inline T bitwise_xnor(T x, T y) §
XNOR operator applied to the bits of an arbitrary type.