You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2023/02/02 23:11:22 UTC
[mynewt-nimble] 01/03: nimble/ll: Optimize num used channels calculation
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit c995fe4fc40cfdb0967c98bff53f7d0bcc36030e
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Jan 31 11:23:20 2023 +0100
nimble/ll: Optimize num used channels calculation
popcount calculates number of bits set without loop.
---
nimble/controller/src/ble_ll_utils.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index 3603742d..5d023b11 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -253,21 +253,8 @@ ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap)
uint8_t
ble_ll_utils_calc_num_used_chans(const uint8_t *chan_map)
{
- uint32_t u32 = 0;
- uint32_t num_used_chans = 0;
- unsigned idx;
-
- for (idx = 0; idx < 37; idx++) {
- if ((idx % 8) == 0) {
- u32 = chan_map[idx / 8];
- }
- if (u32 & 1) {
- num_used_chans++;
- }
- u32 >>= 1;
- }
-
- return num_used_chans;
+ return __builtin_popcountll(((uint64_t)(chan_map[4] & 0x1f) << 32) |
+ get_le32(chan_map));
}
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CSA2)