likely and unlikely

Max Laier max at love2party.net
Fri Mar 12 14:26:16 UTC 2010


On Friday 12 March 2010 13:42:59 Stefan Farfeleder wrote:
> On Fri, Mar 12, 2010 at 01:26:08PM +0100, Ed Schouten wrote:
> > Hi Ivan,
> >
> > * Ivan Voras <ivoras at freebsd.org> wrote:
> > > Wouldn't it be more convenient to have a single global definition of
> > > them, under #ifdef __GNUC__ for example in sys/stddef.h ?
> >
> > Wouldn't it be better to have them in sys/cdefs.h?
> 
> Putting macros 'likely' and 'unlikely' into sys/cdefs.h creates a big
> namespace violation problem; C code using those identifiers will break.

In addition, I don't think it's a good thing to make these too easy to use ... 
I found that they are a pessimisation more often than not.  In addition, it 
seems that at least our base gcc version does forget to apply any other 
optimizations if it encounters one of these.

My point is: Handle with care!!!  Trust your compiler/CPU predictors/... - 
most of the time, they are smarter than you are ;)

Regards,
  Max


More information about the freebsd-arch mailing list