From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H. Peter Anvin" Subject: Re: [PATCH 0/7] preempt_count rework -v2 Date: Wed, 11 Sep 2013 08:29:22 -0700 Message-ID: <52308C52.9080003@zytor.com> References: <20130910130811.507933095@infradead.org> <20130910135152.GD7537@gmail.com> <20130910135636.GA8268@gmail.com> <20130910164519.GL31370@twins.programming.kicks-ass.net> <20130910212509.GA18147@laptop.programming.kicks-ass.net> <20130911131323.GQ31370@twins.programming.kicks-ass.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from terminus.zytor.com ([198.137.202.10]:52736 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753854Ab3IKPaW (ORCPT ); Wed, 11 Sep 2013 11:30:22 -0400 In-Reply-To: <20130911131323.GQ31370@twins.programming.kicks-ass.net> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Peter Zijlstra Cc: Linus Torvalds , Ingo Molnar , Andi Kleen , Mike Galbraith , Thomas Gleixner , Arjan van de Ven , Frederic Weisbecker , Linux Kernel Mailing List , "linux-arch@vger.kernel.org" On 09/11/2013 06:13 AM, Peter Zijlstra wrote: > On Tue, Sep 10, 2013 at 02:43:06PM -0700, Linus Torvalds wrote: >> That said, looking at your patch, I get the *very* strong feeling that >> we could make a macro that does all the repetitions for us, and then >> have a >> >> GENERATE_RMW(atomic_sub_and_test, LOCK_PREFIX "subl", "e", "") > > The below seems to compile.. > > + > +#define GENERATE_ADDcc(var, val, lock, cc) \ > +do { \ > + const int add_ID__ = (__builtin_constant_p(val) && \ > + ((val) == 1 || (val) == -1)) ? (val) : 0; \ > + \ > + switch (sizeof(var)) { \ > + case 4: \ > + if (add_ID__ == 1) { \ > + asm volatile goto(lock "incl %0;" \ > + "j" cc " %l[cc_label]" \ > + : : "m" (var) \ > + : "memory" : cc_label); \ > + } else if (add_ID__ == -1) { \ > + asm volatile goto(lock "decl %0;" \ > + "j" cc " %l[cc_label]" \ > + : : "m" (var) \ > + : "memory" : cc_label); \ > + } else { \ > + asm volatile goto(lock "addl %1, %0;" \ > + "j" cc " %l[cc_label]" \ > + : : "m" (var), "er" (val) \ > + : "memory" : cc_label); \ > + } \ > + break; \ > + \ > + case 8: \ > + if (add_ID__ == 1) { \ > + asm volatile goto(lock "incq %0;" \ > + "j" cc " %l[cc_label]" \ > + : : "m" (var) \ > + : "memory" : cc_label); \ > + } else if (add_ID__ == -1) { \ > + asm volatile goto(lock "decq %0;" \ > + "j" cc " %l[cc_label]" \ > + : : "m" (var) \ > + : "memory" : cc_label); \ > + } else { \ > + asm volatile goto(lock "addq %1, %0;" \ > + "j" cc " %l[cc_label]" \ > + : : "m" (var), "er" (val) \ > + : "memory" : cc_label); \ > + } \ > + break; \ > + \ At least in the "asm goto" case you can use: lock "add%z0 %1,%0;" ... and skip the switch statement. There was a bug in some old (gcc 3.x?) early x86-64 versions which would treat %z0 as if it was %Z0 which means it would emit "ll" instead of "q" but that doesn't apply to any gcc which has "asm goto"... -hpa