From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932485AbcELMPM (ORCPT ); Thu, 12 May 2016 08:15:12 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:41046 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932440AbcELMPJ (ORCPT ); Thu, 12 May 2016 08:15:09 -0400 Date: Thu, 12 May 2016 14:14:52 +0200 From: Peter Zijlstra To: Borislav Petkov Cc: "H. Peter Anvin" , Brian Gerst , x86-ml , Denys Vlasenko , LKML , Dmitry Vyukov , Andi Kleen , zengzhaoxiu@163.com, Thomas Gleixner , Ingo Molnar , Andrew Morton , Kees Cook , Zhaoxiu Zeng , Andy Lutomirski Subject: Re: [PATCH -v2] x86/hweight: Get rid of the special calling convention Message-ID: <20160512121452.GR3192@twins.programming.kicks-ass.net> References: <20160510165318.GD28520@pd.tnic> <20160510172313.GA3192@twins.programming.kicks-ass.net> <8FE6169B-4F2E-4B7D-A271-14FEC245F663@zytor.com> <20160510191041.GI28520@pd.tnic> <20160511041128.GA2180@pd.tnic> <20160511112409.GE3190@twins.programming.kicks-ass.net> <20160512115738.GB10056@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160512115738.GB10056@pd.tnic> 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 Thu, May 12, 2016 at 01:57:38PM +0200, Borislav Petkov wrote: > #ifdef CONFIG_X86_32 > # define PUSH_DX "pushl %%edx\n\t" > # define POP_DX "popl %%edx\n\t" > #else > # define PUSH_DX "pushq %%rdx\n\t" > # define POP_DX "popq %%rdx\n\t" > #endif > > unsigned int __sw_hweight32(unsigned int w) > { > asm volatile(PUSH_DX > "movl %[w], %%edx\n\t" /* w -> t */ > "shrl %%edx\n\t" /* t >> 1 */ > "andl $0x55555555, %%edx\n\t" /* t & 0x55555555 */ > "subl %%edx, %[w]\n" /* w -= t */ > "\n\t" > "movl %[w], %%edx\n\t" /* w -> t */ > "shrl $2, %[w]\n\t" /* w_tmp >> 2 */ > "andl $0x33333333, %%edx\n\t" /* t & 0x33333333 */ > "andl $0x33333333, %[w]\n\t" /* w_tmp & 0x33333333 */ > "addl %%edx, %[w]\n" /* w = w_tmp + t */ > "\n\t" > "movl %[w], %%edx\n\t" /* w -> t */ > "shrl $4, %%edx\n\t" /* t >> 4 */ > "addl %%edx, %[w]\n\t" /* w_tmp += t */ > "andl $0x0f0f0f0f, %[w]\n\t" /* w_tmp &= 0x0f0f0f0f */ > "imull $0x01010101, %[w], %[w]\n\t" /* w_tmp *= 0x01010101 */ > "shrl $24, %[w]\n\t" /* w = w_tmp >> 24 */ > POP_DX > : [w] "+r" (w)); > > return w; > } But this is a C function, with C calling convention. You're now assuming GCC doesn't clobber anything with its prologue/epilogue. I think hpa meant to put it in an .S file and avoid all that.