add a utility macro for getting the bitwise ceiling. (e.i. the next power of 2)

This commit is contained in:
2025-08-26 11:18:23 +02:00
parent e02f4091b8
commit 4e230ae856

6
src/util/util.h Normal file
View File

@@ -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)))