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/fft.h" 24#include "dsputil_ppc.h" 25#include "util_altivec.h" 26#include "dsputil_altivec.h" 27 28/** 29 * Do a complex FFT with the parameters defined in ff_fft_init(). The 30 * input data must be permuted before with s->revtab table. No 31 * 1.0/sqrt(n) normalization is done. 32 * AltiVec-enabled 33 * This code assumes that the 'z' pointer is 16 bytes-aligned 34 * It also assumes all FFTComplex are 8 bytes-aligned pair of float 35 * The code is exactly the same as the SSE version, except 36 * that successive MUL + ADD/SUB have been merged into 37 * fused multiply-add ('vec_madd' in altivec) 38 */ 39static void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z) 40{ 41POWERPC_PERF_DECLARE(altivec_fft_num, s->nbits >= 6); 42 register const vector float vczero = (const vector float)vec_splat_u32(0.); 43 44 int ln = s->nbits; 45 int j, np, np2; 46 int nblocks, nloops; 47 register FFTComplex *p, *q; 48 FFTComplex *cptr, *cptr1; 49 int k; 50 51POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6); 52 53 np = 1 << ln; 54 55 { 56 vector float *r, a, b, a1, c1, c2; 57 58 r = (vector float *)&z[0]; 59 60 c1 = vcii(p,p,n,n); 61 62 if (s->inverse) { 63 c2 = vcii(p,p,n,p); 64 } else { 65 c2 = vcii(p,p,p,n); 66 } 67 68 j = (np >> 2); 69 do { 70 a = vec_ld(0, r); 71 a1 = vec_ld(sizeof(vector float), r); 72 73 b = vec_perm(a,a,vcprmle(1,0,3,2)); 74 a = vec_madd(a,c1,b); 75 /* do the pass 0 butterfly */ 76 77 b = vec_perm(a1,a1,vcprmle(1,0,3,2)); 78 b = vec_madd(a1,c1,b); 79 /* do the pass 0 butterfly */ 80 81 /* multiply third by -i */ 82 b = vec_perm(b,b,vcprmle(2,3,1,0)); 83 84 /* do the pass 1 butterfly */ 85 vec_st(vec_madd(b,c2,a), 0, r); 86 vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r); 87 88 r += 2; 89 } while (--j != 0); 90 } 91 /* pass 2 .. ln-1 */ 92 93 nblocks = np >> 3; 94 nloops = 1 << 2; 95 np2 = np >> 1; 96 97 cptr1 = s->exptab1; 98 do { 99 p = z; 100 q = z + nloops; 101 j = nblocks; 102 do { 103 cptr = cptr1; 104 k = nloops >> 1; 105 do { 106 vector float a,b,c,t1; 107 108 a = vec_ld(0, (float*)p); 109 b = vec_ld(0, (float*)q); 110 111 /* complex mul */ 112 c = vec_ld(0, (float*)cptr); 113 /* cre*re cim*re */ 114 t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero); 115 c = vec_ld(sizeof(vector float), (float*)cptr); 116 /* -cim*im cre*im */ 117 b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1); 118 119 /* butterfly */ 120 vec_st(vec_add(a,b), 0, (float*)p); 121 vec_st(vec_sub(a,b), 0, (float*)q); 122 123 p += 2; 124 q += 2; 125 cptr += 4; 126 } while (--k); 127 128 p += nloops; 129 q += nloops; 130 } while (--j); 131 cptr1 += nloops * 2; 132 nblocks = nblocks >> 1; 133 nloops = nloops << 1; 134 } while (nblocks != 0); 135 136POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6); 137} 138 139av_cold void ff_fft_init_altivec(FFTContext *s) 140{ 141 s->fft_calc = ff_fft_calc_altivec; 142 s->split_radix = 0; 143} 144