C Language Structure Component Considerations - AMD Athlon Processor x86 Optimization Manual

X86 code optimization
Table of Contents

Advertisement

22007E/0—November 1999
Example 1
Example 2

C Language Structure Component Considerations

Sort by Base Type
Size
C Language Structure Component Considerations
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;
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;
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 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.
AMD Athlon™ Processor x86 Code Optimization
27

Advertisement

Table of Contents
loading

Table of Contents