Example 6-2 – Intel ARCHITECTURE IA-32 User Manual

Page 311

Advertising
background image

Optimizing Cache Usage

6

6-21

Example 6-2

Populating an Array for Circular Pointer Chasing with
Constant Stride

register char ** p;

char

*next;

// Populating pArray for circular pointer

// chasing with constant access stride

//

p = (

char

**)*p; loads a value pointing to next load

p = (char **)&pArray;

for (i = 0; i < aperture; i += stride) {

p = (char **)&pArray[i];

if (i + stride >= g_array_aperture) {

next = &pArray[0 ];

} else {

next = &pArray[i + stride];

}

*p = next; // populate the address of the next node

}

Advertising