Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752246AbbEDUPY (ORCPT ); Mon, 4 May 2015 16:15:24 -0400 Received: from terminus.zytor.com ([198.137.202.10]:40610 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751950AbbEDUPV (ORCPT ); Mon, 4 May 2015 16:15:21 -0400 Message-ID: <5547D30B.2020507@zytor.com> Date: Mon, 04 May 2015 13:14:03 -0700 From: "H. Peter Anvin" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Richard Henderson , Peter Zijlstra CC: Linus Torvalds , Vladimir Makarov , Jakub Jelinek , Ingo Molnar , Thomas Gleixner , Linux Kernel Mailing List , Borislav Petkov , "gcc@gcc.gnu.org" Subject: Re: [RFC] Design for flag bit outputs from asms References: <20150501151630.GH5029@twins.programming.kicks-ass.net> <20150501163329.GU1751@tucnak.redhat.com> <5543CDC0.6010206@redhat.com> <20150502123958.GK5029@twins.programming.kicks-ass.net> <5547C992.9000703@redhat.com> In-Reply-To: <5547C992.9000703@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2214 Lines: 63 On 05/04/2015 12:33 PM, Richard Henderson wrote: > > (0) The C level output variable should be an integral type, from bool on up. > > The flags are a scarse resource, easily clobbered. We cannot allow user code > to keep data in the flags. While x86 does have lahf/sahf, they don't exactly > perform well. And other targets like arm don't even have that bad option. > > Therefore, the language level semantics are that the output is a boolean store > into the variable with a condition specified by a magic constraint. > > That said, just like the compiler should be able to optimize > > void bar(int y) > { > int x = (y <= 0); > if (x) foo(); > } > > such that we only use a single compare against y, the expectation is that > within a similarly constrained context the compiler will not require two tests > for these boolean outputs. > > Therefore: > > (1) Each target defines a set of constraint strings, > > E.g. for x86, wherein we're almost out of constraint letters, > > ja aux carry flag > jc carry flag > jo overflow flag > jp parity flag > js sign flag > jz zero flag > I would argue that for x86 what you actually want is to model the *conditions* that are available on the flags, not the flags themselves. There are 16 such conditions, 8 if we discard the inversions. It is notable that the auxiliary carry flag has no Jcc/SETcc/CMOVcc instructions; it is only ever consumed by the DAA/DAS instructions which makes it pointless to try to model it in a compiler any more than, say, IF. > (2) A new target hook post-processes the asm_insn, looking for the > new constraint strings. The hook expands the condition prescribed > by the string, adjusting the asm_insn as required. > > E.g. > > bool x, y, z; > asm ("xyzzy" : "=jc"(x), "=jp"(y), "=jo"(z) : : ); Other than that, this is exactly what would be wonderful to see. -hpa -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/