Re: What to do with inline warnings? - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: What to do with inline warnings?
Date
Msg-id 20080514213201.GC6456@svana.org
Whole thread Raw
In response to Re: What to do with inline warnings?  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-hackers
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   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

pgsql-hackers by date:

Previous
From: "Andrew Hammond"
Date:
Subject: WAL file naming sequence definition
Next
From: Simon Riggs
Date:
Subject: Re: WAL file naming sequence definition