# 0.10 Appendix 3 - ffts with vectorized loops

This Appendix contains source code listings corresponding to the vectorized FFT implementations in Implementation details .

```#include <math.h>#include <complex.h>#include <stdio.h>#include <stdlib.h>#include <xmmintrin.h>  typedef complex float data_t;  #define W(N,k) (cexp(-2.0f * M_PI * I * (float)(k) / (float)(N)))  data_t **LUT;  void ditfft2(data_t *in, data_t *out, int log2stride, int stride, int N) {if(N == 2) { out[0]   = in[0] + in[stride]; out[N/2] = in[0] - in[stride]; }else if(N == 4){ditfft2(in, out, log2stride+1, stride << 1, N >> 1); ditfft2(in+stride, out+N/2, log2stride+1, stride << 1, N >> 1);    data_t temp0 = out[0] + out[2];     data_t temp1 = out[0] - out[2];    data_t temp2 = out[1] - I*out[3];     data_t temp3 = out[1] + I*out[3];    if(log2stride) { out[0] = creal(temp0) + creal(temp2)*I; out[1] = creal(temp1) + creal(temp3)*I; out[2] = cimag(temp0) + cimag(temp2)*I; out[3] = cimag(temp1) + cimag(temp3)*I; }else{out[0] = temp0;out[2] = temp1;out[1] = temp2;out[3] = temp3;} }else if(!log2stride){ditfft2(in, out, log2stride+1, stride << 1, N >> 1); ditfft2(in+stride, out+N/2, log2stride+1, stride << 1, N >> 1);  int k; for(k=0;k<N/2;k+=4) { __m128 Ok_re = _mm_load_ps((float *)&out[k+N/2]);__m128 Ok_im = _mm_load_ps((float *)&out[k+N/2+2]);__m128 w_re = _mm_load_ps((float *)&LUT[log2stride][k]); __m128 w_im = _mm_load_ps((float *)&LUT[log2stride][k+2]); __m128 Ek_re = _mm_load_ps((float *)&out[k]);__m128 Ek_im = _mm_load_ps((float *)&out[k+2]);__m128 wOk_re = _mm_sub_ps(_mm_mul_ps(Ok_re,w_re),_mm_mul_ps(Ok_im,w_im)); __m128 wOk_im = _mm_add_ps(_mm_mul_ps(Ok_re,w_im),_mm_mul_ps(Ok_im,w_re));__m128 out0_re = _mm_add_ps(Ek_re, wOk_re); __m128 out0_im = _mm_add_ps(Ek_im, wOk_im);__m128 out1_re = _mm_sub_ps(Ek_re, wOk_re); __m128 out1_im = _mm_sub_ps(Ek_im, wOk_im);_mm_store_ps((float *)(out+k), _mm_unpacklo_ps(out0_re, out0_im)); _mm_store_ps((float *)(out+k+2), _mm_unpackhi_ps(out0_re, out0_im));_mm_store_ps((float *)(out+k+N/2), _mm_unpacklo_ps(out1_re, out1_im)); _mm_store_ps((float *)(out+k+N/2+2), _mm_unpackhi_ps(out1_re, out1_im));} }else{ditfft2(in, out, log2stride+1, stride << 1, N >> 1); ditfft2(in+stride, out+N/2, log2stride+1, stride << 1, N >> 1);int k; for(k=0;k<N/2;k+=4) { __m128 Ok_re = _mm_load_ps((float *)&out[k+N/2]);__m128 Ok_im = _mm_load_ps((float *)&out[k+N/2+2]);__m128 w_re = _mm_load_ps((float *)&LUT[log2stride][k]); __m128 w_im = _mm_load_ps((float *)&LUT[log2stride][k+2]); __m128 Ek_re = _mm_load_ps((float *)&out[k]);__m128 Ek_im = _mm_load_ps((float *)&out[k+2]);__m128 wOk_re = _mm_sub_ps(_mm_mul_ps(Ok_re,w_re),_mm_mul_ps(Ok_im,w_im)); __m128 wOk_im = _mm_add_ps(_mm_mul_ps(Ok_re,w_im),_mm_mul_ps(Ok_im,w_re));_mm_store_ps((float *)(out+k), _mm_add_ps(Ek_re, wOk_re)); _mm_store_ps((float *)(out+k+2), _mm_add_ps(Ek_im, wOk_im));_mm_store_ps((float *)(out+k+N/2), _mm_sub_ps(Ek_re, wOk_re)); _mm_store_ps((float *)(out+k+N/2+2), _mm_sub_ps(Ek_im, wOk_im));} }}  void fft_init(int N) { int i;#define log2(x) ((int)(log(x)/log(2)))int n_luts = log2(N)-2;LUT = malloc(n_luts * sizeof(data_t *)); for(i=0;i<n_luts;i++) { int n = N / pow(2,i);LUT[i] = _mm_malloc(n/2 * sizeof(data_t), 16);int j; for(j=0;j<n/2;j+=4) { data_t w[4]; int k;for(k=0;k<4;k++) w[k] = W(n,j+k);  LUT[i][j]   = creal(w[0]) + creal(w[1])*I;LUT[i][j+1] = creal(w[2]) + creal(w[3])*I; LUT[i][j+2] = cimag(w[0]) + cimag(w[1])*I;LUT[i][j+3] = cimag(w[2]) + cimag(w[3])*I; }}} Radix-2 FFT with vectorized loops ```

how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
Do somebody tell me a best nano engineering book for beginners?
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
what is the Synthesis, properties,and applications of carbon nano chemistry
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
so some one know about replacing silicon atom with phosphorous in semiconductors device?
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
for screen printed electrodes ?
SUYASH
What is lattice structure?
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
what's the easiest and fastest way to the synthesize AgNP?
China
Cied
types of nano material
I start with an easy one. carbon nanotubes woven into a long filament like a string
Porter
many many of nanotubes
Porter
what is the k.e before it land
Yasmin
what is the function of carbon nanotubes?
Cesar
I'm interested in nanotube
Uday
what is nanomaterials​ and their applications of sensors.
what is nano technology
what is system testing?
preparation of nanomaterial
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
what is system testing
what is the application of nanotechnology?
Stotaw
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
Azam
anybody can imagine what will be happen after 100 years from now in nano tech world
Prasenjit
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
Azam
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
Prasenjit
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
Damian
silver nanoparticles could handle the job?
Damian
not now but maybe in future only AgNP maybe any other nanomaterials
Azam
Hello
Uday
I'm interested in Nanotube
Uday
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
Prasenjit
can nanotechnology change the direction of the face of the world
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!