[svn] / trunk / xvidcore / examples / xvid_bench.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/examples/xvid_bench.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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