Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752172AbbEDUdx (ORCPT ); Mon, 4 May 2015 16:33:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46388 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751161AbbEDUdm (ORCPT ); Mon, 4 May 2015 16:33:42 -0400 Message-ID: <5547D7A3.2010203@redhat.com> Date: Mon, 04 May 2015 13:33:39 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: "H. Peter Anvin" , 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> <5547D30B.2020507@zytor.com> In-Reply-To: <5547D30B.2020507@zytor.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: 2198 Lines: 59 On 05/04/2015 01:14 PM, H. Peter Anvin wrote: > 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. A fair point. Though honestly, I was hoping that this feature would mostly be used for conditions that are "weird" -- that is, not normally describable by arithmetic at all. Otherwise, why are you using inline asm for it? > 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. Oh yeah. Consider that dropped. r~ -- 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/