| From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
|---|---|
| To: | Gregory Stark <stark(at)enterprisedb(dot)com> |
| Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: What to do with inline warnings? |
| Date: | 2008-05-14 21:32:01 |
| Message-ID: | 20080514213201.GC6456@svana.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Simon Riggs | 2008-05-14 22:29:21 | Re: WAL file naming sequence definition |
| Previous Message | Andrew Hammond | 2008-05-14 21:25:34 | WAL file naming sequence definition |