home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / VDLib / h / fft_sse.inl < prev   
Encoding:
Text File  |  2009-09-14  |  10.0 KB  |  394 lines

  1. void __declspec(naked) VDComputeComplexFFT_DIT_radix4_iter0_SSE(float *p, unsigned bits) {
  2.     static const __declspec(align(16)) uint32 kNegate[4]={0,0,0x80000000,0x80000000};
  3.     static const __declspec(align(16)) uint32 kRotate[4]={0,0,0,0x80000000};
  4.  
  5.     __asm {
  6.         mov        eax, 8
  7.         mov        cl, [esp+8]
  8.         shl        eax, cl
  9.         mov        ecx, [esp+4]
  10.         movaps    xmm7, kNegate
  11.         movaps    xmm6, kRotate
  12. xloop:
  13.         movaps    xmm1, [ecx+16]            ;xmm1 =  x3 | x1
  14.         movaps    xmm0, [ecx]                ;xmm0 =  x2 | x0
  15.         movaps    xmm3, xmm1                ;xmm3 =  x3 | x1
  16.         movaps    xmm2, xmm0                ;xmm2 =  x2 | x0
  17.         shufps    xmm1, xmm1, 01001110b    ;xmm1 =  x1 | x3
  18.         xorps    xmm3, kNegate            ;xmm3 = -x3 | x1
  19.         shufps    xmm0, xmm0, 01001110b    ;xmm0 =  x0 | x2
  20.         xorps    xmm2, kNegate                ;xmm2 = -x2 | x0
  21.         addps    xmm1, xmm3                ;xmm1 = x1-x3 | x1+x3 = y3 | y1
  22.         addps    xmm0, xmm2                ;xmm0 = x0-x2 | x0+x2 = y2 | y0
  23.         shufps    xmm1, xmm1, 10110100b    ;xmm1 = y3i,y3r | y1
  24.         movaps    xmm2, xmm0
  25.         xorps    xmm1, kRotate                ;xmm1 = y3*-j | y1
  26.         addps    xmm0, xmm1
  27.         movaps    [ecx], xmm0
  28.         subps    xmm2, xmm1
  29.         movaps    [ecx+16], xmm2
  30.         add        ecx, 32
  31.         sub        eax, 32
  32.         jnz        xloop
  33.  
  34.         ret
  35.     }
  36. }
  37.  
  38. void __declspec(naked) VDComputeComplexFFT_DIT_radix4_table_SSE(float *p, unsigned bits, unsigned subbits, const float *table, int table_step) {
  39.     static const __declspec(align(16)) uint32 kTwiddleInverts[4]={0x80000000,0,0x80000000,0};
  40.     static const __declspec(align(16)) uint32 kRotationInvert[4]={0,0,0,0x80000000};
  41.     static const __declspec(align(16)) float kIdentity[4]={1,0,1,0};
  42.     __asm {
  43.         push    ebp
  44.         mov        ebp, esp
  45.         push    edi
  46.         push    esi
  47.         push    ebx
  48.  
  49. #define p_p            [ebp+8]
  50. #define p_bits        [ebp+12]
  51. #define p_subbits    [ebp+16]
  52. #define p_table        [ebp+20]
  53. #define p_tablestep    [ebp+24]
  54.  
  55. #define l_twiddle0    [esp]
  56. #define l_twiddle1    [esp+16]
  57. #define l_twiddle2    [esp+32]
  58. #define l_twiddle3    [esp+48]
  59. #define l_Mh        [esp+64]
  60. #define l_Np        [esp+68]
  61. #define l_limit        [esp+72]
  62. #define l_p            [esp+76]
  63. #define l_tablestep    [esp+80]
  64. #define l_ebpsav    [esp+84]
  65.  
  66.         sub        esp, 88
  67.         and        esp, -16
  68.  
  69.         mov        l_ebpsav, ebp
  70.  
  71.         mov        edi, p_table        ;edi = table
  72.  
  73.         mov        eax, p_tablestep
  74.         shl        eax, 2
  75.         mov        l_tablestep, eax    ;table_step *= sizeof(float)
  76.  
  77.         mov        cl, p_bits
  78.         mov        eax, 8
  79.         shl        eax, cl                ;Np * sizeof(float)
  80.         mov        l_Np, eax
  81.  
  82.         mov        cl, p_subbits
  83.         mov        eax, 4
  84.         shl        eax, cl                ;eax = 4 << subbits = Mh*sizeof(float)
  85.         mov        l_Mh, eax
  86.         mov        ebx, p_p
  87.         add        eax, ebx        ;eax = p + (1 << subbits)
  88.         mov        l_limit, eax        ;store limit
  89.         mov        l_p, ebx
  90.  
  91.         movaps    xmm7, kRotationInvert
  92.         mov        eax, l_p            ;eax = p
  93.         mov        ebp, l_Mh            ;ebp = 4<<subbits = Mh*sizeof(float)
  94.         lea        ebx, [eax+ebp]        ;ebx = eax + Mh
  95.         lea        ecx, [ebx+ebp]        ;ecx = ebx + Mh
  96.         lea        edx, [ecx+ebp]        ;edx = ecx + Mh
  97.         jmp        short yloop
  98.         align    16
  99. yloop:
  100.         ;load twiddle factors and bump table pointer
  101.         movaps    xmm4, kIdentity            ;2; xmm4 =  ?  |  ?  |  0  |  1
  102.         movhps    xmm4, [edi]                ;1; xmm4 = ss1 | sc1 |  0  |  1
  103.         movlps    xmm5, [edi+8]            ;1; xmm5 =  ?  |  ?  | ss2 | sc2
  104.  
  105.         movaps    xmm6, kTwiddleInverts    ;2
  106.         movhps    xmm5, [edi+16]            ;1; xmm5 = ss3 | sc3 | ss2 | sc2
  107.         movaps    xmm2, xmm4                ;1
  108.  
  109.         shufps    xmm4, xmm4, 11110101b    ;3; xmm4 = ss1 | ss1 |  0  |  0
  110.         movlps    xmm0, [eax]                ;1; xmm0 =  ? |  ? | i0 | r0
  111.         add        edi, l_tablestep        ;1
  112.  
  113.         shufps    xmm2, xmm2, 10100000b    ;3; xmm2 = sc1 | sc1 |  1  |  1
  114.         movhps    xmm0, [ecx]                ;1; xmm0 = i1 | r1 | i0 | r0
  115.         movlps    xmm1, [ebx]                ;1; xmm1 =  ? |  ? | i2 | r2
  116.  
  117.         movaps    xmm3, xmm5                ;2
  118.         movhps    xmm1, [edx]                ;1; xmm1 = i3 | r3 | i2 | r2
  119.         add        ebx, 8                    ;1
  120.  
  121.         xorps    xmm4, xmm6                ;2; xmm4 = ss1 |-ss1 |  0  |  0
  122.         add        ecx, 8                    ;1
  123.         add        edx, 8                    ;1
  124.  
  125.         shufps    xmm5, xmm5, 11110101b    ;3; xmm5 = ss3 | ss3 | ss2 | ss2
  126.         add        eax, 8                    ;1
  127.  
  128.         xorps    xmm5, xmm6                ;2; xmm5 = ss3 |-ss3 | ss2 |-ss2
  129.  
  130.         shufps    xmm3, xmm3, 10100000b    ;3; xmm3 = sc3 | sc3 | sc2 | sc2
  131.  
  132.         movaps    l_twiddle0, xmm2        ;2
  133.         movaps    l_twiddle1, xmm3        ;2
  134.  
  135.  
  136.         ;perform twiddles
  137.         movaps    xmm2, xmm0                ;2; xmm2 = i1 | r1 | i0 | r0
  138.         mulps    xmm0, xmm4                ;2; xmm0 =  i1*ss1 | r1*ss1 |  0     |  0
  139.         movaps    xmm3, xmm1                ;2; xmm3 = i3 | r3 | i2 | r2
  140.         mulps    xmm1, xmm5                ;2; xmm1 =  i3*ss3 |-r3*ss3 | i2*ss2 |-r2*ss2
  141.         shufps    xmm1, xmm1, 10110001b    ;3; xmm1 = -r3*ss3 | i3*ss3 |-r2*ss2 | i2*ss2
  142.         mulps    xmm2, l_twiddle0        ;4; xmm2 =  i1*sc1 | r1*sc1 | i0     | r0
  143.         shufps    xmm0, xmm0, 10110001b    ;3; xmm0 = -r1*ss1 | i1*ss1 |  0     |  0     
  144.         addps    xmm0, xmm2                ;2; xmm0 = i1s | r1s | i0  | r0
  145.         mulps    xmm3, l_twiddle1        ;4; xmm3 =  i3*sc3 | r3*sc3 | i2*sc2 | r2*sc2
  146.         addps    xmm1, xmm3                ;2; xmm1 = i3s | r3s | i2s | r2s
  147.  
  148.         ;first set of butterflies (0/2, 1/3)
  149.         movaps    xmm2, xmm0                ;2
  150.         addps    xmm0, xmm1                ;2; xmm0 = i1b | r1b | i0b | r0b
  151.         subps    xmm2, xmm1                ;2; xmm2 = i3b | r3b | i2b | r2b
  152.  
  153.         ;imaginary rotation
  154.         movaps    xmm3, xmm0                ;2; xmm3 = i1b | r1b | i0b | r0b
  155.         movlhps    xmm0, xmm2                ;2; xmm0 = i2b | r2b | i0b | r0b
  156.         shufps    xmm3, xmm2, 10111110b    ;2; xmm3 = r3b | i3b | i1b | r1b
  157.         xorps    xmm3, xmm7                ;2; xmm3 =-r3b | i3b | i1b | r1b
  158.  
  159.  
  160.         ;second set of butterflies
  161.         ;write out one output for each FFT
  162.         movaps    xmm2, xmm0                ;2; xmm2 = i2b | r2b | i0b | r0b
  163.         cmp        eax, l_limit            ;1; covered all bins in each FFT?
  164.  
  165.         addps    xmm0, xmm3                ;2; xmm0 = i2b-r3b | r2b+i3b | i0b+i1b | r0b+r1b
  166.         movlps    [eax-8], xmm0            ;1
  167.         movhps    [ebx-8], xmm0            ;1
  168.  
  169.         subps    xmm2, xmm3                ;2; xmm2 = i2b+r3b | r2b-i3b | i0b-i1b | r0b-r1b
  170.         movlps    [ecx-8], xmm2            ;1
  171.         movhps    [edx-8], xmm2            ;1
  172.  
  173.         jnz        yloop                    ;1
  174.  
  175.         mov        eax, l_ebpsav
  176.         lea        esp, [eax-12]
  177.         pop        ebx
  178.         pop        esi
  179.         pop        edi
  180.         pop        ebp
  181.         ret
  182. #undef p_p
  183. #undef p_bits
  184. #undef p_subbits
  185. #undef p_table
  186. #undef p_tablestep
  187.  
  188. #undef l_twiddle0
  189. #undef l_twiddle1
  190. #undef l_twiddle2
  191. #undef l_twiddle3
  192. #undef l_Mh
  193. #undef l_Np
  194. #undef l_limit
  195. #undef l_p
  196. #undef l_tablestep
  197. #undef l_ebpsav
  198.     }
  199. }
  200.  
  201. void __declspec(naked) VDComputeComplexFFT_DIT_radix4_table2x_SSE(float *p, unsigned bits, unsigned subbits, const float *table, int table_step) {
  202.     static const __declspec(align(16)) uint32 kTwiddleInverts[4]={0x80000000,0,0x80000000,0};
  203.     static const __declspec(align(16)) uint32 kRotationInvert[4]={0,0x80000000,0,0x80000000};
  204.     static const __declspec(align(16)) float kIdentity[4]={1,0,1,0};
  205.  
  206.     __asm {
  207.         push    ebp
  208.         mov        ebp, esp
  209.         push    edi
  210.         push    esi
  211.         push    ebx
  212.  
  213. #define p_p            [ebp+8]
  214. #define p_bits        [ebp+12]
  215. #define p_subbits    [ebp+16]
  216. #define p_table        [ebp+20]
  217. #define p_tablestep    [ebp+24]
  218.  
  219. #define l_twiddle0    [esp]
  220. #define l_twiddle1    [esp+16]
  221. #define l_twiddle2    [esp+32]
  222. #define l_twiddle3    [esp+48]
  223. #define l_twiddle4    [esp+64]
  224. #define l_twiddle5    [esp+80]
  225. #define l_Mh        [esp+96]
  226. #define l_Np        [esp+100]
  227. #define l_limit        [esp+104]
  228. #define l_p            [esp+108]
  229. #define l_tablestep    [esp+112]
  230. #define l_ebpsav    [esp+116]
  231.  
  232.         sub        esp, 120
  233.         and        esp, -16
  234.  
  235.         mov        l_ebpsav, ebp
  236.  
  237.         mov        edi, p_table        ;edi = table
  238.  
  239.         mov        eax, p_tablestep
  240.         shl        eax, 2
  241.         mov        l_tablestep, eax    ;table_step *= sizeof(float)
  242.  
  243.         mov        cl, p_bits
  244.         mov        eax, 8
  245.         shl        eax, cl                ;Np * sizeof(float)
  246.         mov        l_Np, eax
  247.  
  248.         mov        cl, p_subbits
  249.         mov        eax, 4
  250.         shl        eax, cl                ;eax = 4 << subbits = Mh*sizeof(float)
  251.         mov        l_Mh, eax
  252.         mov        ebx, p_p
  253.         add        eax, ebx        ;eax = p + (1 << subbits)
  254.         mov        l_limit, eax        ;store limit
  255.         mov        l_p, ebx
  256.  
  257.         movaps    xmm7, kRotationInvert
  258.         mov        eax, l_p            ;eax = p
  259. yloop:
  260.         mov        ebp, l_Mh            ;ebp = 4<<subbits = Mh*sizeof(float)
  261.  
  262.         lea        ebx, [eax+ebp]        ;ebx = eax + Mh
  263.         lea        ecx, [ebx+ebp]        ;ecx = ebx + Mh
  264.         lea        edx, [ecx+ebp]        ;edx = ecx + Mh
  265.  
  266.         shl        ebp, 2                ;ebp = Mp*sizeof(float)
  267.         mov        esi, l_Np            ;esi = Np*sizeof(float)
  268.  
  269.         ;load twiddle factors and bump table pointer
  270.         movaps    xmm6, kTwiddleInverts
  271.  
  272.         movlps    xmm0, [edi]
  273.         movlps    xmm1, [edi+8]
  274.         movlps    xmm2, [edi+16]
  275.         add        edi, l_tablestep
  276.  
  277.         movhps    xmm0, [edi]
  278.         movhps    xmm1, [edi+8]
  279.         movhps    xmm2, [edi+16]
  280.         add        edi, l_tablestep
  281.  
  282.         movaps    xmm3, xmm0
  283.         shufps    xmm0, xmm0, 10100000b
  284.         shufps    xmm3, xmm3, 11110101b
  285.         movaps    l_twiddle0, xmm0
  286.         xorps    xmm3, xmm6
  287.         movaps    l_twiddle1, xmm3
  288.  
  289.         movaps    xmm4, xmm1
  290.         shufps    xmm1, xmm1, 10100000b
  291.         shufps    xmm4, xmm4, 11110101b
  292.         movaps    l_twiddle2, xmm1
  293.         xorps    xmm4, xmm6
  294.         movaps    l_twiddle3, xmm4
  295.  
  296.         movaps    xmm5, xmm2
  297.         shufps    xmm2, xmm2, 10100000b
  298.         shufps    xmm5, xmm5, 11110101b
  299.         movaps    l_twiddle4, xmm2
  300.         xorps    xmm5, xmm6
  301.         movaps    l_twiddle5, xmm5
  302.  
  303. xloop:
  304.         movaps    xmm0, [eax]                ;xmm0 = p0
  305.         movaps    xmm1, [ecx]                ;xmm1 = p2
  306.         movaps    xmm2, [ebx]                ;xmm2 = p1
  307.         movaps    xmm3, [edx]                ;xmm3 = p3
  308.  
  309.         ;perform twiddles
  310.  
  311.         movaps    xmm4, xmm1
  312.         movaps    xmm5, xmm2
  313.         movaps    xmm6, xmm3
  314.         mulps    xmm1, l_twiddle0
  315.         mulps    xmm4, l_twiddle1
  316.         shufps    xmm4, xmm4, 10110001b
  317.         mulps    xmm2, l_twiddle2
  318.         mulps    xmm5, l_twiddle3
  319.         shufps    xmm5, xmm5, 10110001b
  320.         mulps    xmm3, l_twiddle4
  321.         mulps    xmm6, l_twiddle5
  322.         shufps    xmm6, xmm6, 10110001b
  323.         addps    xmm1, xmm4
  324.         addps    xmm2, xmm5
  325.         addps    xmm3, xmm6
  326.  
  327.         ;first set of butterflies (0/2, 1/3)
  328.         movaps    xmm4, xmm0
  329.         addps    xmm0, xmm2
  330.         subps    xmm4, xmm2
  331.         movaps    xmm5, xmm1
  332.         addps    xmm1, xmm3
  333.         subps    xmm5, xmm3
  334.  
  335.         ;imaginary rotation
  336.         ;p0-p3: xmm0, xmm1, xmm4, xmm5
  337.         shufps    xmm5, xmm5, 10110001b
  338.         xorps    xmm5, xmm7
  339.  
  340.         ;second set of butterflies
  341.         ;x0-x3: xmm0, xmm1, xmm4, xmm5
  342.         movaps    xmm2, xmm0
  343.         addps    xmm0, xmm1
  344.         subps    xmm2, xmm1
  345.         movaps    [eax], xmm0
  346.         movaps    [ecx], xmm2
  347.         add        eax, ebp                ;p0 += Mp
  348.         add        ecx, ebp                ;p2 += Mp
  349.  
  350.         movaps    xmm3, xmm4
  351.         addps    xmm4, xmm5
  352.         subps    xmm3, xmm5
  353.         movaps    [ebx], xmm4
  354.         add        ebx, ebp                ;p1 += Mp
  355.         movaps    [edx], xmm3
  356.         add        edx, ebp                ;p3 += Mp
  357.  
  358.         sub        esi, ebp                ;i += Mp
  359.         jnz        xloop
  360.  
  361.         mov        eax, l_p
  362.         add        eax, 16                    ;4*sizeof(float)
  363.         cmp        eax, l_limit            ;covered all bins in each FFT?
  364.         mov        l_p, eax
  365.         jnz        yloop
  366.  
  367.         mov        eax, l_ebpsav
  368.         lea        esp, [eax-12]
  369.         pop        ebx
  370.         pop        esi
  371.         pop        edi
  372.         pop        ebp
  373.         ret
  374. #undef p_p
  375. #undef p_bits
  376. #undef p_subbits
  377. #undef p_table
  378. #undef p_tablestep
  379.  
  380. #undef l_twiddle0
  381. #undef l_twiddle1
  382. #undef l_twiddle2
  383. #undef l_twiddle3
  384. #undef l_twiddle4
  385. #undef l_twiddle5
  386. #undef l_Mh
  387. #undef l_Np
  388. #undef l_limit
  389. #undef l_p
  390. #undef l_tablestep
  391. #undef l_ebpsav
  392.     }
  393. }
  394.