AMD Athlon Processor x86 Optimization Manual page 32

X86 code optimization
Table of Contents

Advertisement

AMD Athlon™ Processor x86 Code Optimization
16
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;
dp
= vv->x * *m++;
dp += vv->y * *m++;
dp += vv->z * *m++;
dp += vv->w * *m++;
*res++ = dp;
dp
= vv->x * *m++;
dp += vv->y * *m++;
dp += vv->z * *m++;
dp += vv->w * *m++;
/* write transformed x */
/* write transformed y */
Use Array Style Instead of Pointer Style Code
22007E/0—November 1999

Advertisement

Table of Contents
loading

Table of Contents