Re:Secrets of dispatch_once; x86 performance trickery
by Marat_Dukhan on Saturday June 07, 2014 @02:14AM
(#7861466)
There are hints for taken/non-taken branches in x86. However, the only family to use them was Pentium 4; other processors silently ignore those hints.
As for the write side, you'll find it here: https://opensource.apple.com/source/libdispatch/libdispatch-...
DISPATCH_EXPECT is a macro that tells the compiler to emit code that tells the CPU that the branch where 8predicate is ~0l is the more likely path. This can improve the success of branch prediction, and thus improve performance.
While this is what the macro would do on processors that support such code, x86/x64 isn't one of those processors (Itanium was). Instead, it's more important purpose here is to hint to the compiler (not the processor) to lay out the conditional in assembly such that the expected result is on the faster "branch not taken" path.
That said, is the actual implementation of the "write side" viewable online?