Data layout optimizations, Data layout optimizations -39, Example 2-17 – Intel ARCHITECTURE IA-32 User Manual

Page 111: An example of loop-carried dependence chain -39, Example 2-18, Rearranging a data structure -39

Advertising
background image

General Optimization Guidelines

2

2-39

An example of a loop-carried dependence chain is shown in
Example 2-17.

Data Layout Optimizations

User/Source Coding Rule 2. (H impact, M generality) Pad data structures
defined in the source code so that every data element is aligned to a natural
operand size address boundary.

If the operands are packed in a SIMD instruction, align to the packed
element size (64-bit or 128-bit).

Align data by providing padding inside structures and arrays.
Programmers can reorganize structures and arrays to minimize the
amount of memory wasted by padding. However, compilers might not
have this freedom. The C programming language, for example, specifies
the order in which structure elements are allocated in memory. Section
“Stack and Data Alignment” of Chapter 3, and Appendix D, “Stack
Alignment”, further defines the
exact storage layout.

Example 2-18 shows how a data structure could be rearranged to reduce
its size.

Example 2-17 An Example of Loop-carried Dependence Chain

for (i=0; i<MAX; i++) {

a[i] = b[i] * foo;

foo = a[i]/3;

}

// foo is a loop-carried dependence

Example 2-18 Rearranging a Data Structure

struct unpacked { /* fits in 20 bytes due to padding */

int

a;

char

b;

int

c;

char

d;

int

e;

}

struct packed { /* fits in 16 bytes */

Advertising