This is the mail archive of the
mailing list for the GCC project.
Re: AW: basic asm and memory clobbers - Proposed solution
- From: David Brown <david at westcontrol dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 02 Dec 2015 11:00:51 +0100
- Subject: Re: AW: basic asm and memory clobbers - Proposed solution
- Authentication-results: sourceware.org; auth=none
- References: <56552209 dot 1020306 at LimeGreenSocks dot com> <56592801 dot 9010606 at LimeGreenSocks dot com> <HE1PR07MB09050E30BB6C251DBB454790E4020 at HE1PR07MB0905 dot eurprd07 dot prod dot outlook dot com> <9EAD225F-1323-439F-B697-C90F86F1D959 at dell dot com> <565B8FE2 dot 7000500 at LimeGreenSocks dot com> <2C1A50C8-AC7B-4E9E-BE5D-8CAB7AB8BDDC at dell dot com>,<565E1ED6 dot 6060505 at LimeGreenSocks dot com> <HE1PR07MB0905B92C3D55C7230184860FE40E0 at HE1PR07MB0905 dot eurprd07 dot prod dot outlook dot com>
On 02/12/15 08:51, Bernd Edlinger wrote:
> On 1.12.2015, David Wohlferd wrote:
> On 12/1/2015 10:10 AM, Bernd Edlinger wrote:
>>> But IMHO asm("bla":) isn't any better than asm("bla").
>>> I think _any_ asm with non-empty assembler string, that
>>> claims to clobber _nothing_ is highly suspicious, and worth to be
>>> warned about. I don't see any exceptions from this rule.
>> There's one right now in the basic asm docs: asm("int $3");
>> And I've seen others: asm volatile ("nop"), asm(".byte 0xf1\n"). I've
>> seen a bunch more, but you get the idea.
> I disagree.
> Consider this example where "nop" should be injected
> to guarantee a minimum pulse length:
> int x;
> x = 1;
> asm volatile ("nop");
> x = 0;
> resulting code at -O2 is something like this:
> movl $0,x
> That is because this asm statement allows
> gcc to move the assembler code anywhere.
> It is only guaranteed to be executed once,
> but it not guaranteed to be executed between
> the two assignments. To avoid that we have
> to use a "memory" clobber.
Surely in code like that, you would make "x" volatile? Memory clobbers
are not a substitute for correct use of volatile accesses.