00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavcodec/fft.h"
00023 #include "util_altivec.h"
00024 #include "types_altivec.h"
00025
00035 void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
00036 void ff_fft_calc_interleave_altivec(FFTContext *s, FFTComplex *z);
00037
00038 #if HAVE_GNU_AS
00039 static void ff_imdct_half_altivec(FFTContext *s, FFTSample *output, const FFTSample *input)
00040 {
00041 int j, k;
00042 int n = 1 << s->mdct_bits;
00043 int n4 = n >> 2;
00044 int n8 = n >> 3;
00045 int n32 = n >> 5;
00046 const uint16_t *revtabj = s->revtab;
00047 const uint16_t *revtabk = s->revtab+n4;
00048 const vec_f *tcos = (const vec_f*)(s->tcos+n8);
00049 const vec_f *tsin = (const vec_f*)(s->tsin+n8);
00050 const vec_f *pin = (const vec_f*)(input+n4);
00051 vec_f *pout = (vec_f*)(output+n4);
00052
00053
00054 k = n32-1;
00055 do {
00056 vec_f cos,sin,cos0,sin0,cos1,sin1,re,im,r0,i0,r1,i1,a,b,c,d;
00057 #define CMULA(p,o0,o1,o2,o3)\
00058 a = pin[ k*2+p]; \
00059 b = pin[-k*2-p-1]; \
00060 re = vec_perm(a, b, vcprm(0,2,s0,s2)); \
00061 im = vec_perm(a, b, vcprm(s3,s1,3,1)); \
00062 cos = vec_perm(cos0, cos1, vcprm(o0,o1,s##o2,s##o3)); \
00063 sin = vec_perm(sin0, sin1, vcprm(o0,o1,s##o2,s##o3));\
00064 r##p = im*cos - re*sin;\
00065 i##p = re*cos + im*sin;
00066 #define STORE2(v,dst)\
00067 j = dst;\
00068 vec_ste(v, 0, output+j*2);\
00069 vec_ste(v, 4, output+j*2);
00070 #define STORE8(p)\
00071 a = vec_perm(r##p, i##p, vcprm(0,s0,0,s0));\
00072 b = vec_perm(r##p, i##p, vcprm(1,s1,1,s1));\
00073 c = vec_perm(r##p, i##p, vcprm(2,s2,2,s2));\
00074 d = vec_perm(r##p, i##p, vcprm(3,s3,3,s3));\
00075 STORE2(a, revtabk[ p*2-4]);\
00076 STORE2(b, revtabk[ p*2-3]);\
00077 STORE2(c, revtabj[-p*2+2]);\
00078 STORE2(d, revtabj[-p*2+3]);
00079
00080 cos0 = tcos[k];
00081 sin0 = tsin[k];
00082 cos1 = tcos[-k-1];
00083 sin1 = tsin[-k-1];
00084 CMULA(0, 0,1,2,3);
00085 CMULA(1, 2,3,0,1);
00086 STORE8(0);
00087 STORE8(1);
00088 revtabj += 4;
00089 revtabk -= 4;
00090 k--;
00091 } while(k >= 0);
00092
00093 ff_fft_calc_altivec(s, (FFTComplex*)output);
00094
00095
00096 j = -n32;
00097 k = n32-1;
00098 do {
00099 vec_f cos,sin,re,im,a,b,c,d;
00100 #define CMULB(d0,d1,o)\
00101 re = pout[o*2];\
00102 im = pout[o*2+1];\
00103 cos = tcos[o];\
00104 sin = tsin[o];\
00105 d0 = im*sin - re*cos;\
00106 d1 = re*sin + im*cos;
00107
00108 CMULB(a,b,j);
00109 CMULB(c,d,k);
00110 pout[2*j] = vec_perm(a, d, vcprm(0,s3,1,s2));
00111 pout[2*j+1] = vec_perm(a, d, vcprm(2,s1,3,s0));
00112 pout[2*k] = vec_perm(c, b, vcprm(0,s3,1,s2));
00113 pout[2*k+1] = vec_perm(c, b, vcprm(2,s1,3,s0));
00114 j++;
00115 k--;
00116 } while(k >= 0);
00117 }
00118
00119 static void ff_imdct_calc_altivec(FFTContext *s, FFTSample *output, const FFTSample *input)
00120 {
00121 int k;
00122 int n = 1 << s->mdct_bits;
00123 int n4 = n >> 2;
00124 int n16 = n >> 4;
00125 vec_u32 sign = {1U<<31,1U<<31,1U<<31,1U<<31};
00126 vec_u32 *p0 = (vec_u32*)(output+n4);
00127 vec_u32 *p1 = (vec_u32*)(output+n4*3);
00128
00129 ff_imdct_half_altivec(s, output+n4, input);
00130
00131 for (k = 0; k < n16; k++) {
00132 vec_u32 a = p0[k] ^ sign;
00133 vec_u32 b = p1[-k-1];
00134 p0[-k-1] = vec_perm(a, a, vcprm(3,2,1,0));
00135 p1[k] = vec_perm(b, b, vcprm(3,2,1,0));
00136 }
00137 }
00138 #endif
00139
00140 av_cold void ff_fft_init_altivec(FFTContext *s)
00141 {
00142 #if HAVE_GNU_AS
00143 s->fft_calc = ff_fft_calc_interleave_altivec;
00144 if (s->mdct_bits >= 5) {
00145 s->imdct_calc = ff_imdct_calc_altivec;
00146 s->imdct_half = ff_imdct_half_altivec;
00147 }
00148 #endif
00149 }