Push Memory Data Carefully - AMD Athlon Processor x86 Optimization Manual

X86 code optimization
Table of Contents

Advertisement

22007E/0—November 1999

Push Memory Data Carefully

Push Memory Data Carefully
variable that starts with a negative value and reaches zero when
the loop expires. Note that if the base addresses are held in
registers (e.g., when the base addresses are passed as
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 re 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)
$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
MOV
[ECX*4 + c + MAXSIZE*4], EAX ;write result to c
INC
ECX
JNZ
$add_loop
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]
AMD Athlon™ Processor x86 Code Optimization
;initialize index
;a[i] + b[i]
;increment index
;until index==0
75

Advertisement

Table of Contents
loading

Table of Contents