From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id B51DD3857BAB for ; Tue, 24 May 2022 20:57:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B51DD3857BAB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 24OKulEF000312; Tue, 24 May 2022 15:56:47 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 24OKukSj000311; Tue, 24 May 2022 15:56:46 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Tue, 24 May 2022 15:56:46 -0500 From: Segher Boessenkool To: Ian Worthington Cc: "gcc-help@gcc.gnu.org" Subject: Re: asm() / goto() concern Message-ID: <20220524205646.GM25951@gate.crashing.org> References: <1538337561.2146473.1653382920615.ref@mail.yahoo.com> <1538337561.2146473.1653382920615@mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1538337561.2146473.1653382920615@mail.yahoo.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2022 20:57:49 -0000 Hi! On Tue, May 24, 2022 at 09:02:00AM +0000, Ian Worthington via Gcc-help wrote: > I'm trying to write some inline assembler but I see that asm() does not support branching to labels, and that asm goto() does not support output (at least prior to gcc 11).  > > If I tie them together by declaring an output of the asm() as an input to asm goto() I assume that this will prevent the optimiser from reordering them, but how can I ensure that they are run without any intervening instructions if the goto() has a dependency on the cc generated by the asm(), eg: You cannot. Sorry. >     asm ( "algr %[rs],%[rb] \n\t" >           : [rs] "+r" (sum)     // output >           : [rb] "r"  (u64b)    // input >         ); > >     asm goto ( "bc 3,%l[done]"        // branch if carry bit set (cc 2 or 3) >                :                    // output >                : [rs] "r"  (sum)    // input:  ensure this comes after the algr >                :                     // clobbers >                : done >              );  You have to write to something that is a C variable in that first asm, and read from that in the asm goto. You don't get any advantage over plain C that way, of course, for your example at least. Alternatively you can use a newer compiler. Or you can write the code you want as a real assembler function (in a .s file, not inline asm). gl;hf, Segher