From: Stephen Hemminger Date: Wed, 11 Jan 2006 21:43:24 +0000 (+0100) Subject: [PATCH] x86_64: fls in asm for x86_64 X-Git-Tag: v3.12-rc1~39494 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=636dd2b7def5c9c72551b51d4d516a65c269de08;p=kernel%2Fkernel-generic.git [PATCH] x86_64: fls in asm for x86_64 Use single instruction for find largest set bit on x86_64. [Updated by Jan Beulich to fix wrong asm constraints in original patch -AK] Cc: jbeulich@novell.com Signed-off-by: Stephen Hemminger Signed-off-by: Andi Kleen Signed-off-by: Linus Torvalds --- diff --git a/include/asm-x86_64/bitops.h b/include/asm-x86_64/bitops.h index 3638fff..eb4df23 100644 --- a/include/asm-x86_64/bitops.h +++ b/include/asm-x86_64/bitops.h @@ -397,6 +397,22 @@ static __inline__ int fls64(__u64 x) } /** + * fls - find last bit set + * @x: the word to search + * + * This is defined the same way as ffs. + */ +static __inline__ int fls(int x) +{ + int r; + + __asm__("bsrl %1,%0\n\t" + "cmovzl %2,%0" + : "=&r" (r) : "rm" (x), "rm" (-1)); + return r+1; +} + +/** * hweightN - returns the hamming weight of a N-bit word * @x: the word to weigh * @@ -434,9 +450,6 @@ static __inline__ int fls64(__u64 x) #define minix_find_first_zero_bit(addr,size) \ find_first_zero_bit((void*)addr,size) -/* find last set bit */ -#define fls(x) generic_fls(x) - #endif /* __KERNEL__ */ #endif /* _X86_64_BITOPS_H */