Справочник Пользователя для AMD 250

Скачать
Страница из 384
154
Scheduling Optimizations
Chapter 7
25112
Rev. 3.06
September 2005
Software Optimization Guide for AMD64 Processors
7.6
Pointer Arithmetic in Loops
Optimization
Minimize pointer arithmetic in loops, especially if the loop bodies are small. Take advantage of 
scaled-index addressing modes to utilize the loop counter as an index into memory arrays.
Application
This optimization applies to:
32-bit software
64-bit software
Rationale
In small loops, pointer arithmetic causes significant overhead. Using scaled-index addressing modes 
has no negative impact on execution speed, but the reduced number of instructions preserves decode 
bandwidth.
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];
}