diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-20 22:12:09 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-20 22:12:09 -0700 |
commit | 0febcde46a85855a3f3ec1bf872a2259b207efce (patch) | |
tree | 6f8aedb5976d211f34e471050966ac8ec40c40fe | |
parent | 7ea1400f84d2b9d73f80b242eef4b0ddddc27842 (diff) |
libmisc: macro.h: Fix LM_NEXT_POWER_OF_2(0)
Apparently __builtin_clzll(0) is undefined.
-rw-r--r-- | libmisc/include/libmisc/macro.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libmisc/include/libmisc/macro.h b/libmisc/include/libmisc/macro.h index d11b99f..fe61410 100644 --- a/libmisc/include/libmisc/macro.h +++ b/libmisc/include/libmisc/macro.h @@ -19,7 +19,7 @@ #define LM_ARRAY_LEN(ary) (sizeof(ary)/sizeof((ary)[0])) #define LM_CEILDIV(n, d) ( ((n)+(d)-1) / (d) ) #define LM_ROUND_UP(n, d) ( LM_CEILDIV(n, d) * (d) ) /** Return `n` rounded up to the nearest multiple of `d` */ -#define LM_NEXT_POWER_OF_2(x) ((1ULL)<<((sizeof(unsigned long long)*8)-__builtin_clzll(x))) +#define LM_NEXT_POWER_OF_2(x) ( (x) ? 1ULL<<((sizeof(unsigned long long)*8)-__builtin_clzll(x)) : 1) /* strings */ |