From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752214AbbEBMk0 (ORCPT ); Sat, 2 May 2015 08:40:26 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:42834 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751276AbbEBMkX (ORCPT ); Sat, 2 May 2015 08:40:23 -0400 Date: Sat, 2 May 2015 14:39:58 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Vladimir Makarov , Jakub Jelinek , Richard Henderson , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Linux Kernel Mailing List , Borislav Petkov Subject: Re: [PATCH] x86: Optimize variable_test_bit() Message-ID: <20150502123958.GK5029@twins.programming.kicks-ass.net> References: <20150501151630.GH5029@twins.programming.kicks-ass.net> <20150501163329.GU1751@tucnak.redhat.com> <5543CDC0.6010206@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Fri, May 01, 2015 at 01:49:52PM -0700, Linus Torvalds wrote: > On Fri, May 1, 2015 at 12:02 PM, Vladimir Makarov wrote: > > > > GCC RA is a major reason to prohibit output operands for asm goto. > > Hmm.. Thinking some more about it, I think that what would actually > work really well at least for the kernel is: > > (a) allow *memory* operands (ie "=m") as outputs and having them be > meaningful even at any output labels (obviously with the caveat that > the asm instructions that write to memory would have to happen before > the branch ;) > > This covers the somewhat common case of having magic instructions that > result in conditions that can't be tested at a C level. Things like > "bit clear and test" on x86 (with or without the lock) . Would not something like: static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr) { bool oldbit; asm volatile ("btr %2, %1" : "CF" (oldbit), "+m" (*addr) : "Ir" (nr)); return oldbit; } Be the far better solution for this? Bug 59615 comment 7 states that they actually modeled the flags in the .md file, so the above should be possible to implement. Now GCC can decide to use "sbb %0, %0" to convert CF into a register value or use "jnc" / "jc" for branches, depending on what __test_and_clear_bit() was used for. We don't have to (ab)use asm goto for these things anymore; furthermore I think the above will naturally work with our __builtin_expect() hints, whereas the asm goto stuff has a hard time with that (afaik). That's not to say output operants for asm goto would not still be useful for other things (like your EXTABLE example).