#include #include #include #include #define N 128 #define N2 N/2 main() { /* SSE version of cfft2 - uses Apple intrinsics W. Petersen, SAM. Math. ETHZ 2 May, 2002 */ int first,i,icase,it,n; int nits=1000; /* number of iterations for timing test */ float error,fnm1,sign,z0,z1,ggl(); static float seed = 331.0; float *x,*y,*z,*w; float t1,ln2,mflops; void cffti(),cfft2(); /* allocate storage for x,y,z,w on 4-word bndr. */ x = (float *)malloc(8*N); y = (float *)malloc(8*N); z = (float *)malloc(8*N); w = (float *)malloc(4*N); first = 1; for(icase=0;icase<2;icase++){ if(first){ for(i=0;i<2*N;i+=2){ z0 = ggl(&seed); /* real part of array */ z1 = ggl(&seed); /* imaginary part of array */ x[i] = z0; z[i] = z0; /* copy of initial real data */ x[i+1] = z1; z[i+1] = z1; /* copy of initial imag. data */ } } else { for(i=0;i<2*N;i+=2){ z0 = 0; /* real part of array */ z1 = 0; /* imaginary part of array */ x[i] = z0; z[i] = z0; /* copy of initial real data */ x[i+1] = z1; z[i+1] = z1; /* copy of initial imag. data */ } } /* initialize sine/cosine tables */ n = N; cffti(n,w); /* transform forward, back */ if(first){ sign = 1.0; cfft2(n,x,y,w,sign); sign = -1.0; cfft2(n,y,x,w,sign); /* results should be same as initial multiplied by N */ fnm1 = 1.0/((float) n); error = 0.0; for(i=0;i<2*N;i+=2){ error += (z[i] - fnm1*x[i])*(z[i] - fnm1*x[i]) + (z[i+1] - fnm1*x[i+1])*(z[i+1] - fnm1*x[i+1]); } error = sqrt(fnm1*error); printf(" for n=%d, fwd/bck error=%e\n",N,error); first = 0; } else { t1 = ((float)clock())/((float) CLOCKS_PER_SEC); for(it=0;it=2 case */ wr[0] = rp; wr[1] = rp; wr[2] = rp; wr[3] = rp; wu[0] = up; wu[1] = up; wu[2] = up; wu[3] = up; v6 = vec_ld(0,wr); v7 = vec_ld(0,wu); v7 = vec_xor(v7,vminus); for(k=0; k float ggl(float *ds) { /* generate u(0,1) distributed random numbers. Seed ds must be saved between calls. ggl is essentially the same as the IMSL routine RNUM. W. Petersen and M. Troyer, 24 Oct. 2002, ETHZ: a modification of a fortran version from I. Vattulainen, Tampere Univ. of Technology, Finland, 1992 */ double t,d2=0.2147483647e10; t = (float) *ds; t = fmod(0.16807e5*t,d2); *ds = (float) t; return((float) ((t-1.0e0)/(d2-1.0e0))); }