laforge submitted this change.

View Change


Approvals: laforge: Looks good to me, approved fixeria: Looks good to me, but someone else must approve Jenkins Builder: Verified
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(-)

diff --git a/src/pcu_utils.h b/src/pcu_utils.h
index a6beab0..0be37e9 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)
{

To view, visit change 33118. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: I80ae72d34d53564fc3da1601ee48c8b2ffe79735
Gerrit-Change-Number: 33118
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Hoernchen <ewild@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-MessageType: merged