diff --git a/src/util/util.h b/src/util/util.h new file mode 100644 index 0000000..65ecf94 --- /dev/null +++ b/src/util/util.h @@ -0,0 +1,6 @@ +#pragma once + +/* Acquires the next power of two of value `x`. + * Automatically determines the type (and therefore the width) of `x`. + * Explicitly cast `x` to a desired width, if necessary. */ +#define bit_ceil(x) (1 << (sizeof(__typeof__(x)) * 8 - __builtin_clzg(((x) - !!(x)) | 1)))