This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Clarification Req: Regarding "memory" clobber for cache operation is required (?)


>>>>> "Ashok" == Ashok A <Ashok.A> writes:

 Ashok> Another question is, can we use the following like constraints
 Ashok> instead of using more costlier "memory" clobber?

 Ashok> ---------- typedef char helper [DCACHE_LINE_SIZE]; ...  ...

 Ashok> inline void invalidate_cache_line(void *ptr) { asm volatile
 Ashok> ("cache 17, 0(%1)" : "=m" (*(helper *)ptr) : "r" (ptr)); }

In an earlier discussion (about atomicity) it was pointed out that
this doesn't work -- you can't make use of operands to asm that aren't
actually used in the asm text.  There are no references to %0, so the
"=m" operand doesn't have any effect.

The way to look at whether you need "memory" clobber, or volatile (or
neither) is to look at what the asm statement does. 

Take the specific example of a cache invalidate.  If the compiler had
generated a load before the invalidate, that value is no longer valid
afterwards -- if you did another load, you might get a different
answer.  So "clobber memory" is the safe thing to do here.

If you don't have any loads or stores to the affected memory in the
source text before the invalidate, but you do have some after it, then
"volatile" would be sufficient (it keeys the compiler from moving
things before the asm).

Conversely, if the asm was a cache flush rather than a cache
invalidate, that doesn't make loads or stores invalid.  (It affects
physical memory, but it doesn't affect the view of memory that
software has).  So a flush wouldn't need a memory clobber.  It may
need "volatile", to make sure that externally visible memory
operations happen in the order intended by the program.

	   paul



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]