
Software Optimization Guide for AMD64 Processors | 25112 Rev. 3.06 September 2005 |
Definitions
char j, k[MAX]; |
| |
for (i = 0; i < | MAX; i++) { | |
... |
|
|
j += k[i]; | // | Every byte is used. |
... |
|
|
} |
|
|
double x, y[MAX]; | ||
for (i = 0; i < | MAX; i++) { | |
... |
|
|
x += y[i]; | // | Every byte is used. |
... |
|
|
} |
|
|
Exception to Unit Stride
The
prefetch [eax+n*structure_size]
... |
|
add | eax, structure_size |
You should experiment to find the optimal prefetch distance; there is no formula that works for all situations.
Data Stride per Loop Iteration
Assuming
fldz add_loop:
fadd QWORD PTR [ebx*8+base_address] dec ebx
jnz add_loop
The data stride of the above loop is eight bytes. In general, for optimal use of prefetching, the data stride per iteration is the length of a cache line (64 bytes in the AMD Athlon 64 and AMD Opteron processors). If the loop stride is smaller, unroll the loop enough to use a whole cache line of data per
110 | Cache and Memory Optimizations | Chapter 5 |