summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/util.c b/util.c
index 8b13492..6f252c6 100644
--- a/util.c
+++ b/util.c
@@ -4,8 +4,16 @@
#include "base.h"
static uint util_popcount(u64 x) {
- // @TODO: portability
+#ifdef __GNUC__
return (uint)__builtin_popcountll(x);
+#else
+ uint count = 0;
+ while (x) {
+ x &= x-1;
+ ++count;
+ }
+ return count;
+#endif
}
static bool util_is_power_of_2(u64 x) {