22007E/0 — November 1999

AMD Athlon™ Processor x86 Code Optimization

Example 1

Avoid:

 

 

double

a,b,c,d,e,f;

 

e = b*c/d;

 

f = b/d*a;

 

Preferred:

 

 

double

a,b,c,d,e,f,t;

 

t = b/d;

 

 

e = c*t;

 

 

f = a*t;

 

Example 2

Avoid:

 

 

double a,b,c,e,f;

e = a/c; f = b/c;

Preferred:

double a,b,c,e,f,t;

t = 1/c; e = a*t f = b*t;

C Language Structure Component Considerations

Many compilers have options that allow padding of structures to make their size multiples of words, doublewords, or quadwords, in order to achieve better alignment for structures. In addition, to improve the alignment of structure members, some compilers might allocate structure elements in an order that differs from the order in which they are declared. However, some compilers might not offer any of these features, or their implementation might not work properly in all situations. Therefore, to achieve the best alignment of structures and structure members while minimizing the amount of padding regardless of compiler optimizations, the following methods are suggested.

Sort by Base Type Sort structure members according to their base type size,

Sizedeclaring members with a larger base type size ahead of members with a smaller base type size.

C Language Structure Component Considerations

27

Page 43
Image 43
AMD x86 manual Language Structure Component Considerations, Example, Avoid, Preferred