Skip to content

Commit

Permalink
generic: implement __fls on all 64-bit archs
Browse files Browse the repository at this point in the history
Implement __fls on all 64-bit archs:

alpha has an implementation of fls64.
	Added __fls(x) = fls64(x) - 1.

ia64 has fls, but not __fls.
	Added __fls based on code of fls.

mips and powerpc have __ilog2, which is the same as __fls.
	Added __fls = __ilog2.

parisc, s390, sh and sparc64:
	Include generic __fls.

x86_64 already has __fls.

Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Alexander van Heukelum authored and Ingo Molnar committed Apr 26, 2008
1 parent 7d9dff2 commit 56a6b1e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/asm-alpha/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ static inline int fls64(unsigned long x)
}
#endif

static inline unsigned long __fls(unsigned long x)
{
return fls64(x) - 1;
}

static inline int fls(int x)
{
return fls64((unsigned int) x);
Expand Down
16 changes: 16 additions & 0 deletions include/asm-ia64/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,22 @@ fls (int t)
return ia64_popcnt(x);
}

/*
* Find the last (most significant) bit set. Undefined for x==0.
* Bits are numbered from 0..63 (e.g., __fls(9) == 3).
*/
static inline unsigned long
__fls (unsigned long x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x |= x >> 32;
return ia64_popcnt(x) - 1;
}

#include <asm-generic/bitops/fls64.h>

/*
Expand Down
5 changes: 5 additions & 0 deletions include/asm-mips/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@ static inline int __ilog2(unsigned long x)
return 63 - lz;
}

static inline unsigned long __fls(unsigned long x)
{
return __ilog2(x);
}

#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)

/*
Expand Down
1 change: 1 addition & 0 deletions include/asm-parisc/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ static __inline__ int fls(int x)
return ret;
}

#include <asm-generic/bitops/__fls.h>
#include <asm-generic/bitops/fls64.h>
#include <asm-generic/bitops/hweight.h>
#include <asm-generic/bitops/lock.h>
Expand Down
5 changes: 5 additions & 0 deletions include/asm-powerpc/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ static __inline__ int fls(unsigned int x)
return 32 - lz;
}

static __inline__ unsigned long __fls(unsigned long x)
{
return __ilog2(x);
}

/*
* 64-bit can do this using one cntlzd (count leading zeroes doubleword)
* instruction; for 32-bit we use the generic version, which does two
Expand Down
1 change: 1 addition & 0 deletions include/asm-s390/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ static inline int sched_find_first_bit(unsigned long *b)
}

#include <asm-generic/bitops/fls.h>
#include <asm-generic/bitops/__fls.h>
#include <asm-generic/bitops/fls64.h>

#include <asm-generic/bitops/hweight.h>
Expand Down
1 change: 1 addition & 0 deletions include/asm-sh/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static inline unsigned long ffz(unsigned long word)
#include <asm-generic/bitops/ext2-atomic.h>
#include <asm-generic/bitops/minix.h>
#include <asm-generic/bitops/fls.h>
#include <asm-generic/bitops/__fls.h>
#include <asm-generic/bitops/fls64.h>

#endif /* __KERNEL__ */
Expand Down
1 change: 1 addition & 0 deletions include/asm-sparc64/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern void change_bit(unsigned long nr, volatile unsigned long *addr);
#include <asm-generic/bitops/ffz.h>
#include <asm-generic/bitops/__ffs.h>
#include <asm-generic/bitops/fls.h>
#include <asm-generic/bitops/__fls.h>
#include <asm-generic/bitops/fls64.h>

#ifdef __KERNEL__
Expand Down

0 comments on commit 56a6b1e

Please sign in to comment.