25112 Rev. 3.06 September 2005

Software Optimization Guide for AMD64 Processors

Example

Avoid code, such as the following, which uses pointer notation:

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++;

*res++ = dp; // Write transformed z.

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

*res++ = dp; // Write transformed w.

++vv;

//

Next input vertex

 

m -= 16;

//

Reset to start of

transform matrix.

}

}

Chapter 2

C and C++ Source-Level Optimizations

11

Page 27
Image 27
AMD 250 manual Example, Matrix