ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
[libav.git] / libavcodec / i386 / fft_3dn.c
CommitLineData
82eb4b0f
ZM
1/*
2 * FFT/MDCT transform with 3DNow! optimizations
1e4ecf26 3 * Copyright (c) 2006 Zuxy MENG Jie, Loren Merritt
82eb4b0f
ZM
4 * Based on fft_sse.c copyright (c) 2002 Fabrice Bellard.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include "../dsputil.h"
82eb4b0f
ZM
21
22static const int p1m1[2] __attribute__((aligned(8))) =
23 { 0, 1 << 31 };
24
25static const int m1p1[2] __attribute__((aligned(8))) =
26 { 1 << 31, 0 };
27
28void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z)
29{
30 int ln = s->nbits;
1e4ecf26
LM
31 long i, j;
32 long nblocks, nloops;
33 FFTComplex *p, *cptr;
34
35 asm volatile(
36 /* FEMMS is not a must here but recommended by AMD */
37 "femms \n\t"
38 "movq %0, %%mm7 \n\t"
39 ::"m"(*(s->inverse ? m1p1 : p1m1))
40 );
41
42 i = 8 << ln;
43 asm volatile(
44 "1: \n\t"
45 "sub $32, %0 \n\t"
46 "movq (%0,%1), %%mm0 \n\t"
47 "movq 16(%0,%1), %%mm1 \n\t"
48 "movq 8(%0,%1), %%mm2 \n\t"
49 "movq 24(%0,%1), %%mm3 \n\t"
50 "movq %%mm0, %%mm4 \n\t"
51 "movq %%mm1, %%mm5 \n\t"
52 "pfadd %%mm2, %%mm0 \n\t"
53 "pfadd %%mm3, %%mm1 \n\t"
54 "pfsub %%mm2, %%mm4 \n\t"
55 "pfsub %%mm3, %%mm5 \n\t"
56 "movq %%mm0, %%mm2 \n\t"
57 "punpckldq %%mm5, %%mm6 \n\t"
58 "punpckhdq %%mm6, %%mm5 \n\t"
59 "movq %%mm4, %%mm3 \n\t"
60 "pxor %%mm7, %%mm5 \n\t"
61 "pfadd %%mm1, %%mm0 \n\t"
62 "pfadd %%mm5, %%mm4 \n\t"
63 "pfsub %%mm1, %%mm2 \n\t"
64 "pfsub %%mm5, %%mm3 \n\t"
65 "movq %%mm0, (%0,%1) \n\t"
66 "movq %%mm4, 8(%0,%1) \n\t"
67 "movq %%mm2, 16(%0,%1) \n\t"
68 "movq %%mm3, 24(%0,%1) \n\t"
69 "jg 1b \n\t"
70 :"+r"(i)
71 :"r"(z)
72 );
82eb4b0f
ZM
73 /* pass 2 .. ln-1 */
74
1e4ecf26 75 nblocks = 1 << (ln-3);
82eb4b0f 76 nloops = 1 << 2;
1e4ecf26 77 cptr = s->exptab1;
82eb4b0f
ZM
78 do {
79 p = z;
82eb4b0f
ZM
80 j = nblocks;
81 do {
1e4ecf26
LM
82 i = nloops*8;
83 asm volatile(
84 "1: \n\t"
85 "sub $16, %0 \n\t"
86 "movq (%1,%0), %%mm0 \n\t"
87 "movq 8(%1,%0), %%mm1 \n\t"
88 "movq (%2,%0), %%mm2 \n\t"
89 "movq 8(%2,%0), %%mm3 \n\t"
90 "movq %%mm2, %%mm4 \n\t"
91 "movq %%mm3, %%mm5 \n\t"
92 "punpckldq %%mm2, %%mm2 \n\t"
93 "punpckldq %%mm3, %%mm3 \n\t"
94 "punpckhdq %%mm4, %%mm4 \n\t"
95 "punpckhdq %%mm5, %%mm5 \n\t"
96 "pfmul (%3,%0,2), %%mm2 \n\t" // cre*re cim*re
97 "pfmul 8(%3,%0,2), %%mm3 \n\t"
98 "pfmul 16(%3,%0,2), %%mm4 \n\t" // -cim*im cre*im
99 "pfmul 24(%3,%0,2), %%mm5 \n\t"
100 "pfadd %%mm2, %%mm4 \n\t" // cre*re-cim*im cim*re+cre*im
101 "pfadd %%mm3, %%mm5 \n\t"
102 "movq %%mm0, %%mm2 \n\t"
103 "movq %%mm1, %%mm3 \n\t"
104 "pfadd %%mm4, %%mm0 \n\t"
105 "pfadd %%mm5, %%mm1 \n\t"
106 "pfsub %%mm4, %%mm2 \n\t"
107 "pfsub %%mm5, %%mm3 \n\t"
108 "movq %%mm0, (%1,%0) \n\t"
109 "movq %%mm1, 8(%1,%0) \n\t"
110 "movq %%mm2, (%2,%0) \n\t"
111 "movq %%mm3, 8(%2,%0) \n\t"
112 "jg 1b \n\t"
113 :"+r"(i)
114 :"r"(p), "r"(p + nloops), "r"(cptr)
115 );
116 p += nloops*2;
82eb4b0f 117 } while (--j);
1e4ecf26
LM
118 cptr += nloops*2;
119 nblocks >>= 1;
120 nloops <<= 1;
82eb4b0f 121 } while (nblocks != 0);
1e4ecf26 122 asm volatile("femms");
82eb4b0f 123}