This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A question about "memory" clobbers in asm
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Jamie Lokier <jamie at shareable dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 17 Sep 2004 16:39:20 +0100
- Subject: Re: A question about "memory" clobbers in asm
- Organization: Codesourcery LLC
- References: <20040917144519.GB31970@mail.shareable.org>
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