
C Language Structure Component Considerations
27
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 siz e 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
Size
Sort structure members according to their base type size,
declaring members with a larger base type size ahead of
members with a smaller base type size.
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...