NeKernel dev
|
Functions | |
template<class T, size_t N> | |
constexpr size_t | countof (T(&)[N]) |
Helper to get number of elements in array. | |
template<class T> | |
constexpr auto | bit_size () |
Size of object in terms of bits. | |
template<class T> | |
constexpr T | bit_full () |
Integer with all bits set to 1. | |
template<class T> | |
constexpr T | bit_wrap () |
Wrap around mask for power of two number of bits within given integer type. For example: [ bit_wrap<uint8_t> = 8 - 1 = 0b111 ] [ bit_wrap<uint16_t> = 16 - 1 = 0b1111 ] [ bit_wrap<uint32_t> = 32 - 1 = 0b11111 ]. | |
template<class T> | |
constexpr auto | bit_shft () |
Number of bits to fit bit_wrap<T> result, in other words bit width of (sizeof(T) * 8 - 1). For example: [ bit_shft<uint8_t> = bit_width(0b111) = 3 ] [ bit_shft<uint16_t> = bit_width(0b1111) = 4 ] [ bit_shft<uint32_t> = bit_width(0b11111) = 5 ]. | |
template<class T> | |
constexpr auto | bit_ceil (auto x) |
Round up division by number of bits within given integer type, which sizeof(T) * 8 is power of two. | |
constexpr unsigned | cntlz (auto x) |
Count leading zeros. | |
constexpr unsigned | cnttz (auto x) |
Count trailing zeros. | |
template<class T> | |
constexpr size_t | words_in_bits (size_t n) |
Get number of words (integers) required to store N bits. | |
constexpr size_t | bytes_in_bits (size_t n) |
Get number of bytes required to store N bits. | |
template<class T = unsigned> | |
constexpr T | bit (int n) |
Make integer with bit at given position. | |
template<class T> | |
constexpr bool | get_bit (T x, int n) |
Get n-th bit of an integer. | |
template<class T> | |
constexpr void | set_bit (T &x, int n) |
Set n-th bit of an integer. | |
template<class T> | |
constexpr void | clr_bit (T &x, int n) |
Clear n-th bit of an integer. | |
template<class T> | |
constexpr bool | get_arr_bit (const T *p, unsigned n) |
Get n-th bit in array of words (starting from LSB). | |
template<class T> | |
constexpr void | set_arr_bit (T *p, unsigned n) |
Set n-th bit in array of words (starting from LSB). | |
template<class T> | |
constexpr void | clr_arr_bit (T *p, unsigned n) |
Clear n-th bit in array of words (starting from LSB). | |
template<class T, size_t L> | |
constexpr void | shift_left (T(&x)[L]) |
Shift bits left in array of integer elements from least significant bit and considering 0-th byte as the right most. uint16_t example: 0b10000000'11100001 ==> 0b00000001'11000010. |
|
constexpr |
Make integer with bit at given position.
T | Inetegr type |
n | Bit position |
|
constexpr |
Round up division by number of bits within given integer type, which sizeof(T) * 8 is power of two.
T | Inetegr type |
x | Dividend |
|
constexpr |
Integer with all bits set to 1.
T | Integer type |
|
constexpr |
Number of bits to fit bit_wrap<T> result, in other words bit width of (sizeof(T) * 8 - 1). For example: [ bit_shft<uint8_t> = bit_width(0b111) = 3 ] [ bit_shft<uint16_t> = bit_width(0b1111) = 4 ] [ bit_shft<uint32_t> = bit_width(0b11111) = 5 ].
T | Integer type |
|
constexpr |
Size of object in terms of bits.
T | Object type |
|
constexpr |
Wrap around mask for power of two number of bits within given integer type. For example: [ bit_wrap<uint8_t> = 8 - 1 = 0b111 ] [ bit_wrap<uint16_t> = 16 - 1 = 0b1111 ] [ bit_wrap<uint32_t> = 32 - 1 = 0b11111 ].
T | Integer type |
Get number of bytes required to store N bits.
n | Number of bits to store |
|
constexpr |
Clear n-th bit in array of words (starting from LSB).
T | Word type |
p | Array of words |
n | Index of bit to clear |
|
constexpr |
Clear n-th bit of an integer.
T | Integer type |
x | Integer |
n | Bit position from LSB |
|
constexpr |
Count leading zeros.
x | Unsigned integer argument |
|
constexpr |
Count trailing zeros.
x | Unsigned integer argument |
Helper to get number of elements in array.
T | Auto-deduced element type |
N | Auto-deduced number of elements |
|
constexpr |
Get n-th bit in array of words (starting from LSB).
T | Word type |
p | Array of words |
n | Index of bit to get |
|
constexpr |
Get n-th bit of an integer.
T | Integer type |
x | Integer |
n | Bit position from LSB |
|
constexpr |
Set n-th bit in array of words (starting from LSB).
T | Word type |
p | Array of words |
n | Index of bit to set |
|
constexpr |
Set n-th bit of an integer.
T | Integer type |
x | Integer |
n | Bit position from LSB |
|
constexpr |
Shift bits left in array of integer elements from least significant bit and considering 0-th byte as the right most. uint16_t example: 0b10000000'11100001 ==> 0b00000001'11000010.
T | Integer type |
L | Length of array |
x | Array of integers, nullptr not acceptable! |
len | Number of elements |