[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Why does membar_consumer() do anything on x86_64?
On 11.07.2010 05:19, Dennis Ferguson wrote:
> Unless I'm truly confused, here's what membar_consumer() and membar_producer()
> do on an x86_64 processor:
> addq $0, -8(%rsp)
> /* A store is enough */
> movq $0, -8(%rsp)
> I'm trying to figure out why membar_consumer() does that, since the useless
> read-modify-write is measurably quite expensive. I'm also curious why
> membar_producer() is implemented as the useless write.
On amd64, IIRC, there is one exception regarding ordering; a quick
search in the spec says that "Loads may be reordered with older stores
to different locations."
lock instructions have total order (loads and store are not reordered
with lock instructions). As memory barriers always go by 2 (one
consumer/reader, one producer/writer), the lock avoids load/store
reordering to different locations; see 184.108.40.206, "Loads May Be Reordered
with Earlier Stores to Different Locations."
I could get it wrong though, anyway, it seems plausible to me...
Main Index |
Thread Index |