aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-05-31 18:41:30 +0200
committerlaforge <laforge@osmocom.org>2023-06-03 12:46:26 +0000
commitba8918aae8342497e6e219239f3ed29dc8290349 (patch)
tree0e039d9edca4996f357a4f92462160b26e750dce
parentab571af3f2720eed80bc165106b90b080f7f7cb3 (diff)
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
-rw-r--r--src/pcu_utils.h11
1 files changed, 2 insertions, 9 deletions
diff --git a/src/pcu_utils.h b/src/pcu_utils.h
index a6beab04..0be37e94 100644
--- a/src/pcu_utils.h
+++ b/src/pcu_utils.h
@@ -67,17 +67,10 @@ static inline unsigned fn_next_block(unsigned fn)
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)
{