Hi,

i have to write a poly2d function that runs fast.

The following that i have is not fast, it is 7.06 ACPE, i know that Horner’s

rule would make it much faster but i don't know how to modify what i have

according to that. Please help me in optimizing my code. It has to be <3.00 ACPE

Code:`/* Data structures defined in another file */`

extern val_t C[M][N];

extern val_t *x_p;

extern val_t *y_p;

val_t poly2d_precomp(val_t C[M][N]) {

int i, j;

val_t sol = 0.0;

val_t xpwr = 1.0;

val_t ypwr[N];

val_t x = *x_p;

val_t y = *y_p;

ypwr[0] = 1.0;

for (j = 1; j < N; j++) {

ypwr[j] = ypwr[j-1]*y;

}

for (i = 0; i < M; i++) {

for (j = 0; j < N; j++) {

sol += C[i][j] * (xpwr * ypwr[j]);

}

xpwr *= x;

}

return sol;

}