Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934114AbcDFKNH (ORCPT ); Wed, 6 Apr 2016 06:13:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:36483 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933944AbcDFKNF (ORCPT ); Wed, 6 Apr 2016 06:13:05 -0400 Date: Wed, 6 Apr 2016 12:13:00 +0200 From: Borislav Petkov To: zengzhaoxiu@163.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, dvlasenk@redhat.com, akpm@linux-foundation.org, dvyukov@google.com, keescook@chromium.org, linux-kernel@vger.kernel.org, Zhaoxiu Zeng Subject: Re: [PATCH v2 10/30] Add x86-specific parity functions Message-ID: <20160406101300.GA13719@pd.tnic> References: <57031D9D.801@gmail.com> <1459934085-7152-1-git-send-email-zengzhaoxiu@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1459934085-7152-1-git-send-email-zengzhaoxiu@163.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1227 Lines: 42 On Wed, Apr 06, 2016 at 05:14:45PM +0800, zengzhaoxiu@163.com wrote: > From: Zhaoxiu Zeng > > Use alternatives, lifted from arch_hweight > > Signed-off-by: Zhaoxiu Zeng > --- > 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. -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --