This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Clarification Req: Regarding "memory" clobber for cacheoperation is required (?)
- From: Jim Wilson <wilson at specifixinc dot com>
- To: "Ashok.A" <ashok_kumar_ak at yahoo dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 29 Mar 2004 15:01:35 -0800
- Subject: Re: Clarification Req: Regarding "memory" clobber for cacheoperation is required (?)
- References: <20040326063407.20385.qmail@web12008.mail.yahoo.com>
On Thu, 2004-03-25 at 22:34, Ashok.A wrote:
> To invalidate a cache line, do we really need to
> use "memory" clobber in inline asm?
This is a difficult question to answer.
If it does not work without the memory clobber, then obviously you need
it.
If it does appear to work without the memory clobber, then whether you
need it depends on the context and how the asm is written, and possibly
on what gcc versions you have and what compiler optimizations are
enabled. There is no simple answer here, other than to say that you are
safer with a memory clobber than without one.
You don't need the memory clobber if you use an alternative method for
describing the dependencies. For instance, if you make the asm
volatile. Or if you have memory input(s) with size and address that
covers the cache line being invalidated.
You don't need the memory clobber if you are sure that the function that
contains the asm will never contain any memory references that will
conflict with the cache line that is being invalidated. (And the
function is not marked inline or you are not compiling with
-finline-functions, etc.)
Personally, I would include the clobber, or better yet, make the asm
volatile.
> P.S: I have checked the linux source. Looks neither
> "memory" clobber nor any memory constraint is
> specified in inline asm for similar operations
> in linux source.
It looks like the linux sources use volatile instead of memory
clobbers. Volatile is a stronger statement than a memory clobber.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com