[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5705DA2A.70308@gmail.com>
Date: Thu, 7 Apr 2016 11:55:22 +0800
From: Zeng Zhaoxiu <zhaoxiu.zeng@...il.com>
To: Borislav Petkov <bp@...e.de>, zengzhaoxiu@....com
Cc: tglx@...utronix.de, mingo@...hat.com, hpa@...or.com,
dvlasenk@...hat.com, akpm@...ux-foundation.org, dvyukov@...gle.com,
keescook@...omium.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 10/30] Add x86-specific parity functions
在 2016年04月06日 18:13, Borislav Petkov 写道:
> On Wed, Apr 06, 2016 at 05:14:45PM +0800, zengzhaoxiu@....com wrote:
>> From: Zhaoxiu Zeng <zhaoxiu.zeng@...il.com>
>>
>> Use alternatives, lifted from arch_hweight
>>
>> Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@...il.com>
>> ---
>> arch/x86/include/asm/arch_hweight.h | 5 ++
>> arch/x86/include/asm/arch_parity.h | 102 ++++++++++++++++++++++++++++++++++++
>> arch/x86/include/asm/bitops.h | 4 +-
>> arch/x86/lib/Makefile | 8 +++
>> arch/x86/lib/parity.c | 32 ++++++++++++
>> 5 files changed, 150 insertions(+), 1 deletion(-)
>> create mode 100644 arch/x86/include/asm/arch_parity.h
>> create mode 100644 arch/x86/lib/parity.c
> ...
>
>> +static __always_inline unsigned int __arch_parity32(unsigned int w)
>> +{
>> + unsigned int res;
>> +
>> + asm(ALTERNATIVE("call __sw_parity32", POPCNT32 "; and $1, %0", X86_FEATURE_POPCNT)
>> + : "="REG_OUT (res)
>> + : REG_IN (w)
>> + : "cc");
> So why all that churn instead of simply doing:
>
> static __always_inline unsigned int __arch_parity32(unsigned int w)
> {
> return hweight32(w) & 1;
> }
>
> Ditto for the 64-bit version.
>
__sw_parity32 is faster than __sw_hweight32.
I don't know how many CPUs do not support the popc, if they are outdated,
use __arch_hweight32 is the easiest way.
Powered by blists - more mailing lists