Hacker News new | past | comments | ask | show | jobs | submit login
Optimizing Your C/C++ Applications, Part 1 (amd.com)
9 points by Anon84 on Oct 9, 2008 | hide | past | favorite | 7 comments



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?


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


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?


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.


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.


About which compiler are you talking?


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?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: