This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: How to write optional code for G++


Hi Jan,

In my opinion, code optimization is more art than boilerplate.

In my experience, code optimization of an existing application starts with profiling of code compiled for release (i.e., with the compiler optimizations enabled).  Then when running (or after running, depending on your profiler), you use the profiling information to identify the most obvious culprits to consider for optimization.

Also of note, unfortunately, a program with a bad architecture or poor algorithms cannot necessarily be improved by micro-optimizations as identified by the profiler.

And sometimes, for some problem domains, you may need to employ SIMD technology (such as that available in SSE or AltiVec) to do the heavy duty calculations.  And some folks have even resorted to pushing data calculations onto the GPU, which can do some things amazingly fast.  And when performance is the utmost important thing as identified in a workhorse leaf-node routine, it may pay to take into consideration cycle counts, pipeline stalls, data cache misses, with lovingly handcrafted assembly*.

You indicated that you did not want to re-write your large program without having some sense of what would work better.  I often write very small experimental toy programs to test performance differences, and use those routines that demonstrate better performance than the other ideas.  When optimizing for performance, maybe that approach would work for you too.

Here are some Google hits with additional advice:
http://www.google.com/search?hl=en&q=code+optimization

Good luck!
--Eljay

* I gave up on lovingly handcrafted assembly after I got my first optimizing C compiler that did all the "k-cool super secret" tricks that I used, and a few that I knew about but didn't employ, and a few more that I had never even considered.  That was the day I said, "Hmmm, I'll never have to write another line of assembly code again."  Especially since the C routine took about 15 minutes to write, and the lovingly handcrafted assembly took about 3 days to write and get right (debug).  And I've mostly abided with that conclusion ever since.  But there are meticulous assembly programmers out there that can do amazing things that the compiler won't do, and I am continuously amazed at their prowess.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]