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:
> 
> nop
> 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.



Reply via email to