On Wed, May 14, 2008 at 08:25:10PM +0100, Gregory Stark wrote: > The Linux kernel does have some macros meant to mark unlikely branches > (usually assertion failures) but I'm not sure how they work. And Gcc also has > a few optimizations which are driven by profiling data but I it doesn't sound > like this is one of them.
There's a macro called __builtin_expect() where you can specify what the expected value of an expression is at runtime, so gcc can use this to decide which branch is more likely, or how often a loop might run. Normally you wrap it into macros like: #define likely(x) __builtin_expect(x,1) #define unlikely(x) __builtin_expect(x,0) So you say things like: if( likely( x==0 ) ) And gcc will optimise that the branch is likely to be taken. Using macros means that you can arrange it so that for non-gcc compilers it's a no-op. Have a nice day, -- Martijn van Oosterhout <[EMAIL PROTECTED]> http://svana.org/kleptog/ > Please line up in a tree and maintain the heap invariant while > boarding. Thank you for flying nlogn airlines.
signature.asc
Description: Digital signature