* [PATCH, v2] x86: use tzcnt instead of bsf
@ 2012-09-18 11:16 Jan Beulich
2012-09-19 17:05 ` [tip:x86/asm] x86: Use REP BSF unconditionally tip-bot for Jan Beulich
0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2012-09-18 11:16 UTC (permalink / raw)
To: mingo, tglx, hpa; +Cc: Linus Torvalds, linux-kernel
Following a relatively recent compiler change, make use of the fact
that for non-zero input BSF and TZCNT produce the same result, and that
CPUs not knowing of TZCNT will treat the instruction as BSF (i.e.
ignore what looks like a REP prefix to them). The assumption here is
that TZCNT would never have worse performance than BSF.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
---
v2: Do this unconditionally, and change title accordingly.
---
arch/x86/include/asm/bitops.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--- 3.6-rc6/arch/x86/include/asm/bitops.h
+++ 3.6-rc6-x86-bsf-tzcnt/arch/x86/include/asm/bitops.h
@@ -355,7 +355,7 @@ static int test_bit(int nr, const volati
*/
static inline unsigned long __ffs(unsigned long word)
{
- asm("bsf %1,%0"
+ asm("rep; bsf %1,%0"
: "=r" (word)
: "rm" (word));
return word;
@@ -369,7 +369,7 @@ static inline unsigned long __ffs(unsign
*/
static inline unsigned long ffz(unsigned long word)
{
- asm("bsf %1,%0"
+ asm("rep; bsf %1,%0"
: "=r" (word)
: "r" (~word));
return word;
^ permalink raw reply [flat|nested] 2+ messages in thread
* [tip:x86/asm] x86: Use REP BSF unconditionally
2012-09-18 11:16 [PATCH, v2] x86: use tzcnt instead of bsf Jan Beulich
@ 2012-09-19 17:05 ` tip-bot for Jan Beulich
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Jan Beulich @ 2012-09-19 17:05 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, hpa, mingo, torvalds, jbeulich, JBeulich, tglx
Commit-ID: e26a44a2d618a491d5c6a2a8aaf66ee03a94739f
Gitweb: http://git.kernel.org/tip/e26a44a2d618a491d5c6a2a8aaf66ee03a94739f
Author: Jan Beulich <JBeulich@suse.com>
AuthorDate: Tue, 18 Sep 2012 12:16:14 +0100
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 19 Sep 2012 17:26:08 +0200
x86: Use REP BSF unconditionally
Make "REP BSF" unconditional, as per the suggestion of hpa
and Linus, this removes the insane BSF_PREFIX conditional
and simplifies the logic.
Suggested-by: "H. Peter Anvin" <hpa@zytor.com>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Link: http://lkml.kernel.org/r/5058741E020000780009C014@nat28.tlf.novell.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/include/asm/bitops.h | 19 ++-----------------
1 files changed, 2 insertions(+), 17 deletions(-)
diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index b2af664..6dfd019 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -347,19 +347,6 @@ static int test_bit(int nr, const volatile unsigned long *addr);
? constant_test_bit((nr), (addr)) \
: variable_test_bit((nr), (addr)))
-#if (defined(CONFIG_X86_GENERIC) || defined(CONFIG_GENERIC_CPU)) \
- && !defined(CONFIG_CC_OPTIMIZE_FOR_SIZE)
-/*
- * Since BSF and TZCNT have sufficiently similar semantics for the purposes
- * for which we use them here, BMI-capable hardware will decode the prefixed
- * variant as 'tzcnt ...' and may execute that faster than 'bsf ...', while
- * older hardware will ignore the REP prefix and decode it as 'bsf ...'.
- */
-# define BSF_PREFIX "rep;"
-#else
-# define BSF_PREFIX
-#endif
-
/**
* __ffs - find first set bit in word
* @word: The word to search
@@ -368,7 +355,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
*/
static inline unsigned long __ffs(unsigned long word)
{
- asm(BSF_PREFIX "bsf %1,%0"
+ asm("rep; bsf %1,%0"
: "=r" (word)
: "rm" (word));
return word;
@@ -382,14 +369,12 @@ static inline unsigned long __ffs(unsigned long word)
*/
static inline unsigned long ffz(unsigned long word)
{
- asm(BSF_PREFIX "bsf %1,%0"
+ asm("rep; bsf %1,%0"
: "=r" (word)
: "r" (~word));
return word;
}
-#undef BSF_PREFIX
-
/*
* __fls: find last set bit in word
* @word: The word to search
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-19 17:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-18 11:16 [PATCH, v2] x86: use tzcnt instead of bsf Jan Beulich
2012-09-19 17:05 ` [tip:x86/asm] x86: Use REP BSF unconditionally tip-bot for Jan Beulich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).