#ifndef UTIL_H
#define UTIL_H 1
+#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
return x & -x;
}
+/* Returns 'x' with its rightmost 1-bit changed to a zero (e.g. 01011000 =>
+ * 01010000), or 0 if 'x' is 0. */
+static inline uintmax_t
+zero_rightmost_1bit(uintmax_t x)
+{
+ return x & (x - 1);
+}
+
#ifndef MIN
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#endif
int log_2_floor(uint32_t);
int log_2_ceil(uint32_t);
int ctz(uint32_t);
+int popcount(uint32_t);
bool is_all_zeros(const uint8_t *, size_t);
bool is_all_ones(const uint8_t *, size_t);