[svn] / branches / dev-api-4 / xvidcore / examples / xvid_bench.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/examples/xvid_bench.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1054 - (view) (download)

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

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