annotate ppc/fft_altivec.c @ 12046:ae57be2ef58c libavcodec

PPC: Altivec split-radix FFT 1.8x faster than altivec radix-2 on a G4 8% faster vorbis decoding Patch (mostly) by Loren Merritt
author mru
date Thu, 01 Jul 2010 23:21:39 +0000
parents 3cd4cd0509cd
children c80c7a717156
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
1 /*
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
2 * FFT/IFFT transforms
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
3 * AltiVec-enabled
12046
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
4 * Copyright (c) 2009 Loren Merritt
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
5 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
12 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
16 * Lesser General Public License for more details.
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
17 *
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
21 */
11370
4b3da727d832 Move FFT parts from dsputil.h to fft.h
mru
parents: 10175
diff changeset
22 #include "libavcodec/fft.h"
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents: 5010
diff changeset
23 #include "util_altivec.h"
12046
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
24 #include "types_altivec.h"
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
25 #include "regs.h"
11382
50415a8f1451 PPC: move prototypes to headers and make some functions static
mru
parents: 11370
diff changeset
26
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
27 /**
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1352
diff changeset
28 * Do a complex FFT with the parameters defined in ff_fft_init(). The
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
29 * input data must be permuted before with s->revtab table. No
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
30 * 1.0/sqrt(n) normalization is done.
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
31 * AltiVec-enabled
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
32 * This code assumes that the 'z' pointer is 16 bytes-aligned
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
33 * It also assumes all FFTComplex are 8 bytes-aligned pair of float
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
34 */
12046
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
35
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
36 // Pointers to functions. Not using function pointer syntax, because
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
37 // that involves an extra level of indirection on some PPC ABIs.
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
38 extern void *ff_fft_dispatch_altivec[2][15];
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
39
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
40 // Convert from simd order to C order.
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
41 static void swizzle(vec_f *z, int n)
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
42 {
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
43 int i;
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
44 n >>= 1;
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
45 for (i = 0; i < n; i += 2) {
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
46 vec_f re = z[i];
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
47 vec_f im = z[i+1];
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
48 z[i] = vec_mergeh(re, im);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
49 z[i+1] = vec_mergel(re, im);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
50 }
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
51 }
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
52
11382
50415a8f1451 PPC: move prototypes to headers and make some functions static
mru
parents: 11370
diff changeset
53 static void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
54 {
12046
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
55 register vec_f v14 __asm__("v14") = {0,0,0,0};
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
56 register vec_f v15 __asm__("v15") = *(const vec_f*)ff_cos_16;
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
57 register vec_f v16 __asm__("v16") = {0, 0.38268343, M_SQRT1_2, 0.92387953};
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
58 register vec_f v17 __asm__("v17") = {-M_SQRT1_2, M_SQRT1_2, M_SQRT1_2,-M_SQRT1_2};
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
59 register vec_f v18 __asm__("v18") = { M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, M_SQRT1_2};
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
60 register vec_u8 v19 __asm__("v19") = vcprm(s0,3,2,1);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
61 register vec_u8 v20 __asm__("v20") = vcprm(0,1,s2,s1);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
62 register vec_u8 v21 __asm__("v21") = vcprm(2,3,s0,s3);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
63 register vec_u8 v22 __asm__("v22") = vcprm(2,s3,3,s2);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
64 register vec_u8 v23 __asm__("v23") = vcprm(0,1,s0,s1);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
65 register vec_u8 v24 __asm__("v24") = vcprm(2,3,s2,s3);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
66 register vec_u8 v25 __asm__("v25") = vcprm(2,3,0,1);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
67 register vec_u8 v26 __asm__("v26") = vcprm(1,2,s3,s0);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
68 register vec_u8 v27 __asm__("v27") = vcprm(0,3,s2,s1);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
69 register vec_u8 v28 __asm__("v28") = vcprm(0,2,s1,s3);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
70 register vec_u8 v29 __asm__("v29") = vcprm(1,3,s0,s2);
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
71 register FFTSample *const*cos_tabs __asm__("r12") = ff_cos_tabs;
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
72 register FFTComplex *zarg __asm__("r3") = z;
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
73 __asm__(
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
74 "mtctr %0 \n"
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
75 "li "r(9)", 16 \n"
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
76 "subi "r(1)","r(1) ",%1 \n"
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
77 "bctrl \n"
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
78 "addi "r(1)","r(1) ",%1 \n"
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
79 ::"r"(ff_fft_dispatch_altivec[1][s->nbits-2]), "i"(12*sizeof(void*)),
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
80 "r"(zarg), "r"(cos_tabs),
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
81 "v"(v14),"v"(v15),"v"(v16),"v"(v17),"v"(v18),"v"(v19),"v"(v20),"v"(v21),
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
82 "v"(v22),"v"(v23),"v"(v24),"v"(v25),"v"(v26),"v"(v27),"v"(v28),"v"(v29)
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
83 : "lr","ctr","r0","r4","r5","r6","r7","r8","r9","r10","r11",
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
84 "v0","v1","v2","v3","v4","v5","v6","v7","v8","v9","v10","v11","v12","v13"
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
85 );
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
86 if (s->nbits <= 4)
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
87 swizzle((vec_f*)z, 1<<s->nbits);
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents:
diff changeset
88 }
10175
5cf49858179a Move per-arch fft init bits into the corresponding subdirs
mru
parents: 9364
diff changeset
89
5cf49858179a Move per-arch fft init bits into the corresponding subdirs
mru
parents: 9364
diff changeset
90 av_cold void ff_fft_init_altivec(FFTContext *s)
5cf49858179a Move per-arch fft init bits into the corresponding subdirs
mru
parents: 9364
diff changeset
91 {
12046
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
92 if (HAVE_GNU_AS)
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
93 s->fft_calc = ff_fft_calc_altivec;
ae57be2ef58c PPC: Altivec split-radix FFT
mru
parents: 11969
diff changeset
94 s->split_radix = 1;
10175
5cf49858179a Move per-arch fft init bits into the corresponding subdirs
mru
parents: 9364
diff changeset
95 }