public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fls in asm for i386
@ 2005-12-03  0:22 Stephen Hemminger
  2005-12-03  0:24 ` [PATCH] fls in asm for x86_64 Stephen Hemminger
  2005-12-05 13:46 ` [PATCH] fls in asm for i386 Pádraig Brady
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Hemminger @ 2005-12-03  0:22 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

There is a single instruction on i386 to find largest set bit;
so it makes sense to use it (like we use bfs for ffs()).

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>

--- orig/include/asm-i386/bitops.h
+++ new/include/asm-i386/bitops.h
@@ -367,12 +367,6 @@ static inline unsigned long ffz(unsigned
 	return word;
 }
 
-/*
- * fls: find last bit set.
- */
-
-#define fls(x) generic_fls(x)
-
 #ifdef __KERNEL__
 
 /*
@@ -414,6 +408,23 @@ static inline int ffs(int x)
 }
 
 /**
+ * fls - find last bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs.
+ */
+static inline int fls(int x)
+{
+	int r;
+
+	__asm__("bsrl %1,%0\n\t"
+		"jnz 1f\n\t"
+		"movl $-1,%0\n"
+		"1:" : "=r" (r) : "rm" (x));
+	return r+1;
+}
+
+/**
  * hweightN - returns the hamming weight of a N-bit word
  * @x: the word to weigh
  *

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

end of thread, other threads:[~2005-12-05 13:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-03  0:22 [PATCH] fls in asm for i386 Stephen Hemminger
2005-12-03  0:24 ` [PATCH] fls in asm for x86_64 Stephen Hemminger
2005-12-03  1:44   ` Andi Kleen
2005-12-05 13:46 ` [PATCH] fls in asm for i386 Pádraig Brady

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