AMD Athlon™ Processor x86 Code Optimization

Example:

22007E/0 — November 1999

struct { char a[5]; long k; doublex;

} baz;

The structure components should be allocated (lowest to highest address) as follows:

x, k, a[4], a[3], a[2], a[1], a[0], padbyte6, ..., padbyte0

See “C Language Structure Component Considerations” on page 27 for more information from a C source code perspective.

Sort Variables According to Base Type Size

Sort local variables according to their base type size and allocate variables with larger base type size ahead of those with smaller base type size. Assuming the first variable allocated is naturally aligned, all other variables are naturally aligned without any padding. The following example is a declaration of local variables in a C function:

Example:

short

ga, gu, gi;

long

foo, bar;

double

x,

y, z[3];

char

a,

b;

float

baz;

Allocate in the following order from left to right (from higher to lower addresses):

x, y, z[2], z[1], z[0], foo, bar, baz, ga, gu, gi, a, b;

See “Sort Local Variables According to Base Type Size” on page 28 for more information from a C source code perspective.

56

Sort Variables According to Base Type Size

Page 72
Image 72
AMD x86 manual Sort Variables According to Base Type Size, Example