asm as "memory barrier"

Paul Koning pkoning@equallogic.com
Thu Apr 24 18:56:00 GMT 2003


> From: Richard Henderson <rth@redhat.com>
>>On Wed, Apr 23, 2003 at 03:55:57PM -0400, Paul Koning wrote:
>> But it also (as documented) causes the compiler to assume that memory
>> has changed since then, i.e., anything it loaded before is no longer
>> valid.  That's NOT what I want.
> 
> There doesn't appear to be any way to do this.  I'd have expected
> 
>   int x;
>   int foo()
>   {
>     int r = x;
>     {
>       char *p;
>       asm ("" : "=X"(p));
>       asm volatile ("" : : "X"(*p));
>     }
>     return x + r;
>   }
> 
> to work (as an observed read from a pointer with unknown value),
> but it would seem that CSE doesn't want to combine the two loads
> across the volatile asm.

Perhaps because of the aliasing rules?

I observed that simply asm volatile (""), i.e., "old style asm" *does*
do what I want.  My concern wasn't that -- it was the fact that there
isn't any documented property of old style asm.  Or at least, only
very little, and part of that has traditionally been wrong.

     paul



More information about the Gcc mailing list