[svn] / branches / dev-api-4 / xvidcore / examples / xvid_bench.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/examples/xvid_bench.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1053 - (view) (download)

1 : Isibaar 225 /**************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC - Unit tests and benches
4 :     *
5 :     * This program is free software; you can redistribute it and/or modify
6 :     * it under the terms of the GNU General Public License as published by
7 :     * the Free Software Foundation; either version 2 of the License, or
8 :     * (at your option) any later version.
9 :     *
10 :     * This program is distributed in the hope that it will be useful,
11 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 :     * GNU General Public License for more details.
14 :     *
15 :     * You should have received a copy of the GNU General Public License
16 :     * along with this program; if not, write to the Free Software
17 :     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 :     *
19 :     *************************************************************************/
20 :    
21 :     /************************************************************************
22 :     *
23 :     * 'Reference' output is at the end of file.
24 :     * Don't take the checksums and crc too seriouly, they aren't
25 : Isibaar 262 * bullet-proof (should plug some .md5 here)...
26 : Isibaar 225 *
27 :     * compiles with something like:
28 :     * gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm
29 :     *
30 :     * History:
31 :     *
32 :     * 06.06.2002 initial coding -Skal-
33 :     *
34 :     *************************************************************************/
35 :    
36 :     #include <stdio.h>
37 :     #include <stdlib.h>
38 : edgomez 1053 #include <string.h> /* for memset */
39 : Isibaar 225 #include <assert.h>
40 :    
41 : suxen_drol 860 #ifndef WIN32
42 : edgomez 1053 #include <sys/time.h> /* for gettimeofday */
43 : suxen_drol 860 #else
44 :     #include <time.h>
45 :     #endif
46 :    
47 :    
48 : Isibaar 225 #include "xvid.h"
49 :    
50 : edgomez 851 // inner guts
51 : Isibaar 225 #include "dct/idct.h"
52 :     #include "dct/fdct.h"
53 :     #include "image/colorspace.h"
54 :     #include "image/interpolate8x8.h"
55 :     #include "utils/mem_transfer.h"
56 :     #include "quant/quant_h263.h"
57 :     #include "quant/quant_mpeg4.h"
58 :     #include "motion/sad.h"
59 :     #include "utils/emms.h"
60 :     #include "utils/timer.h"
61 :     #include "quant/quant_matrix.c"
62 :     #include "bitstream/cbp.h"
63 :    
64 : Isibaar 262 #include <math.h>
65 : suxen_drol 860
66 :     #ifndef M_PI
67 :     #define M_PI 3.14159265358979323846
68 :     #endif
69 :    
70 : edgomez 1053 const int speed_ref = 100; /* on slow machines, decrease this value */
71 : Isibaar 225
72 :     /*********************************************************************
73 :     * misc
74 :     *********************************************************************/
75 :    
76 :     /* returns time in micro-s*/
77 :     double gettime_usec()
78 :     {
79 : suxen_drol 860 #ifndef WIN32
80 : Isibaar 225 struct timeval tv;
81 :     gettimeofday(&tv, 0);
82 : ia64p 279 return tv.tv_sec*1.0e6 + tv.tv_usec;
83 : suxen_drol 860 #else
84 :     clock_t clk;
85 :     clk = clock();
86 :     return clk * 1000000 / CLOCKS_PER_SEC;
87 :     #endif
88 : Isibaar 225 }
89 :    
90 :     /* returns squared deviates (mean(v*v)-mean(v)^2) of a 8x8 block */
91 :     double sqr_dev(uint8_t v[8*8])
92 :     {
93 :     double sum=0.;
94 :     double sum2=0.;
95 :     int n;
96 :     for (n=0;n<8*8;n++)
97 :     {
98 :     sum += v[n];
99 :     sum2 += v[n]*v[n];
100 :     }
101 :     sum2 /= n;
102 :     sum /= n;
103 :     return sum2-sum*sum;
104 :     }
105 :    
106 :     /*********************************************************************
107 :     * cpu init
108 :     *********************************************************************/
109 :    
110 :     typedef struct {
111 :     const char *name;
112 :     unsigned int cpu;
113 :     } CPU;
114 :    
115 :     CPU cpu_list[] =
116 :     { { "PLAINC", 0 }
117 :     , { "MMX ", XVID_CPU_MMX }
118 :     , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
119 :     , { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX }
120 :     , { "3DNOW ", XVID_CPU_3DNOW }
121 :     , { "3DNOWE", XVID_CPU_3DNOWEXT }
122 : ia64p 279 , { "IA64 ", XVID_CPU_IA64 }
123 : edgomez 851 //, { "TSC ", XVID_CPU_TSC }
124 : Isibaar 225 , { 0, 0 } }
125 :    
126 :     , cpu_short_list[] =
127 :     { { "PLAINC", 0 }
128 :     , { "MMX ", XVID_CPU_MMX }
129 : edgomez 851 //, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
130 : ia64p 279 , { "IA64 ", XVID_CPU_IA64 }
131 : Isibaar 225 , { 0, 0 } }
132 :    
133 :     , cpu_short_list2[] =
134 :     { { "PLAINC", 0 }
135 :     , { "MMX ", XVID_CPU_MMX }
136 :     , { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX }
137 :     , { 0, 0 } };
138 :    
139 :    
140 :     int init_cpu(CPU *cpu)
141 :     {
142 :     int xerr, cpu_type;
143 :     XVID_INIT_PARAM xinit;
144 :    
145 :     cpu_type = check_cpu_features() & cpu->cpu;
146 :     xinit.cpu_flags = cpu_type | XVID_CPU_FORCE;
147 : edgomez 1053 /* xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; */
148 : Isibaar 225 xerr = xvid_init(NULL, 0, &xinit, NULL);
149 :     if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) {
150 :     printf( "%s - skipped...\n", cpu->name );
151 :     return 0;
152 :     }
153 :     return 1;
154 :     }
155 :    
156 :     /*********************************************************************
157 :     * test DCT
158 :     *********************************************************************/
159 :    
160 :     #define ABS(X) ((X)<0 ? -(X) : (X))
161 :    
162 :     void test_dct()
163 :     {
164 :     const int nb_tests = 300*speed_ref;
165 :     int tst;
166 :     CPU *cpu;
167 :     int i;
168 :     short iDst0[8*8], iDst[8*8], fDst[8*8];
169 :     double overhead;
170 :    
171 :     printf( "\n ===== test fdct/idct =====\n" );
172 :    
173 :     for(i=0; i<8*8; ++i) iDst0[i] = (i*7-i*i) & 0x7f;
174 :     overhead = gettime_usec();
175 :     for(tst=0; tst<nb_tests; ++tst)
176 :     {
177 :     for(i=0; i<8*8; ++i) fDst[i] = iDst0[i];
178 :     for(i=0; i<8*8; ++i) iDst[i] = fDst[i];
179 :     }
180 :     overhead = gettime_usec() - overhead;
181 :    
182 :     for(cpu = cpu_list; cpu->name!=0; ++cpu)
183 :     {
184 : Isibaar 262 double t, PSNR, MSE;
185 : Isibaar 225
186 :     if (!init_cpu(cpu))
187 :     continue;
188 :    
189 :     t = gettime_usec();
190 :     emms();
191 :     for(tst=0; tst<nb_tests; ++tst)
192 :     {
193 :     for(i=0; i<8*8; ++i) fDst[i] = iDst0[i];
194 :     fdct(fDst);
195 :     for(i=0; i<8*8; ++i) iDst[i] = fDst[i];
196 :     idct(iDst);
197 :     }
198 :     emms();
199 :     t = (gettime_usec() - t - overhead) / nb_tests;
200 : Isibaar 262 MSE = 0.;
201 : Isibaar 225 for(i=0; i<8*8; ++i) {
202 : Isibaar 262 double delta = 1.0*(iDst[i] - iDst0[i]);
203 :     MSE += delta*delta;
204 : Isibaar 225 }
205 : Isibaar 262 PSNR = (MSE==0.) ? 1.e6 : -4.3429448*log( MSE/64. );
206 :     printf( "%s - %.3f usec PSNR=%.3f MSE=%.3f\n",
207 :     cpu->name, t, PSNR, MSE );
208 :     if (ABS(MSE)>=64) printf( "*** CRC ERROR! ***\n" );
209 : Isibaar 225 }
210 :     }
211 :    
212 :     /*********************************************************************
213 :     * test SAD
214 :     *********************************************************************/
215 :    
216 :     void test_sad()
217 :     {
218 :     const int nb_tests = 2000*speed_ref;
219 :     int tst;
220 :     CPU *cpu;
221 :     int i;
222 :     uint8_t Cur[16*16], Ref1[16*16], Ref2[16*16];
223 :    
224 :     printf( "\n ====== test SAD ======\n" );
225 :     for(i=0; i<16*16;++i) {
226 :     Cur[i] = (i/5) ^ 0x05;
227 :     Ref1[i] = (i + 0x0b) & 0xff;
228 :     Ref2[i] = i ^ 0x76;
229 :     }
230 :    
231 :     for(cpu = cpu_list; cpu->name!=0; ++cpu)
232 :     {
233 :     double t;
234 :     uint32_t s;
235 :     if (!init_cpu(cpu))
236 :     continue;
237 :    
238 :     t = gettime_usec();
239 :     emms();
240 :     for(tst=0; tst<nb_tests; ++tst) s = sad8(Cur, Ref1, 16);
241 :     emms();
242 :     t = (gettime_usec() - t) / nb_tests;
243 :     printf( "%s - sad8 %.3f usec sad=%d\n", cpu->name, t, s );
244 :     if (s!=3776) printf( "*** CRC ERROR! ***\n" );
245 :    
246 :     t = gettime_usec();
247 :     emms();
248 :     for(tst=0; tst<nb_tests; ++tst) s = sad16(Cur, Ref1, 16, -1);
249 :     emms();
250 :     t = (gettime_usec() - t) / nb_tests;
251 :     printf( "%s - sad16 %.3f usec sad=%d\n", cpu->name, t, s );
252 :     if (s!=27214) printf( "*** CRC ERROR! ***\n" );
253 :    
254 :     t = gettime_usec();
255 :     emms();
256 :     for(tst=0; tst<nb_tests; ++tst) s = sad16bi(Cur, Ref1, Ref2, 16);
257 :     emms();
258 :     t = (gettime_usec() - t) / nb_tests;
259 :     printf( "%s - sad16bi %.3f usec sad=%d\n", cpu->name, t, s );
260 :     if (s!=26274) printf( "*** CRC ERROR! ***\n" );
261 :    
262 :     t = gettime_usec();
263 :     emms();
264 :     for(tst=0; tst<nb_tests; ++tst) s = dev16(Cur, 16);
265 :     emms();
266 :     t = (gettime_usec() - t) / nb_tests;
267 :     printf( "%s - dev16 %.3f usec sad=%d\n", cpu->name, t, s );
268 :     if (s!=3344) printf( "*** CRC ERROR! ***\n" );
269 :    
270 :     printf( " --- \n" );
271 :     }
272 :     }
273 :    
274 :     /*********************************************************************
275 :     * test interpolation
276 :     *********************************************************************/
277 :    
278 :     #define ENTER \
279 :     for(i=0; i<16*8; ++i) Dst[i] = 0; \
280 :     t = gettime_usec(); \
281 :     emms();
282 :    
283 :     #define LEAVE \
284 :     emms(); \
285 :     t = (gettime_usec() - t) / nb_tests; \
286 :     iCrc = 0; \
287 :     for(i=0; i<16*8; ++i) { iCrc += Dst[i]^i; }
288 :    
289 :     #define TEST_MB(FUNC, R) \
290 :     ENTER \
291 :     for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst, Src0, 16, (R)); \
292 :     LEAVE
293 :    
294 :     #define TEST_MB2(FUNC) \
295 :     ENTER \
296 :     for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst, Src0, 16); \
297 :     LEAVE
298 :    
299 :    
300 :     void test_mb()
301 :     {
302 :     const int nb_tests = 2000*speed_ref;
303 :     CPU *cpu;
304 :     const uint8_t Src0[16*9] = {
305 : edgomez 1053 /* try to have every possible combinaison of rounding... */
306 : Isibaar 225 0, 0, 1, 0, 2, 0, 3, 0, 4 ,0,0,0, 0,0,0,0
307 :     , 0, 1, 1, 1, 2, 1, 3, 1, 3 ,0,0,0, 0,0,0,0
308 :     , 0, 2, 1, 2, 2, 2, 3, 2, 2 ,0,0,0, 0,0,0,0
309 :     , 0, 3, 1, 3, 2, 3, 3, 3, 1 ,0,0,0, 0,0,0,0
310 :     , 1, 3, 0, 2, 1, 0, 2, 3, 4 ,0,0,0, 0,0,0,0
311 :     , 2, 2, 1, 2, 0, 1, 3, 5, 3 ,0,0,0, 0,0,0,0
312 :     , 3, 1, 2, 3, 1, 2, 2, 6, 2 ,0,0,0, 0,0,0,0
313 :     , 1, 0, 1, 3, 0, 3, 1, 6, 1 ,0,0,0, 0,0,0,0
314 :     , 4, 3, 2, 1, 2, 3, 4, 0, 3 ,0,0,0, 0,0,0,0
315 :     };
316 :     uint8_t Dst[16*8] = {0};
317 :    
318 :     printf( "\n === test block motion ===\n" );
319 :    
320 :     for(cpu = cpu_list; cpu->name!=0; ++cpu)
321 :     {
322 :     double t;
323 :     int tst, i, iCrc;
324 :    
325 :     if (!init_cpu(cpu))
326 :     continue;
327 :    
328 :     TEST_MB(interpolate8x8_halfpel_h, 0);
329 :     printf( "%s - interp- h-round0 %.3f usec iCrc=%d\n", cpu->name, t, iCrc );
330 :     if (iCrc!=8107) printf( "*** CRC ERROR! ***\n" );
331 :    
332 :     TEST_MB(interpolate8x8_halfpel_h, 1);
333 :     printf( "%s - round1 %.3f usec iCrc=%d\n", cpu->name, t, iCrc );
334 :     if (iCrc!=8100) printf( "*** CRC ERROR! ***\n" );
335 :    
336 :    
337 :     TEST_MB(interpolate8x8_halfpel_v, 0);
338 :     printf( "%s - interp- v-round0 %.3f usec iCrc=%d\n", cpu->name, t, iCrc );
339 :     if (iCrc!=8108) printf( "*** CRC ERROR! ***\n" );
340 :    
341 :     TEST_MB(interpolate8x8_halfpel_v, 1);
342 :     printf( "%s - round1 %.3f usec iCrc=%d\n", cpu->name, t, iCrc );
343 :     if (iCrc!=8105) printf( "*** CRC ERROR! ***\n" );
344 :    
345 :    
346 :     TEST_MB(interpolate8x8_halfpel_hv, 0);
347 :     printf( "%s - interp-hv-round0 %.3f usec iCrc=%d\n", cpu->name, t, iCrc );
348 :     if (iCrc!=8112) printf( "*** CRC ERROR! ***\n" );
349 :    
350 :     TEST_MB(interpolate8x8_halfpel_hv, 1);
351 :     printf( "%s - round1 %.3f usec iCrc=%d\n", cpu->name, t, iCrc );
352 :     if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" );
353 :    
354 : Isibaar 262
355 : edgomez 1053 /* this is a new function, as of 06.06.2002 */
356 : Isibaar 262 #if 0
357 :     TEST_MB2(interpolate8x8_avrg);
358 :     printf( "%s - interpolate8x8_c %.3f usec iCrc=%d\n", cpu->name, t, iCrc );
359 :     if (iCrc!=8107) printf( "*** CRC ERROR! ***\n" );
360 :     #endif
361 :    
362 : Isibaar 225 printf( " --- \n" );
363 :     }
364 :     }
365 :    
366 :     /*********************************************************************
367 :     * test transfer
368 :     *********************************************************************/
369 :    
370 :     #define INIT_TRANSFER \
371 :     for(i=0; i<8*32; ++i) { \
372 :     Src8[i] = i; Src16[i] = i; \
373 :     Dst8[i] = 0; Dst16[i] = 0; \
374 :     Ref1[i] = i^0x27; \
375 :     Ref2[i] = i^0x51; \
376 :     }
377 :    
378 :     #define TEST_TRANSFER_BEGIN(DST) \
379 :     INIT_TRANSFER \
380 :     overhead = -gettime_usec(); \
381 :     for(tst=0; tst<nb_tests; ++tst) { \
382 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\
383 :     } \
384 :     overhead += gettime_usec(); \
385 :     t = gettime_usec(); \
386 :     emms(); \
387 :     for(tst=0; tst<nb_tests; ++tst) { \
388 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;
389 :    
390 :    
391 :     #define TEST_TRANSFER_END(DST) \
392 :     } \
393 :     emms(); \
394 :     t = (gettime_usec()-t -overhead) / nb_tests;\
395 :     s = 0; for(i=0; i<8*32; ++i) { s += (DST)[i]^i; }
396 :    
397 :     #define TEST_TRANSFER(FUNC, DST, SRC) \
398 :     TEST_TRANSFER_BEGIN(DST); \
399 :     (FUNC)((DST), (SRC), 32); \
400 :     TEST_TRANSFER_END(DST)
401 :    
402 :    
403 :     #define TEST_TRANSFER2_BEGIN(DST, SRC) \
404 :     INIT_TRANSFER \
405 :     overhead = -gettime_usec(); \
406 :     for(tst=0; tst<nb_tests; ++tst) { \
407 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\
408 :     for(i=0; i<8*32; ++i) (SRC)[i] = i^0x3e;\
409 :     } \
410 :     overhead += gettime_usec(); \
411 :     t = gettime_usec(); \
412 :     emms(); \
413 :     for(tst=0; tst<nb_tests; ++tst) { \
414 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\
415 :     for(i=0; i<8*32; ++i) (SRC)[i] = i^0x3e;
416 :    
417 :     #define TEST_TRANSFER2_END(DST) \
418 :     } \
419 :     emms(); \
420 :     t = (gettime_usec()-t -overhead) / nb_tests;\
421 :     s = 0; for(i=0; i<8*32; ++i) { s += (DST)[i]; }
422 :    
423 :     #define TEST_TRANSFER2(FUNC, DST, SRC, R1) \
424 :     TEST_TRANSFER2_BEGIN(DST,SRC); \
425 :     (FUNC)((DST), (SRC), (R1), 32); \
426 :     TEST_TRANSFER2_END(DST)
427 :    
428 :     #define TEST_TRANSFER3(FUNC, DST, SRC, R1, R2)\
429 :     TEST_TRANSFER_BEGIN(DST); \
430 :     (FUNC)((DST), (SRC), (R1), (R2), 32); \
431 :     TEST_TRANSFER_END(DST)
432 :    
433 :     void test_transfer()
434 :     {
435 :     const int nb_tests = 4000*speed_ref;
436 :     int i;
437 :     CPU *cpu;
438 :     uint8_t Src8[8*32], Dst8[8*32], Ref1[8*32], Ref2[8*32];
439 :     int16_t Src16[8*32], Dst16[8*32];
440 :    
441 :     printf( "\n === test transfer ===\n" );
442 :    
443 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
444 :     {
445 :     double t, overhead;
446 :     int tst, s;
447 :    
448 :     if (!init_cpu(cpu))
449 :     continue;
450 :    
451 :     TEST_TRANSFER(transfer_8to16copy, Dst16, Src8);
452 :     printf( "%s - 8to16 %.3f usec crc=%d\n", cpu->name, t, s );
453 :     if (s!=28288) printf( "*** CRC ERROR! ***\n" );
454 :    
455 :     TEST_TRANSFER(transfer_16to8copy, Dst8, Src16);
456 :     printf( "%s - 16to8 %.3f usec crc=%d\n", cpu->name, t, s );
457 :     if (s!=28288) printf( "*** CRC ERROR! ***\n" );
458 :    
459 :     TEST_TRANSFER(transfer8x8_copy, Dst8, Src8);
460 :     printf( "%s - 8to8 %.3f usec crc=%d\n", cpu->name, t, s );
461 :     if (s!=20352) printf( "*** CRC ERROR! ***\n" );
462 :    
463 :     TEST_TRANSFER(transfer_16to8add, Dst8, Src16);
464 :     printf( "%s - 16to8add %.3f usec crc=%d\n", cpu->name, t, s );
465 :     if (s!=25536) printf( "*** CRC ERROR! ***\n" );
466 :    
467 :     TEST_TRANSFER2(transfer_8to16sub, Dst16, Src8, Ref1);
468 :     printf( "%s - 8to16sub %.3f usec crc1=%d ", cpu->name, t, s );
469 :     if (s!=28064) printf( "*** CRC ERROR! ***\n" );
470 :     s = 0; for(i=0; i<8*32; ++i) { s += (Src8[i]-Ref1[i])&i; }
471 :     printf( "crc2=%d\n", s);
472 :     if (s!=16256) printf( "*** CRC ERROR! ***\n" );
473 : Isibaar 262 #if 1
474 : Isibaar 225 TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2);
475 :     printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s );
476 :     if (s!=20384) printf( "*** CRC ERROR! ***\n" );
477 : edgomez 851 // for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]);
478 :     // printf("\n");
479 : Isibaar 262 #endif
480 : Isibaar 225 printf( " --- \n" );
481 :     }
482 :     }
483 :    
484 :     /*********************************************************************
485 :     * test quantization
486 :     *********************************************************************/
487 :    
488 : Isibaar 262 #define TEST_QUANT(FUNC, DST, SRC) \
489 :     t = gettime_usec(); \
490 :     for(s=0,qm=1; qm<=255; ++qm) { \
491 :     for(i=0; i<8*8; ++i) Quant[i] = qm; \
492 :     set_inter_matrix( Quant ); \
493 :     emms(); \
494 :     for(q=1; q<=max_Q; ++q) { \
495 :     for(tst=0; tst<nb_tests; ++tst) \
496 :     (FUNC)((DST), (SRC), q); \
497 :     for(i=0; i<64; ++i) s+=(DST)[i]^i^qm; \
498 :     } \
499 :     emms(); \
500 :     } \
501 :     t = (gettime_usec()-t-overhead)/nb_tests/qm;\
502 :     s = (s&0xffff)^(s>>16)
503 : Isibaar 225
504 : Isibaar 262 #define TEST_QUANT2(FUNC, DST, SRC) \
505 :     t = gettime_usec(); \
506 :     for(s=0,qm=1; qm<=255; ++qm) { \
507 :     for(i=0; i<8*8; ++i) Quant[i] = qm; \
508 :     set_intra_matrix( Quant ); \
509 :     emms(); \
510 :     for(q=1; q<=max_Q; ++q) { \
511 :     for(tst=0; tst<nb_tests; ++tst) \
512 :     (FUNC)((DST), (SRC), q, q); \
513 :     for(i=0; i<64; ++i) s+=(DST)[i]^i^qm; \
514 :     } \
515 :     emms(); \
516 :     } \
517 :     t = (gettime_usec()-t-overhead)/nb_tests/qm;\
518 :     s = (s&0xffff)^(s>>16)
519 : Isibaar 225
520 :     void test_quant()
521 :     {
522 : Isibaar 262 const int nb_tests = 1*speed_ref;
523 : Isibaar 225 const int max_Q = 31;
524 : Isibaar 262 int i, qm;
525 : Isibaar 225 CPU *cpu;
526 :     int16_t Src[8*8], Dst[8*8];
527 : Isibaar 262 uint8_t Quant[8*8];
528 : Isibaar 225
529 :     printf( "\n ===== test quant =====\n" );
530 :    
531 : edgomez 1053 /* we deliberately enfringe the norm's specified range [-127,127], */
532 :     /* to test the robustness of the iquant module */
533 : Isibaar 225 for(i=0; i<64; ++i) {
534 : Isibaar 262 Src[i] = 1 + (i-32) * (i&6);
535 : Isibaar 225 Dst[i] = 0;
536 :     }
537 :    
538 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
539 :     {
540 :     double t, overhead;
541 : Isibaar 262 int tst, q;
542 :     uint32_t s;
543 : Isibaar 225
544 :     if (!init_cpu(cpu))
545 :     continue;
546 :    
547 :     overhead = -gettime_usec();
548 : Isibaar 262 for(s=0,qm=1; qm<=255; ++qm) {
549 :     for(i=0; i<8*8; ++i) Quant[i] = qm;
550 :     set_inter_matrix( Quant );
551 :     for(q=1; q<=max_Q; ++q)
552 :     for(i=0; i<64; ++i) s+=Dst[i]^i^qm;
553 :     }
554 : Isibaar 225 overhead += gettime_usec();
555 :    
556 : Isibaar 262 #if 1
557 :     TEST_QUANT2(quant4_intra, Dst, Src);
558 : Isibaar 225 printf( "%s - quant4_intra %.3f usec crc=%d\n", cpu->name, t, s );
559 : Isibaar 262 if (s!=29809) printf( "*** CRC ERROR! ***\n" );
560 : Isibaar 225
561 :     TEST_QUANT(quant4_inter, Dst, Src);
562 :     printf( "%s - quant4_inter %.3f usec crc=%d\n", cpu->name, t, s );
563 : Isibaar 262 if (s!=12574) printf( "*** CRC ERROR! ***\n" );
564 :     #endif
565 :     #if 1
566 :     TEST_QUANT2(dequant4_intra, Dst, Src);
567 : Isibaar 225 printf( "%s - dequant4_intra %.3f usec crc=%d\n", cpu->name, t, s );
568 : Isibaar 262 if (s!=24052) printf( "*** CRC ERROR! ***\n" );
569 : Isibaar 225
570 :     TEST_QUANT(dequant4_inter, Dst, Src);
571 :     printf( "%s - dequant4_inter %.3f usec crc=%d\n", cpu->name, t, s );
572 : Isibaar 262 if (s!=63847) printf( "*** CRC ERROR! ***\n" );
573 :     #endif
574 :     #if 1
575 :     TEST_QUANT2(quant_intra, Dst, Src);
576 : Isibaar 225 printf( "%s - quant_intra %.3f usec crc=%d\n", cpu->name, t, s );
577 : Isibaar 262 if (s!=25662) printf( "*** CRC ERROR! ***\n" );
578 : Isibaar 225
579 :     TEST_QUANT(quant_inter, Dst, Src);
580 :     printf( "%s - quant_inter %.3f usec crc=%d\n", cpu->name, t, s );
581 : Isibaar 262 if (s!=23972) printf( "*** CRC ERROR! ***\n" );
582 :     #endif
583 :     #if 1
584 :     TEST_QUANT2(dequant_intra, Dst, Src);
585 : Isibaar 225 printf( "%s - dequant_intra %.3f usec crc=%d\n", cpu->name, t, s );
586 : Isibaar 262 if (s!=49900) printf( "*** CRC ERROR! ***\n" );
587 : Isibaar 225
588 :     TEST_QUANT(dequant_inter, Dst, Src);
589 :     printf( "%s - dequant_inter %.3f usec crc=%d\n", cpu->name, t, s );
590 : Isibaar 262 if (s!=48899) printf( "*** CRC ERROR! ***\n" );
591 :     #endif
592 : Isibaar 225 printf( " --- \n" );
593 :     }
594 :     }
595 :    
596 :     /*********************************************************************
597 :     * test non-zero AC counting
598 :     *********************************************************************/
599 :    
600 :     #define TEST_CBP(FUNC, SRC) \
601 :     t = gettime_usec(); \
602 :     emms(); \
603 :     for(tst=0; tst<nb_tests; ++tst) { \
604 :     cbp = (FUNC)((SRC)); \
605 :     } \
606 :     emms(); \
607 :     t = (gettime_usec()-t ) / nb_tests;
608 :    
609 :     void test_cbp()
610 :     {
611 :     const int nb_tests = 10000*speed_ref;
612 :     int i;
613 :     CPU *cpu;
614 :     int16_t Src1[6*64], Src2[6*64], Src3[6*64], Src4[6*64];
615 :    
616 :     printf( "\n ===== test cbp =====\n" );
617 :    
618 :     for(i=0; i<6*64; ++i) {
619 : edgomez 1053 Src1[i] = (i*i*3/8192)&(i/64)&1; /* 'random' */
620 :     Src2[i] = (i<3*64); /* half-full */
621 : Isibaar 225 Src3[i] = ((i+32)>3*64);
622 :     Src4[i] = (i==(3*64+2) || i==(5*64+9));
623 :     }
624 :    
625 :     for(cpu = cpu_short_list2; cpu->name!=0; ++cpu)
626 :     {
627 :     double t;
628 :     int tst, cbp;
629 :    
630 :     if (!init_cpu(cpu))
631 :     continue;
632 :    
633 :     TEST_CBP(calc_cbp, Src1);
634 :     printf( "%s - calc_cbp#1 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
635 :     if (cbp!=0x15) printf( "*** CRC ERROR! ***\n" );
636 :     TEST_CBP(calc_cbp, Src2);
637 :     printf( "%s - calc_cbp#2 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
638 :     if (cbp!=0x38) printf( "*** CRC ERROR! ***\n" );
639 :     TEST_CBP(calc_cbp, Src3);
640 :     printf( "%s - calc_cbp#3 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
641 :     if (cbp!=0x0f) printf( "*** CRC ERROR! ***\n" );
642 :     TEST_CBP(calc_cbp, Src4);
643 :     printf( "%s - calc_cbp#4 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
644 :     if (cbp!=0x05) printf( "*** CRC ERROR! ***\n" );
645 :     printf( " --- \n" );
646 :     }
647 :     }
648 :    
649 :     /*********************************************************************
650 : Isibaar 262 * fdct/idct IEEE1180 compliance
651 :     *********************************************************************/
652 :    
653 :     typedef struct {
654 :     long Errors[64];
655 :     long Sqr_Errors[64];
656 :     long Max_Errors[64];
657 :     long Nb;
658 :     } STATS_8x8;
659 :    
660 :     void init_stats(STATS_8x8 *S)
661 :     {
662 :     int i;
663 :     for(i=0; i<64; ++i) {
664 :     S->Errors[i] = 0;
665 :     S->Sqr_Errors[i] = 0;
666 :     S->Max_Errors[i] = 0;
667 :     }
668 :     S->Nb = 0;
669 :     }
670 :    
671 :     void store_stats(STATS_8x8 *S, short Blk[64], short Ref[64])
672 :     {
673 :     int i;
674 :     for(i=0; i<64; ++i)
675 :     {
676 :     short Err = Blk[i] - Ref[i];
677 :     S->Errors[i] += Err;
678 :     S->Sqr_Errors[i] += Err * Err;
679 :     if (Err<0) Err = -Err;
680 :     if (S->Max_Errors[i]<Err)
681 :     S->Max_Errors[i] = Err;
682 :     }
683 :     S->Nb++;
684 :     }
685 :    
686 :     void print_stats(STATS_8x8 *S)
687 :     {
688 :     int i;
689 :     double Norm;
690 :    
691 :     assert(S->Nb>0);
692 :     Norm = 1. / (double)S->Nb;
693 :     printf("\n== Max absolute values of errors ==\n");
694 :     for(i=0; i<64; i++) {
695 :     printf(" %4ld", S->Max_Errors[i]);
696 :     if ((i&7)==7) printf("\n");
697 :     }
698 :    
699 :     printf("\n== Mean square errors ==\n");
700 :     for(i=0; i<64; i++)
701 :     {
702 :     double Err = Norm * (double)S->Sqr_Errors[i];
703 :     printf(" %.3f", Err);
704 :     if ((i&7)==7) printf("\n");
705 :     }
706 :    
707 :     printf("\n== Mean errors ==\n");
708 :     for(i=0; i<64; i++)
709 :     {
710 :     double Err = Norm * (double)S->Errors[i];
711 :     printf(" %.3f", Err);
712 :     if ((i&7)==7) printf("\n");
713 :     }
714 :     printf("\n");
715 :     }
716 :    
717 :     static const char *CHECK(double v, double l) {
718 :     if (fabs(v)<=l) return "ok";
719 :     else return "FAIL!";
720 :     }
721 :    
722 :     void report_stats(STATS_8x8 *S, const double *Limits)
723 :     {
724 :     int i;
725 :     double Norm, PE, PMSE, OMSE, PME, OME;
726 :    
727 :     assert(S->Nb>0);
728 :     Norm = 1. / (double)S->Nb;
729 :     PE = 0.;
730 :     for(i=0; i<64; i++) {
731 :     if (PE<S->Max_Errors[i])
732 :     PE = S->Max_Errors[i];
733 :     }
734 :    
735 :     PMSE = 0.;
736 :     OMSE = 0.;
737 :     for(i=0; i<64; i++)
738 :     {
739 :     double Err = Norm * (double)S->Sqr_Errors[i];
740 :     OMSE += Err;
741 :     if (PMSE < Err) PMSE = Err;
742 :     }
743 :     OMSE /= 64.;
744 :    
745 :     PME = 0.;
746 :     OME = 0.;
747 :     for(i=0; i<64; i++)
748 :     {
749 :     double Err = Norm * (double)S->Errors[i];
750 :     OME += Err;
751 :     Err = fabs(Err);
752 :     if (PME < Err) PME = Err;
753 :     }
754 :     OME /= 64.;
755 :    
756 :     printf( "Peak error: %4.4f\n", PE );
757 :     printf( "Peak MSE: %4.4f\n", PMSE );
758 :     printf( "Overall MSE: %4.4f\n", OMSE );
759 :     printf( "Peak ME: %4.4f\n", PME );
760 :     printf( "Overall ME: %4.4f\n", OME );
761 :    
762 :     if (Limits!=0)
763 :     {
764 :     printf( "[PE<=%.4f %s] ", Limits[0], CHECK(PE, Limits[0]) );
765 :     printf( "\n" );
766 :     printf( "[PMSE<=%.4f %s]", Limits[1], CHECK(PMSE, Limits[1]) );
767 :     printf( "[OMSE<=%.4f %s]", Limits[2], CHECK(OMSE, Limits[2]) );
768 :     printf( "\n" );
769 :     printf( "[PME<=%.4f %s] ", Limits[3], CHECK(PME , Limits[3]) );
770 :     printf( "[OME<=%.4f %s] ", Limits[4], CHECK(OME , Limits[4]) );
771 :     printf( "\n" );
772 :     }
773 :     }
774 :    
775 : edgomez 1053 ///* ////////////////////////////////////////////////////// */
776 : Isibaar 262 /* Pseudo-random generator specified by IEEE 1180 */
777 :    
778 :     static long ieee_seed = 1;
779 :     static void ieee_reseed(long s) {
780 :     ieee_seed = s;
781 :     }
782 :     static long ieee_rand(int Min, int Max)
783 :     {
784 :     static double z = (double) 0x7fffffff;
785 :    
786 :     long i,j;
787 :     double x;
788 :    
789 :     ieee_seed = (ieee_seed * 1103515245) + 12345;
790 :     i = ieee_seed & 0x7ffffffe;
791 :     x = ((double) i) / z;
792 :     x *= (Max-Min+1);
793 :     j = (long)x;
794 :     j = j + Min;
795 :     assert(j>=Min && j<=Max);
796 :     return (short)j;
797 :     }
798 :    
799 :     #define CLAMP(x, M) (x) = ((x)<-(M)) ? (-(M)) : ((x)>=(M) ? ((M)-1) : (x))
800 :    
801 :     static double Cos[8][8];
802 :     static void init_ref_dct()
803 :     {
804 :     int i, j;
805 :     for(i=0; i<8; i++)
806 :     {
807 :     double scale = (i == 0) ? sqrt(0.125) : 0.5;
808 :     for (j=0; j<8; j++)
809 :     Cos[i][j] = scale*cos( (M_PI/8.0)*i*(j + 0.5) );
810 :     }
811 :     }
812 :    
813 :     void ref_idct(short *M)
814 :     {
815 :     int i, j, k;
816 :     double Tmp[8][8];
817 :    
818 :     for(i=0; i<8; i++) {
819 :     for(j=0; j<8; j++)
820 :     {
821 :     double Sum = 0.0;
822 :     for (k=0; k<8; k++) Sum += Cos[k][j]*M[8*i+k];
823 :     Tmp[i][j] = Sum;
824 :     }
825 :     }
826 :     for(i=0; i<8; i++) {
827 :     for(j=0; j<8; j++) {
828 :     double Sum = 0.0;
829 :     for (k=0; k<8; k++) Sum += Cos[k][i]*Tmp[k][j];
830 :     M[8*i+j] = (short)floor(Sum + .5);
831 :     }
832 :     }
833 :     }
834 :    
835 :     void ref_fdct(short *M)
836 :     {
837 :     int i, j, k;
838 :     double Tmp[8][8];
839 :    
840 :     for(i=0; i<8; i++) {
841 :     for(j=0; j<8; j++)
842 :     {
843 :     double Sum = 0.0;
844 :     for (k=0; k<8; k++) Sum += Cos[j][k]*M[8*i+k];
845 :     Tmp[i][j] = Sum;
846 :     }
847 :     }
848 :     for(i=0; i<8; i++) {
849 :     for(j=0; j<8; j++) {
850 :     double Sum = 0.0;
851 :     for (k=0; k<8; k++) Sum += Cos[i][k]*Tmp[k][j];
852 :     M[8*i+j] = (short)floor(Sum + 0.5);
853 :     }
854 :     }
855 :     }
856 :    
857 :     void test_IEEE1180_compliance(int Min, int Max, int Sign)
858 :     {
859 :     static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 };
860 :     int Loops = 10000;
861 :     int i, m, n;
862 : edgomez 1053 short Blk0[64]; /* reference */
863 : Isibaar 262 short Blk[64], iBlk[64];
864 :     short Ref_FDCT[64];
865 :     short Ref_IDCT[64];
866 :    
867 : edgomez 1053 STATS_8x8 FStats; /* forward dct stats */
868 :     STATS_8x8 IStats; /* inverse dct stats */
869 : Isibaar 262
870 :     CPU *cpu;
871 :    
872 :     init_ref_dct();
873 :    
874 :     for(cpu = cpu_list; cpu->name!=0; ++cpu)
875 :     {
876 :     if (!init_cpu(cpu))
877 :     continue;
878 :    
879 :     printf( "\n===== IEEE test for %s ==== (Min=%d Max=%d Sign=%d Loops=%d)\n",
880 :     cpu->name, Min, Max, Sign, Loops);
881 :    
882 :     init_stats(&IStats);
883 :     init_stats(&FStats);
884 :    
885 :     ieee_reseed(1);
886 :     for(n=0; n<Loops; ++n)
887 :     {
888 :     for(i=0; i<64; ++i)
889 :     Blk0[i] = (short)ieee_rand(Min,Max) * Sign;
890 :    
891 : edgomez 1053 /* hmm, I'm not quite sure this is exactly */
892 :     /* the tests described in the norm. check... */
893 : Isibaar 262
894 :     memcpy(Ref_FDCT, Blk0, 64*sizeof(short));
895 :     ref_fdct(Ref_FDCT);
896 :     for(i=0; i<64; i++) CLAMP( Ref_FDCT[i], 2048 );
897 :    
898 :     memcpy(Blk, Blk0, 64*sizeof(short));
899 :     emms(); fdct(Blk); emms();
900 :     for(i=0; i<64; i++) CLAMP( Blk[i], 2048 );
901 :    
902 :     store_stats(&FStats, Blk, Ref_FDCT);
903 :    
904 :    
905 :     memcpy(Ref_IDCT, Ref_FDCT, 64*sizeof(short));
906 :     ref_idct(Ref_IDCT);
907 :     for (i=0; i<64; i++) CLAMP( Ref_IDCT[i], 256 );
908 :    
909 :     memcpy(iBlk, Ref_FDCT, 64*sizeof(short));
910 :     emms(); idct(iBlk); emms();
911 :     for(i=0; i<64; i++) CLAMP( iBlk[i], 256 );
912 :    
913 :     store_stats(&IStats, iBlk, Ref_IDCT);
914 :     }
915 :    
916 :    
917 :     printf( "\n -- FDCT report --\n" );
918 : edgomez 851 // print_stats(&FStats);
919 : edgomez 1053 report_stats(&FStats, 0); /* so far I know, IEEE1180 says nothing for fdct */
920 : Isibaar 262
921 :     for(i=0; i<64; i++) Blk[i] = 0;
922 :     emms(); fdct(Blk); emms();
923 :     for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;
924 :     printf( "FDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." );
925 :    
926 :     printf( "\n -- IDCT report --\n" );
927 : edgomez 851 // print_stats(&IStats);
928 : Isibaar 262 report_stats(&IStats, ILimits);
929 :    
930 :    
931 :     for(i=0; i<64; i++) Blk[i] = 0;
932 :     emms(); idct(Blk); emms();
933 :     for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;
934 :     printf( "IDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." );
935 :     }
936 :     }
937 :    
938 :    
939 :     void test_dct_saturation(int Min, int Max)
940 :     {
941 : edgomez 1053 /* test behaviour on input range fringe */
942 : Isibaar 262
943 :     int i, n, p;
944 :     CPU *cpu;
945 : edgomez 1053 // const short IDCT_MAX = 2047; /* 12bits input */
946 : edgomez 851 // const short IDCT_MIN = -2048;
947 : edgomez 1053 // const short IDCT_OUT = 256; /* 9bits ouput */
948 : Isibaar 262 const int Partitions = 4;
949 :     const int Loops = 10000 / Partitions;
950 :    
951 :     init_ref_dct();
952 :    
953 :     for(cpu = cpu_list; cpu->name!=0; ++cpu)
954 :     {
955 :     short Blk0[64], Blk[64];
956 :     STATS_8x8 Stats;
957 :    
958 :     if (!init_cpu(cpu))
959 :     continue;
960 :    
961 :     printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n",
962 :     cpu->name, Min, Max );
963 :    
964 : edgomez 1053 /* FDCT tests // */
965 : Isibaar 262
966 :     init_stats(&Stats);
967 :    
968 : edgomez 1053 /* test each computation channels separately */
969 : Isibaar 262 for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0;
970 :     ref_fdct(Blk0);
971 :     emms(); fdct(Blk); emms();
972 :     store_stats(&Stats, Blk, Blk0);
973 :    
974 :     for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Min : 0;
975 :     ref_fdct(Blk0);
976 :     emms(); fdct(Blk); emms();
977 :     store_stats(&Stats, Blk, Blk0);
978 :    
979 : edgomez 1053 /* randomly saturated inputs */
980 : Isibaar 262 for(p=0; p<Partitions; ++p)
981 :     {
982 :     for(n=0; n<Loops; ++n)
983 :     {
984 :     for(i=0; i<64; ++i)
985 :     Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? Max : Min;
986 :     ref_fdct(Blk0);
987 :     emms(); fdct(Blk); emms();
988 :     store_stats(&Stats, Blk, Blk0);
989 :     }
990 :     }
991 :     printf( "\n -- FDCT saturation report --\n" );
992 :     report_stats(&Stats, 0);
993 :    
994 :    
995 : edgomez 1053 /* IDCT tests // */
996 : Isibaar 262 #if 0
997 : edgomez 1053 /* no finished yet */
998 : Isibaar 262
999 :     init_stats(&Stats);
1000 :    
1001 : edgomez 1053 /* test each computation channel separately */
1002 : Isibaar 262 for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0;
1003 :     ref_idct(Blk0);
1004 :     emms(); idct(Blk); emms();
1005 :     for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }
1006 :     store_stats(&Stats, Blk, Blk0);
1007 :    
1008 :     for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MIN : 0;
1009 :     ref_idct(Blk0);
1010 :     emms(); idct(Blk); emms();
1011 :     for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }
1012 :     store_stats(&Stats, Blk, Blk0);
1013 :    
1014 : edgomez 1053 /* randomly saturated inputs */
1015 : Isibaar 262 for(p=0; p<Partitions; ++p)
1016 :     {
1017 :     for(n=0; n<Loops; ++n)
1018 :     {
1019 :     for(i=0; i<64; ++i)
1020 :     Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? IDCT_MAX : IDCT_MIN;
1021 :     ref_idct(Blk0);
1022 :     emms(); idct(Blk); emms();
1023 :     for(i=0; i<64; i++) { CLAMP(Blk0[i],IDCT_OUT); CLAMP(Blk[i],IDCT_OUT); }
1024 :     store_stats(&Stats, Blk, Blk0);
1025 :     }
1026 :     }
1027 :    
1028 :     printf( "\n -- IDCT saturation report --\n" );
1029 :     print_stats(&Stats);
1030 :     report_stats(&Stats, 0);
1031 :     #endif
1032 :     }
1033 :     }
1034 :    
1035 :     /*********************************************************************
1036 : Isibaar 225 * measure raw decoding speed
1037 :     *********************************************************************/
1038 :    
1039 :     void test_dec(const char *name, int width, int height, int with_chksum)
1040 :     {
1041 :     FILE *f = 0;
1042 :     void *dechandle = 0;
1043 :     int xerr;
1044 :     XVID_INIT_PARAM xinit;
1045 :     XVID_DEC_PARAM xparam;
1046 :     XVID_DEC_FRAME xframe;
1047 :     double t = 0.;
1048 :     int nb = 0;
1049 :     uint8_t *buf = 0;
1050 :     uint8_t *rgb_out = 0;
1051 :     int buf_size, pos;
1052 :     uint32_t chksum = 0;
1053 :    
1054 : Isibaar 262 xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;
1055 : Isibaar 225 xvid_init(NULL, 0, &xinit, NULL);
1056 :     printf( "API version: %d, core build:%d\n", xinit.api_version, xinit.core_build);
1057 :    
1058 :    
1059 :     xparam.width = width;
1060 :     xparam.height = height;
1061 :     xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);
1062 :     if (xerr!=XVID_ERR_OK) {
1063 :     printf("can't init decoder (err=%d)\n", xerr);
1064 :     return;
1065 :     }
1066 :     dechandle = xparam.handle;
1067 :    
1068 :    
1069 :     f = fopen(name, "rb");
1070 :     if (f==0) {
1071 :     printf( "can't open file '%s'\n", name);
1072 :     return;
1073 :     }
1074 :     fseek(f, 0, SEEK_END);
1075 :     buf_size = ftell(f);
1076 :     fseek(f, 0, SEEK_SET);
1077 :     if (buf_size<=0) {
1078 :     printf("error while stating file\n");
1079 :     goto End;
1080 :     }
1081 :     else printf( "Input size: %d\n", buf_size);
1082 :    
1083 : edgomez 1053 buf = malloc(buf_size); /* should be enuf' */
1084 :     rgb_out = calloc(4, width*height); /* <-room for _RGB24 */
1085 : Isibaar 225 if (buf==0 || rgb_out==0) {
1086 :     printf( "malloc failed!\n" );
1087 :     goto End;
1088 :     }
1089 :    
1090 :     if (fread(buf, buf_size, 1, f)!=1) {
1091 :     printf( "file-read failed\n" );
1092 :     goto End;
1093 :     }
1094 :    
1095 :     nb = 0;
1096 :     pos = 0;
1097 :     t = -gettime_usec();
1098 :     while(1) {
1099 :     xframe.bitstream = buf + pos;
1100 :     xframe.length = buf_size - pos;
1101 :     xframe.image = rgb_out;
1102 :     xframe.stride = width;
1103 :     xframe.colorspace = XVID_CSP_RGB24;
1104 :     xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);
1105 :     nb++;
1106 :     pos += xframe.length;
1107 :     if (with_chksum) {
1108 :     int k = width*height;
1109 :     uint32_t *ptr = (uint32_t *)rgb_out;
1110 :     while(k-->0) chksum += *ptr++;
1111 :     }
1112 :     if (pos==buf_size)
1113 :     break;
1114 :     if (xerr!=XVID_ERR_OK) {
1115 :     printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);
1116 :     break;
1117 :     }
1118 :     }
1119 :     t += gettime_usec();
1120 :     if (t>0.)
1121 :     printf( "%d frames decoded in %.3f s -> %.1f FPS\n", nb, t*1.e-6f, (float)(nb*1.e6f/t) );
1122 :     if (with_chksum)
1123 :     printf("checksum: 0x%.8x\n", chksum);
1124 :    
1125 :     End:
1126 :     if (rgb_out!=0) free(rgb_out);
1127 :     if (buf!=0) free(buf);
1128 :     if (dechandle!=0) {
1129 :     xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);
1130 :     if (xerr!=XVID_ERR_OK)
1131 :     printf("destroy-decoder failed (err=%d)!\n", xerr);
1132 :     }
1133 :     if (f!=0) fclose(f);
1134 :     }
1135 :    
1136 :     /*********************************************************************
1137 :     * non-regression tests
1138 :     *********************************************************************/
1139 :    
1140 :     void test_bugs1()
1141 :     {
1142 :     CPU *cpu;
1143 :    
1144 :     printf( "\n ===== (de)quant4_intra saturation bug? =====\n" );
1145 :    
1146 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
1147 :     {
1148 :     int i;
1149 :     int16_t Src[8*8], Dst[8*8];
1150 :    
1151 :     if (!init_cpu(cpu))
1152 :     continue;
1153 :    
1154 :     for(i=0; i<64; ++i) Src[i] = i-32;
1155 :     set_intra_matrix( get_default_intra_matrix() );
1156 : Isibaar 262 dequant4_intra(Dst, Src, 31, 5);
1157 : Isibaar 225 printf( "dequant4_intra with CPU=%s: ", cpu->name);
1158 :     printf( " Out[]= " );
1159 :     for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
1160 :     printf( "\n" );
1161 :     }
1162 :    
1163 :     printf( "\n ===== (de)quant4_inter saturation bug? =====\n" );
1164 :    
1165 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
1166 :     {
1167 :     int i;
1168 :     int16_t Src[8*8], Dst[8*8];
1169 :    
1170 :     if (!init_cpu(cpu))
1171 :     continue;
1172 :    
1173 :     for(i=0; i<64; ++i) Src[i] = i-32;
1174 :     set_inter_matrix( get_default_inter_matrix() );
1175 : Isibaar 262 dequant4_inter(Dst, Src, 31);
1176 : Isibaar 225 printf( "dequant4_inter with CPU=%s: ", cpu->name);
1177 :     printf( " Out[]= " );
1178 :     for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
1179 :     printf( "\n" );
1180 :     }
1181 :     }
1182 :    
1183 :     void test_dct_precision_diffs()
1184 :     {
1185 :     CPU *cpu;
1186 :     short Blk[8*8], Blk0[8*8];
1187 :    
1188 : Isibaar 262 printf( "\n ===== fdct/idct precision diffs =====\n" );
1189 : Isibaar 225
1190 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
1191 :     {
1192 :     int i;
1193 :    
1194 :     if (!init_cpu(cpu))
1195 :     continue;
1196 :    
1197 :     for(i=0; i<8*8; ++i) {
1198 :     Blk0[i] = (i*7-i*i) & 0x7f;
1199 :     Blk[i] = Blk0[i];
1200 :     }
1201 :    
1202 :     fdct(Blk);
1203 :     idct(Blk);
1204 :     printf( " fdct+idct diffs with CPU=%s: \n", cpu->name );
1205 :     for(i=0; i<8; ++i) {
1206 :     int j;
1207 :     for(j=0; j<8; ++j) printf( " %d ", Blk[i*8+j]-Blk0[i*8+j]);
1208 :     printf("\n");
1209 :     }
1210 :     printf("\n");
1211 :     }
1212 :     }
1213 :    
1214 : Isibaar 262 void test_quant_bug()
1215 :     {
1216 :     const int max_Q = 31;
1217 :     int i, n, qm, q;
1218 :     CPU *cpu;
1219 :     int16_t Src[8*8], Dst[8*8];
1220 :     uint8_t Quant[8*8];
1221 :     CPU cpu_bug_list[] = { { "PLAINC", 0 }, { "MMX ", XVID_CPU_MMX }, {0,0} };
1222 :     uint16_t Crcs_Inter[2][32];
1223 :     uint16_t Crcs_Intra[2][32];
1224 :     printf( "\n ===== test MPEG4-quantize bug =====\n" );
1225 : Isibaar 225
1226 : Isibaar 262 for(i=0; i<64; ++i) Src[i] = 2048*(i-32)/32;
1227 :    
1228 :     #if 1
1229 :     for(qm=1; qm<=255; ++qm)
1230 :     {
1231 :     for(i=0; i<8*8; ++i) Quant[i] = qm;
1232 :     set_inter_matrix( Quant );
1233 :    
1234 :     for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n)
1235 :     {
1236 :     uint16_t s;
1237 :    
1238 :     if (!init_cpu(cpu))
1239 :     continue;
1240 :    
1241 :     for(q=1; q<=max_Q; ++q) {
1242 :     emms();
1243 :     quant4_inter( Dst, Src, q );
1244 :     emms();
1245 :     for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i;
1246 :     Crcs_Inter[n][q] = s;
1247 :     }
1248 :     }
1249 :    
1250 :     for(q=1; q<=max_Q; ++q)
1251 :     for(i=0; i<n-1; ++i)
1252 :     if (Crcs_Inter[i][q]!=Crcs_Inter[i+1][q])
1253 :     printf( "Discrepancy Inter: qm=%d, q=%d -> %d/%d !\n",
1254 :     qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]);
1255 :     }
1256 :     #endif
1257 :    
1258 :     #if 1
1259 :     for(qm=1; qm<=255; ++qm)
1260 :     {
1261 :     for(i=0; i<8*8; ++i) Quant[i] = qm;
1262 :     set_intra_matrix( Quant );
1263 :    
1264 :     for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n)
1265 :     {
1266 :     uint16_t s;
1267 :    
1268 :     if (!init_cpu(cpu))
1269 :     continue;
1270 :    
1271 :     for(q=1; q<=max_Q; ++q) {
1272 :     emms();
1273 :     quant4_intra( Dst, Src, q, q);
1274 :     emms();
1275 :     for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i;
1276 :     Crcs_Intra[n][q] = s;
1277 :     }
1278 :     }
1279 :    
1280 :     for(q=1; q<=max_Q; ++q)
1281 :     for(i=0; i<n-1; ++i)
1282 :     if (Crcs_Intra[i][q]!=Crcs_Intra[i+1][q])
1283 :     printf( "Discrepancy Intra: qm=%d, q=%d -> %d/%d!\n",
1284 :     qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]);
1285 :     }
1286 :     #endif
1287 :     }
1288 :    
1289 : Isibaar 225 /*********************************************************************
1290 :     * main
1291 :     *********************************************************************/
1292 :    
1293 :     int main(int argc, char *argv[])
1294 :     {
1295 :     int what = 0;
1296 :     if (argc>1) what = atoi(argv[1]);
1297 :     if (what==0 || what==1) test_dct();
1298 :     if (what==0 || what==2) test_mb();
1299 :     if (what==0 || what==3) test_sad();
1300 :     if (what==0 || what==4) test_transfer();
1301 :     if (what==0 || what==5) test_quant();
1302 :     if (what==0 || what==6) test_cbp();
1303 :    
1304 : Isibaar 262 if (what==7) {
1305 :     test_IEEE1180_compliance(-256, 255, 1);
1306 :     #if 0
1307 :     test_IEEE1180_compliance(-256, 255,-1);
1308 :     test_IEEE1180_compliance( -5, 5, 1);
1309 :     test_IEEE1180_compliance( -5, 5,-1);
1310 :     test_IEEE1180_compliance(-300, 300, 1);
1311 :     test_IEEE1180_compliance(-300, 300,-1);
1312 :     #endif
1313 :     }
1314 :     if (what==8) test_dct_saturation(-256, 255);
1315 :    
1316 :     if (what==9) {
1317 : Isibaar 225 int width, height;
1318 :     if (argc<5) {
1319 :     printf("usage: %s %d [bitstream] [width] [height]\n", argv[0], what);
1320 :     return 1;
1321 :     }
1322 :     width = atoi(argv[3]);
1323 :     height = atoi(argv[4]);
1324 :     test_dec(argv[2], width, height, (argc>5));
1325 :     }
1326 :    
1327 :     if (what==-1) {
1328 : Isibaar 262 test_dct_precision_diffs();
1329 : Isibaar 225 test_bugs1();
1330 :     }
1331 : Isibaar 262 if (what==-2)
1332 :     test_quant_bug();
1333 :    
1334 : Isibaar 225 return 0;
1335 :     }
1336 :    
1337 :     /*********************************************************************
1338 :     * 'Reference' output (except for timing) on a PIII 1.13Ghz/linux
1339 :     *********************************************************************/
1340 : Isibaar 262
1341 :     /* as of 07/01/2002, there's a problem with mpeg4-quantization */
1342 : Isibaar 225 /*
1343 :    
1344 :     ===== test fdct/idct =====
1345 : Isibaar 262 PLAINC - 3.312 usec PSNR=13.291 MSE=3.000
1346 :     MMX - 0.591 usec PSNR=13.291 MSE=3.000
1347 :     MMXEXT - 0.577 usec PSNR=13.291 MSE=3.000
1348 :     SSE2 - 0.588 usec PSNR=13.291 MSE=3.000
1349 : Isibaar 225 3DNOW - skipped...
1350 :     3DNOWE - skipped...
1351 :    
1352 :     === test block motion ===
1353 : Isibaar 262 PLAINC - interp- h-round0 0.911 usec iCrc=8107
1354 :     PLAINC - round1 0.863 usec iCrc=8100
1355 :     PLAINC - interp- v-round0 0.860 usec iCrc=8108
1356 :     PLAINC - round1 0.857 usec iCrc=8105
1357 :     PLAINC - interp-hv-round0 2.103 usec iCrc=8112
1358 :     PLAINC - round1 2.050 usec iCrc=8103
1359 : Isibaar 225 ---
1360 :     MMX - interp- h-round0 0.105 usec iCrc=8107
1361 : Isibaar 262 MMX - round1 0.106 usec iCrc=8100
1362 : Isibaar 225 MMX - interp- v-round0 0.106 usec iCrc=8108
1363 : Isibaar 262 MMX - round1 0.106 usec iCrc=8105
1364 : Isibaar 225 MMX - interp-hv-round0 0.145 usec iCrc=8112
1365 :     MMX - round1 0.145 usec iCrc=8103
1366 :     ---
1367 : Isibaar 262 MMXEXT - interp- h-round0 0.028 usec iCrc=8107
1368 : Isibaar 225 MMXEXT - round1 0.041 usec iCrc=8100
1369 :     MMXEXT - interp- v-round0 0.027 usec iCrc=8108
1370 : Isibaar 262 MMXEXT - round1 0.041 usec iCrc=8105
1371 :     MMXEXT - interp-hv-round0 0.066 usec iCrc=8112
1372 :     MMXEXT - round1 0.065 usec iCrc=8103
1373 : Isibaar 225 ---
1374 : Isibaar 262 SSE2 - interp- h-round0 0.109 usec iCrc=8107
1375 : Isibaar 225 SSE2 - round1 0.105 usec iCrc=8100
1376 :     SSE2 - interp- v-round0 0.106 usec iCrc=8108
1377 : Isibaar 262 SSE2 - round1 0.109 usec iCrc=8105
1378 : Isibaar 225 SSE2 - interp-hv-round0 0.145 usec iCrc=8112
1379 :     SSE2 - round1 0.145 usec iCrc=8103
1380 :     ---
1381 :     3DNOW - skipped...
1382 :     3DNOWE - skipped...
1383 :    
1384 :     ====== test SAD ======
1385 : Isibaar 262 PLAINC - sad8 0.251 usec sad=3776
1386 :     PLAINC - sad16 1.601 usec sad=27214
1387 :     PLAINC - sad16bi 2.371 usec sad=26274
1388 :     PLAINC - dev16 1.564 usec sad=3344
1389 : Isibaar 225 ---
1390 :     MMX - sad8 0.057 usec sad=3776
1391 : Isibaar 262 MMX - sad16 0.182 usec sad=27214
1392 :     MMX - sad16bi 2.462 usec sad=26274
1393 :     MMX - dev16 0.311 usec sad=3344
1394 : Isibaar 225 ---
1395 :     MMXEXT - sad8 0.036 usec sad=3776
1396 : Isibaar 262 MMXEXT - sad16 0.109 usec sad=27214
1397 :     MMXEXT - sad16bi 0.143 usec sad=26274
1398 :     MMXEXT - dev16 0.192 usec sad=3344
1399 : Isibaar 225 ---
1400 :     SSE2 - sad8 0.057 usec sad=3776
1401 : Isibaar 262 SSE2 - sad16 0.179 usec sad=27214
1402 :     SSE2 - sad16bi 2.456 usec sad=26274
1403 :     SSE2 - dev16 0.321 usec sad=3344
1404 : Isibaar 225 ---
1405 :     3DNOW - skipped...
1406 :     3DNOWE - skipped...
1407 :    
1408 :     === test transfer ===
1409 : Isibaar 262 PLAINC - 8to16 0.151 usec crc=28288
1410 :     PLAINC - 16to8 1.113 usec crc=28288
1411 :     PLAINC - 8to8 0.043 usec crc=20352
1412 :     PLAINC - 16to8add 1.069 usec crc=25536
1413 :     PLAINC - 8to16sub 0.631 usec crc1=28064 crc2=16256
1414 :     PLAINC - 8to16sub2 0.597 usec crc=20384
1415 : Isibaar 225 ---
1416 : Isibaar 262 MMX - 8to16 0.032 usec crc=28288
1417 :     MMX - 16to8 0.024 usec crc=28288
1418 :     MMX - 8to8 0.020 usec crc=20352
1419 :     MMX - 16to8add 0.043 usec crc=25536
1420 :     MMX - 8to16sub 0.066 usec crc1=28064 crc2=16256
1421 :     MMX - 8to16sub2 0.111 usec crc=20384
1422 : Isibaar 225 ---
1423 :    
1424 :     ===== test quant =====
1425 : Isibaar 262 PLAINC - quant4_intra 74.248 usec crc=29809
1426 :     PLAINC - quant4_inter 70.850 usec crc=12574
1427 :     PLAINC - dequant4_intra 40.628 usec crc=24052
1428 :     PLAINC - dequant4_inter 45.691 usec crc=63847
1429 :     PLAINC - quant_intra 43.357 usec crc=25662
1430 :     PLAINC - quant_inter 33.410 usec crc=23972
1431 :     PLAINC - dequant_intra 36.384 usec crc=49900
1432 :     PLAINC - dequant_inter 48.930 usec crc=48899
1433 : Isibaar 225 ---
1434 : Isibaar 262 MMX - quant4_intra 7.445 usec crc=3459
1435 :     *** CRC ERROR! ***
1436 :     MMX - quant4_inter 5.384 usec crc=51072
1437 :     *** CRC ERROR! ***
1438 :     MMX - dequant4_intra 5.515 usec crc=24052
1439 :     MMX - dequant4_inter 7.745 usec crc=63847
1440 :     MMX - quant_intra 4.661 usec crc=25662
1441 :     MMX - quant_inter 4.406 usec crc=23972
1442 :     MMX - dequant_intra 4.928 usec crc=49900
1443 :     MMX - dequant_inter 4.532 usec crc=48899
1444 : Isibaar 225 ---
1445 :    
1446 :     ===== test cbp =====
1447 : Isibaar 262 PLAINC - calc_cbp#1 0.371 usec cbp=0x15
1448 :     PLAINC - calc_cbp#2 0.432 usec cbp=0x38
1449 :     PLAINC - calc_cbp#3 0.339 usec cbp=0xf
1450 :     PLAINC - calc_cbp#4 0.506 usec cbp=0x5
1451 : Isibaar 225 ---
1452 :     MMX - calc_cbp#1 0.136 usec cbp=0x15
1453 : Isibaar 262 MMX - calc_cbp#2 0.134 usec cbp=0x38
1454 :     MMX - calc_cbp#3 0.138 usec cbp=0xf
1455 : Isibaar 225 MMX - calc_cbp#4 0.135 usec cbp=0x5
1456 :     ---
1457 : Isibaar 262 SSE2 - calc_cbp#1 0.136 usec cbp=0x15
1458 :     SSE2 - calc_cbp#2 0.133 usec cbp=0x38
1459 :     SSE2 - calc_cbp#3 0.133 usec cbp=0xf
1460 :     SSE2 - calc_cbp#4 0.141 usec cbp=0x5
1461 : Isibaar 225 ---
1462 : Isibaar 262
1463 : Isibaar 225 */

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4