From: "tip-bot for H. Peter Anvin" <hpa@linux.intel.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
torvalds@linux-foundation.org, tglx@linutronix.de,
hpa@linux.intel.com, borislav.petkov@amd.com
Subject: [tip:core/hweight] x86, hweight: Use a 32-bit popcnt for __arch_hweight32()
Date: Mon, 17 May 2010 22:57:36 GMT [thread overview]
Message-ID: <tip-c59bd5688299cddb71183e156e7a3c1409b90df2@git.kernel.org> (raw)
In-Reply-To: <alpine.LFD.2.00.1005171443060.4195@i5.linux-foundation.org>
Commit-ID: c59bd5688299cddb71183e156e7a3c1409b90df2
Gitweb: http://git.kernel.org/tip/c59bd5688299cddb71183e156e7a3c1409b90df2
Author: H. Peter Anvin <hpa@linux.intel.com>
AuthorDate: Mon, 17 May 2010 15:13:23 -0700
Committer: H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Mon, 17 May 2010 15:17:16 -0700
x86, hweight: Use a 32-bit popcnt for __arch_hweight32()
Use a 32-bit popcnt instruction for __arch_hweight32(), even on
x86-64. Even though the input register will *usually* be
zero-extended due to the standard operation of the hardware, it isn't
necessarily so if the input value was the result of truncating a
64-bit operation.
Note: the POPCNT32 variant used on x86-64 has a technically
unnecessary REX prefix to make it five bytes long, the same as a CALL
instruction, therefore avoiding an unnecessary NOP.
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Borislav Petkov <borislav.petkov@amd.com>
LKML-Reference: <alpine.LFD.2.00.1005171443060.4195@i5.linux-foundation.org>
---
arch/x86/include/asm/arch_hweight.h | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/arch_hweight.h b/arch/x86/include/asm/arch_hweight.h
index d1fc3c2..9686c3d 100644
--- a/arch/x86/include/asm/arch_hweight.h
+++ b/arch/x86/include/asm/arch_hweight.h
@@ -2,13 +2,15 @@
#define _ASM_X86_HWEIGHT_H
#ifdef CONFIG_64BIT
+/* popcnt %edi, %eax -- redundant REX prefix for alignment */
+#define POPCNT32 ".byte 0xf3,0x40,0x0f,0xb8,0xc7"
/* popcnt %rdi, %rax */
-#define POPCNT ".byte 0xf3,0x48,0x0f,0xb8,0xc7"
+#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc7"
#define REG_IN "D"
#define REG_OUT "a"
#else
/* popcnt %eax, %eax */
-#define POPCNT ".byte 0xf3,0x0f,0xb8,0xc0"
+#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0"
#define REG_IN "a"
#define REG_OUT "a"
#endif
@@ -23,7 +25,7 @@ static inline unsigned int __arch_hweight32(unsigned int w)
{
unsigned int res = 0;
- asm (ALTERNATIVE("call __sw_hweight32", POPCNT, X86_FEATURE_POPCNT)
+ asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT)
: "="REG_OUT (res)
: REG_IN (w));
@@ -48,7 +50,7 @@ static inline unsigned long __arch_hweight64(__u64 w)
return __arch_hweight32((u32)w) +
__arch_hweight32((u32)(w >> 32));
#else
- asm (ALTERNATIVE("call __sw_hweight64", POPCNT, X86_FEATURE_POPCNT)
+ asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
: "="REG_OUT (res)
: REG_IN (w));
#endif /* CONFIG_X86_32 */
next prev parent reply other threads:[~2010-05-17 22:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-17 21:21 [GIT PULL] core/hweight changes for v2.6.35 Ingo Molnar
2010-05-17 21:46 ` Linus Torvalds
2010-05-17 22:06 ` H. Peter Anvin
2010-05-17 22:57 ` tip-bot for H. Peter Anvin [this message]
2010-05-17 23:04 ` [GIT PULL] UPDATED - " H. Peter Anvin
2010-08-13 21:42 ` [GIT PULL] " Mike Frysinger
2010-08-13 21:56 ` H. Peter Anvin
2010-08-13 21:59 ` Mike Frysinger
2010-08-14 0:11 ` H. Peter Anvin
2010-08-14 13:44 ` Borislav Petkov
2010-08-14 0:32 ` [PATCH] arch/tile: Rename the hweight() implementations to __arch_hweight() Chris Metcalf
2010-08-14 1:02 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-c59bd5688299cddb71183e156e7a3c1409b90df2@git.kernel.org \
--to=hpa@linux.intel.com \
--cc=borislav.petkov@amd.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome