4 * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
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.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavcodec/dsputil.h"
26 #define c1 1.38703984532214752434 /* sqrt(2)*cos(1*pi/16) */
27 #define c2 1.30656296487637657577 /* sqrt(2)*cos(2*pi/16) */
28 #define c3 1.17587560241935884520 /* sqrt(2)*cos(3*pi/16) */
29 #define c4 1.00000000000000000000 /* sqrt(2)*cos(4*pi/16) */
30 #define c5 0.78569495838710234903 /* sqrt(2)*cos(5*pi/16) */
31 #define c6 0.54119610014619712324 /* sqrt(2)*cos(6*pi/16) */
32 #define c7 0.27589937928294311353 /* sqrt(2)*cos(7*pi/16) */
34 static const float even_table
[] __attribute__ ((aligned(8))) = {
41 static const float odd_table
[] __attribute__ ((aligned(8))) = {
58 #define load_matrix(table) \
60 const float *t = table; \
77 __asm__ volatile("ftrv xmtrx,fv0" \
78 : "+f"(fr0),"+f"(fr1),"+f"(fr2),"+f"(fr3));
81 register float fr0 __asm__("fr0"); \
82 register float fr1 __asm__("fr1"); \
83 register float fr2 __asm__("fr2"); \
84 register float fr3 __asm__("fr3")
88 /* generic C code for check */
90 static void ftrv_(const float xf
[],float fv
[])
97 fv
[0] = xf
[0]*f0
+ xf
[4]*f1
+ xf
[ 8]*f2
+ xf
[12]*f3
;
98 fv
[1] = xf
[1]*f0
+ xf
[5]*f1
+ xf
[ 9]*f2
+ xf
[13]*f3
;
99 fv
[2] = xf
[2]*f0
+ xf
[6]*f1
+ xf
[10]*f2
+ xf
[14]*f3
;
100 fv
[3] = xf
[3]*f0
+ xf
[7]*f1
+ xf
[11]*f2
+ xf
[15]*f3
;
103 static void load_matrix_(float xf
[],const float table
[])
106 for(i
=0;i
<16;i
++) xf
[i
]=table
[i
];
109 #define ftrv() ftrv_(xf,fv)
110 #define load_matrix(table) load_matrix_(xf,table)
123 #define DESCALE(x,n) (x)*(1.0f/(1<<(n)))
125 #define DESCALE(x,n) (((int)(x)+(1<<(n-1)))>>(n))
128 /* this code work worse on gcc cvs. 3.2.3 work fine */
134 void idct_sh4(DCTELEM
*block
)
139 float tblock
[8*8],*fblock
;
143 fp_single_enter(fpscr
);
148 load_matrix(even_table
);
168 load_matrix(odd_table
);
185 *--fblock
= t0
- fr0
;
186 *--fblock
= t1
- fr1
;
187 *--fblock
= t2
- fr2
;
188 *--fblock
= t3
- fr3
;
189 *--fblock
= t3
+ fr3
;
190 *--fblock
= t2
+ fr2
;
191 *--fblock
= t1
+ fr1
;
192 *--fblock
= t0
+ fr0
;
201 load_matrix(even_table
);
203 ofs1
= sizeof(float)*2*8;
204 ofs2
= sizeof(float)*4*8;
205 ofs3
= sizeof(float)*6*8;
209 #define OA(fblock,ofs) *(float*)((char*)fblock + ofs)
213 fr1
= OA(fblock
,ofs1
);
214 fr2
= OA(fblock
,ofs2
);
215 fr3
= OA(fblock
,ofs3
);
218 OA(fblock
,ofs1
) = fr1
;
219 OA(fblock
,ofs2
) = fr2
;
220 OA(fblock
,ofs3
) = fr3
;
225 load_matrix(odd_table
);
230 t0
= OA(fblock
, 0); /* [8*0] */
231 t1
= OA(fblock
,ofs1
); /* [8*2] */
232 t2
= OA(fblock
,ofs2
); /* [8*4] */
233 t3
= OA(fblock
,ofs3
); /* [8*6] */
235 fr0
= OA(fblock
, 0); /* [8*1] */
236 fr1
= OA(fblock
,ofs1
); /* [8*3] */
237 fr2
= OA(fblock
,ofs2
); /* [8*5] */
238 fr3
= OA(fblock
,ofs3
); /* [8*7] */
241 block
[8*0] = DESCALE(t0
+ fr0
,3);
242 block
[8*7] = DESCALE(t0
- fr0
,3);
243 block
[8*1] = DESCALE(t1
+ fr1
,3);
244 block
[8*6] = DESCALE(t1
- fr1
,3);
245 block
[8*2] = DESCALE(t2
+ fr2
,3);
246 block
[8*5] = DESCALE(t2
- fr2
,3);
247 block
[8*3] = DESCALE(t3
+ fr3
,3);
248 block
[8*4] = DESCALE(t3
- fr3
,3);
252 fp_single_leave(fpscr
);
255 void idct_sh4(DCTELEM
*block
)
260 float tblock
[8*8],*fblock
;
265 load_matrix(even_table
);
285 load_matrix(odd_table
);
301 fblock
[0] = t0
+ fr0
;
302 fblock
[7] = t0
- fr0
;
303 fblock
[1] = t1
+ fr1
;
304 fblock
[6] = t1
- fr1
;
305 fblock
[2] = t2
+ fr2
;
306 fblock
[5] = t2
- fr2
;
307 fblock
[3] = t3
+ fr3
;
308 fblock
[4] = t3
- fr3
;
317 load_matrix(even_table
);
335 load_matrix(odd_table
);
350 block
[8*0] = DESCALE(t0
+ fr0
,3);
351 block
[8*7] = DESCALE(t0
- fr0
,3);
352 block
[8*1] = DESCALE(t1
+ fr1
,3);
353 block
[8*6] = DESCALE(t1
- fr1
,3);
354 block
[8*2] = DESCALE(t2
+ fr2
,3);
355 block
[8*5] = DESCALE(t2
- fr2
,3);
356 block
[8*3] = DESCALE(t3
+ fr3
,3);
357 block
[8*4] = DESCALE(t3
- fr3
,3);