This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: basic asm and memory clobbers


Hi Bernd,

On Fri, Nov 27, 2015 at 09:26:40AM +0000, Bernd Edlinger wrote:
> On Tue, 17 Nov 2015 14:31:29, Jeff Law wrote:
> > The benefit is traditional asms do the expected thing. With no way to describe dataflow, the only rational behaviour for a traditional asm is that it has to be considered a
> use/clobber of memory and hard registers.
> 
> I'd like to mention here, that there is also another use-case for a basic asms:
> 
> It is most often used as a fairly portable memory barrier like this:
> 
> x = 1;
> asm(""); // memory barrier
> y = 2;
> 
> that is also the reason why every basic asm is implicitly a volatile asm.

But that is not a memory barrier, not as currently implemented anyway:

===
int a, b;

void f(void)
{
        int j;
        for (j = 0; j < 10; j++) {
                a = 42;
                asm("lolz");
                b = 31;
        }
}
===

does the asms in a loop, followed by the two stores.  Making it
asm("lolz" ::: "memory"); works as you seem to expect.

It has behaved like this since at least 4.0 (the oldest compiler I have
around currently).

[ Yes I'm a broken record. ]


Segher


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]