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: Is "memory" clobber required for all inline asm which does atomic operation???


Richard Henderson <rth@redhat.com> writes:

> On Tue, Jun 15, 2004 at 05:06:09PM -0300, Alexandre Oliva wrote:
> > You should use "memory" clobber if the asm statement modifies memory
> > that is not otherwise passed as an output operand to the asm
> > statement.  That's about it.  It doesn't matter if you're doing atomic
> > operations or not.
> 
> Not true.  Memory clobbers are also used to force the data
> being protected by the lock back to memory.  A volatile asm
> is not sufficient as a scheduling barrier.

I think two things are being confused here.

Acquiring or releasing a lock requires a memory barrier, since most
locks protect things that are in memory.  A memory barrier, by
definition, clobbers memory.  (Typically, you need more than a memory
clobber; there's usually some kind of instruction that actually
performs the memory barrier.)

However, a plain atomic operation (like an atomic increment) does not
involve locks and does not need a memory barrier.  The only memory
involved is the memory that holds the value operated on, and that
will be specified by a 'm' constraint, and so there is no need for a
memory clobber.


You don't usually need to make a memory barrier volatile; it clobbers
all of memory, so no memory operations can be moved across it, and it's
safe to move register computations across it.

You may or may not need to make an atomic operation volatile.  It
depends on whether you care what time it happens.

-- 
- Geoffrey Keating <geoffk@geoffk.org>


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