CHECK(ffsl, 1UL << 32, 33);
CHECK(ffsl, 1UL << 63, 64);
#endif
+
+ /*
+ * unsigned int ffs64(uint64_t)
+ *
+ * 32-bit builds of Xen have to split this into two adjacent operations,
+ * so test all interesting bit positions across the divide.
+ */
+ CHECK(ffs64, 0, 0);
+ CHECK(ffs64, 1, 1);
+ CHECK(ffs64, 3, 1);
+ CHECK(ffs64, 7, 1);
+ CHECK(ffs64, 6, 2);
+
+ CHECK(ffs64, 0x8000000080000000ULL, 32);
+ CHECK(ffs64, 0x8000000100000000ULL, 33);
+ CHECK(ffs64, 0x8000000000000000ULL, 64);
}
static void __init test_fls(void)
CHECK(flsl, 1 | (1UL << 32), 33);
CHECK(flsl, 1 | (1UL << 63), 64);
#endif
+
+ /*
+ * unsigned int fls64(uint64_t)
+ *
+ * 32-bit builds of Xen have to split this into two adjacent operations,
+ * so test all interesting bit positions across the divide.
+ */
+ CHECK(fls64, 0, 0);
+ CHECK(fls64, 1, 1);
+ CHECK(fls64, 3, 2);
+ CHECK(fls64, 7, 3);
+ CHECK(fls64, 6, 3);
+
+ CHECK(fls64, 0x0000000080000001ULL, 32);
+ CHECK(fls64, 0x0000000100000001ULL, 33);
+ CHECK(fls64, 0x8000000000000001ULL, 64);
}
static void __init __constructor test_bitops(void)
#endif
}
+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;
+}
+
static always_inline __pure unsigned int fls(unsigned int x)
{
if ( __builtin_constant_p(x) )
#endif
}
+static always_inline __pure unsigned int fls64(uint64_t x)
+{
+ if ( BITS_PER_LONG == 64 )
+ return flsl(x);
+ else
+ {
+ uint32_t h = x >> 32;
+
+ return h ? fls(h) + 32 : fls(x);
+ }
+}
+
/* --------------------- Please tidy below here --------------------- */
#ifndef find_next_bit
unsigned long size);
#endif
-#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)
-{
- __u32 h = x >> 32;
-
- return h ? fls(h) + 32 : fls(x);
-}
-# define fls64 generic_fls64
-# endif
-#endif
-
static inline int get_bitmask_order(unsigned int count)
{
int order;