diff options
author | Stephen Hemminger <shemminger@osdl.org> | 2006-01-06 09:12:12 +0100 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-06 17:33:38 +0100 |
commit | d832245d7cc16d50b29c1b708ccbe9c75ac376a3 (patch) | |
tree | 2fc22b6337fc433a6b392e9b008339d8031e8e1c /include/asm-i386/bitops.h | |
parent | [PATCH] x86: missing printk newline in apic boot option parser (diff) | |
download | linux-d832245d7cc16d50b29c1b708ccbe9c75ac376a3.tar.xz linux-d832245d7cc16d50b29c1b708ccbe9c75ac376a3.zip |
[PATCH] x86: fls() in asm
There is a single instruction on i386 to find largest set bit; so it makes
sense to use it (like we use bfs for ffs()).
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to '')
-rw-r--r-- | include/asm-i386/bitops.h | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/include/asm-i386/bitops.h b/include/asm-i386/bitops.h index 26eb9811712f..65679aca4b22 100644 --- a/include/asm-i386/bitops.h +++ b/include/asm-i386/bitops.h @@ -367,11 +367,6 @@ static inline unsigned long ffz(unsigned long word) return word; } -/* - * fls: find last bit set. - */ - -#define fls(x) generic_fls(x) #define fls64(x) generic_fls64(x) #ifdef __KERNEL__ @@ -415,6 +410,23 @@ static inline int ffs(int 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" + "jnz 1f\n\t" + "movl $-1,%0\n" + "1:" : "=r" (r) : "rm" (x)); + return r+1; +} + +/** * hweightN - returns the hamming weight of a N-bit word * @x: the word to weigh * |