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

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