diff options
author | Damjan Marion <damarion@cisco.com> | 2021-04-25 10:58:07 +0200 |
---|---|---|
committer | Damjan Marion <damarion@cisco.com> | 2021-04-25 10:59:42 +0200 |
commit | e21a0b26042f615fdbe8d2c6b29612c212079d52 (patch) | |
tree | fc261beb3264d8c0f44717c916554fe50cd190a1 /src | |
parent | 1ca6c65e5109b220d25dace08ae758c31e5ea5a2 (diff) |
vppinfra: add clear_lowest_set_bit() function, use BMI2 if available
Type: improvement
Change-Id: I973cacd0cade0ca98e6261c1fb026a5eb38b44d3
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/vppinfra/clib.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/vppinfra/clib.h b/src/vppinfra/clib.h index 22377c61440..05af8fe7168 100644 --- a/src/vppinfra/clib.h +++ b/src/vppinfra/clib.h @@ -159,6 +159,16 @@ #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 +} + +always_inline uword min_log2 (uword x) { uword n; |