A question about "memory" clobbers in asm
Nathan Sidwell
nathan@codesourcery.com
Fri Sep 17 16:07:00 GMT 2004
Jamie Lokier wrote:
> I'm having trouble understand when it's appropriate to use a "memory"
> clobber, when to use volatile, and when to use both. The manual is
> unclear to me. Although I see that someone has tried to clarify it
> since I last read it, it's still not obvious how "memory" is different
> from `volatile'.
my understanding is
* volatile asm says something to the effect 'this changes state that you
(the compiler) don't know about' -- such as writing to an IO port.
* memory clobber says 'this asm will change memory, so don't cache anything
across this asm'.
So,
asm volatile ("pokeIOport");
v = *ptr;
could hoist the load before the asm, but the asm will never be deleted
from the code sequence. Whereas
asm ("readsomething %0" :"=r" (v2) :: "memory");
v = *ptr;
would do no such hoisting, but would delete the asm, if V2 was never
subsequently used.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
More information about the Gcc
mailing list