annotate ext/kissfft/README.simd @ 206:335be766a54d

Fix erroneous header guard
author Chris Cannam
date Fri, 30 Sep 2016 19:04:06 +0100
parents 76ec2365b250
children
rev   line source
Chris@184 1 If you are reading this, it means you think you may be interested in using the SIMD extensions in kissfft
Chris@184 2 to do 4 *separate* FFTs at once.
Chris@184 3
Chris@184 4 Beware! Beyond here there be dragons!
Chris@184 5
Chris@184 6 This API is not easy to use, is not well documented, and breaks the KISS principle.
Chris@184 7
Chris@184 8
Chris@184 9 Still reading? Okay, you may get rewarded for your patience with a considerable speedup
Chris@184 10 (2-3x) on intel x86 machines with SSE if you are willing to jump through some hoops.
Chris@184 11
Chris@184 12 The basic idea is to use the packed 4 float __m128 data type as a scalar element.
Chris@184 13 This means that the format is pretty convoluted. It performs 4 FFTs per fft call on signals A,B,C,D.
Chris@184 14
Chris@184 15 For complex data, the data is interlaced as follows:
Chris@184 16 rA0,rB0,rC0,rD0, iA0,iB0,iC0,iD0, rA1,rB1,rC1,rD1, iA1,iB1,iC1,iD1 ...
Chris@184 17 where "rA0" is the real part of the zeroth sample for signal A
Chris@184 18
Chris@184 19 Real-only data is laid out:
Chris@184 20 rA0,rB0,rC0,rD0, rA1,rB1,rC1,rD1, ...
Chris@184 21
Chris@184 22 Compile with gcc flags something like
Chris@184 23 -O3 -mpreferred-stack-boundary=4 -DUSE_SIMD=1 -msse
Chris@184 24
Chris@184 25 Be aware of SIMD alignment. This is the most likely cause of segfaults.
Chris@184 26 The code within kissfft uses scratch variables on the stack.
Chris@184 27 With SIMD, these must have addresses on 16 byte boundaries.
Chris@184 28 Search on "SIMD alignment" for more info.
Chris@184 29
Chris@184 30
Chris@184 31
Chris@184 32 Robin at Divide Concept was kind enough to share his code for formatting to/from the SIMD kissfft.
Chris@184 33 I have not run it -- use it at your own risk. It appears to do 4xN and Nx4 transpositions
Chris@184 34 (out of place).
Chris@184 35
Chris@184 36 void SSETools::pack128(float* target, float* source, unsigned long size128)
Chris@184 37 {
Chris@184 38 __m128* pDest = (__m128*)target;
Chris@184 39 __m128* pDestEnd = pDest+size128;
Chris@184 40 float* source0=source;
Chris@184 41 float* source1=source0+size128;
Chris@184 42 float* source2=source1+size128;
Chris@184 43 float* source3=source2+size128;
Chris@184 44
Chris@184 45 while(pDest<pDestEnd)
Chris@184 46 {
Chris@184 47 *pDest=_mm_set_ps(*source3,*source2,*source1,*source0);
Chris@184 48 source0++;
Chris@184 49 source1++;
Chris@184 50 source2++;
Chris@184 51 source3++;
Chris@184 52 pDest++;
Chris@184 53 }
Chris@184 54 }
Chris@184 55
Chris@184 56 void SSETools::unpack128(float* target, float* source, unsigned long size128)
Chris@184 57 {
Chris@184 58
Chris@184 59 float* pSrc = source;
Chris@184 60 float* pSrcEnd = pSrc+size128*4;
Chris@184 61 float* target0=target;
Chris@184 62 float* target1=target0+size128;
Chris@184 63 float* target2=target1+size128;
Chris@184 64 float* target3=target2+size128;
Chris@184 65
Chris@184 66 while(pSrc<pSrcEnd)
Chris@184 67 {
Chris@184 68 *target0=pSrc[0];
Chris@184 69 *target1=pSrc[1];
Chris@184 70 *target2=pSrc[2];
Chris@184 71 *target3=pSrc[3];
Chris@184 72 target0++;
Chris@184 73 target1++;
Chris@184 74 target2++;
Chris@184 75 target3++;
Chris@184 76 pSrc+=4;
Chris@184 77 }
Chris@184 78 }