diff options
author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2016-01-19 15:48:03 +0100 |
---|---|---|
committer | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2016-02-02 17:06:35 +0100 |
commit | e68c6b6d1dd64572bdb9818d4c18de0c21cc18d0 (patch) | |
tree | b4913e1aea651164a0fefd5edea9c39e50506f7a /src/pcu_utils.h | |
parent | a08e7afee9043442be48aa47659393eac4b50ef6 (diff) |
utils: Add pcu_bitcount and pcu_lsb (TODO)
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.
TODO:
- remove old functions
Sponsored-by: On-Waves ehf
Diffstat (limited to 'src/pcu_utils.h')
-rw-r--r-- | src/pcu_utils.h | 16 |
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; +} |