4 * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
5 * Based on code Copyright (c) 2002 Fabrice Bellard
7 * This file is part of FFmpeg.
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.
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.
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
23 #include "libavcodec/dsputil.h"
24 #include "dsputil_ppc.h"
25 #include "util_altivec.h"
27 * Do a complex FFT with the parameters defined in ff_fft_init(). The
28 * input data must be permuted before with s->revtab table. No
29 * 1.0/sqrt(n) normalization is done.
31 * This code assumes that the 'z' pointer is 16 bytes-aligned
32 * It also assumes all FFTComplex are 8 bytes-aligned pair of float
33 * The code is exactly the same as the SSE version, except
34 * that successive MUL + ADD/SUB have been merged into
35 * fused multiply-add ('vec_madd' in altivec)
37 void ff_fft_calc_altivec(FFTContext
*s
, FFTComplex
*z
)
39 POWERPC_PERF_DECLARE(altivec_fft_num
, s
->nbits
>= 6);
40 register const vector
float vczero
= (const vector
float)vec_splat_u32(0.);
45 register FFTComplex
*p
, *q
;
46 FFTComplex
*cptr
, *cptr1
;
49 POWERPC_PERF_START_COUNT(altivec_fft_num
, s
->nbits
>= 6);
54 vector
float *r
, a
, b
, a1
, c1
, c2
;
56 r
= (vector
float *)&z
[0];
69 a1
= vec_ld(sizeof(vector
float), r
);
71 b
= vec_perm(a
,a
,vcprmle(1,0,3,2));
73 /* do the pass 0 butterfly */
75 b
= vec_perm(a1
,a1
,vcprmle(1,0,3,2));
76 b
= vec_madd(a1
,c1
,b
);
77 /* do the pass 0 butterfly */
79 /* multiply third by -i */
80 b
= vec_perm(b
,b
,vcprmle(2,3,1,0));
82 /* do the pass 1 butterfly */
83 vec_st(vec_madd(b
,c2
,a
), 0, r
);
84 vec_st(vec_nmsub(b
,c2
,a
), sizeof(vector
float), r
);
104 vector
float a
,b
,c
,t1
;
106 a
= vec_ld(0, (float*)p
);
107 b
= vec_ld(0, (float*)q
);
110 c
= vec_ld(0, (float*)cptr
);
112 t1
= vec_madd(c
, vec_perm(b
,b
,vcprmle(2,2,0,0)),vczero
);
113 c
= vec_ld(sizeof(vector
float), (float*)cptr
);
115 b
= vec_madd(c
, vec_perm(b
,b
,vcprmle(3,3,1,1)),t1
);
118 vec_st(vec_add(a
,b
), 0, (float*)p
);
119 vec_st(vec_sub(a
,b
), 0, (float*)q
);
130 nblocks
= nblocks
>> 1;
131 nloops
= nloops
<< 1;
132 } while (nblocks
!= 0);
134 POWERPC_PERF_STOP_COUNT(altivec_fft_num
, s
->nbits
>= 6);