AMD 250 Computer Hardware User Manual


 
Chapter 5 Cache and Memory Optimizations 119
Software Optimization Guide for AMD64 Processors
25112 Rev. 3.06 September 2005
5.12 Sorting Local Variables
Optimization
Sort local variables according to their type sizes, allocating those with larger type sizes ahead of those
with smaller type sizes.
Application
This optimization applies to:
32-bit software
64-bit software
Rationale
If the first variable is allocated for natural alignment, all other variables are allocated contiguously in
the order they are declared and are naturally aligned without any padding.
Example
Consider the following declarations in a C function:
short ga, gu, gi;
long foo, bar;
double x, y, z[3];
char a, b;
float baz;
Instead of allocating the variables in the order in which they are declared, allocate them from lower to
higher addresses in the following order:
x, y, z[2], z[1], z[0], foo, bar, baz, ga, gu, gi, a, b
Related Information
For information on sorting local variables at the C-source level, see “Sorting Local Variables” on
page 41.