aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-04-15 17:45:47 -0400
committerJack Lloyd <[email protected]>2018-04-15 17:45:47 -0400
commit2e3050c98994a4f4792839a3a1e1f294b24ba363 (patch)
tree97ab26cdb25860332acecbe51c7cc3bcdc046471 /src/lib
parent92605ef479e6b12a095a5451d20bcbcc72007c09 (diff)
Use GCC builtins for clz operation
Diffstat (limited to 'src/lib')
-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)