6

In regards to this question, I'm interested only in x86 and x86-64.

For MSVC 2005, the documentation for __faststorefence says: "Guarantees that every preceding store is globally visible before any subsequent store."

For MSVC 2008 and 2010, it changed to: "Guarantees that every previous memory reference, including both load and store memory references, is globally visible before any subsequent memory reference."

The way the latter is written, it implies in my opinion that this would also block the CPU's reordering of loads before older stores. This is different from the first definition, which implies that the intrinsic is only to deal with blocking or the reordering of non-temporal stores with older stores (the only other reordering x86(-64) does).

However, then the documentation appears to contradict itself: "On the x64 platform, this routine generates an instruction that is a faster store fence than the sfence instruction. Use this intrinsic instead of _mm_sfence on the x64 platform."

This implies that it still has sfence-like functionality, and thus loads can still be reordered with older stores. So which is it? Can someone clear up my confusion?

PS: looking for a GCC version of this function, I came across long local; __asm__ __volatile__("lock; orl $0, %0;" : : "m"(local)); but I think it's from 32-bit code; what would be the 64-bit analog?

2
  • 7
    Can you possibly give a better question title than __faststorefence? Jun 25, 2011 at 21:25
  • 1
    @JaredFarrish: Better late than never? :)
    – GManNickG
    Sep 6, 2012 at 22:25

1 Answer 1

3

The GCC version you quote is equivalent to the code that MSVC generates. It relies on the fact that the x86/x86-64 processor architecture docs specify that loads and stores are not reordered with a LOCKed instruction.

I am not clear whether this applies to non-temporal stores, since in general the memory model restrictions do not apply to those instructions.

2
  • Hi Anthony, thanks for the answer. What remains unclear is why the documentation for this intrinsic specifies that it is faster on the x64 platform, rather than on both 32 and 64. Does it mean to imply that a locked instruction is cheaper than an mfence only on x86-64? Additionally, if it prevents both loads and stores from being reordered, is this a sufficient fence for sequential consistency (excluding the case of non-temporal stores)? Jun 28, 2011 at 20:09
  • 2
    This intrinsic is only available in MSVC on x86-64; I don't know why. I would expect it to have the same cost on x86-64 as on x86 with respect to MFENCE, since the architecture is essentially the same. If you ignore non-temporal stores then this is a sufficient fence for sequential consistency. Jun 28, 2011 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.