79constexpr unsigned cntlz(
auto x) {
80 if constexpr (std::is_same_v<
decltype(x),
int>)
81 return std::countl_zero(
unsigned(x));
83 return std::countl_zero(x);
92constexpr unsigned cnttz(
auto x) {
93 if constexpr (std::is_same_v<
decltype(x),
int>)
94 return std::countr_zero(
unsigned(x));
96 return std::countr_zero(x);
128template <
class T =
unsigned>
217template <
class T,
size_t L>
219 for (
int i = L - 1; i > 0; --i) {
constexpr T bit_full()
Integer with all bits set to 1.
Definition bit.h:26
constexpr unsigned cnttz(auto x)
Count trailing zeros.
Definition bit.h:92
constexpr void clr_arr_bit(T *p, unsigned n)
Clear n-th bit in array of words (starting from LSB).
Definition bit.h:203
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.
Definition bit.h:69
constexpr size_t words_in_bits(size_t n)
Get number of words (integers) required to store N bits.
Definition bit.h:107
constexpr auto bit_shft()
Number of bits to fit bit_wrap<T> result, in other words bit width of (sizeof(T) * 8 - 1)....
Definition bit.h:56
constexpr size_t bytes_in_bits(size_t n)
Get number of bytes required to store N bits.
Definition bit.h:117
constexpr void set_arr_bit(T *p, unsigned n)
Set n-th bit in array of words (starting from LSB).
Definition bit.h:191
constexpr T bit_wrap()
Wrap around mask for power of two number of bits within given integer type. For example: [ bit_wrap<u...
Definition bit.h:41
constexpr bool get_arr_bit(const T *p, unsigned n)
Get n-th bit in array of words (starting from LSB).
Definition bit.h:179
constexpr unsigned cntlz(auto x)
Count leading zeros.
Definition bit.h:79
constexpr auto bit_size()
Size of object in terms of bits.
Definition bit.h:15
constexpr void set_bit(T &x, int n)
Set n-th bit of an integer.
Definition bit.h:154
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 ...
Definition bit.h:218
constexpr T bit(int n)
Make integer with bit at given position.
Definition bit.h:129
constexpr bool get_bit(T x, int n)
Get n-th bit of an integer.
Definition bit.h:142
constexpr void clr_bit(T &x, int n)
Clear n-th bit of an integer.
Definition bit.h:166