Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2008-04-19 08:20:56


Patrick Twohig wrote:
>
> Another article talks about writing on the Xbox360, which is what I needed a
> queue for: http://msdn2.microsoft.com/en-us/library/bb310595(VS.85).aspx

"On Xbox 360 MemoryBarrier is defined as lwsync (lightweight sync), also
available through the __lwsync intrinsic, which is defined in
ppcintrinsics.h. __lwsync also serves as a compiler memory barrier,
preventing rearranging of reads and writes by the compiler.

The lwsync instruction is a memory barrier on Xbox 360 that synchronizes
one processor core with the L2 cache. It guarantees that all writes
before lwsync make it to the L2 cache before any writes that follow. It
also guarantees that any reads that follow lwsync don't get older data
from L2 than previous reads."

Ich verstehe nur Bahnhof.

The thing is that architecturally (on PPC/Power) lwsync doesn't prevent
hardware from hoisting subsequent loads above preceding stores (or
sinking preceding stores below subsequent loads) unless it's constrained
by UP consistency or data/control dependencies. That's what makes lwsync
"light weight" sync. To make the story short, if you're a going to code
banking or some such on Xbox 360, I suggest you better use

  ordered load: sync; lr-sc loop; isync;

  ordered store: lwsync; store; sync;

  acquire load: load; "branch never taken"; isync // See B.2.3 Safe
                                                    // Fetch (Book II)

  release store: lwsync; store;

and decorate each *sync above with _ReadWriteBarrier thing just to be
sure that compiler won't screw up.

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk