|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 5/7] xen/bitops: Implement ffs64() in common logic
As per ffs()/ffsl() in previous patches. Add tests for all interesting bit
positions at 32bit boundaries.
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Julien Grall <julien@xxxxxxx>
CC: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
CC: Bertrand Marquis <bertrand.marquis@xxxxxxx>
CC: Michal Orzel <michal.orzel@xxxxxxx>
CC: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
CC: Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>
CC: consulting@xxxxxxxxxxx <consulting@xxxxxxxxxxx>
CC: Simone Ballarin <simone.ballarin@xxxxxxxxxxx>
CC: Federico Serafini <federico.serafini@xxxxxxxxxxx>
CC: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
---
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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |