diff options
author | Stephen Hemminger <shemminger@osdl.org> | 2006-01-06 03:12:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-06 11:33:38 -0500 |
commit | d832245d7cc16d50b29c1b708ccbe9c75ac376a3 (patch) | |
tree | 2fc22b6337fc433a6b392e9b008339d8031e8e1c /include/asm-i386/bitops.h | |
parent | e31b88ba49460653bab87423287bb68743f5de5c (diff) |
[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 'include/asm-i386/bitops.h')
-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) | |||
367 | return word; | 367 | return word; |
368 | } | 368 | } |
369 | 369 | ||
370 | /* | ||
371 | * fls: find last bit set. | ||
372 | */ | ||
373 | |||
374 | #define fls(x) generic_fls(x) | ||
375 | #define fls64(x) generic_fls64(x) | 370 | #define fls64(x) generic_fls64(x) |
376 | 371 | ||
377 | #ifdef __KERNEL__ | 372 | #ifdef __KERNEL__ |
@@ -415,6 +410,23 @@ static inline int ffs(int x) | |||
415 | } | 410 | } |
416 | 411 | ||
417 | /** | 412 | /** |
413 | * fls - find last bit set | ||
414 | * @x: the word to search | ||
415 | * | ||
416 | * This is defined the same way as ffs. | ||
417 | */ | ||
418 | static inline int fls(int x) | ||
419 | { | ||
420 | int r; | ||
421 | |||
422 | __asm__("bsrl %1,%0\n\t" | ||
423 | "jnz 1f\n\t" | ||
424 | "movl $-1,%0\n" | ||
425 | "1:" : "=r" (r) : "rm" (x)); | ||
426 | return r+1; | ||
427 | } | ||
428 | |||
429 | /** | ||
418 | * hweightN - returns the hamming weight of a N-bit word | 430 | * hweightN - returns the hamming weight of a N-bit word |
419 | * @x: the word to weigh | 431 | * @x: the word to weigh |
420 | * | 432 | * |