AMD x86 manual Avoid Unnecessary Store-to-Load Dependencies

Models: x86

1 256
Download 256 pages 58.62 Kb
Page 35
Image 35

22007E/0 — November 1999

AMD Athlon™ Processor x86 Code Optimization

code in a way that avoids the store-to-load dependency. In some instances the language definition may prohibit the compiler from using code transformations that would remove the store- to-load dependency. It is therefore recommended that the programmer remove the dependency manually, e.g., by introducing a temporary variable that can be kept in a register. This can result in a significant performance increase. The following is an example of this.

Example 1 (Avoid):

double x[VECLEN], y[VECLEN], z[VECLEN]; unsigned int k;

for (k = 1; k < VECLEN; k++) { x[k] = x[k-1] + y[k];

}

for (k = 1; k < VECLEN; k++) { x[k] = z[k] * (y[k] - x[k-1]);

}

Example 2 (Preferred):

double x[VECLEN], y[VECLEN], z[VECLEN]; unsigned int k;

double t;

t = x[0];

for (k = 1; k < VECLEN; k++) { t = t + y[k];

x[k] = t;

}

t = x[0];

for (k = 1; k < VECLEN; k++) { t = z[k] * (y[k] - t); x[k] = t;

}

Avoid Unnecessary Store-to-Load Dependencies

19

Page 35
Image 35
AMD x86 manual Avoid Unnecessary Store-to-Load Dependencies