annotate i386/fft_3dn2.c @ 3333:6bfe6c09d837 libavcodec

Fixed a possible bug, checked against the assembly. No sample that used the code has been found though.
author banan
date Fri, 02 Jun 2006 07:50:12 +0000
parents c20c181e0eca
children 5ea82888103e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3175
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
1 /*
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
2 * FFT/MDCT transform with Extended 3DNow! optimizations
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
3 * Copyright (c) 2006 Zuxy MENG Jie.
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
4 * Based on fft_sse.c copyright (c) 2002 Fabrice Bellard.
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
5 *
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
10 *
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
14 * Lesser General Public License for more details.
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
15 *
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
19 */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
20 #include "../dsputil.h"
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
21 #include <math.h>
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
22
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
23 #ifdef HAVE_MM3DNOW
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
24
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
25 #include <mm3dnow.h>
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
26
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
27 static const int p1m1[2] __attribute__((aligned(8))) =
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
28 { 0, 1 << 31 };
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
29
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
30 static const int m1p1[2] __attribute__((aligned(8))) =
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
31 { 1 << 31, 0 };
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
32
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
33 void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z)
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
34 {
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
35 int ln = s->nbits;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
36 int j, np, np2;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
37 int nblocks, nloops;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
38 register FFTComplex *p, *q;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
39 FFTComplex *cptr, *cptr1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
40 int k;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
41
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
42 np = 1 << ln;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
43 /* FEMMS is not a must here but recommended by AMD */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
44 _m_femms();
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
45
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
46 {
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
47 __m64 *r, a0, a1, b0, b1, c;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
48
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
49 r = (__m64 *)&z[0];
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
50 if (s->inverse)
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
51 c = *(__m64 *)m1p1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
52 else
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
53 c = *(__m64 *)p1m1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
54
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
55 j = (np >> 2);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
56 do {
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
57 /* do the pass 0 butterfly */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
58 a0 = _m_pfadd(r[0], r[1]);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
59 a1 = _m_pfsub(r[0], r[1]);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
60
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
61 /* do the pass 0 butterfly */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
62 b0 = _m_pfadd(r[2], r[3]);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
63 b1 = _m_pfsub(r[2], r[3]);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
64
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
65 /* multiply third by -i */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
66 b1 = _m_pswapd(b1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
67 b1 = _m_pxor(b1, c);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
68
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
69 r[0] = _m_pfadd(a0, b0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
70 r[1] = _m_pfadd(a1, b1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
71 r[2] = _m_pfsub(a0, b0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
72 r[3] = _m_pfsub(a1, b1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
73 r += 4;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
74 } while (--j != 0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
75 }
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
76 /* pass 2 .. ln-1 */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
77
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
78 nblocks = np >> 3;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
79 nloops = 1 << 2;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
80 np2 = np >> 1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
81
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
82 cptr1 = s->exptab1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
83 do {
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
84 p = z;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
85 q = z + nloops;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
86 j = nblocks;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
87 do {
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
88 cptr = cptr1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
89 k = nloops >> 1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
90 do {
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
91 __m64 a0, a1, b0, b1, c0, c1, t10, t11, t20, t21;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
92
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
93 a0 = *(__m64 *)&p[0];
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
94 a1 = *(__m64 *)&p[1];
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
95 b0 = *(__m64 *)&q[0];
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
96 b1 = *(__m64 *)&q[1];
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
97
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
98 /* complex mul */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
99 c0 = *(__m64 *)&cptr[0];
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
100 c1 = *(__m64 *)&cptr[1];
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
101 /* cre*re cim*im */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
102 t10 = _m_pfmul(c0, b0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
103 t11 = _m_pfmul(c1, b1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
104 /* no need to access cptr[2] & cptr[3] */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
105 c0 = _m_pswapd(c0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
106 c1 = _m_pswapd(c1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
107 /* cim*re cre*im */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
108 t20 = _m_pfmul(c0, b0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
109 t21 = _m_pfmul(c1, b1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
110
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
111 /* cre*re-cim*im cim*re+cre*im */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
112 b0 = _m_pfpnacc(t10, t20);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
113 b1 = _m_pfpnacc(t11, t21);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
114
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
115 /* butterfly */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
116 *(__m64 *)&p[0] = _m_pfadd(a0, b0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
117 *(__m64 *)&p[1] = _m_pfadd(a1, b1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
118 *(__m64 *)&q[0] = _m_pfsub(a0, b0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
119 *(__m64 *)&q[1] = _m_pfsub(a1, b1);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
120
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
121 p += 2;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
122 q += 2;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
123 cptr += 4;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
124 } while (--k);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
125
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
126 p += nloops;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
127 q += nloops;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
128 } while (--j);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
129 cptr1 += nloops * 2;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
130 nblocks = nblocks >> 1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
131 nloops = nloops << 1;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
132 } while (nblocks != 0);
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
133 _m_femms();
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
134 }
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
135
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents:
diff changeset
136 #endif