aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/bit_ops.h27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/lib/utils/bit_ops.h b/src/lib/utils/bit_ops.h
index aa41db391..c7e401492 100644
--- a/src/lib/utils/bit_ops.h
+++ b/src/lib/utils/bit_ops.h
@@ -107,11 +107,36 @@ inline size_t ctz(T n)
template<>
inline size_t ctz(uint32_t n)
{
+ if(n == 0)
+ return 32;
return __builtin_ctz(n);
}
-#endif
+template<>
+inline size_t ctz(uint64_t n)
+ {
+ if(n == 0)
+ return 64;
+ return __builtin_ctzll(n);
+ }
+template<>
+inline size_t high_bit(uint32_t x)
+ {
+ if(x == 0)
+ return 0;
+ return (32 - __builtin_clz(x));
+ }
+
+template<>
+inline size_t high_bit(uint64_t x)
+ {
+ if(x == 0)
+ return 0;
+ return (64 - __builtin_clzll(x));
+ }
+
+#endif
template<typename T>
size_t ceil_log2(T x)