summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-03-03 12:05:11 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-03-03 12:05:11 -0500
commit6f7c1546d6f57160644745429c13c5c9e8ca5b2e (patch)
tree9228cbfa495c6b9309c9c737c7577d71eb4cd731 /util.c
parent31b4505161f19e7b94cdd224bd4a3049970a0988 (diff)
finally figured out what wasn't working with buffer_set_line_len!
hooray!!!!!
Diffstat (limited to 'util.c')
-rw-r--r--util.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/util.c b/util.c
index 632bd0e..f0daa09 100644
--- a/util.c
+++ b/util.c
@@ -20,16 +20,24 @@ static u8 util_popcount(u64 x) {
#endif
}
-static u8 util_count_leading_zeroes(u64 x) {
+static u8 util_count_leading_zeroes32(u32 x) {
+ if (x == 0) return 32; // GCC's __builtin_clz is undefined for x = 0
#if __GNUC__
- return (u8)__builtin_clzll(x);
+#if UINT_MAX == 4294967295
+ return (u8)__builtin_clz(x);
+#else
+ #error "unsigned int isn't 32 bits. this function needs fixing to work on sytems like yours."
+#endif
#elif _WIN32
- return (u8)__lzcnt64(x);
+ return (u8)__lzcnt(x);
#else
u8 count = 0;
- for (int i = 63; i >= 0; --i)
- if (x & ((u64)1<<i))
- ++count;
+ for (int i = 31; i >= 0; --i) {
+ if (x & ((u32)1<<i)) {
+ break;
+ }
+ ++count;
+ }
return count;
#endif
}