public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] FRV: Fix fls() to handle bit 31 being set correctly
@ 2006-09-13 13:02 David Howells
  2006-09-13 13:02 ` [PATCH 2/6] FRV: Implement fls64() David Howells
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: David Howells @ 2006-09-13 13:02 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] 15+ messages in thread

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

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-13 13:02 [PATCH 1/6] FRV: Fix fls() to handle bit 31 being set correctly David Howells
2006-09-13 13:02 ` [PATCH 2/6] FRV: Implement fls64() David Howells
2006-09-13 13:02 ` [PATCH 3/6] FRV: Optimise ffs() David Howells
2006-09-13 13:03 ` [PATCH 4/6] Implement a general log2 facility in the kernel David Howells
2006-09-13 15:57   ` Luck, Tony
2006-09-13 16:50     ` David Howells
2006-09-13 16:17   ` Adrian Bunk
2006-09-13 16:31     ` Matthew Wilcox
2006-09-13 16:38       ` Russell King
2006-09-13 16:56         ` David Howells
2006-09-13 18:38           ` Geert Uytterhoeven
2006-09-13 18:45             ` Russell King
2006-09-13 19:09               ` Geert Uytterhoeven
2006-09-13 13:03 ` [PATCH 5/6] Alter get_order() so that it can make use of long_log2() on a constant David Howells
2006-09-13 13:03 ` [PATCH 6/6] Alter roundup_pow_of_two() " David Howells

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