x86: Use assembly instruction mnemonics instead of .byte streams in arch_hweight.h
PATCH v2 1/1 x86: Use assembly instruction mnemonics instead of .byte streams in arch_hweight.h
Recently the minimum required version of binutils was changed to 2.20, which supports popcnt instruction mnemonics. The patch removes corresponding #defines that implement popcnt instructions using target-dependant .byte streams and uses unified instruction mnemonics instead.
Tested by building x86_64 and i386 version of the kernel and comparing objdump dumps of the pathced and unpatched vmlinux.o. They were the same.
v2: Update commit message to emphasize removal of #defines.
--- arch/x86/include/asm/arch_hweight.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
arch/x86/include/asm/arch_hweight.h +4 -8
@@ -5,15 +5,9 @@#include <asm/cpufeatures.h> #ifdef CONFIG_64BIT -/* popcnt %edi, %eax */ -#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc7" -/* popcnt %rdi, %rax */ -#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc7"#define REG_IN "D"#define REG_OUT "a"#else -/* popcnt %eax, %eax */ -#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0"#define REG_IN "a"#define REG_OUT "a"#endif
@@ -24,7 +18,8 @@ static __always_inline unsigned int __arch_hweight32(unsigned int w) {unsigned int res; - asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT) + asm (ALTERNATIVE("call __sw_hweight32", + "popcntl %1, %0", X86_FEATURE_POPCNT) : "="REG_OUT (res) : REG_IN (w));
@@ -52,7 +47,8 @@ static __always_inline unsigned long __arch_hweight64(__u64 w) {unsigned long res; - asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT) + asm (ALTERNATIVE("call __sw_hweight64", + "popcntq %1, %0", X86_FEATURE_POPCNT) : "="REG_OUT (res) : REG_IN (w));
Signature · 1 line
2.17.2
Borislav Petkov
maintainerQuoted 8 lines · Uros Bizjak
Recently the minimum required version of binutils was changed to 2.20, which supports popcnt instruction mnemonics. The patch removes corresponding #defines that implement popcnt instructions using target-dependant .byte streams and uses unified instruction mnemonics instead.
Tested by building
x86_64and i386 version of the kernel and comparing objdump dumps of the pathced and unpatched vmlinux.o. They were the same.
Quoted 6 lines
v2: Update commit message to emphasize removal of #defines.
Signed-off-by Uros Bizjak <[email protected]>--- arch/x86/include/asm/arch_hweight.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
Thanks.
But with one week before the merge window and this being not nearly urgent, it'll have to wait for after the merge window.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.tip-bot for Uros Bizjak
merge bot[tip:x86/asm] x86: Use POPCNT mnemonics in arch_hweight.h
In reply to Uros Bizjakx86: Use POPCNT mnemonics in arch_hweight.h
Commit-ID: 566b62a3676caed1f8c626e26066ff3ae3a38918 Gitweb: https://git.kernel.org/tip/566b62a3676caed1f8c626e26066ff3ae3a38918 Author: Uros Bizjak <[email protected]> AuthorDate: Sun, 14 Oct 2018 22:23:54 +0200 Committer: Borislav Petkov <[email protected]> CommitDate: Mon, 5 Nov 2018 10:42:32 +0100
x86: Use POPCNT mnemonics in arch_hweight.h
Recently, the minimum required version of binutils was changed to 2.20, which supports POPCNT instruction mnemonics.
Replace the byte-wise specification of POPCNT with those proper mnemonics.
[ bp: massage commit message and remove line breaks. ]
--- arch/x86/include/asm/arch_hweight.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/x86/include/asm/arch_hweight.h +2 -8
@@ -5,15 +5,9 @@#include <asm/cpufeatures.h> #ifdef CONFIG_64BIT -/* popcnt %edi, %eax */ -#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc7" -/* popcnt %rdi, %rax */ -#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc7"#define REG_IN "D"#define REG_OUT "a"#else -/* popcnt %eax, %eax */ -#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0"#define REG_IN "a"#define REG_OUT "a"#endif
@@ -24,7 +18,7 @@ static __always_inline unsigned int __arch_hweight32(unsigned int w) {unsigned int res; - asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT) + asm (ALTERNATIVE("call __sw_hweight32", "popcntl %1, %0", X86_FEATURE_POPCNT) : "="REG_OUT (res) : REG_IN (w));
@@ -52,7 +46,7 @@ static __always_inline unsigned long __arch_hweight64(__u64 w) {unsigned long res; - asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT) + asm (ALTERNATIVE("call __sw_hweight64", "popcntq %1, %0", X86_FEATURE_POPCNT) : "="REG_OUT (res) : REG_IN (w));