Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756965AbcC2MMH (ORCPT ); Tue, 29 Mar 2016 08:12:07 -0400 Received: from lxorguk.ukuu.org.uk ([81.2.110.251]:58098 "EHLO lxorguk.ukuu.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751558AbcC2MME (ORCPT ); Tue, 29 Mar 2016 08:12:04 -0400 Date: Tue, 29 Mar 2016 13:11:42 +0100 From: One Thousand Gnomes To: "zhaoxiu.zeng" Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Denys Vlasenko , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH 11/31] Add x86-specific parity functions Message-ID: <20160329131142.6c6f6b94@lxorguk.ukuu.org.uk> In-Reply-To: <56F7819E.5020502@gmail.com> References: <1458788612-4367-1-git-send-email-zhaoxiu.zeng@gmail.com> <56F7819E.5020502@gmail.com> Organization: Intel Corporation X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.29; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1408 Lines: 37 On Sun, 27 Mar 2016 14:45:50 +0800 "zhaoxiu.zeng" wrote: > From: Zeng Zhaoxiu > > Signed-off-by: Zeng Zhaoxiu > --- > arch/x86/include/asm/bitops.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h > index 7766d1c..d3210c0 100644 > --- a/arch/x86/include/asm/bitops.h > +++ b/arch/x86/include/asm/bitops.h > @@ -501,6 +501,18 @@ static __always_inline int fls64(__u64 x) > > #include > > +#define __arch_parity32(x) (__arch_hweight32(x) & 1) > +#define __arch_parity4(x) (__arch_parity32((x) & 0xf)) > +#define __arch_parity8(x) (__arch_parity32((x) & 0xff)) > +#define __arch_parity16(x) (__arch_parity32((x) & 0xffff)) > +#ifdef CONFIG_X86_32 > +#define __arch_parity64(x) (__arch_parity32((unsigned int)((x) >> 32) ^ (unsigned int)(x))) > +#else > +#define __arch_parity64(x) (__arch_hweight64(x) & 1) > +#endif arch_hweight32() is a subroutine call to a helper on x86 and the rest appears to make no sense for this CPU. Gcc has its own parity helper and even if you are not using that the CPU itself has a parity flag for doing 8bit parity so you just use TEST/J[N]P for parity 8 (and the obvious for 4 and 16). For 32bit parity there is __builtin_parity(). For 64bit __builtin_parityll(). Alan