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

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