Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?



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


Hints are useless, but arranging for cold code to be on a forward branch can be beneficial.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: