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"
24 #define c1 1.38703984532214752434 /* sqrt(2)*cos(1*pi/16) */
25 #define c2 1.30656296487637657577 /* sqrt(2)*cos(2*pi/16) */
26 #define c3 1.17587560241935884520 /* sqrt(2)*cos(3*pi/16) */
27 #define c4 1.00000000000000000000 /* sqrt(2)*cos(4*pi/16) */
28 #define c5 0.78569495838710234903 /* sqrt(2)*cos(5*pi/16) */
29 #define c6 0.54119610014619712324 /* sqrt(2)*cos(6*pi/16) */
30 #define c7 0.27589937928294311353 /* sqrt(2)*cos(7*pi/16) */
32 static const float even_table
[] __attribute__ ((aligned(8))) = {
39 static const float odd_table
[] __attribute__ ((aligned(8))) = {
54 #if defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__)
56 #define load_matrix(table) \
74 asm volatile("ftrv xmtrx,fv0" \
75 : "=f"(fr0),"=f"(fr1),"=f"(fr2),"=f"(fr3) \
76 : "0"(fr0), "1"(fr1), "2"(fr2), "3"(fr3) );
79 register float fr0 asm("fr0"); \
80 register float fr1 asm("fr1"); \
81 register float fr2 asm("fr2"); \
82 register float fr3 asm("fr3")
86 /* generic C code for check */
88 static void ftrv_(const float xf
[],float fv
[])
95 fv
[0] = xf
[0]*f0
+ xf
[4]*f1
+ xf
[ 8]*f2
+ xf
[12]*f3
;
96 fv
[1] = xf
[1]*f0
+ xf
[5]*f1
+ xf
[ 9]*f2
+ xf
[13]*f3
;
97 fv
[2] = xf
[2]*f0
+ xf
[6]*f1
+ xf
[10]*f2
+ xf
[14]*f3
;
98 fv
[3] = xf
[3]*f0
+ xf
[7]*f1
+ xf
[11]*f2
+ xf
[15]*f3
;
101 static void load_matrix_(float xf
[],const float table
[])
104 for(i
=0;i
<16;i
++) xf
[i
]=table
[i
];
107 #define ftrv() ftrv_(xf,fv)
108 #define load_matrix(table) load_matrix_(xf,table)
121 #define DESCALE(x,n) (x)*(1.0f/(1<<(n)))
123 #define DESCALE(x,n) (((int)(x)+(1<<(n-1)))>>(n))
126 /* this code work worse on gcc cvs. 3.2.3 work fine */
132 void idct_sh4(DCTELEM
*block
)
137 float tblock
[8*8],*fblock
;
141 #error "FIXME!! change to single float"
147 load_matrix(even_table
);
167 load_matrix(odd_table
);
171 // ofs1 = sizeof(float)*1;
172 // ofs2 = sizeof(float)*2;
173 // ofs3 = sizeof(float)*3;
188 *--fblock
= t0
- fr0
;
189 *--fblock
= t1
- fr1
;
190 *--fblock
= t2
- fr2
;
191 *--fblock
= t3
- fr3
;
192 *--fblock
= t3
+ fr3
;
193 *--fblock
= t2
+ fr2
;
194 *--fblock
= t1
+ fr1
;
195 *--fblock
= t0
+ fr0
;
204 load_matrix(even_table
);
206 ofs1
= sizeof(float)*2*8;
207 ofs2
= sizeof(float)*4*8;
208 ofs3
= sizeof(float)*6*8;
212 #define OA(fblock,ofs) *(float*)((char*)fblock + ofs)
216 fr1
= OA(fblock
,ofs1
);
217 fr2
= OA(fblock
,ofs2
);
218 fr3
= OA(fblock
,ofs3
);
221 OA(fblock
,ofs1
) = fr1
;
222 OA(fblock
,ofs2
) = fr2
;
223 OA(fblock
,ofs3
) = fr3
;
228 load_matrix(odd_table
);
233 t0
= OA(fblock
, 0); /* [8*0] */
234 t1
= OA(fblock
,ofs1
); /* [8*2] */
235 t2
= OA(fblock
,ofs2
); /* [8*4] */
236 t3
= OA(fblock
,ofs3
); /* [8*6] */
238 fr0
= OA(fblock
, 0); /* [8*1] */
239 fr1
= OA(fblock
,ofs1
); /* [8*3] */
240 fr2
= OA(fblock
,ofs2
); /* [8*5] */
241 fr3
= OA(fblock
,ofs3
); /* [8*7] */
244 block
[8*0] = DESCALE(t0
+ fr0
,3);
245 block
[8*7] = DESCALE(t0
- fr0
,3);
246 block
[8*1] = DESCALE(t1
+ fr1
,3);
247 block
[8*6] = DESCALE(t1
- fr1
,3);
248 block
[8*2] = DESCALE(t2
+ fr2
,3);
249 block
[8*5] = DESCALE(t2
- fr2
,3);
250 block
[8*3] = DESCALE(t3
+ fr3
,3);
251 block
[8*4] = DESCALE(t3
- fr3
,3);
256 #error "FIXME!! change to double"
260 void idct_sh4(DCTELEM
*block
)
265 float tblock
[8*8],*fblock
;
270 load_matrix(even_table
);
290 load_matrix(odd_table
);
306 fblock
[0] = t0
+ fr0
;
307 fblock
[7] = t0
- fr0
;
308 fblock
[1] = t1
+ fr1
;
309 fblock
[6] = t1
- fr1
;
310 fblock
[2] = t2
+ fr2
;
311 fblock
[5] = t2
- fr2
;
312 fblock
[3] = t3
+ fr3
;
313 fblock
[4] = t3
- fr3
;
322 load_matrix(even_table
);
340 load_matrix(odd_table
);
355 block
[8*0] = DESCALE(t0
+ fr0
,3);
356 block
[8*7] = DESCALE(t0
- fr0
,3);
357 block
[8*1] = DESCALE(t1
+ fr1
,3);
358 block
[8*6] = DESCALE(t1
- fr1
,3);
359 block
[8*2] = DESCALE(t2
+ fr2
,3);
360 block
[8*5] = DESCALE(t2
- fr2
,3);
361 block
[8*3] = DESCALE(t3
+ fr3
,3);
362 block
[8*4] = DESCALE(t3
- fr3
,3);