On Sat, Apr 12, 2008 at 11:01:19PM +0200, Daniel Mack wrote:
Hi,
On Sat, Apr 12, 2008 at 11:21:27PM +0300, Adrian Bunk wrote:
Does it bring any measurable advantage?
Otherwise it's usually better to let the compiler decide how to optimize the code.
I didn't really measure, but how should the compiler know how likely a certain condition in hardware state is? I thought, in such cases it's generally a good idea to give the compiler some hints.
gcc's heuristics often tends to guess better than programmers on how to optimize code since most people who think they know better how code should get optimized than the compiler do not actually know better...
And what you call "some hints" _forces_ the compiler to optimize for a certain condition (even if this e.g. results in bigger code or omitting some optimization).
Considering the lines of code and the number of contributors to the Linux kernel some annotations are always wrong and might cause more harm than the correct ones gain.
If it's some hotpath and a current gcc does generate measurably faster code with a likely/unlikely it's justified, but otherwise it's better to leave gcc all freedom on how to optimize it.
Daniel
cu Adrian