README.simd 2.4 KB

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