aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcu_utils.h
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2016-01-19 15:48:03 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2016-02-08 00:45:36 +0100
commit8cba7e9b6d11918c9865006b41f768943e1e44df (patch)
treea6182e97c2e93cbf609557a1eb2b0ad7cc48cbcf /src/pcu_utils.h
parent13965aed74ae1c59cfd4f52275ac3e98f9aa9e3a (diff)
utils: Add pcu_bitcount and pcu_lsb
These functions are currently defined in src/gprs_rlcmac_ts_alloc.cpp but will be needed elsewhere. Turn them into template functions to support different types and move them to pcu_utils.h. Sponsored-by: On-Waves ehf
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 5ca234a4..d6644462 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;
+}