65inline uint32_t
log2i(uint32_t x)
69 return (uint32_t)(31 - __builtin_clz(x));
71 #define S(k) if (x >= (1 << k)) { i += k; x >>= k; }
72 int i = 0; S(16); S(8); S(4); S(2); S(1);
return i;
98 const uint32_t i =
log2i(x);
100 return (i + ((x >> (i - 1U)) == 3U));
117 return (shift > 31U) ? 0 : 1U << shift;
131 x = x - ((x >> 1) & 0x55555555);
132 x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
133 return (((x + (x >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
146 return x && !(x & (x - 1));
158 return x < 0 ? ((~(uint32_t)(x)) + 1) : (uint32_t)x;
175inline uint32_t
floor2(uint32_t x, uint_fast8_t n)
188inline uint32_t
ceiling2(uint32_t x, uint_fast8_t n)
191 return x ? (1 + ((x - 1) >> n)) : 0;
201inline uint32_t
ceildiv(uint32_t x, uint32_t y)
204 return x ? (1 + ((x - 1) / y)) : 0;
214#define MAX(a, b) ((a) > (b) ? (a) : (b))
223#define MIN(a, b) ((a) < (b) ? (a) : (b))
237#define CLAMP(x, min, max) (MIN(MAX((x), (min)), (max)))
252inline uint32_t isqrt(uint32_t v)
uint32_t floor2(uint32_t x, uint_fast8_t n)
Calculates the floor division by a factor of 2: floor(x / 2^n).
Definition int_math.h:175
uint32_t ispowoftwo(uint32_t x)
Determining if an integer is a power of 2.
Definition int_math.h:144
uint32_t log2i(uint32_t x)
Integer Base-2 Logarithm.
Definition int_math.h:65
uint32_t ceiling2(uint32_t x, uint_fast8_t n)
Calculates the ceildiv division by a factor of 2: ceildiv(x / 2^n).
Definition int_math.h:188
uint32_t popcount(uint32_t x)
Counting bits set in a 32-bit unsigned integer.
Definition int_math.h:128
uint32_t ceildiv(uint32_t x, uint32_t y)
Calculates the ceildiv division: ceildiv(x / y).
Definition int_math.h:201
uint32_t absval(int32_t x)
Calculates the absolute value.
Definition int_math.h:155
uint32_t binary_round(uint32_t x)
Finding the nearest power-of-two value.
Definition int_math.h:113
uint32_t log2_round(uint32_t x)
Integer Base-2 Logarithm with rounded result.
Definition int_math.h:90