[PATCH] speed up on find_first_bit for i386 (let compiler do the work)
Avoid using "rep scas", just let the compiler select a sequence of regular instructions. Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
committed by
Linus Torvalds
parent
79a8810221
commit
cd85c8b445
@@ -310,6 +310,20 @@ static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
|
|||||||
*/
|
*/
|
||||||
int find_next_zero_bit(const unsigned long *addr, int size, int offset);
|
int find_next_zero_bit(const unsigned long *addr, int size, int offset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __ffs - find first bit in word.
|
||||||
|
* @word: The word to search
|
||||||
|
*
|
||||||
|
* Undefined if no bit exists, so code should check against 0 first.
|
||||||
|
*/
|
||||||
|
static inline unsigned long __ffs(unsigned long word)
|
||||||
|
{
|
||||||
|
__asm__("bsfl %1,%0"
|
||||||
|
:"=r" (word)
|
||||||
|
:"rm" (word));
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find_first_bit - find the first set bit in a memory region
|
* find_first_bit - find the first set bit in a memory region
|
||||||
* @addr: The address to start the search at
|
* @addr: The address to start the search at
|
||||||
@@ -320,22 +334,16 @@ int find_next_zero_bit(const unsigned long *addr, int size, int offset);
|
|||||||
*/
|
*/
|
||||||
static inline int find_first_bit(const unsigned long *addr, unsigned size)
|
static inline int find_first_bit(const unsigned long *addr, unsigned size)
|
||||||
{
|
{
|
||||||
int d0, d1;
|
int x = 0;
|
||||||
int res;
|
do {
|
||||||
|
if (*addr)
|
||||||
/* This looks at memory. Mark it volatile to tell gcc not to move it around */
|
return __ffs(*addr) + x;
|
||||||
__asm__ __volatile__(
|
addr++;
|
||||||
"xorl %%eax,%%eax\n\t"
|
if (x >= size)
|
||||||
"repe; scasl\n\t"
|
break;
|
||||||
"jz 1f\n\t"
|
x += (sizeof(*addr)<<3);
|
||||||
"leal -4(%%edi),%%edi\n\t"
|
} while (1);
|
||||||
"bsfl (%%edi),%%eax\n"
|
return x;
|
||||||
"1:\tsubl %%ebx,%%edi\n\t"
|
|
||||||
"shll $3,%%edi\n\t"
|
|
||||||
"addl %%edi,%%eax"
|
|
||||||
:"=a" (res), "=&c" (d0), "=&D" (d1)
|
|
||||||
:"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory");
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,20 +368,6 @@ static inline unsigned long ffz(unsigned long word)
|
|||||||
return word;
|
return word;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* __ffs - find first bit in word.
|
|
||||||
* @word: The word to search
|
|
||||||
*
|
|
||||||
* Undefined if no bit exists, so code should check against 0 first.
|
|
||||||
*/
|
|
||||||
static inline unsigned long __ffs(unsigned long word)
|
|
||||||
{
|
|
||||||
__asm__("bsfl %1,%0"
|
|
||||||
:"=r" (word)
|
|
||||||
:"rm" (word));
|
|
||||||
return word;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fls: find last bit set.
|
* fls: find last bit set.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user