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