Skip to content

Commit

Permalink
[POWERPC] Optimize fls64() on 64-bit processors
Browse files Browse the repository at this point in the history
64-bit powerpc processors can find the leftmost 1 bit in a 64-bit
doubleword in one instruction, so use that rather than using the
generic fls64(), which does two 32-bit fls() calls.

Signed-off-by: Paul Mackerras <paulus@samba.org>
  • Loading branch information
Paul Mackerras committed Apr 18, 2008
1 parent 945feb1 commit 9f264be
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/asm-powerpc/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,24 @@ static __inline__ int fls(unsigned int x)
asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
return 32 - lz;
}

/*
* 64-bit can do this using one cntlzd (count leading zeroes doubleword)
* instruction; for 32-bit we use the generic version, which does two
* 32-bit fls calls.
*/
#ifdef __powerpc64__
static __inline__ int fls64(__u64 x)
{
int lz;

asm ("cntlzd %0,%1" : "=r" (lz) : "r" (x));
return 64 - lz;
}
#else
#include <asm-generic/bitops/fls64.h>
#endif /* __powerpc64__ */

#include <asm-generic/bitops/hweight.h>
#include <asm-generic/bitops/find.h>

Expand Down

0 comments on commit 9f264be

Please sign in to comment.