aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.h
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-01 23:16:48 +0200
committerlemon <lsof@mailbox.org>2023-06-01 23:27:20 +0200
commit65ace14e184807df026e985e073b3b5c5aaf576c (patch)
treed4554e0eef30b6f8771bfa90835ff6dcb95198a7 /common.h
parenta98075934ece8c7ff351f8449f6515c12b9feec8 (diff)
basic ABI lowering of aggregates
Diffstat (limited to 'common.h')
-rw-r--r--common.h14
1 files changed, 12 insertions, 2 deletions
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
}
/******************/