some progress
This commit is contained in:
+19
-14
@@ -6,23 +6,28 @@
|
||||
|
||||
/* How many bits needed to represent a given number */
|
||||
/* Alternitive semntic: nearest upper power of two */
|
||||
static inline int com_bits_needed(uint32_t v) {
|
||||
#ifdef COM_DEF_COMPILE_MODERN
|
||||
static inline uint8_t com_bits_needed(uint32_t v) {
|
||||
// #ifdef COM_DEF_COMPILE_MODERN
|
||||
return v == 0 ? 1 : 32 - __builtin_clz(v);
|
||||
#else
|
||||
#endif
|
||||
if (v == 0)
|
||||
return 1;
|
||||
// #else
|
||||
// #endif
|
||||
// if (v == 0)
|
||||
// return 1;
|
||||
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
// v--;
|
||||
// v |= v >> 1;
|
||||
// v |= v >> 2;
|
||||
// v |= v >> 4;
|
||||
// v |= v >> 8;
|
||||
// v |= v >> 16;
|
||||
// v++;
|
||||
|
||||
return v;
|
||||
// return v;
|
||||
}
|
||||
|
||||
/* Next aligned value. */
|
||||
static inline uint32_t com_bits_nalign(uint32_t v, uint8_t a) {
|
||||
return (v + (a - 1)) & ~(a - 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user