summaryrefslogtreecommitdiff
path: root/src/base/bitfield.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/bitfield.hh')
-rw-r--r--src/base/bitfield.hh11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index 23c8b4b12..d696715b3 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -282,4 +282,15 @@ inline uint64_t alignToPowerOfTwo(uint64_t val)
return val;
};
+/**
+ * Count trailing zeros in a 32-bit value.
+ *
+ * Returns 32 if the value is zero. Note that the GCC builtin is
+ * undefined if the value is zero.
+ */
+inline int ctz32(uint32_t value)
+{
+ return value ? __builtin_ctz(value) : 32;
+}
+
#endif // __BASE_BITFIELD_HH__