From: Segher Boessenkool <segher@kernel.crashing.org>
To: Ian Worthington <ianworthington@yahoo.com>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: asm() / goto() concern
Date: Tue, 24 May 2022 15:56:46 -0500 [thread overview]
Message-ID: <20220524205646.GM25951@gate.crashing.org> (raw)
In-Reply-To: <1538337561.2146473.1653382920615@mail.yahoo.com>
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
prev parent reply other threads:[~2022-05-24 20:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1538337561.2146473.1653382920615.ref@mail.yahoo.com>
2022-05-24 9:02 ` Ian Worthington
2022-05-24 20:56 ` Segher Boessenkool [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220524205646.GM25951@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=gcc-help@gcc.gnu.org \
--cc=ianworthington@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).