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

Annotation of /xvidcore/examples/xvid_bench.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download)

1 : Isibaar 1.1 /**************************************************************************
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 :     * bullet-proof...
26 :     *
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 :     const int speed_ref = 100; // on slow machines, decrease this value
59 :    
60 :     /*********************************************************************
61 :     * misc
62 :     *********************************************************************/
63 :    
64 :     /* returns time in micro-s*/
65 :     double gettime_usec()
66 :     {
67 :     struct timeval tv;
68 :     gettimeofday(&tv, 0);
69 : ia64p 1.2 return tv.tv_sec*1.0e6 + tv.tv_usec;
70 : Isibaar 1.1 }
71 :    
72 :     /* returns squared deviates (mean(v*v)-mean(v)^2) of a 8x8 block */
73 :     double sqr_dev(uint8_t v[8*8])
74 :     {
75 :     double sum=0.;
76 :     double sum2=0.;
77 :     int n;
78 :     for (n=0;n<8*8;n++)
79 :     {
80 :     sum += v[n];
81 :     sum2 += v[n]*v[n];
82 :     }
83 :     sum2 /= n;
84 :     sum /= n;
85 :     return sum2-sum*sum;
86 :     }
87 :    
88 :     /*********************************************************************
89 :     * cpu init
90 :     *********************************************************************/
91 :    
92 :     typedef struct {
93 :     const char *name;
94 :     unsigned int cpu;
95 :     } CPU;
96 :    
97 :     CPU cpu_list[] =
98 :     { { "PLAINC", 0 }
99 :     , { "MMX ", XVID_CPU_MMX }
100 :     , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
101 :     , { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX }
102 :     , { "3DNOW ", XVID_CPU_3DNOW }
103 :     , { "3DNOWE", XVID_CPU_3DNOWEXT }
104 : ia64p 1.2
105 : Isibaar 1.1 //, { "TSC ", XVID_CPU_TSC }
106 :     , { 0, 0 } }
107 :    
108 :     , cpu_short_list[] =
109 :     { { "PLAINC", 0 }
110 :     , { "MMX ", XVID_CPU_MMX }
111 :     , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
112 : ia64p 1.2 , { "IA64 ", XVID_CPU_IA64 }
113 : Isibaar 1.1 , { 0, 0 } }
114 :    
115 :     , cpu_short_list2[] =
116 :     { { "PLAINC", 0 }
117 :     , { "MMX ", XVID_CPU_MMX }
118 :     , { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX }
119 :     , { 0, 0 } };
120 :    
121 :    
122 :     int init_cpu(CPU *cpu)
123 :     {
124 :     int xerr, cpu_type;
125 :     XVID_INIT_PARAM xinit;
126 :    
127 :     cpu_type = check_cpu_features() & cpu->cpu;
128 :     xinit.cpu_flags = cpu_type | XVID_CPU_FORCE;
129 :     // xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;
130 :     xerr = xvid_init(NULL, 0, &xinit, NULL);
131 :     if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) {
132 :     printf( "%s - skipped...\n", cpu->name );
133 :     return 0;
134 :     }
135 :     return 1;
136 :     }
137 :    
138 :     /*********************************************************************
139 :     * test DCT
140 :     *********************************************************************/
141 :    
142 :     #define ABS(X) ((X)<0 ? -(X) : (X))
143 :    
144 :     void test_dct()
145 :     {
146 :     const int nb_tests = 300*speed_ref;
147 :     int tst;
148 :     CPU *cpu;
149 :     int i;
150 :     short iDst0[8*8], iDst[8*8], fDst[8*8];
151 :     double overhead;
152 :    
153 :     printf( "\n ===== test fdct/idct =====\n" );
154 :    
155 :     for(i=0; i<8*8; ++i) iDst0[i] = (i*7-i*i) & 0x7f;
156 :     overhead = gettime_usec();
157 :     for(tst=0; tst<nb_tests; ++tst)
158 :     {
159 :     for(i=0; i<8*8; ++i) fDst[i] = iDst0[i];
160 :     for(i=0; i<8*8; ++i) iDst[i] = fDst[i];
161 :     }
162 :     overhead = gettime_usec() - overhead;
163 :    
164 :     for(cpu = cpu_list; cpu->name!=0; ++cpu)
165 :     {
166 :     double t;
167 :     int iCrc, fCrc;
168 :    
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 :     iCrc=0; fCrc=0;
184 :     for(i=0; i<8*8; ++i) {
185 :     iCrc += ABS(iDst[i] - iDst0[i]);
186 :     fCrc += fDst[i]^i;
187 :     }
188 :     printf( "%s - %.3f usec iCrc=%d fCrc=%d\n",
189 :     cpu->name, t, iCrc, fCrc );
190 :     // the norm tolerates ~1 bit of diff per coeff
191 :     if (ABS(iCrc)>=64) printf( "*** CRC ERROR! ***\n" );
192 :     }
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 :     printf( " --- \n" );
338 :     }
339 :     }
340 :    
341 :     /*********************************************************************
342 :     * test transfer
343 :     *********************************************************************/
344 :    
345 :     #define INIT_TRANSFER \
346 :     for(i=0; i<8*32; ++i) { \
347 :     Src8[i] = i; Src16[i] = i; \
348 :     Dst8[i] = 0; Dst16[i] = 0; \
349 :     Ref1[i] = i^0x27; \
350 :     Ref2[i] = i^0x51; \
351 :     }
352 :    
353 :     #define TEST_TRANSFER_BEGIN(DST) \
354 :     INIT_TRANSFER \
355 :     overhead = -gettime_usec(); \
356 :     for(tst=0; tst<nb_tests; ++tst) { \
357 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\
358 :     } \
359 :     overhead += gettime_usec(); \
360 :     t = gettime_usec(); \
361 :     emms(); \
362 :     for(tst=0; tst<nb_tests; ++tst) { \
363 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;
364 :    
365 :    
366 :     #define TEST_TRANSFER_END(DST) \
367 :     } \
368 :     emms(); \
369 :     t = (gettime_usec()-t -overhead) / nb_tests;\
370 :     s = 0; for(i=0; i<8*32; ++i) { s += (DST)[i]^i; }
371 :    
372 :     #define TEST_TRANSFER(FUNC, DST, SRC) \
373 :     TEST_TRANSFER_BEGIN(DST); \
374 :     (FUNC)((DST), (SRC), 32); \
375 :     TEST_TRANSFER_END(DST)
376 :    
377 :    
378 :     #define TEST_TRANSFER2_BEGIN(DST, SRC) \
379 :     INIT_TRANSFER \
380 :     overhead = -gettime_usec(); \
381 :     for(tst=0; tst<nb_tests; ++tst) { \
382 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\
383 :     for(i=0; i<8*32; ++i) (SRC)[i] = i^0x3e;\
384 :     } \
385 :     overhead += gettime_usec(); \
386 :     t = gettime_usec(); \
387 :     emms(); \
388 :     for(tst=0; tst<nb_tests; ++tst) { \
389 :     for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\
390 :     for(i=0; i<8*32; ++i) (SRC)[i] = i^0x3e;
391 :    
392 :     #define TEST_TRANSFER2_END(DST) \
393 :     } \
394 :     emms(); \
395 :     t = (gettime_usec()-t -overhead) / nb_tests;\
396 :     s = 0; for(i=0; i<8*32; ++i) { s += (DST)[i]; }
397 :    
398 :     #define TEST_TRANSFER2(FUNC, DST, SRC, R1) \
399 :     TEST_TRANSFER2_BEGIN(DST,SRC); \
400 :     (FUNC)((DST), (SRC), (R1), 32); \
401 :     TEST_TRANSFER2_END(DST)
402 :    
403 :     #define TEST_TRANSFER3(FUNC, DST, SRC, R1, R2)\
404 :     TEST_TRANSFER_BEGIN(DST); \
405 :     (FUNC)((DST), (SRC), (R1), (R2), 32); \
406 :     TEST_TRANSFER_END(DST)
407 :    
408 :     void test_transfer()
409 :     {
410 :     const int nb_tests = 4000*speed_ref;
411 :     int i;
412 :     CPU *cpu;
413 :     uint8_t Src8[8*32], Dst8[8*32], Ref1[8*32], Ref2[8*32];
414 :     int16_t Src16[8*32], Dst16[8*32];
415 :    
416 :     printf( "\n === test transfer ===\n" );
417 :    
418 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
419 :     {
420 :     double t, overhead;
421 :     int tst, s;
422 :    
423 :     if (!init_cpu(cpu))
424 :     continue;
425 :    
426 :     TEST_TRANSFER(transfer_8to16copy, Dst16, Src8);
427 :     printf( "%s - 8to16 %.3f usec crc=%d\n", cpu->name, t, s );
428 :     if (s!=28288) printf( "*** CRC ERROR! ***\n" );
429 :    
430 :     TEST_TRANSFER(transfer_16to8copy, Dst8, Src16);
431 :     printf( "%s - 16to8 %.3f usec crc=%d\n", cpu->name, t, s );
432 :     if (s!=28288) printf( "*** CRC ERROR! ***\n" );
433 :    
434 :     TEST_TRANSFER(transfer8x8_copy, Dst8, Src8);
435 :     printf( "%s - 8to8 %.3f usec crc=%d\n", cpu->name, t, s );
436 :     if (s!=20352) printf( "*** CRC ERROR! ***\n" );
437 :    
438 :     TEST_TRANSFER(transfer_16to8add, Dst8, Src16);
439 :     printf( "%s - 16to8add %.3f usec crc=%d\n", cpu->name, t, s );
440 :     if (s!=25536) printf( "*** CRC ERROR! ***\n" );
441 :    
442 :     TEST_TRANSFER2(transfer_8to16sub, Dst16, Src8, Ref1);
443 :     printf( "%s - 8to16sub %.3f usec crc1=%d ", cpu->name, t, s );
444 :     if (s!=28064) printf( "*** CRC ERROR! ***\n" );
445 :     s = 0; for(i=0; i<8*32; ++i) { s += (Src8[i]-Ref1[i])&i; }
446 :     printf( "crc2=%d\n", s);
447 :     if (s!=16256) printf( "*** CRC ERROR! ***\n" );
448 :    
449 :     TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2);
450 :     printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s );
451 :     if (s!=20384) printf( "*** CRC ERROR! ***\n" );
452 :    
453 :     printf( " --- \n" );
454 :     }
455 :     }
456 :    
457 :     /*********************************************************************
458 :     * test quantization
459 :     *********************************************************************/
460 :    
461 :     #define TEST_QUANT(FUNC, DST, SRC) \
462 :     t = gettime_usec(); \
463 :     emms(); \
464 :     for(tst=0; tst<nb_tests; ++tst) \
465 :     for(s=0, q=1; q<=max_Q; ++q) { \
466 :     (FUNC)((DST), (SRC), q); \
467 :     for(i=0; i<64; ++i) s+=(DST)[i]^i; \
468 :     } \
469 :     emms(); \
470 :     t = (gettime_usec()-t-overhead)/nb_tests;
471 :    
472 :     #define TEST_QUANT2(FUNC, DST, SRC, MULT) \
473 :     t = gettime_usec(); \
474 :     emms(); \
475 :     for(tst=0; tst<nb_tests; ++tst) \
476 :     for(s=0, q=1; q<=max_Q; ++q) { \
477 :     (FUNC)((DST), (SRC), q, MULT); \
478 :     for(i=0; i<64; ++i) s+=(DST)[i]^i; \
479 :     } \
480 :     emms(); \
481 :     t = (gettime_usec()-t-overhead)/nb_tests;
482 :    
483 :     void test_quant()
484 :     {
485 :     const int nb_tests = 150*speed_ref;
486 :     const int max_Q = 31;
487 :     int i;
488 :     CPU *cpu;
489 :     int16_t Src[8*8], Dst[8*8];
490 :    
491 :     printf( "\n ===== test quant =====\n" );
492 :    
493 :     for(i=0; i<64; ++i) {
494 :     Src[i] = i-32;
495 :     Dst[i] = 0;
496 :     }
497 :    
498 :    
499 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
500 :     {
501 :     double t, overhead;
502 :     int tst, s, q;
503 :    
504 :     if (!init_cpu(cpu))
505 :     continue;
506 :    
507 :     set_inter_matrix( get_default_inter_matrix() );
508 :     set_intra_matrix( get_default_intra_matrix() );
509 :     overhead = -gettime_usec();
510 :     for(tst=0; tst<nb_tests; ++tst)
511 :     for(s=0, q=1; q<=max_Q; ++q)
512 :     for(i=0; i<64; ++i) s+=Dst[i]^i;
513 :     overhead += gettime_usec();
514 :    
515 :     TEST_QUANT2(quant4_intra, Dst, Src, 7);
516 :     printf( "%s - quant4_intra %.3f usec crc=%d\n", cpu->name, t, s );
517 :     if (s!=55827) printf( "*** CRC ERROR! ***\n" );
518 :    
519 :     TEST_QUANT(quant4_inter, Dst, Src);
520 :     printf( "%s - quant4_inter %.3f usec crc=%d\n", cpu->name, t, s );
521 :     if (s!=58201) printf( "*** CRC ERROR! ***\n" );
522 :    
523 :    
524 :     TEST_QUANT2(dequant4_intra, Dst, Src, 7);
525 :     printf( "%s - dequant4_intra %.3f usec crc=%d\n", cpu->name, t, s );
526 :     if (s!=193340) printf( "*** CRC ERROR! ***\n" );
527 :    
528 :     TEST_QUANT(dequant4_inter, Dst, Src);
529 :     printf( "%s - dequant4_inter %.3f usec crc=%d\n", cpu->name, t, s );
530 :     if (s!=116483) printf( "*** CRC ERROR! ***\n" );
531 :    
532 :     TEST_QUANT2(quant_intra, Dst, Src, 7);
533 :     printf( "%s - quant_intra %.3f usec crc=%d\n", cpu->name, t, s );
534 :     if (s!=56885) printf( "*** CRC ERROR! ***\n" );
535 :    
536 :     TEST_QUANT(quant_inter, Dst, Src);
537 :     printf( "%s - quant_inter %.3f usec crc=%d\n", cpu->name, t, s );
538 :     if (s!=58056) printf( "*** CRC ERROR! ***\n" );
539 :    
540 :     TEST_QUANT2(dequant_intra, Dst, Src, 7);
541 :     printf( "%s - dequant_intra %.3f usec crc=%d\n", cpu->name, t, s );
542 :     if (s!=-7936) printf( "*** CRC ERROR! ***\n" );
543 :    
544 :     TEST_QUANT(dequant_inter, Dst, Src);
545 :     printf( "%s - dequant_inter %.3f usec crc=%d\n", cpu->name, t, s );
546 :     // { int k,l; for(k=0; k<8; ++k) { for(l=0; l<8; ++l) printf( "[%.4d]", Dst[k*8+l]); printf("\n"); } }
547 :     if (s!=-33217) printf( "*** CRC ERROR! ***\n" );
548 :    
549 :     printf( " --- \n" );
550 :     }
551 :     }
552 :    
553 :     /*********************************************************************
554 :     * test non-zero AC counting
555 :     *********************************************************************/
556 :    
557 :     #define TEST_CBP(FUNC, SRC) \
558 :     t = gettime_usec(); \
559 :     emms(); \
560 :     for(tst=0; tst<nb_tests; ++tst) { \
561 :     cbp = (FUNC)((SRC)); \
562 :     } \
563 :     emms(); \
564 :     t = (gettime_usec()-t ) / nb_tests;
565 :    
566 :     void test_cbp()
567 :     {
568 :     const int nb_tests = 10000*speed_ref;
569 :     int i;
570 :     CPU *cpu;
571 :     int16_t Src1[6*64], Src2[6*64], Src3[6*64], Src4[6*64];
572 :    
573 :     printf( "\n ===== test cbp =====\n" );
574 :    
575 :     for(i=0; i<6*64; ++i) {
576 :     Src1[i] = (i*i*3/8192)&(i/64)&1; // 'random'
577 :     Src2[i] = (i<3*64); // half-full
578 :     Src3[i] = ((i+32)>3*64);
579 :     Src4[i] = (i==(3*64+2) || i==(5*64+9));
580 :     }
581 :    
582 :     for(cpu = cpu_short_list2; cpu->name!=0; ++cpu)
583 :     {
584 :     double t;
585 :     int tst, cbp;
586 :    
587 :     if (!init_cpu(cpu))
588 :     continue;
589 :    
590 :     TEST_CBP(calc_cbp, Src1);
591 :     printf( "%s - calc_cbp#1 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
592 :     if (cbp!=0x15) printf( "*** CRC ERROR! ***\n" );
593 :     TEST_CBP(calc_cbp, Src2);
594 :     printf( "%s - calc_cbp#2 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
595 :     if (cbp!=0x38) printf( "*** CRC ERROR! ***\n" );
596 :     TEST_CBP(calc_cbp, Src3);
597 :     printf( "%s - calc_cbp#3 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
598 :     if (cbp!=0x0f) printf( "*** CRC ERROR! ***\n" );
599 :     TEST_CBP(calc_cbp, Src4);
600 :     printf( "%s - calc_cbp#4 %.3f usec cbp=0x%x\n", cpu->name, t, cbp );
601 :     if (cbp!=0x05) printf( "*** CRC ERROR! ***\n" );
602 :     printf( " --- \n" );
603 :     }
604 :     }
605 :    
606 :     /*********************************************************************
607 :     * measure raw decoding speed
608 :     *********************************************************************/
609 :    
610 :     void test_dec(const char *name, int width, int height, int with_chksum)
611 :     {
612 :     FILE *f = 0;
613 :     void *dechandle = 0;
614 :     int xerr;
615 :     XVID_INIT_PARAM xinit;
616 :     XVID_DEC_PARAM xparam;
617 :     XVID_DEC_FRAME xframe;
618 :     double t = 0.;
619 :     int nb = 0;
620 :     uint8_t *buf = 0;
621 :     uint8_t *rgb_out = 0;
622 :     int buf_size, pos;
623 :     uint32_t chksum = 0;
624 :    
625 :     xinit.cpu_flags = 0;
626 :     xvid_init(NULL, 0, &xinit, NULL);
627 :     printf( "API version: %d, core build:%d\n", xinit.api_version, xinit.core_build);
628 :    
629 :    
630 :     xparam.width = width;
631 :     xparam.height = height;
632 :     xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);
633 :     if (xerr!=XVID_ERR_OK) {
634 :     printf("can't init decoder (err=%d)\n", xerr);
635 :     return;
636 :     }
637 :     dechandle = xparam.handle;
638 :    
639 :    
640 :     f = fopen(name, "rb");
641 :     if (f==0) {
642 :     printf( "can't open file '%s'\n", name);
643 :     return;
644 :     }
645 :     fseek(f, 0, SEEK_END);
646 :     buf_size = ftell(f);
647 :     fseek(f, 0, SEEK_SET);
648 :     if (buf_size<=0) {
649 :     printf("error while stating file\n");
650 :     goto End;
651 :     }
652 :     else printf( "Input size: %d\n", buf_size);
653 :    
654 :     buf = malloc(buf_size); // should be enuf'
655 :     rgb_out = calloc(4, width*height); // <-room for _RGB24
656 :     if (buf==0 || rgb_out==0) {
657 :     printf( "malloc failed!\n" );
658 :     goto End;
659 :     }
660 :    
661 :     if (fread(buf, buf_size, 1, f)!=1) {
662 :     printf( "file-read failed\n" );
663 :     goto End;
664 :     }
665 :    
666 :     nb = 0;
667 :     pos = 0;
668 :     t = -gettime_usec();
669 :     while(1) {
670 :     xframe.bitstream = buf + pos;
671 :     xframe.length = buf_size - pos;
672 :     xframe.image = rgb_out;
673 :     xframe.stride = width;
674 :     xframe.colorspace = XVID_CSP_RGB24;
675 :     xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);
676 :     nb++;
677 :     pos += xframe.length;
678 :     if (with_chksum) {
679 :     int k = width*height;
680 :     uint32_t *ptr = (uint32_t *)rgb_out;
681 :     while(k-->0) chksum += *ptr++;
682 :     }
683 :     if (pos==buf_size)
684 :     break;
685 :     if (xerr!=XVID_ERR_OK) {
686 :     printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);
687 :     break;
688 :     }
689 :     }
690 :     t += gettime_usec();
691 :     if (t>0.)
692 :     printf( "%d frames decoded in %.3f s -> %.1f FPS\n", nb, t*1.e-6f, (float)(nb*1.e6f/t) );
693 :     if (with_chksum)
694 :     printf("checksum: 0x%.8x\n", chksum);
695 :    
696 :     End:
697 :     if (rgb_out!=0) free(rgb_out);
698 :     if (buf!=0) free(buf);
699 :     if (dechandle!=0) {
700 :     xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);
701 :     if (xerr!=XVID_ERR_OK)
702 :     printf("destroy-decoder failed (err=%d)!\n", xerr);
703 :     }
704 :     if (f!=0) fclose(f);
705 :     }
706 :    
707 :     /*********************************************************************
708 :     * non-regression tests
709 :     *********************************************************************/
710 :    
711 :     void test_bugs1()
712 :     {
713 :     CPU *cpu;
714 :    
715 :     printf( "\n ===== (de)quant4_intra saturation bug? =====\n" );
716 :    
717 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
718 :     {
719 :     int i;
720 :     int16_t Src[8*8], Dst[8*8];
721 :    
722 :     if (!init_cpu(cpu))
723 :     continue;
724 :    
725 :     for(i=0; i<64; ++i) Src[i] = i-32;
726 :     set_intra_matrix( get_default_intra_matrix() );
727 :     dequant4_intra(Dst, Src, 32, 5);
728 :     printf( "dequant4_intra with CPU=%s: ", cpu->name);
729 :     printf( " Out[]= " );
730 :     for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
731 :     printf( "\n" );
732 :     }
733 :    
734 :     printf( "\n ===== (de)quant4_inter saturation bug? =====\n" );
735 :    
736 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
737 :     {
738 :     int i;
739 :     int16_t Src[8*8], Dst[8*8];
740 :    
741 :     if (!init_cpu(cpu))
742 :     continue;
743 :    
744 :     for(i=0; i<64; ++i) Src[i] = i-32;
745 :     set_inter_matrix( get_default_inter_matrix() );
746 :     dequant4_inter(Dst, Src, 32);
747 :     printf( "dequant4_inter with CPU=%s: ", cpu->name);
748 :     printf( " Out[]= " );
749 :     for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
750 :     printf( "\n" );
751 :     }
752 :     }
753 :    
754 :     void test_dct_precision_diffs()
755 :     {
756 :     CPU *cpu;
757 :     short Blk[8*8], Blk0[8*8];
758 :    
759 :     printf( "\n ===== fdct/idct saturation diffs =====\n" );
760 :    
761 :     for(cpu = cpu_short_list; cpu->name!=0; ++cpu)
762 :     {
763 :     int i;
764 :    
765 :     if (!init_cpu(cpu))
766 :     continue;
767 :    
768 :     for(i=0; i<8*8; ++i) {
769 :     Blk0[i] = (i*7-i*i) & 0x7f;
770 :     Blk[i] = Blk0[i];
771 :     }
772 :    
773 :     fdct(Blk);
774 :     idct(Blk);
775 :     printf( " fdct+idct diffs with CPU=%s: \n", cpu->name );
776 :     for(i=0; i<8; ++i) {
777 :     int j;
778 :     for(j=0; j<8; ++j) printf( " %d ", Blk[i*8+j]-Blk0[i*8+j]);
779 :     printf("\n");
780 :     }
781 :     printf("\n");
782 :     }
783 :     }
784 :    
785 :    
786 :     /*********************************************************************
787 :     * main
788 :     *********************************************************************/
789 :    
790 :     int main(int argc, char *argv[])
791 :     {
792 :     int what = 0;
793 :     if (argc>1) what = atoi(argv[1]);
794 :     if (what==0 || what==1) test_dct();
795 :     if (what==0 || what==2) test_mb();
796 :     if (what==0 || what==3) test_sad();
797 :     if (what==0 || what==4) test_transfer();
798 :     if (what==0 || what==5) test_quant();
799 :     if (what==0 || what==6) test_cbp();
800 :    
801 :     if (what==8) {
802 :     int width, height;
803 :     if (argc<5) {
804 :     printf("usage: %s %d [bitstream] [width] [height]\n", argv[0], what);
805 :     return 1;
806 :     }
807 :     width = atoi(argv[3]);
808 :     height = atoi(argv[4]);
809 :     test_dec(argv[2], width, height, (argc>5));
810 :     }
811 :    
812 :     if (what==-1) {
813 :     test_bugs1();
814 :     test_dct_precision_diffs();
815 :     }
816 :     return 0;
817 :     }
818 :    
819 :     /*********************************************************************
820 :     * 'Reference' output (except for timing) on a PIII 1.13Ghz/linux
821 :     *********************************************************************/
822 :     /*
823 :    
824 :     ===== test fdct/idct =====
825 :     PLAINC - 2.631 usec iCrc=3 fCrc=-85
826 :     MMX - 0.596 usec iCrc=3 fCrc=-67
827 :     MMXEXT - 0.608 usec iCrc=3 fCrc=-67
828 :     SSE2 - 0.605 usec iCrc=3 fCrc=-67
829 :     3DNOW - skipped...
830 :     3DNOWE - skipped...
831 :    
832 :     === test block motion ===
833 :     PLAINC - interp- h-round0 1.031 usec iCrc=8107
834 :     PLAINC - round1 1.022 usec iCrc=8100
835 :     PLAINC - interp- v-round0 1.002 usec iCrc=8108
836 :     PLAINC - round1 1.011 usec iCrc=8105
837 :     PLAINC - interp-hv-round0 1.623 usec iCrc=8112
838 :     PLAINC - round1 1.621 usec iCrc=8103
839 :     PLAINC - interpolate8x8_c 0.229 usec iCrc=8107
840 :     ---
841 :     MMX - interp- h-round0 0.105 usec iCrc=8107
842 :     MMX - round1 0.105 usec iCrc=8100
843 :     MMX - interp- v-round0 0.106 usec iCrc=8108
844 :     MMX - round1 0.107 usec iCrc=8105
845 :     MMX - interp-hv-round0 0.145 usec iCrc=8112
846 :     MMX - round1 0.145 usec iCrc=8103
847 :     MMX - interpolate8x8_c 0.229 usec iCrc=8107
848 :     ---
849 :     MMXEXT - interp- h-round0 0.027 usec iCrc=8107
850 :     MMXEXT - round1 0.041 usec iCrc=8100
851 :     MMXEXT - interp- v-round0 0.027 usec iCrc=8108
852 :     MMXEXT - round1 0.040 usec iCrc=8105
853 :     MMXEXT - interp-hv-round0 0.070 usec iCrc=8112
854 :     MMXEXT - round1 0.066 usec iCrc=8103
855 :     MMXEXT - interpolate8x8_c 0.027 usec iCrc=8107
856 :     ---
857 :     SSE2 - interp- h-round0 0.106 usec iCrc=8107
858 :     SSE2 - round1 0.105 usec iCrc=8100
859 :     SSE2 - interp- v-round0 0.106 usec iCrc=8108
860 :     SSE2 - round1 0.106 usec iCrc=8105
861 :     SSE2 - interp-hv-round0 0.145 usec iCrc=8112
862 :     SSE2 - round1 0.145 usec iCrc=8103
863 :     SSE2 - interpolate8x8_c 0.237 usec iCrc=8107
864 :     ---
865 :     3DNOW - skipped...
866 :     3DNOWE - skipped...
867 :    
868 :     ====== test SAD ======
869 :     PLAINC - sad8 0.296 usec sad=3776
870 :     PLAINC - sad16 1.599 usec sad=27214
871 :     PLAINC - sad16bi 2.350 usec sad=26274
872 :     PLAINC - dev16 1.610 usec sad=3344
873 :     ---
874 :     MMX - sad8 0.057 usec sad=3776
875 :     MMX - sad16 0.178 usec sad=27214
876 :     MMX - sad16bi 2.381 usec sad=26274
877 :     MMX - dev16 0.312 usec sad=3344
878 :     ---
879 :     MMXEXT - sad8 0.036 usec sad=3776
880 :     MMXEXT - sad16 0.106 usec sad=27214
881 :     MMXEXT - sad16bi 0.182 usec sad=26274
882 :     MMXEXT - dev16 0.193 usec sad=3344
883 :     ---
884 :     SSE2 - sad8 0.057 usec sad=3776
885 :     SSE2 - sad16 0.178 usec sad=27214
886 :     SSE2 - sad16bi 2.427 usec sad=26274
887 :     SSE2 - dev16 0.313 usec sad=3344
888 :     ---
889 :     3DNOW - skipped...
890 :     3DNOWE - skipped...
891 :    
892 :     === test transfer ===
893 :     PLAINC - 8to16 0.124 usec crc=28288
894 :     PLAINC - 16to8 0.753 usec crc=28288
895 :     PLAINC - 8to8 0.041 usec crc=20352
896 :     PLAINC - 16to8add 0.916 usec crc=25536
897 :     PLAINC - 8to16sub 0.812 usec crc1=28064 crc2=16256
898 :     PLAINC - 8to16sub2 0.954 usec crc=20384
899 :     ---
900 :     MMX - 8to16 0.037 usec crc=28288
901 :     MMX - 16to8 0.016 usec crc=28288
902 :     MMX - 8to8 0.018 usec crc=20352
903 :     MMX - 16to8add 0.044 usec crc=25536
904 :     MMX - 8to16sub 0.065 usec crc1=28064 crc2=16256
905 :     MMX - 8to16sub2 0.110 usec crc=20384
906 :     ---
907 :     MMXEXT - 8to16 0.032 usec crc=28288
908 :     MMXEXT - 16to8 0.023 usec crc=28288
909 :     MMXEXT - 8to8 0.018 usec crc=20352
910 :     MMXEXT - 16to8add 0.041 usec crc=25536
911 :     MMXEXT - 8to16sub 0.065 usec crc1=28064 crc2=16256
912 :     MMXEXT - 8to16sub2 0.069 usec crc=20384
913 :     ---
914 :    
915 :     ===== test quant =====
916 :     PLAINC - quant4_intra 78.889 usec crc=55827
917 :     PLAINC - quant4_inter 71.957 usec crc=58201
918 :     PLAINC - dequant4_intra 34.968 usec crc=193340
919 :     PLAINC - dequant4_inter 40.792 usec crc=116483
920 :     PLAINC - quant_intra 30.845 usec crc=56885
921 :     PLAINC - quant_inter 34.842 usec crc=58056
922 :     PLAINC - dequant_intra 33.211 usec crc=-7936
923 :     PLAINC - dequant_inter 45.486 usec crc=-33217
924 :     ---
925 :     MMX - quant4_intra 9.030 usec crc=55827
926 :     MMX - quant4_inter 8.234 usec crc=58201
927 :     MMX - dequant4_intra 18.330 usec crc=193340
928 :     MMX - dequant4_inter 19.181 usec crc=116483
929 :     MMX - quant_intra 7.124 usec crc=56885
930 :     MMX - quant_inter 6.861 usec crc=58056
931 :     MMX - dequant_intra 9.048 usec crc=-7936
932 :     MMX - dequant_inter 8.203 usec crc=-33217
933 :     ---
934 :     MMXEXT - quant4_intra 9.045 usec crc=55827
935 :     MMXEXT - quant4_inter 8.232 usec crc=58201
936 :     MMXEXT - dequant4_intra 18.250 usec crc=193340
937 :     MMXEXT - dequant4_inter 19.256 usec crc=116483
938 :     MMXEXT - quant_intra 7.121 usec crc=56885
939 :     MMXEXT - quant_inter 6.855 usec crc=58056
940 :     MMXEXT - dequant_intra 9.034 usec crc=-7936
941 :     MMXEXT - dequant_inter 8.202 usec crc=-33217
942 :     ---
943 :    
944 :     ===== test cbp =====
945 :     PLAINC - calc_cbp#1 0.545 usec cbp=0x15
946 :     PLAINC - calc_cbp#2 0.540 usec cbp=0x38
947 :     PLAINC - calc_cbp#3 0.477 usec cbp=0xf
948 :     PLAINC - calc_cbp#4 0.739 usec cbp=0x5
949 :     ---
950 :     MMX - calc_cbp#1 0.136 usec cbp=0x15
951 :     MMX - calc_cbp#2 0.131 usec cbp=0x38
952 :     MMX - calc_cbp#3 0.132 usec cbp=0xf
953 :     MMX - calc_cbp#4 0.135 usec cbp=0x5
954 :     ---
955 :     SSE2 - calc_cbp#1 0.135 usec cbp=0x15
956 :     SSE2 - calc_cbp#2 0.131 usec cbp=0x38
957 :     SSE2 - calc_cbp#3 0.134 usec cbp=0xf
958 :     SSE2 - calc_cbp#4 0.136 usec cbp=0x5
959 :     ---
960 :     */

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