Re: asm() / goto() concern

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux