lkml.org 
[lkml]   [2007]   [Jan]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: kernel + gcc 4.1 = several problems


On Wed, 3 Jan 2007, Denis Vlasenko wrote:
>
> Why CPU people do not internally convert cmov into jmp,mov pair?

Probably because

- it's not worth it. cmov's certainly _can_ be faster for unpredictable
input. So expecially if you teach your compiler (by using profiling) to
use cmov's mainly for unpredictable cases, turning it into a
conditional jump internally would likely be a bad idea.

- the biggest reason to do it would likely be microarchitectural: if you
have an ALU or a bypass network that just isn't suitable for bypassing
the flags that way (because you designed your pipeline for a
conditional branch), you might decide that it just simplifies things to
turn the cmov internally into a branch+mov uop pair.

- cmov's simply aren't common enough to be worth worrying about,
especially as it's not likely that the difference is all that big in
the end. The limitations on cmov's means that the compiler can only use
them under certain fairly limited circumstances anyway, so it's not
like you'll make a huge difference by doing anything clever. So see
above - it's simply a wash, and likely ends up just depending on other
issues.

And don't get me wrong. cmov's can make a difference. You can use them to
avoid polluting your branch prediction tables, you can use them to make
code smaller, and you can use them when they simply just fit the problem
really well. It's just _not_ the case that they are "obviously better".
They simply aren't. Conditional branches aren't "evil". There are many
MUCH worse things you can do, and other things you should avoid.

It really all boils down to: there's simply no real reason to use cmov.
It's not horrible either, so go ahead and use it if you want to, but don't
expect your code to really magically run any faster.

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-11-18 23:46    [W:0.119 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site