summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-13 13:33:05 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-13 13:33:05 -0500
commitcdca3cc10dceda9580b2d87c2105c0654aa084fc (patch)
tree9da58ddc281c7cb002e4102b5d39e095c1b4d9b0 /util.c
parent94aba782d6e2a4ec287c8159e087b3fd621a8a67 (diff)
removed line->capacity
also fixed shift+click to select
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/util.c b/util.c
index 1584e0b..73f1e02 100644
--- a/util.c
+++ b/util.c
@@ -1,3 +1,7 @@
+#if _WIN32
+#include <intrin.h>
+#endif
+
static u8 util_popcount(u64 x) {
#ifdef __GNUC__
return (u8)__builtin_popcountll(x);
@@ -11,6 +15,20 @@ static u8 util_popcount(u64 x) {
#endif
}
+static u8 util_count_leading_zeroes(u64 x) {
+#if __GNUC__
+ return (u8)__builtin_clzll(x);
+#elif _WIN32
+ return (u8)__lzcnt64(x);
+#else
+ u8 count = 0;
+ for (int i = 63; i >= 0; --i)
+ if (x & ((u64)1<<i))
+ ++count;
+ return count;
+#endif
+}
+
static bool util_is_power_of_2(u64 x) {
return util_popcount(x) == 1;
}