mirror of
https://github.com/Stichting-MINIX-Research-Foundation/u-boot.git
synced 2025-09-10 12:39:22 -04:00
PPC: Added fls, fls64, __ilog2_u64, and ffs64 to bitops
fls64, __ilog2_u64, ffs64 are variants that work on an u64, and fls is used to implement them. Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
This commit is contained in:
parent
83002a77cb
commit
4928e97c85
@ -152,6 +152,7 @@ extern __inline__ int test_bit(int nr, __const__ volatile void *addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return the bit position of the most significant 1 bit in a word */
|
/* Return the bit position of the most significant 1 bit in a word */
|
||||||
|
/* - the result is undefined when x == 0 */
|
||||||
extern __inline__ int __ilog2(unsigned int x)
|
extern __inline__ int __ilog2(unsigned int x)
|
||||||
{
|
{
|
||||||
int lz;
|
int lz;
|
||||||
@ -167,6 +168,57 @@ extern __inline__ int ffz(unsigned int x)
|
|||||||
return __ilog2(x & -x);
|
return __ilog2(x & -x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fls: find last (most-significant) bit set.
|
||||||
|
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
|
||||||
|
*
|
||||||
|
* On powerpc, __ilog2(0) returns -1, but this is not safe in general
|
||||||
|
*/
|
||||||
|
static __inline__ int fls(unsigned int x)
|
||||||
|
{
|
||||||
|
return __ilog2(x) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fls64 - find last set bit in a 64-bit word
|
||||||
|
* @x: the word to search
|
||||||
|
*
|
||||||
|
* This is defined in a similar way as the libc and compiler builtin
|
||||||
|
* ffsll, but returns the position of the most significant set bit.
|
||||||
|
*
|
||||||
|
* fls64(value) returns 0 if value is 0 or the position of the last
|
||||||
|
* set bit if value is nonzero. The last (most significant) bit is
|
||||||
|
* at position 64.
|
||||||
|
*/
|
||||||
|
#if BITS_PER_LONG == 32
|
||||||
|
static inline int fls64(__u64 x)
|
||||||
|
{
|
||||||
|
__u32 h = x >> 32;
|
||||||
|
if (h)
|
||||||
|
return fls(h) + 32;
|
||||||
|
return fls(x);
|
||||||
|
}
|
||||||
|
#elif BITS_PER_LONG == 64
|
||||||
|
static inline int fls64(__u64 x)
|
||||||
|
{
|
||||||
|
if (x == 0)
|
||||||
|
return 0;
|
||||||
|
return __ilog2(x) + 1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error BITS_PER_LONG not 32 or 64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline int __ilog2_u64(u64 n)
|
||||||
|
{
|
||||||
|
return fls64(n) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int ffs64(u64 x)
|
||||||
|
{
|
||||||
|
return __ilog2_u64(x & -x) + 1ull;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user