From 6c2f758cee266f764828b05fb7811ee3d4a7adec Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Thu, 5 Nov 2015 12:43:25 -0200 Subject: [PATCH] x86: Use the generic bitops headers Use the generic bitops and also add custom __ffs() implementation as per the kernel. Also align the ffs() implementation with the kernel. Signed-off-by: Fabio Estevam Reviewed-by: Tom Rini Reviewed-by: Heiko Schocher Reviewed-by: Jagan Teki --- arch/x86/include/asm/bitops.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h index 5a7e4cba2b..f97dc66439 100644 --- a/arch/x86/include/asm/bitops.h +++ b/arch/x86/include/asm/bitops.h @@ -14,6 +14,10 @@ * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). */ +#include +#include +#include + #ifdef CONFIG_SMP #define LOCK_PREFIX "lock ; " #else @@ -331,6 +335,20 @@ static __inline__ unsigned long ffz(unsigned long word) #ifdef __KERNEL__ +/** + * __ffs - find first set bit in word + * @word: The word to search + * + * Undefined if no bit exists, so code should check against 0 first. + */ +static inline unsigned long __ffs(unsigned long word) +{ + __asm__("rep; bsf %1,%0" + : "=r" (word) + : "rm" (word)); + return word; +} + /** * ffs - find first bit set * @x: the word to search @@ -346,7 +364,8 @@ static __inline__ int ffs(int x) __asm__("bsfl %1,%0\n\t" "jnz 1f\n\t" "movl $-1,%0\n" - "1:" : "=r" (r) : "g" (x)); + "1:" : "=r" (r) : "rm" (x)); + return r+1; } #define PLATFORM_FFS