aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcu_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pcu_utils.h')
-rw-r--r--src/pcu_utils.h24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/pcu_utils.h b/src/pcu_utils.h
index e1a8572a..540f7049 100644
--- a/src/pcu_utils.h
+++ b/src/pcu_utils.h
@@ -10,10 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#pragma once
#ifdef __cplusplus
@@ -71,23 +67,25 @@ 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
+/* Trim all 1 bits except the Least Significat Bit, which is kept.
+ * equivalent of (1 << ffs(u)) / 2
+ */
static inline uint8_t pcu_lsb(uint8_t x)
{
return x & -x;
}
+#define RFN_MODULUS 42432
+static inline uint16_t fn2rfn(uint32_t fn)
+{
+ return fn % RFN_MODULUS;
+}
+
/* Used to store a C++ class in a llist used by C code */
struct llist_item {
struct llist_head list; /* item used by llist */