
Push Memory Data Carefully
75
22007E/0—November 1999
AMD Athlon™ Processor x86 Code Optimization
variable that starts with a negative value and reaches zero when
the loop expires. Note that if the base addresses are held in
reg isters (e. g. , w hen the ba se a ddre sse s are pa sse d a s
arguments of a function) biasing the base addresses requires
additional instructions to perform the biasing at run time and a
small amount of additional overhead is incurred. In the
examples shown here the base addresses are used in the
d i s p l a c e m e n t p o r t i o n o f t h e a d d r e s s a n d b i a s i n g i s
accomplished at compile time by simply modifying the
displacement.
Example 3 (Preferred):
int a[MAXSIZE], b[MAXSIZE], c[MAXSIZE], i;
for (i=0; i < MAXSIZE; i++) {
c [i] = a[i] + b[i];
}
MOV
ECX, (-MAXSIZE)
;initialize index
$add_loop:
MOV
EAX, [ECX*4 + a + MAXSIZE*4] ;get a element
MOV
EDX, [ECX*4 + b + MAXSIZE*4] ;get b element
ADD
EAX, EDX
;a[i] + b[i]
MOV
[ECX*4 + c + MAXSIZE*4], EAX ;write result to c
INC
ECX
;increment index
JNZ
$add_loop
;until index==0
Push Memory Data Carefully
Carefully choose the best method for pushing memory data. To
reduce register pressure and code dependencies, follow
example 2 below.
Example 1 (Avoid):
MOV
EAX, [MEM]
PUSH EAX
Example 2 (Preferred):
PUSH [MEM]
Summary of Contents for Athlon Processor x86
Page 1: ...AMD Athlon Processor x86 Code Optimization Guide TM...
Page 12: ...xii List of Figures AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 16: ...xvi Revision History AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 202: ...186 Page Attribute Table PAT AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 252: ...236 VectorPath Instructions AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 256: ...240 Index AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...