summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-11-25 09:17:00 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-11-25 09:17:00 -0500
commit4e51199f1103d2d9daa563b63d0e8f22c36fbe8a (patch)
tree707b7cf557f1b9937a58c66f593847bd957e07b3 /util.c
parente3aa668ef358739148adb1a4965b629d07467575 (diff)
got windows build to work
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) {