From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932411AbcEKJcH (ORCPT ); Wed, 11 May 2016 05:32:07 -0400 Received: from merlin.infradead.org ([205.233.59.134]:59497 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932104AbcEKJcC (ORCPT ); Wed, 11 May 2016 05:32:02 -0400 Date: Wed, 11 May 2016 11:31:39 +0200 From: Peter Zijlstra To: zengzhaoxiu@163.com Cc: linux-kernel@vger.kernel.org, bp@suse.de, gnomes@lxorguk.ukuu.org.uk, andi@firstfloor.org, dvyukov@google.com, Zhaoxiu Zeng , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Denys Vlasenko Subject: Re: [patch V4 09/31] bitops: Add x86-specific parity functions Message-ID: <20160511093139.GA3206@twins.programming.kicks-ass.net> References: <1462955158-28394-1-git-send-email-zengzhaoxiu@163.com> <1462958205-24890-1-git-send-email-zengzhaoxiu@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1462958205-24890-1-git-send-email-zengzhaoxiu@163.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 11, 2016 at 05:16:38PM +0800, zengzhaoxiu@163.com wrote: > +static inline unsigned int __arch_parity4(unsigned int w) > +{ > + unsigned int res = 0; > + > + asm("test $0xf, %1; setpo %b0" > + : "+q" (res) > + : "r" (w) > + : "cc"); > + > + return res; > +} > + > +static inline unsigned int __arch_parity8(unsigned int w) > +{ > + unsigned int res = 0; > + > + asm("test %1, %1; setpo %b0" > + : "+q" (res) > + : "r" (w) > + : "cc"); > + > + return res; > +} > + > +static inline unsigned int __arch_parity16(unsigned int w) > +{ > + unsigned int res = 0; > + > + asm("xor %h1, %b1; setpo %b0" > + : "+q" (res), "+q" (w) > + : : "cc"); > + > + return res; > +} Please use the GEN_*_RMWcc() stuff to avoid the setpo where possible. > + > +#ifdef CONFIG_64BIT > +/* popcnt %eax, %eax -- redundant REX prefix for alignment */ > +#define POPCNT32 ".byte 0xf3,0x40,0x0f,0xb8,0xc0" > +/* popcnt %rax, %rax */ > +#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc0" > +#else > +/* popcnt %eax, %eax */ > +#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0" > +#endif Yuck, please don't duplicate stuff like this. > + > +static __always_inline unsigned int __arch_parity32(unsigned int w) > +{ > + unsigned int res; > + unsigned int tmp; > + > + asm(ALTERNATIVE( > + " mov %%eax, %1 \n" > + " shr $16, %%eax \n" > + " xor %1, %%eax \n" > + " xor %%ah, %%al \n" > + " mov $0, %%eax \n" > + " setpo %%al \n", > + POPCNT32 " \n" > + " and $1, %%eax \n", > + X86_FEATURE_POPCNT) > + : "=a" (res), "=&r" (tmp) > + : "a" (w) > + : "cc"); > + > + return res; > +} How many bytes does that end up being? Should we make it a call?