Optimizing software in C++: An optimization guide for Windows, Linux and Mac platforms

Categories:

Recommended

This manual is for advanced programmers and software developers who want to make their software faster. It is assumed that the reader has a good knowledge of the C++ programming language and a basic understanding of how compilers work. The C++ language is chosen as the basis for this manual for reasons explained on page 8 below.

C++ (pronounced “C plus plus”) is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or “C with Classes”. The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation. It is almost always implemented as a compiled language, and many vendors provide C++ compilers, including the Free Software FoundationLLVMMicrosoftIntelEmbarcaderoOracle, and IBM, so it is available on many platforms.

This manual is based mainly on my study of how compilers and microprocessors work. The recommendations are based on the x86 family of microprocessors from Intel, AMD, and VIA including the 64-bit versions. The x86 processors are used in the most common platforms with Windows, Linux, BSD, and Mac OS X operating systems, though these operating systems can also be used with other microprocessors and instruction sets. Much of the advices may apply to other platforms and other compiled programming languages as well.

This is the first in a series of five manuals: 1. Optimizing software in C++: An optimization guide for Windows, Linux, and Mac platforms. 2. Optimizing subroutines in assembly language: An optimization guide for x86 platforms. 4 3. The microarchitecture of Intel, AMD, and VIA CPUs: An optimization guide for assembly programmers and compiler makers. 4. Instruction tables: Lists of instruction latencies, throughputs and micro-operation breakdowns for Intel, AMD, and VIA CPUs. 5. Calling conventions for different C++ compilers and operating systems.

The latest versions of these manuals are always available from www.agner.org/optimize. Copyright conditions are listed on page 180 below.

Programmers who are satisfied with making software in a high-level language need only read this first manual. The subsequent manuals are for those who want to go deeper into the technical details of instruction timing, assembly language programming, compiler technology, and microprocessor microarchitecture.

Please note that my optimization manuals are used by thousands of people around the world. I simply do not have the time to answer questions from everybody. So please do not send your programming questions to me. You will not get any answer. Beginners are advised to seek information elsewhere and get a good deal of programming experience before trying the techniques in the present manual. There are various discussion forums on the Internet where you can get answers to your programming questions if you cannot find the answers in the relevant books and manuals.

I want to thank the many people who have sent me corrections and suggestions for my optimization manuals. I am always happy to receive new relevant information.