From 65ace14e184807df026e985e073b3b5c5aaf576c Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 1 Jun 2023 23:16:48 +0200 Subject: basic ABI lowering of aggregates --- common.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'common.h') diff --git a/common.h b/common.h index 0871257..bd78a26 100644 --- a/common.h +++ b/common.h @@ -58,7 +58,7 @@ ptrhash(const void *p) { } static inline uint popcnt(uvlong x) { -#ifdef __GNUC__ +#if defined __has_builtin && __has_builtin(__builtin_popcountll) return __builtin_popcountll(x); #else uint n = 0; @@ -68,7 +68,17 @@ popcnt(uvlong x) { } static inline bool ispo2(uvlong x) { - return (x & (x - 1)) == 0; + return x & ((x & (x - 1)) == 0); +} +static inline uint +ilog2(uint x) { /* assumes x is a power of 2 */ +#if defined __has_builtin && __has_builtin(__builtin_ctz) + return __builtin_ctz(x); +#else + uint n = 0; + while (x >>= 1) ++n; + return n; +#endif } /******************/ -- cgit v1.2.3