AMD Athlon™ Processor x86 Code Optimization

22007E/0 — November 1999

Note that source code transformations will interact with a compiler’s code generator and that it is difficult to control the generated machine code from the source level. It is even possible that source code transformations for improving performance and compiler optimizations "fight" each other. Depending on the compiler and the specific source code it is therefore possible that pointer style code will be compiled into machine code that is faster than that generated from equivalent array style code. It is advisable to check the performance after any source code transformation to see whether performance indeed increased.

Example 1 (Avoid):

typedef struct { float x,y,z,w;

} VERTEX;

typedef struct { float m[4][4];

} MATRIX;

void XForm (float *res, const float *v, const float *m, int numverts)

{

float dp; int i;

const VERTEX* vv = (VERTEX *)v;

for (i = 0; i < numverts; i++) { dp = vv->x * *m++;

dp += vv->y * *m++; dp += vv->z * *m++; dp += vv->w * *m++;

*res++ = dp; /* write transformed x */

dp = vv->x * *m++; dp += vv->y * *m++; dp += vv->z * *m++; dp += vv->w * *m++;

*res++ = dp; /* write transformed y */

dp = vv->x * *m++; dp += vv->y * *m++; dp += vv->z * *m++; dp += vv->w * *m++;

16

Use Array Style Instead of Pointer Style Code

Page 32
Image 32
AMD x86 manual Vertex