
Optimizing Your C/C++ Applications, Part 1 - Anon84
http://developer.amd.com/documentation/articles/pages/6212004126.aspx
======
anamax
From the article "However, if the case expressions are noncontiguous values,
most compilers translate the switch statement as a comparison chain."

The recommendationi in that case seems to be to write the comparison chain
yourself. How is my comparison chain better than the compiler's?

~~~
ConradHex
Yeah, totally. I hate to be cynical, but #6 seems bogus.

------
newt0311
I am not sure about the other but #3 is completely superseded by gcc's
optimization algorithms. Besides, is this kind of low level stuff really
something a developer should be wasting their time with?

~~~
DarkShikari
You trust GCC way too much. Certainly one should do a bit of low-level
profiling before making such changes, but I have actually never seen GCC
_intelligently_ unroll a loop in all my years of C programming. It completely
ignores constant propagation when doing so (even in gcc 4.4!), making the
unrolling algorithm basically useless, since constant propagation is far more
useful than the savings gained from taking fewer jumps.

I actually have one case where I made a function 3 times shorter code-wise and
run over 2x faster simply by unrolling it completely--the rules for deriving
values based on the loop index were so complicated that they were actually
longer than the unrolled loop itself.

------
albertcardona
It's sad that C/C++ is _still_ incapable of unrolling small loops on its own,
as suggested by tip #3.

Same shame for the switch statement at tip #6.

~~~
eru
About which compiler are you talking?

~~~
albertcardona
Just talking about the fact that a tutorial mentions low level _manual_
optimizations.

-O2 and -O3 flags may do such low-level optimizations, I hope. But then why the tutorial?

