Attention is currently required from: Hoernchen, pespin.
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcu/+/33118 )
Change subject: pcu_utils.h: Replace software based bitcount impl with gcc builtin ......................................................................
pcu_utils.h: Replace software based bitcount impl with gcc builtin
The cast for different types it's not really needed, simply use the unsigned long long version to make sure we don't drop 1s, in any case __builtin_popcountll() will be quicker than what we used to have.
Change-Id: I80ae72d34d53564fc3da1601ee48c8b2ffe79735 --- M src/pcu_utils.h 1 file changed, 15 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/18/33118/1
diff --git a/src/pcu_utils.h b/src/pcu_utils.h index 1c698ca..2dd86ac 100644 --- a/src/pcu_utils.h +++ b/src/pcu_utils.h @@ -67,17 +67,10 @@ return fn % GSM_MAX_FN; }
-#ifdef __cplusplus -template <typename T> -inline unsigned int pcu_bitcount(T x) +inline unsigned int pcu_bitcount(unsigned long long x) { - unsigned int count = 0; - for (count = 0; x; count += 1) - x &= x - 1; - - return count; + return __builtin_popcountll(x); } -#endif
static inline uint8_t pcu_lsb(uint8_t x) {