Indent
[libav.git] / libavcodec / ppc / fft_altivec.c
CommitLineData
8d268a7d
FB
1/*
2 * FFT/IFFT transforms
3 * AltiVec-enabled
bf7ba153 4 * Copyright (c) 2009 Loren Merritt
8d268a7d 5 *
b78e7197
DB
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
8d268a7d
FB
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
b78e7197 11 * version 2.1 of the License, or (at your option) any later version.
8d268a7d 12 *
b78e7197 13 * FFmpeg is distributed in the hope that it will be useful,
8d268a7d
FB
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
b78e7197 19 * License along with FFmpeg; if not, write to the Free Software
5509bffa 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8d268a7d 21 */
1429224b 22#include "libavcodec/fft.h"
89523bee 23#include "util_altivec.h"
bf7ba153
MR
24#include "types_altivec.h"
25#include "regs.h"
ddb8c2c0 26
8d268a7d 27/**
68951ecf 28 * Do a complex FFT with the parameters defined in ff_fft_init(). The
8d268a7d
FB
29 * input data must be permuted before with s->revtab table. No
30 * 1.0/sqrt(n) normalization is done.
31 * AltiVec-enabled
32 * This code assumes that the 'z' pointer is 16 bytes-aligned
33 * It also assumes all FFTComplex are 8 bytes-aligned pair of float
8d268a7d 34 */
115329f1 35
bf7ba153
MR
36// Pointers to functions. Not using function pointer syntax, because
37// that involves an extra level of indirection on some PPC ABIs.
38extern void *ff_fft_dispatch_altivec[2][15];
115329f1 39
bf7ba153
MR
40// Convert from simd order to C order.
41static void swizzle(vec_f *z, int n)
42{
43 int i;
44 n >>= 1;
45 for (i = 0; i < n; i += 2) {
46 vec_f re = z[i];
47 vec_f im = z[i+1];
48 z[i] = vec_mergeh(re, im);
49 z[i+1] = vec_mergel(re, im);
8d268a7d 50 }
bf7ba153 51}
115329f1 52
bf7ba153
MR
53static void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
54{
55 register vec_f v14 __asm__("v14") = {0,0,0,0};
56 register vec_f v15 __asm__("v15") = *(const vec_f*)ff_cos_16;
57 register vec_f v16 __asm__("v16") = {0, 0.38268343, M_SQRT1_2, 0.92387953};
58 register vec_f v17 __asm__("v17") = {-M_SQRT1_2, M_SQRT1_2, M_SQRT1_2,-M_SQRT1_2};
59 register vec_f v18 __asm__("v18") = { M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, M_SQRT1_2};
60 register vec_u8 v19 __asm__("v19") = vcprm(s0,3,2,1);
61 register vec_u8 v20 __asm__("v20") = vcprm(0,1,s2,s1);
62 register vec_u8 v21 __asm__("v21") = vcprm(2,3,s0,s3);
63 register vec_u8 v22 __asm__("v22") = vcprm(2,s3,3,s2);
64 register vec_u8 v23 __asm__("v23") = vcprm(0,1,s0,s1);
65 register vec_u8 v24 __asm__("v24") = vcprm(2,3,s2,s3);
66 register vec_u8 v25 __asm__("v25") = vcprm(2,3,0,1);
67 register vec_u8 v26 __asm__("v26") = vcprm(1,2,s3,s0);
68 register vec_u8 v27 __asm__("v27") = vcprm(0,3,s2,s1);
69 register vec_u8 v28 __asm__("v28") = vcprm(0,2,s1,s3);
70 register vec_u8 v29 __asm__("v29") = vcprm(1,3,s0,s2);
71 register FFTSample *const*cos_tabs __asm__("r12") = ff_cos_tabs;
72 register FFTComplex *zarg __asm__("r3") = z;
73 __asm__(
74 "mtctr %0 \n"
75 "li "r(9)", 16 \n"
76 "subi "r(1)","r(1) ",%1 \n"
77 "bctrl \n"
78 "addi "r(1)","r(1) ",%1 \n"
79 ::"r"(ff_fft_dispatch_altivec[1][s->nbits-2]), "i"(12*sizeof(void*)),
80 "r"(zarg), "r"(cos_tabs),
81 "v"(v14),"v"(v15),"v"(v16),"v"(v17),"v"(v18),"v"(v19),"v"(v20),"v"(v21),
82 "v"(v22),"v"(v23),"v"(v24),"v"(v25),"v"(v26),"v"(v27),"v"(v28),"v"(v29)
83 : "lr","ctr","r0","r4","r5","r6","r7","r8","r9","r10","r11",
84 "v0","v1","v2","v3","v4","v5","v6","v7","v8","v9","v10","v11","v12","v13"
85 );
86 if (s->nbits <= 4)
87 swizzle((vec_f*)z, 1<<s->nbits);
db40a39a 88}
f4863213
MR
89
90av_cold void ff_fft_init_altivec(FFTContext *s)
91{
bf7ba153
MR
92 if (HAVE_GNU_AS)
93 s->fft_calc = ff_fft_calc_altivec;
f4863213 94}