As per ffs()/ffsl() in previous patches. Add tests for all interesting bit positions at 32bit boundaries.
Signed-off-by: Andrew Cooper <[email protected]> --- CC: Jan Beulich <[email protected]> CC: Roger Pau Monné <[email protected]> CC: Wei Liu <[email protected]> CC: Stefano Stabellini <[email protected]> CC: Julien Grall <[email protected]> CC: Volodymyr Babchuk <[email protected]> CC: Bertrand Marquis <[email protected]> CC: Michal Orzel <[email protected]> CC: Oleksii Kurochko <[email protected]> CC: Shawn Anastasio <[email protected]> CC: [email protected] <[email protected]> CC: Simone Ballarin <[email protected]> CC: Federico Serafini <[email protected]> CC: Nicola Vetrini <[email protected]> --- xen/common/bitops.c | 12 ++++++++++++ xen/include/xen/bitops.h | 16 ++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/xen/common/bitops.c b/xen/common/bitops.c index eceffe5029d6..cd194fe672b7 100644 --- a/xen/common/bitops.c +++ b/xen/common/bitops.c @@ -47,6 +47,18 @@ static void test_ffs(void) CHECK(ffsl, 1UL << (BITS_PER_LONG - 1), BITS_PER_LONG); if ( BITS_PER_LONG > 32 ) CHECK(ffsl, 1UL << 32, 33); + + /* + * unsigned int ffs64(uint64_t) + * + * 32-bit builds of Xen have to split this into two adjacent operations, + * so test all interesting bit positions. + */ + CHECK(ffs64, 0, 0); + CHECK(ffs64, 1, 1); + CHECK(ffs64, (uint64_t)0x0000000080000000, 32); + CHECK(ffs64, (uint64_t)0x0000000100000000, 33); + CHECK(ffs64, (uint64_t)0x8000000000000000, 64); } static int __init cf_check test_bitops(void) diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index b85b35c40781..f14ad0d33aa3 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -96,6 +96,14 @@ static always_inline __pure unsigned int ffsl(unsigned long x) return arch_ffsl(x); } +static always_inline __pure unsigned int ffs64(uint64_t x) +{ + if ( BITS_PER_LONG == 64 ) + return ffsl(x); + else + return !x || (uint32_t)x ? ffs(x) : ffs(x >> 32) + 32; +} + /* --------------------- Please tidy below here --------------------- */ #ifndef find_next_bit @@ -148,15 +156,7 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #if BITS_PER_LONG == 64 # define fls64 flsl -# define ffs64 ffsl #else -# ifndef ffs64 -static inline int generic_ffs64(__u64 x) -{ - return !x || (__u32)x ? ffs(x) : ffs(x >> 32) + 32; -} -# define ffs64 generic_ffs64 -# endif # ifndef fls64 static inline int generic_fls64(__u64 x) { -- 2.30.2
