aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcu_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pcu_utils.h')
-rw-r--r--src/pcu_utils.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pcu_utils.h b/src/pcu_utils.h
index 5ca234a..d664446 100644
--- a/src/pcu_utils.h
+++ b/src/pcu_utils.h
@@ -24,3 +24,19 @@ inline void csecs_to_timeval(unsigned csecs, struct timeval *tv) {
tv->tv_sec = csecs / 100;
tv->tv_usec = (csecs % 100) * 10000;
}
+
+template <typename T>
+inline unsigned int pcu_bitcount(T x)
+{
+ unsigned int count = 0;
+ for (count = 0; x; count += 1)
+ x &= x - 1;
+
+ return count;
+}
+
+template <typename T>
+inline T pcu_lsb(T x)
+{
+ return x & -x;
+}