Friday, June 17, 2011

Intel Architecture Code Analyzer

Intel provides a great tool for static code analysis of C++ code at assembly-code-level. It is called the Intel Architecture Code Analyzer and will allow you to analyze how instructions are executed on an Intel CPU (including instruction pairing and the critical path).

It is very easy to use. Just download the binaries, include the iacaMarks.h header and insert marks at the code positions that you want to analyze. Take a look at the following example:
// source code of example.exe
#include <iacaMarks.h>

/* ... */

IACA_START
/* insert your code that should be analyzed here */
IACA_END
After compiling your source code (release build!) you can start the iaca command line tool and pass the exe-file as a parameter. For example:
C:\> iaca.exe -mark 0 -o analysis.txt example.exe
The -mark 0 parameter will analyze all marked blocks in your code (only needed if you have more than one START/END pair) and -o analysis.txt forces iaca.exe to store the results in a text file (this has the benefit that lines are not truncated to 80 characters as would happen if you output to the console).

Your program will not be able to execute when you have the IACA macros enabled in your code. If you want to execute the program again, remove the macros or define IACA_MARKS_OFF.

I will add an example of the output in the future on this blog post. So check back later if you are interested. There is however a good documentation available (look for User's Guide on the IACA webpage).

1 comment: