24static inline unsigned bitcount(
unsigned v) {
25#if defined(__GNUC__) || defined(__clang__)
26 unsigned rv = __builtin_popcount(v);
37static inline int floor_log2(
unsigned v) {
39#if defined(__GNUC__) || defined(__clang__)
40 if (v) rv = CHAR_BIT *
sizeof(unsigned) - __builtin_clz(v) - 1;
50static inline int ceil_log2(
unsigned v) {
return v ? floor_log2(v - 1) + 1 : -1; }
52static inline unsigned bitmask2bytemask(
const bitvec &a) {
53 int max = a.max().index();
54 if (max < 0)
return 0;
56 for (
unsigned i = 0; i <= max / 8U; i++)
57 if (a.getrange(i * 8, 8)) rv |= 1 << i;