From 8cba7e9b6d11918c9865006b41f768943e1e44df Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 19 Jan 2016 15:48:03 +0100 Subject: utils: Add pcu_bitcount and pcu_lsb 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. Sponsored-by: On-Waves ehf --- src/gprs_rlcmac_ts_alloc.cpp | 29 ++++++++--------------------- src/pcu_utils.h | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp index e6c8ad4..57197b2 100644 --- a/src/gprs_rlcmac_ts_alloc.cpp +++ b/src/gprs_rlcmac_ts_alloc.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -80,20 +81,6 @@ static const struct gprs_ms_multislot_class gprs_ms_multislot_class[32] = { /* N/A */ { MS_NA,MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA }, }; -static unsigned lsb(unsigned x) -{ - return x & -x; -} - -static unsigned bitcount(unsigned x) -{ - unsigned count = 0; - for (count = 0; x; count += 1) - x &= x - 1; - - return count; -} - static char *set_flag_chars(char *buf, uint8_t val, char set_char, char unset_char = 0) { int i; @@ -640,7 +627,7 @@ static int find_multi_slots(struct gprs_rlcmac_bts *bts, if ((tx_window & (1 << ((ul_ts+num_tx-1) % 8))) == 0) continue; - tx_slot_count = bitcount(tx_window); + tx_slot_count = pcu_bitcount(tx_window); max_rx = OSMO_MIN(ms_class->rx, ms_class->sum - num_tx); rx_valid_win = (1 << max_rx) - 1; @@ -669,7 +656,7 @@ static int find_multi_slots(struct gprs_rlcmac_bts *bts, * testing */ rx_window = rx_good & rx_valid_win; - rx_slot_count = bitcount(rx_window); + rx_slot_count = pcu_bitcount(rx_window); #if 0 LOGP(DRLCMAC, LOGL_DEBUG, "n_tx=%d, n_rx=%d, mask_sel=%d, " @@ -734,7 +721,7 @@ static int find_multi_slots(struct gprs_rlcmac_bts *bts, continue; /* Check number of common slots according to TS 54.002, 6.4.2.2 */ - common_slot_count = bitcount(tx_window & rx_window); + common_slot_count = pcu_bitcount(tx_window & rx_window); req_common_slots = OSMO_MIN(tx_slot_count, rx_slot_count); if (ms_class->type == 1) req_common_slots = OSMO_MIN(req_common_slots, 2); @@ -891,7 +878,7 @@ int alloc_algorithm_b(struct gprs_rlcmac_bts *bts, dl_slots & ul_slots, compute_usage_by_num_tbfs, NULL, NULL); if (ts < 0) - ul_slots = dl_slots = lsb(dl_slots & ul_slots); + ul_slots = dl_slots = pcu_lsb(dl_slots & ul_slots); else ul_slots = dl_slots = (dl_slots & ul_slots) & (1<tv_sec = csecs / 100; tv->tv_usec = (csecs % 100) * 10000; } + +template +inline unsigned int pcu_bitcount(T x) +{ + unsigned int count = 0; + for (count = 0; x; count += 1) + x &= x - 1; + + return count; +} + +template +inline T pcu_lsb(T x) +{ + return x & -x; +} -- cgit v1.2.1