* [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
* [PATCH] fls in asm for x86_64
2005-12-03 0:22 [PATCH] fls in asm for i386 Stephen Hemminger
@ 2005-12-03 0:24 ` Stephen Hemminger
2005-12-03 1:44 ` Andi Kleen
2005-12-05 13:46 ` [PATCH] fls in asm for i386 Pádraig Brady
1 sibling, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2005-12-03 0:24 UTC (permalink / raw)
To: Andi Kleen, Linus Torvalds; +Cc: linux-kernel
Use single instruction for find largest set bit on x86_64.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- orig/include/asm-x86_64/bitops.h
+++ new/include/asm-x86_64/bitops.h
@@ -370,6 +370,22 @@ 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"
+ "cmovzl %2,%0"
+ : "=r" (r) : "rm" (x), "r" (-1));
+ return r+1;
+}
+
+/**
* hweightN - returns the hamming weight of a N-bit word
* @x: the word to weigh
*
@@ -407,9 +423,6 @@ static __inline__ int ffs(int x)
#define minix_find_first_zero_bit(addr,size) \
find_first_zero_bit((void*)addr,size)
-/* find last set bit */
-#define fls(x) generic_fls(x)
-
#endif /* __KERNEL__ */
#endif /* _X86_64_BITOPS_H */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fls in asm for x86_64
2005-12-03 0:24 ` [PATCH] fls in asm for x86_64 Stephen Hemminger
@ 2005-12-03 1:44 ` Andi Kleen
0 siblings, 0 replies; 4+ messages in thread
From: Andi Kleen @ 2005-12-03 1:44 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Andi Kleen, Linus Torvalds, linux-kernel
On Fri, Dec 02, 2005 at 04:24:36PM -0800, Stephen Hemminger wrote:
> Use single instruction for find largest set bit on x86_64.
Thanks queued.
-Andi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fls in asm for i386
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-05 13:46 ` Pádraig Brady
1 sibling, 0 replies; 4+ messages in thread
From: Pádraig Brady @ 2005-12-05 13:46 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: linux-kernel
Stephen Hemminger wrote:
>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()).
>
>
Interesting, I thought this had already been done:
http://lkml.org/lkml/2003/1/28/296
http://lkml.org/lkml/2003/4/29/173
Pádraig.
^ 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