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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]