This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: basic asm and memory clobbers
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- Cc: Jeff Law <law at redhat dot com>, David Wohlferd <dw at LimeGreenSocks dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, "rth at gcc dot gnu dot org" <rth at gcc dot gnu dot org>, "pinskia at gcc dot gnu dot org" <pinskia at gcc dot gnu dot org>, Sandra Loosemore <sandra at codesourcery dot com>
- Date: Fri, 27 Nov 2015 10:40:37 -0600
- Subject: Re: basic asm and memory clobbers
- Authentication-results: sourceware.org; auth=none
- References: <HE1PR07MB0905A9023A6C43ACB4B1D8DFE4030 at HE1PR07MB0905 dot eurprd07 dot prod dot outlook dot com>
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