public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] FRV: Fix fls() to handle bit 31 being set correctly [try #3]
@ 2006-09-13 18:35 David Howells
  2006-09-13 18:35 ` [PATCH 2/7] FRV: Implement fls64() " David Howells
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: David Howells @ 2006-09-13 18:35 UTC (permalink / raw)
  To: torvalds, akpm; +Cc: linux-kernel, linux-arch, dhowells

From: David Howells <dhowells@redhat.com>

Fix FRV fls() to handle bit 31 being set correctly (it should return 32 not 0).

Signed-Off-By: David Howells <dhowells@redhat.com>
---

 include/asm-frv/bitops.h |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/include/asm-frv/bitops.h b/include/asm-frv/bitops.h
index 980ae1b..97fb746 100644
--- a/include/asm-frv/bitops.h
+++ b/include/asm-frv/bitops.h
@@ -161,16 +161,29 @@ #include <asm-generic/bitops/ffs.h>
 #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>

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2006-09-19 15:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-13 18:35 [PATCH 1/7] FRV: Fix fls() to handle bit 31 being set correctly [try #3] David Howells
2006-09-13 18:35 ` [PATCH 2/7] FRV: Implement fls64() " David Howells
2006-09-13 18:35 ` [PATCH 3/7] FRV: Optimise ffs() " David Howells
2006-09-13 18:35 ` [PATCH 4/7] Implement a general integer log2 facility in the kernel " David Howells
2006-09-14  1:19   ` Stephen Rothwell
2006-09-13 18:35 ` [PATCH 5/7] Alter get_order() so that it can make use of ilog2() on a constant " David Howells
2006-09-14  1:24   ` Stephen Rothwell
2006-09-14 11:52     ` David Howells
2006-09-15  1:35       ` Stephen Rothwell
2006-09-15 14:42         ` David Howells
2006-09-17 10:04           ` Stephen Rothwell
2006-09-19  7:30   ` Andrew Morton
2006-09-19  9:08     ` David Howells
2006-09-19 15:03       ` Andrew Morton
2006-09-19 15:08         ` Christoph Hellwig
2006-09-13 18:35 ` [PATCH 6/7] Alter roundup_pow_of_two() " David Howells
2006-09-13 18:35 ` [PATCH 7/7] Provide ilog2() fallbacks for powerpc " David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox