News for hackers. Stuff that matters.
Re:Secrets of dispatch_once; x86 performance trickery by nkurz on Saturday June 07, 2014 @01:56AM (#7861443)
Great article! I'm still trying to wrap my head around this, but in the meantime I'll quibble about one tiny throwaway aside:

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?

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-...

Re:Secrets of dispatch_once; x86 performance trickery by gsg on Saturday June 07, 2014 @05:13AM (#7861680)
Hints are useless, but arranging for cold code to be on a forward branch can be beneficial.