Include Optimized Assembly Code in Compilation for 64-Bit Intel® Architecture

Submit New Article

March 4, 2009 11:00 PM PST



Challenge

Include assembly code in compilation and determine its effectiveness. Once you have optimized assembly code by hand, you must include that optimized assembly in the compilation and then determine that optimization's level of success.


Solution

Extern the function to include it in the executable, and then create a mechanism to measure the function's execution duration. In order to include the function in the compilation, simply extern it like so:

#define FACTORIAL 12 
extern "C" {
unsigned long long fact(int n);
unsigned long long int nanotime(void);
}

void main() {
… 

 

and have a command line like

ecl Factorial.cpp fact.asm nanotime.asm 

 

The assembly code is now included in the executable.

Now that the code is compiled and ready to go, a method for determining effectiveness is needed. One method is to use time functions. However, some functions need finer resolutions than standard C calls. For those functions, do the following:

Nanotime gets the Interval Time Counter from the processor, measured in clockticks, and returns it as an unsigned long long.


Source

Optimizing Itanium® Processor Family Assembly Code