Search code examples
c++windowsvisual-studio-2008optimization

Producing the fastest possible executable


I have a very large program which I have been compiling under visual studio (v6 then migrated to 2008). I need the executable to run as fast as possible. The program spends most of its time processing integers of various sizes and does very little IO.

Obviously I will select maximum optimization, but it seems that there are a variety of things that can be done which don't come under the heading of optimization which do still affect the speed of the executable. For example selecting the __fastcall calling convention or setting structure member alignment to a large number.

So my question is: Are there other compiler/linker options I should be using to make the program faster which are not controlled from the "optimization" page of the "properties" dialog.

EDIT: I already make extensive use of profilers.


Solution

    1. Reduce aliasing by using __restrict.

    2. Help the compiler in common subexpression elimination / dead code elimination by using __pure.

    3. An introduction to SSE/SIMD can be found here and here. The internet isn't exactly overflowing with articles about the topic, but there's enough. For a reference list of intrinsics, you can search MSDN for 'compiler intrinsics'.

    4. For 'macro parallelization', you can try OpenMP. It's a compiler standard for easy task parallelization -- essentially, you tell the compiler using a handful of #pragmas that certain sections of the code are reentrant, and the compiler creates the threads for you automagically.

    5. I second interjay's point that PGO can be pretty helpful. And unlike #3 and #4, it's almost effortless to add in.