
Software Optimization Guide for AMD64 Processors | 25112 Rev. 3.06 September 2005 |
7.6Pointer Arithmetic in Loops
Optimization
Minimize pointer arithmetic in loops, especially if the loop bodies are small. Take advantage of
Application
This optimization applies to:
•
•
Rationale
In small loops, pointer arithmetic causes significant overhead. Using
Example
Consider the following C code, which adds the elements of two arrays and stores them in a third array:
int a[MAXSIZE], b[MAXSIZE], c[MAXSIZE], i;
for (i = 0; i < MAXSIZE; i++) { c[i] = a[i] + b[i];
}
154 | Scheduling Optimizations | Chapter 7 |