提交 636dd2b7 编写于 作者: S Stephen Hemminger 提交者: Linus Torvalds

[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: NStephen Hemminger <shemminger@osdl.org>
Signed-off-by: NAndi Kleen <ak@suse.de>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 bd9cb64d
...@@ -396,6 +396,22 @@ static __inline__ int fls64(__u64 x) ...@@ -396,6 +396,22 @@ static __inline__ int fls64(__u64 x)
return __fls(x) + 1; return __fls(x) + 1;
} }
/**
* 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 * hweightN - returns the hamming weight of a N-bit word
* @x: the word to weigh * @x: the word to weigh
...@@ -434,9 +450,6 @@ static __inline__ int fls64(__u64 x) ...@@ -434,9 +450,6 @@ static __inline__ int fls64(__u64 x)
#define minix_find_first_zero_bit(addr,size) \ #define minix_find_first_zero_bit(addr,size) \
find_first_zero_bit((void*)addr,size) find_first_zero_bit((void*)addr,size)
/* find last set bit */
#define fls(x) generic_fls(x)
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _X86_64_BITOPS_H */ #endif /* _X86_64_BITOPS_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册