mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Since objtool's inception, frame pointer warnings have been manually
silenced for __arch_hweight*() to allow those functions' inline asm to
avoid using ASM_CALL_CONSTRAINT.
The potentially dubious reasoning for that decision over nine years ago
was that since !X86_FEATURE_POPCNT is exceedingly rare, it's not worth
hurting the code layout for a function call that will never happen on
the vast majority of systems.
However, those functions actually started using ASM_CALL_CONSTRAINT with
the following commit:
194a613088
("x86/hweight: Use ASM_CALL_CONSTRAINT in inline asm()")
And rightfully so, as it makes the code correct. ASM_CALL_CONSTRAINT
will soon have no effect for non-FP configs anyway.
With ASM_CALL_CONSTRAINT in place, ANNOTATE_IGNORE_ALTERNATIVE no longer
has a purpose for the hweight functions. Remove it.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/e7070dba3278c90f1a836b16157dcd34ccd21e21.1744318586.git.jpoimboe@kernel.org
57 lines
1.2 KiB
C
57 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_X86_HWEIGHT_H
|
|
#define _ASM_X86_HWEIGHT_H
|
|
|
|
#include <asm/cpufeatures.h>
|
|
|
|
#ifdef CONFIG_64BIT
|
|
#define REG_IN "D"
|
|
#define REG_OUT "a"
|
|
#else
|
|
#define REG_IN "a"
|
|
#define REG_OUT "a"
|
|
#endif
|
|
|
|
static __always_inline unsigned int __arch_hweight32(unsigned int w)
|
|
{
|
|
unsigned int res;
|
|
|
|
asm_inline (ALTERNATIVE("call __sw_hweight32",
|
|
"popcntl %[val], %[cnt]", X86_FEATURE_POPCNT)
|
|
: [cnt] "=" REG_OUT (res), ASM_CALL_CONSTRAINT
|
|
: [val] REG_IN (w));
|
|
|
|
return res;
|
|
}
|
|
|
|
static inline unsigned int __arch_hweight16(unsigned int w)
|
|
{
|
|
return __arch_hweight32(w & 0xffff);
|
|
}
|
|
|
|
static inline unsigned int __arch_hweight8(unsigned int w)
|
|
{
|
|
return __arch_hweight32(w & 0xff);
|
|
}
|
|
|
|
#ifdef CONFIG_X86_32
|
|
static inline unsigned long __arch_hweight64(__u64 w)
|
|
{
|
|
return __arch_hweight32((u32)w) +
|
|
__arch_hweight32((u32)(w >> 32));
|
|
}
|
|
#else
|
|
static __always_inline unsigned long __arch_hweight64(__u64 w)
|
|
{
|
|
unsigned long res;
|
|
|
|
asm_inline (ALTERNATIVE("call __sw_hweight64",
|
|
"popcntq %[val], %[cnt]", X86_FEATURE_POPCNT)
|
|
: [cnt] "=" REG_OUT (res), ASM_CALL_CONSTRAINT
|
|
: [val] REG_IN (w));
|
|
|
|
return res;
|
|
}
|
|
#endif /* CONFIG_X86_32 */
|
|
|
|
#endif
|