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

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