views:

38

answers:

2

Whenever I talk to people that work with real-time preformance they tend to point out that the generated X86 assembly instructions are not that efficent.

With things like VMX on the horizon I have to ask, how likely is it that commercial C++ compilers will utilize these instruction sets? I get the feeling that compiler vendors don't emit particulary fancy assembly or focus on keeping ther compilers up to date.

And for that matter, what constitutes good X86 assembly in the first place?

+1  A: 

"Good assembly" means that the compiled program utilizes resources optimally. There's a wisdom "write code in clear manner and let the compiler do the optimizations". For this wisdom to hold true compilers go to great extent to generate really fast code.

From my experience Visual C++ often produces surprisingly consice code for complex looking C++ construct, so the idea that compiler vendors don't care about code emisson is not that true.

sharptooth
Could you elaborate a bit? Like what's the point of rearranging instructions and how that works better on X86 architectures? And if you know of some other obscure optimization that's very important for generating fast code, I'd love to hear about that.
John Leidegren
@John Leidegren: The CPU is very complex inside - it breaks instructions into subinstructions that are executed on a huge set of interdependent parts of the CPU. Wise choice of instructions leads to better utilizing those part and thus faster overall execution. Google for "AMD Athlon optimization guide" - this will give an impression of what problems are there and how ignoring them can lead to really bad code.
sharptooth
+2  A: 

The guys you're talking to must be performance nuts. Most modern compilers will generate very efficient code that makes use of branch-prediction and pipeline-stall tables and a host of optimisation techniques. They will generally emit better code than all but the smartest programmers can match. There are oddball exceptions, which is why it's nice to have __asm and intrinsics on standby, but the situations in which these prove necessary (and helpful) are few and far between these days.

Marcelo Cantos
The guys I'm talking about feel that a conditional branch is better served by replacing it with things like selZero (an XBOX360 thing) which is this spiffy instruction that takes the first operand, and if it is zero, it yields the second operand, else the third operand in, without branching. These things are not always applicable and I'm most definitely not advocating writing assembly my self, but I'm intrigued to learn more about the things the compiler does to actually be that good. They also trash talk MSVC for generating bad assembly a lot of the time... I trust thier judgment.
John Leidegren
@John: I wasn't being at all facetious when referring to performance nuts. Some programmers, due to their problem domain, have good reason to be concerned about every last cycle. But they are definitely the exception, not the rule. Most programmers find MSVC to be much better than what gcc or hand-coding could produce for the same degree of effort, and when that's not good enough, rather than resorting to assembly language, plan B is often the Intel compiler, which does auto-vectorisation and auto-parallelisation, among other things.
Marcelo Cantos