Skip to content

Commit

Permalink
[ARM] fix fls() for 64-bit arguments
Browse files Browse the repository at this point in the history
arm's fls() is implemented as a macro, causing it to misbehave when passed
64-bit arguments.  Fix.

Cc: Nickolay Vinogradov <nickolay@protei.ru>
Tested-by: Krzysztof Halasa <khc@pm.waw.pl>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Andrew Morton authored and Russell King committed Jul 26, 2008
1 parent 9d9fa83 commit 0c65f45
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/asm-arm/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,16 @@ static inline int constant_fls(int x)
* the clz instruction for much better code efficiency.
*/

#define fls(x) \
#define __fls(x) \
( __builtin_constant_p(x) ? constant_fls(x) : \
({ int __r; asm("clz\t%0, %1" : "=r"(__r) : "r"(x) : "cc"); 32-__r; }) )

/* Implement fls() in C so that 64-bit args are suitably truncated */
static inline int fls(int x)
{
return __fls(x);
}

#define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
#define __ffs(x) (ffs(x) - 1)
#define ffz(x) __ffs( ~(x) )
Expand Down

0 comments on commit 0c65f45

Please sign in to comment.