summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2006-09-25 23:32:07 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-26 08:48:53 -0700
commit92fc707208bb2e601c24b5ab65db37bcb361b658 (patch)
treea0b2d56c30ade74946e9edd74f2d516f475c68f5
parentaf8c65b57aaa4ae321af34dbfc5ca7f5625263fe (diff)
downloadlinux-3.10-92fc707208bb2e601c24b5ab65db37bcb361b658.tar.gz
linux-3.10-92fc707208bb2e601c24b5ab65db37bcb361b658.tar.bz2
linux-3.10-92fc707208bb2e601c24b5ab65db37bcb361b658.zip
[PATCH] FRV: Fix fls() to handle bit 31 being set correctly
Fix FRV fls() to handle bit 31 being set correctly (it should return 32 not 0). Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--include/asm-frv/bitops.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/include/asm-frv/bitops.h b/include/asm-frv/bitops.h
index 980ae1b0cd2..97fb746f76c 100644
--- a/include/asm-frv/bitops.h
+++ b/include/asm-frv/bitops.h
@@ -161,16 +161,29 @@ static inline int __test_bit(int nr, const volatile void * addr)
#include <asm-generic/bitops/__ffs.h>
#include <asm-generic/bitops/find.h>
-/*
- * fls: find last bit set.
+/**
+ * fls - find last bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs:
+ * - return 32..1 to indicate bit 31..0 most significant bit set
+ * - return 0 to indicate no bits set
*/
#define fls(x) \
({ \
int bit; \
\
- asm("scan %1,gr0,%0" : "=r"(bit) : "r"(x)); \
+ asm(" subcc %1,gr0,gr0,icc0 \n" \
+ " ckne icc0,cc4 \n" \
+ " cscan.p %1,gr0,%0 ,cc4,#1 \n" \
+ " csub %0,%0,%0 ,cc4,#0 \n" \
+ " csub %2,%0,%0 ,cc4,#1 \n" \
+ : "=&r"(bit) \
+ : "r"(x), "r"(32) \
+ : "icc0", "cc4" \
+ ); \
\
- bit ? 33 - bit : bit; \
+ bit; \
})
#include <asm-generic/bitops/fls64.h>