lkml.org 
[lkml]   [2009]   [Jan]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: if (unlikely(...)) == unnecessary?
Davide Libenzi wrote:
> I noticed that GCC >= 3.3 (not tried the ones before) automatically
> branches out the "if" code (and follow-through the "else" code, if there).
> Is that a coincidence or a rule we can rely on going forward?

That's the default behavior, but there are lots of things that can cause it to
behave differently. Also, not all branch predictors behave the same way, and
some architectures use things like conditional instructions to fill their
pipeline bubbles, so it's still generally useful to have a real compiler hint in
fast-path code, even if it ends up being a no-op most of the time.

Most kernel code isn't so clock-cycle-critical that it needs these annotations.
If you're working on code that already has them, that's a good indication you
should probably use them too, but otherwise you don't need to worry about it
unless your code starts chewing up a lot of CPU time.

-- Chris


\
 
 \ /
  Last update: 2009-01-28 18:59    [W:0.049 / U:0.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site