From 7b90f669d83f432f3610ec0da522bd8ccc4dff01 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Thu, 13 Jan 2022 00:28:14 +0100 Subject: vppinfra: bitops cleanup Type: refactor Change-Id: I7fa113e924640f9d798c1eb6ae64b9c0a9e2104c Signed-off-by: Damjan Marion --- src/vppinfra/clib.h | 71 +---------------------------------------------------- 1 file changed, 1 insertion(+), 70 deletions(-) (limited to 'src/vppinfra/clib.h') diff --git a/src/vppinfra/clib.h b/src/vppinfra/clib.h index 1b6ab4157d7..b3a2580e73a 100644 --- a/src/vppinfra/clib.h +++ b/src/vppinfra/clib.h @@ -164,25 +164,7 @@ decl __attribute ((destructor)); \ decl -/* Use __builtin_clz if available. */ -#if uword_bits == 64 -#define count_leading_zeros(x) __builtin_clzll (x) -#define count_trailing_zeros(x) __builtin_ctzll (x) -#else -#define count_leading_zeros(x) __builtin_clzl (x) -#define count_trailing_zeros(x) __builtin_ctzl (x) -#endif - -#if defined (count_leading_zeros) -always_inline uword -clear_lowest_set_bit (uword x) -{ -#ifdef __BMI2__ - return _blsr_u64 (x); -#else - return x ^ (1ULL << count_trailing_zeros (x)); -#endif -} +#include always_inline uword min_log2 (uword x) @@ -191,45 +173,6 @@ min_log2 (uword x) n = count_leading_zeros (x); return BITS (uword) - n - 1; } -#else -always_inline uword -min_log2 (uword x) -{ - uword a = x, b = BITS (uword) / 2, c = 0, r = 0; - - /* Reduce x to 4 bit result. */ -#define _ \ -{ \ - c = a >> b; \ - if (c) a = c; \ - if (c) r += b; \ - b /= 2; \ -} - - if (BITS (uword) > 32) - _; - _; - _; - _; -#undef _ - - /* Do table lookup on 4 bit partial. */ - if (BITS (uword) > 32) - { - const u64 table = 0x3333333322221104LL; - uword t = (table >> (4 * a)) & 0xf; - r = t < 4 ? r + t : ~0; - } - else - { - const u32 table = 0x22221104; - uword t = (a & 8) ? 3 : ((table >> (4 * a)) & 0xf); - r = t < 4 ? r + t : ~0; - } - - return r; -} -#endif always_inline uword max_log2 (uword x) @@ -308,18 +251,6 @@ first_set (uword x) return x & -x; } -always_inline uword -log2_first_set (uword x) -{ - uword result; -#ifdef count_trailing_zeros - result = count_trailing_zeros (x); -#else - result = min_log2 (first_set (x)); -#endif - return result; -} - always_inline f64 flt_round_down (f64 x) { -- cgit 1.2.3-korg