Commit d832245d authored by Stephen Hemminger's avatar Stephen Hemminger Committed by Linus Torvalds

[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: default avatarStephen Hemminger <shemminger@osdl.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e31b88ba
...@@ -367,11 +367,6 @@ static inline unsigned long ffz(unsigned long word) ...@@ -367,11 +367,6 @@ static inline unsigned long ffz(unsigned long word)
return word; return word;
} }
/*
* fls: find last bit set.
*/
#define fls(x) generic_fls(x)
#define fls64(x) generic_fls64(x) #define fls64(x) generic_fls64(x)
#ifdef __KERNEL__ #ifdef __KERNEL__
...@@ -414,6 +409,23 @@ static inline int ffs(int x) ...@@ -414,6 +409,23 @@ static inline int ffs(int x)
return r+1; return r+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"
"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 * hweightN - returns the hamming weight of a N-bit word
* @x: the word to weigh * @x: the word to weigh
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment