asm and "cc" "memory" volatile etc.. (slightly offtopic)

Richard Henderson rth@cygnus.com
Tue Nov 11 16:21:00 GMT 1997


On Tue, Nov 11, 1997 at 05:48:55PM -0500, Paul Koning wrote:
>  Richard> extern inline int test_bit(int nr, void *addr) { int ret;
>  Richard> __asm__("btl %2,%1\n\tsbbl %0,%0" : "=r"(ret) :
>  Richard> "m"(m(addr)), "ir"(nr)); return ret; }
> 
> I've found that some backends are perfectly happy to rearrange asm
> statements (gnu extended asm, that is) even if wrapped inside an
> inline function.  As far as I understand it, the only reliable way to
> force that not to happen is to say "asm volatile".  (Note that
> declaring the inline function "volatile" doesn't help.)

Yes, but it primarily depends on what you want to have happen. 

In this case the asm does not affect the external system, it just looks
at it.  Thus if the result of test_bit() is not used, we want the asm to
be removed as well, which would not happen if you declared it volatile.

Mostly you just have to think "does this absolutely have to happen right
here to get correct results".


r~



More information about the Gcc mailing list