mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
util: log2_ceil
This commit is contained in:
@@ -23,6 +23,13 @@ static inline unsigned long log2(unsigned long x) {
|
|||||||
return sizeof(unsigned long) * 8 - __builtin_clzll(x) - 1;
|
return sizeof(unsigned long) * 8 - __builtin_clzll(x) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline unsigned long ceil_log2(unsigned long x) {
|
||||||
|
if (x <= 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return log2(x - 1) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
#define min(x, y) (x > y ? y : x)
|
#define min(x, y) (x > y ? y : x)
|
||||||
#define max(x, y) (x < y ? y : x)
|
#define max(x, y) (x < y ? y : x)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user