News for hackers. Stuff that matters.
Re:Open Source at Google: Introducing CityHash by andrewcooke on Monday April 11, 2011 @06:53PM (#2434812)
what does this do: #define LIKELY(x) (__builtin_expect(!!(x), 1))

oh, to answer myself, is to help predict the branch direction - it indicates which is likely the common case in the test. http://kerneltrap.org/node/4705

Re:Open Source at Google: Introducing CityHash by edge17 on Monday April 11, 2011 @07:08PM (#2434875)
haven't seen this stuff in a while... given the complexity and large history-tracking tables of modern branch predictors, is this stuff still useful?

or is the code written in this manner just to make it more platform independent (i.e. cycles still matter for embedded applications, etc)?

Re:Open Source at Google: Introducing CityHash by pmr_ on Monday April 11, 2011 @07:39PM (#2435012)
There is really no connection between the likely macro and branch prediction here.

The gcc built-in simply will organize the code in a manner that makes the likely statement faster to execute (e.g. branching the unlikely block).

Branch predictors are a runtime mechanism so the processor guesses which outcome of the "if" is more likely.

One is a static optimization, the other is dynamic; if you like to think about it that way.

Re:Open Source at Google: Introducing CityHash by haberman on Monday April 11, 2011 @08:22PM (#2435136)
A lot of instruction sets (including x86) let you encode branch prediction hints into the actual instructions to help out the branch predictors. But for x86 at least these hints didn't turn out to be too useful, so they're ignored (except on P4, I believe).