]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blob - libavcodec/ppc/fft_altivec.c
cosmetics: Remove pointless period after copyright statement non-sentences.
[frescor/ffmpeg.git] / libavcodec / ppc / fft_altivec.c
1 /*
2  * FFT/IFFT transforms
3  * AltiVec-enabled
4  * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
5  * Based on code Copyright (c) 2002 Fabrice Bellard
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 #include "libavcodec/dsputil.h"
24
25 #include "gcc_fixes.h"
26
27 #include "dsputil_ppc.h"
28 #include "util_altivec.h"
29 /**
30  * Do a complex FFT with the parameters defined in ff_fft_init(). The
31  * input data must be permuted before with s->revtab table. No
32  * 1.0/sqrt(n) normalization is done.
33  * AltiVec-enabled
34  * This code assumes that the 'z' pointer is 16 bytes-aligned
35  * It also assumes all FFTComplex are 8 bytes-aligned pair of float
36  * The code is exactly the same as the SSE version, except
37  * that successive MUL + ADD/SUB have been merged into
38  * fused multiply-add ('vec_madd' in altivec)
39  */
40 void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
41 {
42 POWERPC_PERF_DECLARE(altivec_fft_num, s->nbits >= 6);
43     register const vector float vczero = (const vector float)vec_splat_u32(0.);
44
45     int ln = s->nbits;
46     int j, np, np2;
47     int nblocks, nloops;
48     register FFTComplex *p, *q;
49     FFTComplex *cptr, *cptr1;
50     int k;
51
52 POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6);
53
54     np = 1 << ln;
55
56     {
57         vector float *r, a, b, a1, c1, c2;
58
59         r = (vector float *)&z[0];
60
61         c1 = vcii(p,p,n,n);
62
63         if (s->inverse) {
64             c2 = vcii(p,p,n,p);
65         } else {
66             c2 = vcii(p,p,p,n);
67         }
68
69         j = (np >> 2);
70         do {
71             a = vec_ld(0, r);
72             a1 = vec_ld(sizeof(vector float), r);
73
74             b = vec_perm(a,a,vcprmle(1,0,3,2));
75             a = vec_madd(a,c1,b);
76             /* do the pass 0 butterfly */
77
78             b = vec_perm(a1,a1,vcprmle(1,0,3,2));
79             b = vec_madd(a1,c1,b);
80             /* do the pass 0 butterfly */
81
82             /* multiply third by -i */
83             b = vec_perm(b,b,vcprmle(2,3,1,0));
84
85             /* do the pass 1 butterfly */
86             vec_st(vec_madd(b,c2,a), 0, r);
87             vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r);
88
89             r += 2;
90         } while (--j != 0);
91     }
92     /* pass 2 .. ln-1 */
93
94     nblocks = np >> 3;
95     nloops = 1 << 2;
96     np2 = np >> 1;
97
98     cptr1 = s->exptab1;
99     do {
100         p = z;
101         q = z + nloops;
102         j = nblocks;
103         do {
104             cptr = cptr1;
105             k = nloops >> 1;
106             do {
107                 vector float a,b,c,t1;
108
109                 a = vec_ld(0, (float*)p);
110                 b = vec_ld(0, (float*)q);
111
112                 /* complex mul */
113                 c = vec_ld(0, (float*)cptr);
114                 /*  cre*re cim*re */
115                 t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero);
116                 c = vec_ld(sizeof(vector float), (float*)cptr);
117                 /*  -cim*im cre*im */
118                 b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1);
119
120                 /* butterfly */
121                 vec_st(vec_add(a,b), 0, (float*)p);
122                 vec_st(vec_sub(a,b), 0, (float*)q);
123
124                 p += 2;
125                 q += 2;
126                 cptr += 4;
127             } while (--k);
128
129             p += nloops;
130             q += nloops;
131         } while (--j);
132         cptr1 += nloops * 2;
133         nblocks = nblocks >> 1;
134         nloops = nloops << 1;
135     } while (nblocks != 0);
136
137 POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
138 }