Hi, ppl.

I want to optimize the wave function in the main code. I tried SSE instructions but the code become slower. I'm compiling using gcc -O3 -march=i686 -mcpu=i686 -malign-double -funroll-loops -fomit-frame-pointer -o float_conv float_conv.c -lm

Can anybody help me?

Thanx.


#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <sys/time.h>

float points[] = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1};

float y[] = {3, 3.38382, 3.14269, 2.47603, 1.59766, 0.698843, -0.0755374, -0.637482, -0.954788, -1.04158, -0.944139};

float xx[4] = {1.02938, 7.39821, 5.98217, 3.8127};

float vt;

int main(void){
struct timeval ts,te;
int i,j,k = 500000;
int nx=11;

float somaN = 0;
float val;

printf("Calculation...\n");

gettimeofday(&ts,NULL);

for (j = 0; j < k; j++)
{
for (i=0;i<=nx;i++)
{
//WAVE FUNCTION
val = exp(-xx[2]*points[i]/2.0)*(xx[0]*cos(xx[3]*points[i])+ xx[1]*sin(xx[3]*points[i]));
somaN = somaN+(y[i]-val)*(y[i]-val);
}
val = sqrt(somaN)/(nx+1);
}
gettimeofday(&te,NULL);
printf("Time: %f\n",(double)(te.tv_sec-ts.tv_sec)+0.000001*(double)(te.tv_usec-ts.tv_usec));

return 0;
}