mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-16 05:26:07 +00:00
[MIPS] Fix bitops for MIPS32/MIPS64 CPUs.
With recent rewrite for generic bitops, fls() for 32bit kernel with MIPS64_CPU is broken. Also, ffs(), fls() should be defined the same way as the libc and compiler built-in routines (returns int instead of unsigned long). Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
This commit is contained in:
parent
c0858d82fa
commit
bc81824720
@ -466,65 +466,57 @@ static inline unsigned long __ffs(unsigned long word)
|
|||||||
return __ilog2(word & -word);
|
return __ilog2(word & -word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fls - find last bit set.
|
||||||
|
* @word: The word to search
|
||||||
|
*
|
||||||
|
* This is defined the same way as ffs.
|
||||||
|
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
|
||||||
|
*/
|
||||||
|
static inline int fls(int word)
|
||||||
|
{
|
||||||
|
__asm__ ("clz %0, %1" : "=r" (word) : "r" (word));
|
||||||
|
|
||||||
|
return 32 - word;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPS64)
|
||||||
|
static inline int fls64(__u64 word)
|
||||||
|
{
|
||||||
|
__asm__ ("dclz %0, %1" : "=r" (word) : "r" (word));
|
||||||
|
|
||||||
|
return 64 - word;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#include <asm-generic/bitops/fls64.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ffs - find first bit set.
|
* ffs - find first bit set.
|
||||||
* @word: The word to search
|
* @word: The word to search
|
||||||
*
|
*
|
||||||
* Returns 1..SZLONG
|
* This is defined the same way as
|
||||||
* Returns 0 if no bit exists
|
* the libc and compiler builtin ffs routines, therefore
|
||||||
|
* differs in spirit from the above ffz (man ffs).
|
||||||
*/
|
*/
|
||||||
|
static inline int ffs(int word)
|
||||||
static inline unsigned long ffs(unsigned long word)
|
|
||||||
{
|
{
|
||||||
if (!word)
|
if (!word)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return __ffs(word) + 1;
|
return fls(word & -word);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ffz - find first zero in word.
|
|
||||||
* @word: The word to search
|
|
||||||
*
|
|
||||||
* Undefined if no zero exists, so code should check against ~0UL first.
|
|
||||||
*/
|
|
||||||
static inline unsigned long ffz(unsigned long word)
|
|
||||||
{
|
|
||||||
return __ffs (~word);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* fls - find last bit set.
|
|
||||||
* @word: The word to search
|
|
||||||
*
|
|
||||||
* Returns 1..SZLONG
|
|
||||||
* Returns 0 if no bit exists
|
|
||||||
*/
|
|
||||||
static inline unsigned long fls(unsigned long word)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_CPU_MIPS32
|
|
||||||
__asm__ ("clz %0, %1" : "=r" (word) : "r" (word));
|
|
||||||
|
|
||||||
return 32 - word;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_CPU_MIPS64
|
|
||||||
__asm__ ("dclz %0, %1" : "=r" (word) : "r" (word));
|
|
||||||
|
|
||||||
return 64 - word;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <asm-generic/bitops/__ffs.h>
|
#include <asm-generic/bitops/__ffs.h>
|
||||||
#include <asm-generic/bitops/ffs.h>
|
#include <asm-generic/bitops/ffs.h>
|
||||||
#include <asm-generic/bitops/ffz.h>
|
|
||||||
#include <asm-generic/bitops/fls.h>
|
#include <asm-generic/bitops/fls.h>
|
||||||
|
#include <asm-generic/bitops/fls64.h>
|
||||||
|
|
||||||
#endif /*defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) */
|
#endif /*defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) */
|
||||||
|
|
||||||
#include <asm-generic/bitops/fls64.h>
|
#include <asm-generic/bitops/ffz.h>
|
||||||
#include <asm-generic/bitops/find.h>
|
#include <asm-generic/bitops/find.h>
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user