fix(common): use stdbit.h for C23
This commit is contained in:
parent
2cc4fcc83b
commit
96d05f7e61
|
@ -7,12 +7,17 @@
|
|||
#define max(a, b) ((a) > (b) ? (a) : (b)) /* find the maximum of two numbers */
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b)) /* find the minimum of two numbers */
|
||||
|
||||
#if UINTPTR_MAX == 0xffffffffffffffff
|
||||
# define next_pow_of_two(n) (((size_t) 1) << (64 - __builtin_clzll (n))) /* round up a size_t number to the next power of two (64-bit) */
|
||||
#elif UINTPTR_MAX == 0xffffffff
|
||||
# define next_pow_of_two(n) (((size_t) 1) << (64 - __builtin_clz (n))) /* round up a size_t number to the next power of two (32-bit) */
|
||||
#if __STDC_VERSION__ >= 202000L // C23 or above
|
||||
# include <stdbit.h>
|
||||
# define next_pow_of_two(n) (((size_t) 1) << (64 - stdc_leading_zeros (n))) /* round up a size_t number to the next power of two (64-bit) */
|
||||
#else
|
||||
# error unsupported architecture: size_t expected to be 64-bit or 32-bit.
|
||||
# if UINTPTR_MAX == 0xffffffffffffffff
|
||||
# define next_pow_of_two(n) (((size_t) 1) << (64 - __builtin_clzll (n))) /* round up a size_t number to the next power of two (64-bit) */
|
||||
# elif UINTPTR_MAX == 0xffffffff
|
||||
# define next_pow_of_two(n) (((size_t) 1) << (64 - __builtin_clz (n))) /* round up a size_t number to the next power of two (32-bit) */
|
||||
# else
|
||||
# error unsupported architecture: size_t expected to be 64-bit or 32-bit.
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void *smalloc (size_t size); /* safe malloc */
|
||||
|
|
Loading…
Reference in New Issue