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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/xvidcore/examples/xvid_bench.c revision 257, Fri Jul 5 14:54:15 2002 UTC branches/dev-api-4/xvidcore/examples/xvid_bench.c revision 1220, Wed Nov 19 21:27:25 2003 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC - Unit tests and benches   *  XVID MPEG-4 VIDEO CODEC
4     *  - Unit tests and benches -
5     *
6     *  Copyright(C) 2002 Pascal Massimino <skal@planet-d.net>
7   *   *
8   *      This program is free software; you can redistribute it and/or modify   *      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   *      it under the terms of the GNU General Public License as published by
# Line 14  Line 17 
17   *   *
18   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
19   *      along with this program; if not, write to the Free Software   *      along with this program; if not, write to the Free Software
20   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21     *
22     * $Id: xvid_bench.c,v 1.9.2.8 2003-11-19 21:27:25 edgomez Exp $
23   *   *
24   *************************************************************************/   ****************************************************************************/
25    
26  /************************************************************************  /*****************************************************************************
27   *   *
28   *  'Reference' output is at the end of file.   *  'Reference' output is at the end of file.
29   *  Don't take the checksums and crc too seriouly, they aren't   *  Don't take the checksums and crc too seriouly, they aren't
30   *  bullet-proof...   *  bullet-proof (should plug some .md5 here)...
31   *   *
32   *   compiles with something like:   *   compiles with something like:
33   *   gcc -o xvid_bench xvid_bench.c  -I../src/ -lxvidcore -lm   *   gcc -o xvid_bench xvid_bench.c  -I../src/ -lxvidcore -lm
34   *   *
35   *      History:   ****************************************************************************/
  *  
  *      06.06.2002  initial coding      -Skal-  
  *  
  *************************************************************************/  
36    
37  #include <stdio.h>  #include <stdio.h>
38  #include <stdlib.h>  #include <stdlib.h>
39  #include <sys/time.h>  // for gettimeofday  #include <string.h>    /* for memset */
 #include <string.h>    // for memset  
40  #include <assert.h>  #include <assert.h>
41    
42    #ifndef WIN32
43    #include <sys/time.h>   /* for gettimeofday */
44    #else
45    #include <time.h>
46    #endif
47    
48    
49  #include "xvid.h"  #include "xvid.h"
50    
51  // inner guts  // inner guts
# Line 47  Line 54 
54  #include "image/colorspace.h"  #include "image/colorspace.h"
55  #include "image/interpolate8x8.h"  #include "image/interpolate8x8.h"
56  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
57  #include "quant/quant_h263.h"  #include "quant/quant.h"
 #include "quant/quant_mpeg4.h"  
58  #include "motion/sad.h"  #include "motion/sad.h"
59  #include "utils/emms.h"  #include "utils/emms.h"
60  #include "utils/timer.h"  #include "utils/timer.h"
61  #include "quant/quant_matrix.c"  #include "quant/quant_matrix.c"
62  #include "bitstream/cbp.h"  #include "bitstream/cbp.h"
63    
64  const int speed_ref = 100;  // on slow machines, decrease this value  #include <math.h>
65    
66    #ifndef M_PI
67    #define M_PI            3.14159265358979323846
68    #endif
69    
70    const int speed_ref = 100;  /* on slow machines, decrease this value */
71    
72  /*********************************************************************  /*********************************************************************
73   * misc   * misc
# Line 64  Line 76 
76   /* returns time in micro-s*/   /* returns time in micro-s*/
77  double gettime_usec()  double gettime_usec()
78  {  {
79    #ifndef WIN32
80    struct timeval  tv;    struct timeval  tv;
81    gettimeofday(&tv, 0);    gettimeofday(&tv, 0);
82    return tv.tv_sec*1.0e6 + tv.tv_usec;    return tv.tv_sec*1.0e6 + tv.tv_usec;
83    #else
84            clock_t clk;
85            clk = clock();
86            return clk * 1000000 / CLOCKS_PER_SEC;
87    #endif
88  }  }
89    
90   /* returns squared deviates (mean(v*v)-mean(v)^2) of a 8x8 block */   /* returns squared deviates (mean(v*v)-mean(v)^2) of a 8x8 block */
# Line 96  Line 114 
114    
115  CPU cpu_list[] =  CPU cpu_list[] =
116  { { "PLAINC", 0 }  { { "PLAINC", 0 }
117    #ifdef ARCH_IS_IA32
118  , { "MMX   ", XVID_CPU_MMX }  , { "MMX   ", XVID_CPU_MMX }
119  , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }  , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
120  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }
121  , { "3DNOW ", XVID_CPU_3DNOW }  , { "3DNOW ", XVID_CPU_3DNOW }
122  , { "3DNOWE", XVID_CPU_3DNOWEXT }  , { "3DNOWE", XVID_CPU_3DNOWEXT }
123    #endif
124    //, { "IA64  ", XVID_CPU_IA64 }
125  //, { "TSC   ", XVID_CPU_TSC }  //, { "TSC   ", XVID_CPU_TSC }
126  , { 0, 0 } }    , { 0, 0 } };
127    
128  , cpu_short_list[] =  CPU  cpu_short_list[] =
129  { { "PLAINC", 0 }  { { "PLAINC", 0 }
130    #ifdef ARCH_IS_IA32
131  , { "MMX   ", XVID_CPU_MMX }  , { "MMX   ", XVID_CPU_MMX }
132  , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }  //, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
133  , { "IA64  ", XVID_CPU_IA64 }  #endif
134  , { 0, 0 } }  //, { "IA64  ", XVID_CPU_IA64 }
135      , { 0, 0 } };
136    
137  , cpu_short_list2[] =  CPU cpu_short_list2[] =
138  { { "PLAINC", 0 }  { { "PLAINC", 0 }
139    #ifdef ARCH_IS_IA32
140  , { "MMX   ", XVID_CPU_MMX }  , { "MMX   ", XVID_CPU_MMX }
141  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }
142    #endif
143  , { 0, 0 } };  , { 0, 0 } };
144    
145    
146  int init_cpu(CPU *cpu)  int init_cpu(CPU *cpu)
147  {  {
148    int xerr, cpu_type;          xvid_gbl_info_t xinfo;
   XVID_INIT_PARAM xinit;  
149    
150    cpu_type = check_cpu_features() & cpu->cpu;          /* Get the available CPU flags */
151    xinit.cpu_flags = cpu_type | XVID_CPU_FORCE;          memset(&xinfo, 0, sizeof(xinfo));
152    //    xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;          xinfo.version = XVID_VERSION;
153    xerr = xvid_init(NULL, 0, &xinit, NULL);          xvid_global(NULL, XVID_GBL_INFO, &xinfo, NULL);
154    if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) {  
155      printf( "%s - skipped...\n", cpu->name );          /* Are we trying to test a subset of the host CPU features */
156            if ((xinfo.cpu_flags & cpu->cpu) == cpu->cpu) {
157                    int xerr;
158                    xvid_gbl_init_t xinit;
159                    memset(&xinit, 0, sizeof(xinit));
160                    xinit.cpu_flags = cpu->cpu | XVID_CPU_FORCE;
161                    xinit.version = XVID_VERSION;
162                    xerr = xvid_global(NULL, XVID_GBL_INIT, &xinit, NULL);
163                    if (xerr==XVID_ERR_FAIL) {
164                            /* libxvidcore failed to init */
165      return 0;      return 0;
166    }    }
167            } else {
168                    /* The host CPU doesn't support some required feature for this test */
169                    return(0);
170            }
171    return 1;    return 1;
172  }  }
173    
# Line 147  Line 183 
183    int tst;    int tst;
184    CPU *cpu;    CPU *cpu;
185    int i;    int i;
186    short iDst0[8*8], iDst[8*8], fDst[8*8];          DECLARE_ALIGNED_MATRIX(iDst0, 8, 8, short, 16);
187            DECLARE_ALIGNED_MATRIX(iDst,  8, 8, short, 16);
188            DECLARE_ALIGNED_MATRIX(fDst,  8, 8, short, 16);
189    double overhead;    double overhead;
190    
191    printf( "\n ===== test fdct/idct =====\n" );    printf( "\n ===== test fdct/idct =====\n" );
# Line 163  Line 201 
201    
202    for(cpu = cpu_list; cpu->name!=0; ++cpu)    for(cpu = cpu_list; cpu->name!=0; ++cpu)
203    {    {
204      double t;                  double t, PSNR, MSE;
     int iCrc, fCrc;  
205    
206      if (!init_cpu(cpu))      if (!init_cpu(cpu))
207        continue;        continue;
# Line 180  Line 217 
217      }      }
218      emms();      emms();
219      t = (gettime_usec() - t - overhead) / nb_tests;      t = (gettime_usec() - t - overhead) / nb_tests;
220      iCrc=0; fCrc=0;                  MSE = 0.;
221      for(i=0; i<8*8; ++i) {      for(i=0; i<8*8; ++i) {
222        iCrc += ABS(iDst[i] - iDst0[i]);                          double delta = 1.0*(iDst[i] - iDst0[i]);
223        fCrc += fDst[i]^i;                          MSE += delta*delta;
224      }      }
225      printf( "%s -  %.3f usec       iCrc=%d  fCrc=%d\n",                  PSNR = (MSE==0.) ? 1.e6 : -4.3429448*log( MSE/64. );
226        cpu->name, t, iCrc, fCrc );                  printf( "%s -  %.3f usec       PSNR=%.3f  MSE=%.3f\n",
227        // the norm tolerates ~1 bit of diff per coeff                                  cpu->name, t, PSNR, MSE );
228      if (ABS(iCrc)>=64) printf( "*** CRC ERROR! ***\n" );                  if (ABS(MSE)>=64) printf( "*** CRC ERROR! ***\n" );
229    }    }
230  }  }
231    
# Line 285  Line 322 
322    const int nb_tests = 2000*speed_ref;    const int nb_tests = 2000*speed_ref;
323    CPU *cpu;    CPU *cpu;
324    const uint8_t Src0[16*9] = {    const uint8_t Src0[16*9] = {
325          // try to have every possible combinaison of rounding...                  /* try to have every possible combinaison of rounding... */
326        0, 0, 1, 0, 2, 0, 3, 0, 4             ,0,0,0, 0,0,0,0        0, 0, 1, 0, 2, 0, 3, 0, 4             ,0,0,0, 0,0,0,0
327      , 0, 1, 1, 1, 2, 1, 3, 1, 3             ,0,0,0, 0,0,0,0      , 0, 1, 1, 1, 2, 1, 3, 1, 3             ,0,0,0, 0,0,0,0
328      , 0, 2, 1, 2, 2, 2, 3, 2, 2             ,0,0,0, 0,0,0,0      , 0, 2, 1, 2, 2, 2, 3, 2, 2             ,0,0,0, 0,0,0,0
# Line 334  Line 371 
371      printf( "%s -           round1 %.3f usec       iCrc=%d\n", cpu->name, t, iCrc );      printf( "%s -           round1 %.3f usec       iCrc=%d\n", cpu->name, t, iCrc );
372      if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" );      if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" );
373    
374    
375                    /* this is a new function, as of 06.06.2002 */
376    #if 0
377                    TEST_MB2(interpolate8x8_avrg);
378                    printf( "%s - interpolate8x8_c %.3f usec       iCrc=%d\n", cpu->name, t, iCrc );
379                    if (iCrc!=8107) printf( "*** CRC ERROR! ***\n" );
380    #endif
381    
382      printf( " --- \n" );      printf( " --- \n" );
383    }    }
384  }  }
# Line 415  Line 460 
460    
461    printf( "\n ===  test transfer ===\n" );    printf( "\n ===  test transfer ===\n" );
462    
463    for(cpu = cpu_short_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
464    {    {
465      double t, overhead;      double t, overhead;
466      int tst, s;      int tst, s;
# Line 448  Line 493 
493    
494      TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2);      TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2);
495      printf( "%s - 8to16sub2 %.3f usec       crc=%d\n", cpu->name, t, s );      printf( "%s - 8to16sub2 %.3f usec       crc=%d\n", cpu->name, t, s );
496      if (s!=20384) printf( "*** CRC ERROR! ***\n" );                  if (s!=22368) printf( "*** CRC ERROR! ***\n" );
497    
498      printf( " --- \n" );      printf( " --- \n" );
499    }    }
# Line 460  Line 505 
505    
506  #define TEST_QUANT(FUNC, DST, SRC)            \  #define TEST_QUANT(FUNC, DST, SRC)            \
507      t = gettime_usec();                       \      t = gettime_usec();                       \
508    for(s=0,qm=1; qm<=255; ++qm) {              \
509      for(i=0; i<8*8; ++i) Quant[i] = qm;       \
510      set_inter_matrix( Quant );                \
511      emms();                                   \      emms();                                   \
512      for(q=1; q<=max_Q; ++q) {                 \
513      for(tst=0; tst<nb_tests; ++tst)           \      for(tst=0; tst<nb_tests; ++tst)           \
       for(s=0, q=1; q<=max_Q; ++q) {          \  
514          (FUNC)((DST), (SRC), q);              \          (FUNC)((DST), (SRC), q);              \
515          for(i=0; i<64; ++i) s+=(DST)[i]^i;    \          for(i=0; i<64; ++i) s+=(DST)[i]^i^qm;   \
516        }                                       \        }                                       \
517      emms();                                   \      emms();                                   \
518      t = (gettime_usec()-t-overhead)/nb_tests;  }                                           \
519    t = (gettime_usec()-t-overhead)/nb_tests/qm;\
520    s = (s&0xffff)^(s>>16)
521    
522  #define TEST_QUANT2(FUNC, DST, SRC, MULT)     \  #define TEST_QUANT2(FUNC, DST, SRC)             \
523      t = gettime_usec();                       \      t = gettime_usec();                       \
524    for(s=0,qm=1; qm<=255; ++qm) {              \
525      for(i=0; i<8*8; ++i) Quant[i] = qm;       \
526      set_intra_matrix( Quant );                \
527      emms();                                   \      emms();                                   \
528      for(q=1; q<=max_Q; ++q) {                 \
529      for(tst=0; tst<nb_tests; ++tst)           \      for(tst=0; tst<nb_tests; ++tst)           \
530        for(s=0, q=1; q<=max_Q; ++q) {          \            (FUNC)((DST), (SRC), q, q);           \
531          (FUNC)((DST), (SRC), q, MULT);        \          for(i=0; i<64; ++i) s+=(DST)[i]^i^qm;   \
         for(i=0; i<64; ++i) s+=(DST)[i]^i;    \  
532        }                                       \        }                                       \
533      emms();                                   \      emms();                                   \
534      t = (gettime_usec()-t-overhead)/nb_tests;  }                                           \
535    t = (gettime_usec()-t-overhead)/nb_tests/qm;\
536    s = (s&0xffff)^(s>>16)
537    
538  void test_quant()  void test_quant()
539  {  {
540    const int nb_tests = 150*speed_ref;          const int nb_tests = 1*speed_ref;
541    const int max_Q = 31;    const int max_Q = 31;
542    int i;          int i, qm;
543    CPU *cpu;    CPU *cpu;
544    int16_t  Src[8*8], Dst[8*8];    int16_t  Src[8*8], Dst[8*8];
545            uint8_t Quant[8*8];
546    
547    printf( "\n =====  test quant =====\n" );    printf( "\n =====  test quant =====\n" );
548    
549    /* we deliberately enfringe the norm's specified range [-127,127], */
550    /* to test the robustness of the iquant module */
551    for(i=0; i<64; ++i) {    for(i=0; i<64; ++i) {
552      Src[i] = i-32;                  Src[i] = 1 + (i-32) * (i&6);
553      Dst[i] = 0;      Dst[i] = 0;
554    }    }
555    
556            for(cpu = cpu_list; cpu->name!=0; ++cpu)
   for(cpu = cpu_short_list; cpu->name!=0; ++cpu)  
557    {    {
558      double t, overhead;      double t, overhead;
559      int tst, s, q;                  int tst, q;
560                    uint32_t s;
561    
562      if (!init_cpu(cpu))      if (!init_cpu(cpu))
563        continue;        continue;
564    
     set_inter_matrix( get_default_inter_matrix() );  
     set_intra_matrix( get_default_intra_matrix() );  
565      overhead = -gettime_usec();      overhead = -gettime_usec();
566      for(tst=0; tst<nb_tests; ++tst)                  for(s=0,qm=1; qm<=255; ++qm) {
567        for(s=0, q=1; q<=max_Q; ++q)                          for(i=0; i<8*8; ++i) Quant[i] = qm;
568          for(i=0; i<64; ++i) s+=Dst[i]^i;                          set_inter_matrix( Quant );
569                            for(q=1; q<=max_Q; ++q)
570                                    for(i=0; i<64; ++i) s+=Dst[i]^i^qm;
571                    }
572      overhead += gettime_usec();      overhead += gettime_usec();
573    
574      TEST_QUANT2(quant4_intra, Dst, Src, 7);  #if 1
575      printf( "%s -   quant4_intra %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT2(quant_mpeg_intra, Dst, Src);
576      if (s!=55827) printf( "*** CRC ERROR! ***\n" );                  printf( "%s -   quant_mpeg_intra %.3f usec       crc=%d\n", cpu->name, t, s );
577                    if (s!=29809) printf( "*** CRC ERROR! ***\n" );
578      TEST_QUANT(quant4_inter, Dst, Src);  
579      printf( "%s -   quant4_inter %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT(quant_mpeg_inter, Dst, Src);
580      if (s!=58201) printf( "*** CRC ERROR! ***\n" );                  printf( "%s -   quant_mpeg_inter %.3f usec       crc=%d\n", cpu->name, t, s );
581                    if (s!=12574) printf( "*** CRC ERROR! ***\n" );
582    #endif
583      TEST_QUANT2(dequant4_intra, Dst, Src, 7);  #if 1
584      printf( "%s - dequant4_intra %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT2(dequant_mpeg_intra, Dst, Src);
585      if (s!=193340) printf( "*** CRC ERROR! ***\n" );                  printf( "%s - dequant_mpeg_intra %.3f usec       crc=%d\n", cpu->name, t, s );
586                    if (s!=24052) printf( "*** CRC ERROR! ***\n" );
587      TEST_QUANT(dequant4_inter, Dst, Src);  
588      printf( "%s - dequant4_inter %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT(dequant_mpeg_inter, Dst, Src);
589      if (s!=116483) printf( "*** CRC ERROR! ***\n" );                  printf( "%s - dequant_mpeg_inter %.3f usec       crc=%d\n", cpu->name, t, s );
590                    if (s!=63847) printf( "*** CRC ERROR! ***\n" );
591      TEST_QUANT2(quant_intra, Dst, Src, 7);  #endif
592      printf( "%s -    quant_intra %.3f usec       crc=%d\n", cpu->name, t, s );  #if 1
593      if (s!=56885) printf( "*** CRC ERROR! ***\n" );                  TEST_QUANT2(quant_h263_intra, Dst, Src);
594                    printf( "%s -   quant_h263_intra %.3f usec       crc=%d\n", cpu->name, t, s );
595      TEST_QUANT(quant_inter, Dst, Src);                  if (s!=25662) printf( "*** CRC ERROR! ***\n" );
596      printf( "%s -    quant_inter %.3f usec       crc=%d\n", cpu->name, t, s );  
597      if (s!=58056) printf( "*** CRC ERROR! ***\n" );                  TEST_QUANT(quant_h263_inter, Dst, Src);
598                    printf( "%s -   quant_h263_inter %.3f usec       crc=%d\n", cpu->name, t, s );
599      TEST_QUANT2(dequant_intra, Dst, Src, 7);                  if (s!=23972) printf( "*** CRC ERROR! ***\n" );
600      printf( "%s -  dequant_intra %.3f usec       crc=%d\n", cpu->name, t, s );  #endif
601      if (s!=-7936) printf( "*** CRC ERROR! ***\n" );  #if 1
602                    TEST_QUANT2(dequant_h263_intra, Dst, Src);
603      TEST_QUANT(dequant_inter, Dst, Src);                  printf( "%s - dequant_h263_intra %.3f usec       crc=%d\n", cpu->name, t, s );
604      printf( "%s -  dequant_inter %.3f usec       crc=%d\n", cpu->name, t, s );                  if (s!=49900) printf( "*** CRC ERROR! ***\n" );
605  //    { int k,l; for(k=0; k<8; ++k) { for(l=0; l<8; ++l) printf( "[%.4d]", Dst[k*8+l]); printf("\n"); } }  
606      if (s!=-33217) printf( "*** CRC ERROR! ***\n" );                  TEST_QUANT(dequant_h263_inter, Dst, Src);
607                    printf( "%s - dequant_h263_inter %.3f usec       crc=%d\n", cpu->name, t, s );
608                    if (s!=48899) printf( "*** CRC ERROR! ***\n" );
609    #endif
610      printf( " --- \n" );      printf( " --- \n" );
611    }    }
612  }  }
# Line 573  Line 634 
634    printf( "\n =====  test cbp =====\n" );    printf( "\n =====  test cbp =====\n" );
635    
636    for(i=0; i<6*64; ++i) {    for(i=0; i<6*64; ++i) {
637      Src1[i] = (i*i*3/8192)&(i/64)&1;  // 'random'                  Src1[i] = (i*i*3/8192)&(i/64)&1;  /* 'random' */
638      Src2[i] = (i<3*64);               // half-full                  Src2[i] = (i<3*64);               /* half-full */
639      Src3[i] = ((i+32)>3*64);      Src3[i] = ((i+32)>3*64);
640      Src4[i] = (i==(3*64+2) || i==(5*64+9));      Src4[i] = (i==(3*64+2) || i==(5*64+9));
641    }    }
642    
643    for(cpu = cpu_short_list2; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
644    {    {
645      double t;      double t;
646      int tst, cbp;      int tst, cbp;
# Line 604  Line 665 
665  }  }
666    
667  /*********************************************************************  /*********************************************************************
668     * fdct/idct IEEE1180 compliance
669     *********************************************************************/
670    
671    typedef struct {
672            long Errors[64];
673            long Sqr_Errors[64];
674            long Max_Errors[64];
675            long Nb;
676    } STATS_8x8;
677    
678    void init_stats(STATS_8x8 *S)
679    {
680            int i;
681            for(i=0; i<64; ++i) {
682                    S->Errors[i]     = 0;
683                    S->Sqr_Errors[i] = 0;
684                    S->Max_Errors[i] = 0;
685            }
686            S->Nb = 0;
687    }
688    
689    void store_stats(STATS_8x8 *S, short Blk[64], short Ref[64])
690    {
691            int i;
692            for(i=0; i<64; ++i)
693            {
694                    short Err = Blk[i] - Ref[i];
695                    S->Errors[i] += Err;
696                    S->Sqr_Errors[i] += Err * Err;
697                    if (Err<0) Err = -Err;
698                    if (S->Max_Errors[i]<Err)
699                            S->Max_Errors[i] = Err;
700            }
701            S->Nb++;
702    }
703    
704    void print_stats(STATS_8x8 *S)
705    {
706            int i;
707            double Norm;
708    
709            assert(S->Nb>0);
710            Norm = 1. / (double)S->Nb;
711            printf("\n== Max absolute values of errors ==\n");
712            for(i=0; i<64; i++) {
713                    printf("  %4ld", S->Max_Errors[i]);
714                    if ((i&7)==7) printf("\n");
715            }
716    
717            printf("\n== Mean square errors ==\n");
718            for(i=0; i<64; i++)
719            {
720                    double Err = Norm * (double)S->Sqr_Errors[i];
721                    printf(" %.3f", Err);
722                    if ((i&7)==7) printf("\n");
723            }
724    
725            printf("\n== Mean errors ==\n");
726            for(i=0; i<64; i++)
727            {
728                    double Err = Norm * (double)S->Errors[i];
729                    printf(" %.3f", Err);
730                    if ((i&7)==7) printf("\n");
731            }
732            printf("\n");
733    }
734    
735    static const char *CHECK(double v, double l) {
736            if (fabs(v)<=l) return "ok";
737            else return "FAIL!";
738    }
739    
740    void report_stats(STATS_8x8 *S, const double *Limits)
741    {
742            int i;
743            double Norm, PE, PMSE, OMSE, PME, OME;
744    
745            assert(S->Nb>0);
746            Norm = 1. / (double)S->Nb;
747            PE = 0.;
748            for(i=0; i<64; i++) {
749                    if (PE<S->Max_Errors[i])
750                            PE = S->Max_Errors[i];
751            }
752    
753            PMSE = 0.;
754            OMSE = 0.;
755            for(i=0; i<64; i++)
756            {
757                    double Err = Norm * (double)S->Sqr_Errors[i];
758                    OMSE += Err;
759                    if (PMSE < Err) PMSE = Err;
760            }
761            OMSE /= 64.;
762    
763            PME = 0.;
764            OME = 0.;
765            for(i=0; i<64; i++)
766            {
767                    double Err = Norm * (double)S->Errors[i];
768                    OME += Err;
769                    Err = fabs(Err);
770                    if (PME < Err) PME = Err;
771            }
772            OME /= 64.;
773    
774            printf( "Peak error:   %4.4f\n", PE );
775            printf( "Peak MSE:     %4.4f\n", PMSE );
776            printf( "Overall MSE:  %4.4f\n", OMSE );
777            printf( "Peak ME:      %4.4f\n", PME );
778            printf( "Overall ME:   %4.4f\n", OME );
779    
780            if (Limits!=0)
781            {
782                    printf( "[PE<=%.4f %s]  ", Limits[0], CHECK(PE,   Limits[0]) );
783                    printf( "\n" );
784                    printf( "[PMSE<=%.4f %s]", Limits[1], CHECK(PMSE, Limits[1]) );
785                    printf( "[OMSE<=%.4f %s]", Limits[2], CHECK(OMSE, Limits[2]) );
786                    printf( "\n" );
787                    printf( "[PME<=%.4f %s] ", Limits[3], CHECK(PME , Limits[3]) );
788                    printf( "[OME<=%.4f %s] ", Limits[4], CHECK(OME , Limits[4]) );
789                    printf( "\n" );
790            }
791    }
792    
793    ///* ////////////////////////////////////////////////////// */
794    /* Pseudo-random generator specified by IEEE 1180 */
795    
796    static long ieee_seed = 1;
797    static void ieee_reseed(long s) {
798            ieee_seed = s;
799    }
800    static long ieee_rand(int Min, int Max)
801    {
802            static double z = (double) 0x7fffffff;
803    
804            long i,j;
805            double x;
806    
807            ieee_seed = (ieee_seed * 1103515245) + 12345;
808            i = ieee_seed & 0x7ffffffe;
809            x = ((double) i) / z;
810            x *= (Max-Min+1);
811            j = (long)x;
812            j = j + Min;
813            assert(j>=Min && j<=Max);
814            return (short)j;
815    }
816    
817    #define CLAMP(x, M)   (x) = ((x)<-(M)) ? (-(M)) : ((x)>=(M) ? ((M)-1) : (x))
818    
819    static double Cos[8][8];
820    static void init_ref_dct()
821    {
822            int i, j;
823            for(i=0; i<8; i++)
824            {
825                    double scale = (i == 0) ? sqrt(0.125) : 0.5;
826                    for (j=0; j<8; j++)
827                            Cos[i][j] = scale*cos( (M_PI/8.0)*i*(j + 0.5) );
828            }
829    }
830    
831    void ref_idct(short *M)
832    {
833            int i, j, k;
834            double Tmp[8][8];
835    
836            for(i=0; i<8; i++) {
837                    for(j=0; j<8; j++)
838                    {
839                            double Sum = 0.0;
840                            for (k=0; k<8; k++) Sum += Cos[k][j]*M[8*i+k];
841                            Tmp[i][j] = Sum;
842                    }
843            }
844            for(i=0; i<8; i++) {
845                    for(j=0; j<8; j++) {
846                            double Sum = 0.0;
847                            for (k=0; k<8; k++) Sum += Cos[k][i]*Tmp[k][j];
848                            M[8*i+j] = (short)floor(Sum + .5);
849                    }
850            }
851    }
852    
853    void ref_fdct(short *M)
854    {
855            int i, j, k;
856            double Tmp[8][8];
857    
858            for(i=0; i<8; i++) {
859                    for(j=0; j<8; j++)
860                    {
861                            double Sum = 0.0;
862                            for (k=0; k<8; k++) Sum += Cos[j][k]*M[8*i+k];
863                            Tmp[i][j] = Sum;
864                    }
865            }
866            for(i=0; i<8; i++) {
867                    for(j=0; j<8; j++) {
868                            double Sum = 0.0;
869                            for (k=0; k<8; k++) Sum += Cos[i][k]*Tmp[k][j];
870                            M[8*i+j] = (short)floor(Sum + 0.5);
871                    }
872            }
873    }
874    
875    void test_IEEE1180_compliance(int Min, int Max, int Sign)
876    {
877            static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 };
878            int Loops = 10000;
879            int i, m, n;
880            DECLARE_ALIGNED_MATRIX(Blk0, 8, 8, short, 16); /* reference */
881            DECLARE_ALIGNED_MATRIX(Blk,  8, 8, short, 16);
882            DECLARE_ALIGNED_MATRIX(iBlk, 8, 8, short, 16);
883            DECLARE_ALIGNED_MATRIX(Ref_FDCT, 8, 8, short, 16);
884            DECLARE_ALIGNED_MATRIX(Ref_IDCT, 8, 8, short, 16);
885    
886            STATS_8x8 FStats; /* forward dct stats */
887            STATS_8x8 IStats; /* inverse dct stats */
888    
889            CPU *cpu;
890    
891            init_ref_dct();
892    
893            for(cpu = cpu_list; cpu->name!=0; ++cpu)
894            {
895                    if (!init_cpu(cpu))
896                            continue;
897    
898                    printf( "\n===== IEEE test for %s ==== (Min=%d Max=%d Sign=%d Loops=%d)\n",
899                                    cpu->name, Min, Max, Sign, Loops);
900    
901                    init_stats(&IStats);
902                    init_stats(&FStats);
903    
904                    ieee_reseed(1);
905                    for(n=0; n<Loops; ++n)
906                    {
907                            for(i=0; i<64; ++i)
908                                    Blk0[i] = (short)ieee_rand(Min,Max) * Sign;
909    
910                            /* hmm, I'm not quite sure this is exactly */
911                            /* the tests described in the norm. check... */
912    
913                            memcpy(Ref_FDCT, Blk0, 64*sizeof(short));
914                            ref_fdct(Ref_FDCT);
915                            for(i=0; i<64; i++) CLAMP( Ref_FDCT[i], 2048 );
916    
917                            memcpy(Blk, Blk0, 64*sizeof(short));
918                            emms(); fdct(Blk); emms();
919                            for(i=0; i<64; i++) CLAMP( Blk[i], 2048 );
920    
921                            store_stats(&FStats, Blk, Ref_FDCT);
922    
923    
924                            memcpy(Ref_IDCT, Ref_FDCT, 64*sizeof(short));
925                            ref_idct(Ref_IDCT);
926                            for (i=0; i<64; i++) CLAMP( Ref_IDCT[i], 256 );
927    
928                            memcpy(iBlk, Ref_FDCT, 64*sizeof(short));
929                            emms(); idct(iBlk); emms();
930                            for(i=0; i<64; i++) CLAMP( iBlk[i], 256 );
931    
932                            store_stats(&IStats, iBlk, Ref_IDCT);
933                    }
934    
935    
936                    printf( "\n  -- FDCT report --\n" );
937    //    print_stats(&FStats);
938                    report_stats(&FStats, 0); /* so far I know, IEEE1180 says nothing for fdct */
939    
940                    for(i=0; i<64; i++) Blk[i] = 0;
941                    emms(); fdct(Blk); emms();
942                    for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;
943                    printf( "FDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );
944    
945                    printf( "\n  -- IDCT report --\n" );
946    //    print_stats(&IStats);
947                    report_stats(&IStats, ILimits);
948    
949    
950                    for(i=0; i<64; i++) Blk[i] = 0;
951                    emms(); idct(Blk); emms();
952                    for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;
953                    printf( "IDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );
954            }
955    }
956    
957    
958    void test_dct_saturation(int Min, int Max)
959    {
960    /* test behaviour on input range fringe */
961    
962            int i, n, p;
963            CPU *cpu;
964    //  const short IDCT_MAX =  2047;  /* 12bits input */
965    //  const short IDCT_MIN = -2048;
966    //  const short IDCT_OUT =   256;  /* 9bits ouput */
967            const int Partitions = 4;
968            const int Loops = 10000 / Partitions;
969    
970            init_ref_dct();
971    
972            for(cpu = cpu_list; cpu->name!=0; ++cpu)
973            {
974                    short Blk0[64], Blk[64];
975                    STATS_8x8 Stats;
976    
977                    if (!init_cpu(cpu))
978                            continue;
979    
980                    printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n",
981                                    cpu->name, Min, Max );
982    
983                    /* FDCT tests // */
984    
985                    init_stats(&Stats);
986    
987                    /* test each computation channels separately */
988                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0;
989                    ref_fdct(Blk0);
990                    emms(); fdct(Blk); emms();
991                    store_stats(&Stats, Blk, Blk0);
992    
993                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Min : 0;
994                    ref_fdct(Blk0);
995                    emms(); fdct(Blk); emms();
996                    store_stats(&Stats, Blk, Blk0);
997    
998                    /* randomly saturated inputs */
999                    for(p=0; p<Partitions; ++p)
1000                    {
1001                            for(n=0; n<Loops; ++n)
1002                            {
1003                                    for(i=0; i<64; ++i)
1004                                            Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? Max : Min;
1005                                    ref_fdct(Blk0);
1006                                    emms(); fdct(Blk); emms();
1007                                    store_stats(&Stats, Blk, Blk0);
1008                            }
1009                    }
1010                    printf( "\n  -- FDCT saturation report --\n" );
1011                    report_stats(&Stats, 0);
1012    
1013    
1014                    /* IDCT tests // */
1015    #if 0
1016                    /* no finished yet */
1017    
1018                    init_stats(&Stats);
1019    
1020    /* test each computation channel separately */
1021                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0;
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                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MIN : 0;
1028                    ref_idct(Blk0);
1029                    emms(); idct(Blk); emms();
1030                    for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }
1031                    store_stats(&Stats, Blk, Blk0);
1032    
1033                    /* randomly saturated inputs */
1034                    for(p=0; p<Partitions; ++p)
1035                    {
1036                            for(n=0; n<Loops; ++n)
1037                            {
1038                                    for(i=0; i<64; ++i)
1039                                            Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? IDCT_MAX : IDCT_MIN;
1040                                    ref_idct(Blk0);
1041                                    emms(); idct(Blk); emms();
1042                                    for(i=0; i<64; i++) { CLAMP(Blk0[i],IDCT_OUT); CLAMP(Blk[i],IDCT_OUT); }
1043                                    store_stats(&Stats, Blk, Blk0);
1044                            }
1045                    }
1046    
1047                    printf( "\n  -- IDCT saturation report --\n" );
1048                    print_stats(&Stats);
1049                    report_stats(&Stats, 0);
1050    #endif
1051            }
1052    }
1053    
1054    /*********************************************************************
1055   * measure raw decoding speed   * measure raw decoding speed
1056   *********************************************************************/   *********************************************************************/
1057    
# Line 612  Line 1060 
1060    FILE *f = 0;    FILE *f = 0;
1061    void *dechandle = 0;    void *dechandle = 0;
1062    int xerr;    int xerr;
1063          XVID_INIT_PARAM xinit;          xvid_gbl_init_t xinit;
1064          XVID_DEC_PARAM xparam;          xvid_dec_create_t xparam;
1065          XVID_DEC_FRAME xframe;          xvid_dec_frame_t xframe;
1066          double t = 0.;          double t = 0.;
1067          int nb = 0;          int nb = 0;
1068    uint8_t *buf = 0;    uint8_t *buf = 0;
# Line 622  Line 1070 
1070    int buf_size, pos;    int buf_size, pos;
1071    uint32_t chksum = 0;    uint32_t chksum = 0;
1072    
1073          xinit.cpu_flags = 0;          memset(&xinit, 0, sizeof(xinit));
1074          xvid_init(NULL, 0, &xinit, NULL);          xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;
1075          printf( "API version: %d, core build:%d\n", xinit.api_version, xinit.core_build);          xinit.version = XVID_VERSION;
1076            xvid_global(NULL, 0, &xinit, NULL);
1077    
1078            memset(&xparam, 0, sizeof(xparam));
1079          xparam.width = width;          xparam.width = width;
1080          xparam.height = height;          xparam.height = height;
1081            xparam.version = XVID_VERSION;
1082          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);
1083          if (xerr!=XVID_ERR_OK) {          if (xerr==XVID_ERR_FAIL) {
1084            printf("can't init decoder (err=%d)\n", xerr);            printf("can't init decoder (err=%d)\n", xerr);
1085            return;            return;
1086          }          }
# Line 651  Line 1101 
1101    }    }
1102    else printf( "Input size: %d\n", buf_size);    else printf( "Input size: %d\n", buf_size);
1103    
1104    buf = malloc(buf_size); // should be enuf'          buf = malloc(buf_size); /* should be enuf' */
1105    rgb_out = calloc(4, width*height);  // <-room for _RGB24          rgb_out = calloc(4, width*height);  /* <-room for _RGB24 */
1106    if (buf==0 || rgb_out==0) {    if (buf==0 || rgb_out==0) {
1107      printf( "malloc failed!\n" );      printf( "malloc failed!\n" );
1108      goto End;      goto End;
# Line 667  Line 1117 
1117    pos = 0;    pos = 0;
1118    t = -gettime_usec();    t = -gettime_usec();
1119    while(1) {    while(1) {
1120                    memset(&xframe, 0, sizeof(xframe));
1121                    xframe.version = XVID_VERSION;
1122      xframe.bitstream = buf + pos;      xframe.bitstream = buf + pos;
1123      xframe.length = buf_size - pos;      xframe.length = buf_size - pos;
1124      xframe.image = rgb_out;                  xframe.output.plane[0] = rgb_out;
1125      xframe.stride = width;                  xframe.output.stride[0] = width;
1126      xframe.colorspace = XVID_CSP_RGB24;                  xframe.output.csp = XVID_CSP_BGR;
1127      xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);      xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);
1128      nb++;      nb++;
1129      pos += xframe.length;      pos += xframe.length;
# Line 682  Line 1134 
1134      }      }
1135      if (pos==buf_size)      if (pos==buf_size)
1136        break;        break;
1137      if (xerr!=XVID_ERR_OK) {                  if (xerr==XVID_ERR_FAIL) {
1138            printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);            printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);
1139            break;            break;
1140          }          }
# Line 698  Line 1150 
1150    if (buf!=0) free(buf);    if (buf!=0) free(buf);
1151    if (dechandle!=0) {    if (dechandle!=0) {
1152      xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);      xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);
1153      if (xerr!=XVID_ERR_OK)                  if (xerr==XVID_ERR_FAIL)
1154              printf("destroy-decoder failed (err=%d)!\n", xerr);              printf("destroy-decoder failed (err=%d)!\n", xerr);
1155    }    }
1156    if (f!=0) fclose(f);    if (f!=0) fclose(f);
# Line 714  Line 1166 
1166    
1167    printf( "\n =====  (de)quant4_intra saturation bug? =====\n" );    printf( "\n =====  (de)quant4_intra saturation bug? =====\n" );
1168    
1169    for(cpu = cpu_short_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
1170    {    {
1171      int i;      int i;
1172      int16_t  Src[8*8], Dst[8*8];      int16_t  Src[8*8], Dst[8*8];
# Line 724  Line 1176 
1176    
1177      for(i=0; i<64; ++i) Src[i] = i-32;      for(i=0; i<64; ++i) Src[i] = i-32;
1178      set_intra_matrix( get_default_intra_matrix() );      set_intra_matrix( get_default_intra_matrix() );
1179      dequant4_intra(Dst, Src, 32, 5);                  dequant_mpeg_intra(Dst, Src, 31, 5);
1180      printf( "dequant4_intra with CPU=%s:  ", cpu->name);                  printf( "dequant_mpeg_intra with CPU=%s:  ", cpu->name);
1181      printf( "  Out[]= " );      printf( "  Out[]= " );
1182      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
1183      printf( "\n" );      printf( "\n" );
# Line 733  Line 1185 
1185    
1186    printf( "\n =====  (de)quant4_inter saturation bug? =====\n" );    printf( "\n =====  (de)quant4_inter saturation bug? =====\n" );
1187    
1188    for(cpu = cpu_short_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
1189    {    {
1190      int i;      int i;
1191      int16_t  Src[8*8], Dst[8*8];      int16_t  Src[8*8], Dst[8*8];
# Line 743  Line 1195 
1195    
1196      for(i=0; i<64; ++i) Src[i] = i-32;      for(i=0; i<64; ++i) Src[i] = i-32;
1197      set_inter_matrix( get_default_inter_matrix() );      set_inter_matrix( get_default_inter_matrix() );
1198      dequant4_inter(Dst, Src, 32);                  dequant_mpeg_inter(Dst, Src, 31);
1199      printf( "dequant4_inter with CPU=%s:  ", cpu->name);                  printf( "dequant_mpeg_inter with CPU=%s:  ", cpu->name);
1200      printf( "  Out[]= " );      printf( "  Out[]= " );
1201      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
1202      printf( "\n" );      printf( "\n" );
# Line 756  Line 1208 
1208    CPU *cpu;    CPU *cpu;
1209    short Blk[8*8], Blk0[8*8];    short Blk[8*8], Blk0[8*8];
1210    
1211    printf( "\n =====  fdct/idct saturation diffs =====\n" );          printf( "\n =====  fdct/idct precision diffs =====\n" );
1212    
1213    for(cpu = cpu_short_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
1214    {    {
1215      int i;      int i;
1216    
# Line 782  Line 1234 
1234    }    }
1235  }  }
1236    
1237    void test_quant_bug()
1238    {
1239            const int max_Q = 31;
1240            int i, n, qm, q;
1241            CPU *cpu;
1242            int16_t  Src[8*8], Dst[8*8];
1243            uint8_t Quant[8*8];
1244            CPU cpu_bug_list[] = { { "PLAINC", 0 }, { "MMX   ", XVID_CPU_MMX }, {0,0} };
1245            uint16_t Crcs_Inter[2][32];
1246            uint16_t Crcs_Intra[2][32];
1247            printf( "\n =====  test MPEG4-quantize bug =====\n" );
1248    
1249            for(i=0; i<64; ++i) Src[i] = 2048*(i-32)/32;
1250    
1251    #if 1
1252            for(qm=1; qm<=255; ++qm)
1253            {
1254                    for(i=0; i<8*8; ++i) Quant[i] = qm;
1255                    set_inter_matrix( Quant );
1256    
1257                    for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n)
1258                    {
1259                            uint16_t s;
1260    
1261                            if (!init_cpu(cpu))
1262                                    continue;
1263    
1264                            for(q=1; q<=max_Q; ++q) {
1265                                    emms();
1266                                    quant_mpeg_inter( Dst, Src, q );
1267                                    emms();
1268                                    for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i;
1269                                    Crcs_Inter[n][q] = s;
1270                            }
1271                    }
1272    
1273                    for(q=1; q<=max_Q; ++q)
1274                            for(i=0; i<n-1; ++i)
1275                                    if (Crcs_Inter[i][q]!=Crcs_Inter[i+1][q])
1276                                            printf( "Discrepancy Inter: qm=%d, q=%d  -> %d/%d !\n",
1277                                                            qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]);
1278            }
1279    #endif
1280    
1281    #if 1
1282            for(qm=1; qm<=255; ++qm)
1283            {
1284                    for(i=0; i<8*8; ++i) Quant[i] = qm;
1285                    set_intra_matrix( Quant );
1286    
1287                    for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n)
1288                    {
1289                            uint16_t s;
1290    
1291                            if (!init_cpu(cpu))
1292                                    continue;
1293    
1294                            for(q=1; q<=max_Q; ++q) {
1295                                    emms();
1296                                    quant_mpeg_intra( Dst, Src, q, q);
1297                                    emms();
1298                                    for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i;
1299                                    Crcs_Intra[n][q] = s;
1300                            }
1301                    }
1302    
1303                    for(q=1; q<=max_Q; ++q)
1304                            for(i=0; i<n-1; ++i)
1305                                    if (Crcs_Intra[i][q]!=Crcs_Intra[i+1][q])
1306                                            printf( "Discrepancy Intra: qm=%d, q=%d  -> %d/%d!\n",
1307                                                            qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]);
1308            }
1309    #endif
1310    }
1311    
1312  /*********************************************************************  /*********************************************************************
1313   * main   * main
# Line 798  Line 1324 
1324    if (what==0 || what==5) test_quant();    if (what==0 || what==5) test_quant();
1325    if (what==0 || what==6) test_cbp();    if (what==0 || what==6) test_cbp();
1326    
1327    if (what==8) {          if (what==7) {
1328                    test_IEEE1180_compliance(-256, 255, 1);
1329                    test_IEEE1180_compliance(-256, 255,-1);
1330                    test_IEEE1180_compliance(  -5,   5, 1);
1331                    test_IEEE1180_compliance(  -5,   5,-1);
1332                    test_IEEE1180_compliance(-300, 300, 1);
1333                    test_IEEE1180_compliance(-300, 300,-1);
1334            }
1335            if (what==8) test_dct_saturation(-256, 255);
1336    
1337            if (what==9) {
1338      int width, height;      int width, height;
1339      if (argc<5) {      if (argc<5) {
1340        printf("usage: %s %d [bitstream] [width] [height]\n", argv[0], what);        printf("usage: %s %d [bitstream] [width] [height]\n", argv[0], what);
# Line 810  Line 1346 
1346    }    }
1347    
1348    if (what==-1) {    if (what==-1) {
     test_bugs1();  
1349      test_dct_precision_diffs();      test_dct_precision_diffs();
1350                    test_bugs1();
1351    }    }
1352            if (what==-2)
1353                    test_quant_bug();
1354    
1355    return 0;    return 0;
1356  }  }
1357    
1358  /*********************************************************************  /*********************************************************************
1359   * 'Reference' output (except for timing) on a PIII 1.13Ghz/linux   * 'Reference' output (except for timing) on an Athlon XP 2200+
1360   *********************************************************************/   *********************************************************************/
1361    
1362    /* as of 07/01/2002, there's a problem with MMX mpeg4-quantization */
1363  /*  /*
1364    
1365   ===== test fdct/idct =====   ===== test fdct/idct =====
1366  PLAINC -  2.631 usec       iCrc=3  fCrc=-85  PLAINC -  1.446 usec       PSNR=13.291  MSE=3.000
1367  MMX    -  0.596 usec       iCrc=3  fCrc=-67  MMX    -  -0.260 usec       PSNR=9.611  MSE=7.000
1368  MMXEXT -  0.608 usec       iCrc=3  fCrc=-67  MMXEXT -  -0.293 usec       PSNR=9.611  MSE=7.000
1369  SSE2   -  0.605 usec       iCrc=3  fCrc=-67  3DNOW  -  1.535 usec       PSNR=13.291  MSE=3.000
1370  3DNOW  - skipped...  3DNOWE -  0.376 usec       PSNR=13.291  MSE=3.000
 3DNOWE - skipped...  
1371    
1372   ===  test block motion ===   ===  test block motion ===
1373  PLAINC - interp- h-round0 1.031 usec       iCrc=8107  PLAINC - interp- h-round0 0.126 usec       iCrc=8107
1374  PLAINC -           round1 1.022 usec       iCrc=8100  PLAINC -           round1 0.136 usec       iCrc=8100
1375  PLAINC - interp- v-round0 1.002 usec       iCrc=8108  PLAINC - interp- v-round0 0.121 usec       iCrc=8108
1376  PLAINC -           round1 1.011 usec       iCrc=8105  PLAINC -           round1 0.127 usec       iCrc=8105
1377  PLAINC - interp-hv-round0 1.623 usec       iCrc=8112  PLAINC - interp-hv-round0 0.192 usec       iCrc=8112
1378  PLAINC -           round1 1.621 usec       iCrc=8103  PLAINC -           round1 0.213 usec       iCrc=8103
1379  PLAINC - interpolate8x8_c 0.229 usec       iCrc=8107   ---
1380   ---  MMX    - interp- h-round0 0.048 usec       iCrc=8107
1381  MMX    - interp- h-round0 0.105 usec       iCrc=8107  MMX    -           round1 0.048 usec       iCrc=8100
1382  MMX    -           round1 0.105 usec       iCrc=8100  MMX    - interp- v-round0 0.046 usec       iCrc=8108
1383  MMX    - interp- v-round0 0.106 usec       iCrc=8108  MMX    -           round1 0.047 usec       iCrc=8105
1384  MMX    -           round1 0.107 usec       iCrc=8105  MMX    - interp-hv-round0 0.074 usec       iCrc=8112
1385  MMX    - interp-hv-round0 0.145 usec       iCrc=8112  MMX    -           round1 0.074 usec       iCrc=8103
1386  MMX    -           round1 0.145 usec       iCrc=8103   ---
1387  MMX    - interpolate8x8_c 0.229 usec       iCrc=8107  MMXEXT - interp- h-round0 0.019 usec       iCrc=8107
1388   ---  MMXEXT -           round1 0.025 usec       iCrc=8100
1389  MMXEXT - interp- h-round0 0.027 usec       iCrc=8107  MMXEXT - interp- v-round0 0.015 usec       iCrc=8108
1390  MMXEXT -           round1 0.041 usec       iCrc=8100  MMXEXT -           round1 0.024 usec       iCrc=8105
1391  MMXEXT - interp- v-round0 0.027 usec       iCrc=8108  MMXEXT - interp-hv-round0 0.039 usec       iCrc=8112
1392  MMXEXT -           round1 0.040 usec       iCrc=8105  MMXEXT -           round1 0.037 usec       iCrc=8103
1393  MMXEXT - interp-hv-round0 0.070 usec       iCrc=8112   ---
1394  MMXEXT -           round1 0.066 usec       iCrc=8103  3DNOW  - interp- h-round0 0.019 usec       iCrc=8107
1395  MMXEXT - interpolate8x8_c 0.027 usec       iCrc=8107  3DNOW  -           round1 0.023 usec       iCrc=8100
1396   ---  3DNOW  - interp- v-round0 0.015 usec       iCrc=8108
1397  SSE2   - interp- h-round0 0.106 usec       iCrc=8107  3DNOW  -           round1 0.024 usec       iCrc=8105
1398  SSE2   -           round1 0.105 usec       iCrc=8100  3DNOW  - interp-hv-round0 0.037 usec       iCrc=8112
1399  SSE2   - interp- v-round0 0.106 usec       iCrc=8108  3DNOW  -           round1 0.038 usec       iCrc=8103
1400  SSE2   -           round1 0.106 usec       iCrc=8105   ---
1401  SSE2   - interp-hv-round0 0.145 usec       iCrc=8112  3DNOWE - interp- h-round0 0.022 usec       iCrc=8107
1402  SSE2   -           round1 0.145 usec       iCrc=8103  3DNOWE -           round1 0.023 usec       iCrc=8100
1403  SSE2   - interpolate8x8_c 0.237 usec       iCrc=8107  3DNOWE - interp- v-round0 0.016 usec       iCrc=8108
1404    3DNOWE -           round1 0.021 usec       iCrc=8105
1405    3DNOWE - interp-hv-round0 0.036 usec       iCrc=8112
1406    3DNOWE -           round1 0.036 usec       iCrc=8103
1407   ---   ---
 3DNOW  - skipped...  
 3DNOWE - skipped...  
1408    
1409   ======  test SAD ======   ======  test SAD ======
1410  PLAINC - sad8    0.296 usec       sad=3776  PLAINC - sad8    0.165 usec       sad=3776
1411  PLAINC - sad16   1.599 usec       sad=27214  PLAINC - sad16   0.587 usec       sad=27214
1412  PLAINC - sad16bi 2.350 usec       sad=26274  PLAINC - sad16bi 1.290 usec       sad=26274
1413  PLAINC - dev16   1.610 usec       sad=3344  PLAINC - dev16   1.535 usec       sad=3344
1414   ---   ---
1415  MMX    - sad8    0.057 usec       sad=3776  MMX    - sad8    0.036 usec       sad=3776
1416  MMX    - sad16   0.178 usec       sad=27214  MMX    - sad16   0.113 usec       sad=27214
1417  MMX    - sad16bi 2.381 usec       sad=26274  MMX    - sad16bi 0.250 usec       sad=26274
1418  MMX    - dev16   0.312 usec       sad=3344  MMX    - dev16   0.187 usec       sad=3344
1419   ---   ---
1420  MMXEXT - sad8    0.036 usec       sad=3776  MMXEXT - sad8    0.015 usec       sad=3776
1421  MMXEXT - sad16   0.106 usec       sad=27214  MMXEXT - sad16   0.046 usec       sad=27214
1422  MMXEXT - sad16bi 0.182 usec       sad=26274  MMXEXT - sad16bi 0.059 usec       sad=26274
1423  MMXEXT - dev16   0.193 usec       sad=3344  MMXEXT - dev16   0.088 usec       sad=3344
1424   ---   ---
1425  SSE2   - sad8    0.057 usec       sad=3776  3DNOW  - sad8    0.165 usec       sad=3776
1426  SSE2   - sad16   0.178 usec       sad=27214  3DNOW  - sad16   0.589 usec       sad=27214
1427  SSE2   - sad16bi 2.427 usec       sad=26274  3DNOW  - sad16bi 0.119 usec       sad=26274
1428  SSE2   - dev16   0.313 usec       sad=3344  3DNOW  - dev16   1.541 usec       sad=3344
1429     ---
1430    3DNOWE - sad8    0.018 usec       sad=3776
1431    3DNOWE - sad16   0.039 usec       sad=27214
1432    3DNOWE - sad16bi 0.051 usec       sad=26274
1433    3DNOWE - dev16   0.070 usec       sad=3344
1434   ---   ---
 3DNOW  - skipped...  
 3DNOWE - skipped...  
1435    
1436   ===  test transfer ===   ===  test transfer ===
1437  PLAINC - 8to16     0.124 usec       crc=28288  PLAINC - 8to16     0.207 usec       crc=28288
1438  PLAINC - 16to8     0.753 usec       crc=28288  PLAINC - 16to8     0.357 usec       crc=28288
1439  PLAINC - 8to8      0.041 usec       crc=20352  PLAINC - 8to8      0.154 usec       crc=20352
1440  PLAINC - 16to8add  0.916 usec       crc=25536  PLAINC - 16to8add  0.391 usec       crc=25536
1441  PLAINC - 8to16sub  0.812 usec       crc1=28064 crc2=16256  PLAINC - 8to16sub  0.562 usec       crc1=28064 crc2=16256
1442  PLAINC - 8to16sub2 0.954 usec       crc=20384  PLAINC - 8to16sub2 0.519 usec       crc=22368
1443   ---   ---
1444  MMX    - 8to16     0.037 usec       crc=28288  MMX    - 8to16     0.048 usec       crc=28288
1445  MMX    - 16to8     0.016 usec       crc=28288  MMX    - 16to8     0.205 usec       crc=28288
1446  MMX    - 8to8      0.018 usec       crc=20352  MMX    - 8to8      -0.158 usec       crc=20352
1447  MMX    - 16to8add  0.044 usec       crc=25536  MMX    - 16to8add  0.015 usec       crc=25536
1448  MMX    - 8to16sub  0.065 usec       crc1=28064 crc2=16256  MMX    - 8to16sub  0.203 usec       crc1=28064 crc2=16256
1449  MMX    - 8to16sub2 0.110 usec       crc=20384  MMX    - 8to16sub2 0.087 usec       crc=22368
1450   ---   ---
1451  MMXEXT - 8to16     0.032 usec       crc=28288  MMXEXT - 8to16     0.013 usec       crc=28288
1452  MMXEXT - 16to8     0.023 usec       crc=28288  MMXEXT - 16to8     0.011 usec       crc=28288
1453  MMXEXT - 8to8      0.018 usec       crc=20352  MMXEXT - 8to8      -0.023 usec       crc=20352
1454  MMXEXT - 16to8add  0.041 usec       crc=25536  MMXEXT - 16to8add  0.023 usec       crc=25536
1455  MMXEXT - 8to16sub  0.065 usec       crc1=28064 crc2=16256  MMXEXT - 8to16sub  0.072 usec       crc1=28064 crc2=16256
1456  MMXEXT - 8to16sub2 0.069 usec       crc=20384  MMXEXT - 8to16sub2 0.093 usec       crc=22368
1457     ---
1458    3DNOW  - 8to16     0.192 usec       crc=28288
1459    3DNOW  - 16to8     0.367 usec       crc=28288
1460    3DNOW  - 8to8      0.132 usec       crc=20352
1461    3DNOW  - 16to8add  0.440 usec       crc=25536
1462    3DNOW  - 8to16sub  0.557 usec       crc1=28064 crc2=16256
1463    3DNOW  - 8to16sub2 0.691 usec       crc=22368
1464     ---
1465    3DNOWE - 8to16     0.004 usec       crc=28288
1466    3DNOWE - 16to8     0.019 usec       crc=28288
1467    3DNOWE - 8to8      -0.294 usec       crc=20352
1468    3DNOWE - 16to8add  0.028 usec       crc=25536
1469    3DNOWE - 8to16sub  0.065 usec       crc1=28064 crc2=16256
1470    3DNOWE - 8to16sub2 0.027 usec       crc=22368
1471   ---   ---
1472    
1473   =====  test quant =====   =====  test quant =====
1474  PLAINC -   quant4_intra 78.889 usec       crc=55827  PLAINC -   quant_mpeg_intra 67.757 usec       crc=29809
1475  PLAINC -   quant4_inter 71.957 usec       crc=58201  PLAINC -   quant_mpeg_inter 68.482 usec       crc=12574
1476  PLAINC - dequant4_intra 34.968 usec       crc=193340  PLAINC - dequant_mpeg_intra 20.764 usec       crc=24052
1477  PLAINC - dequant4_inter 40.792 usec       crc=116483  PLAINC - dequant_mpeg_inter 24.413 usec       crc=63847
1478  PLAINC -    quant_intra 30.845 usec       crc=56885  PLAINC -   quant_h263_intra 16.446 usec       crc=25662
1479  PLAINC -    quant_inter 34.842 usec       crc=58056  PLAINC -   quant_h263_inter 14.499 usec       crc=23972
1480  PLAINC -  dequant_intra 33.211 usec       crc=-7936  PLAINC - dequant_h263_intra 16.419 usec       crc=49900
1481  PLAINC -  dequant_inter 45.486 usec       crc=-33217  PLAINC - dequant_h263_inter 18.679 usec       crc=48899
1482   ---   ---
1483  MMX    -   quant4_intra 9.030 usec       crc=55827  MMX    -   quant_mpeg_intra 8.299 usec       crc=3459
1484  MMX    -   quant4_inter 8.234 usec       crc=58201  *** CRC ERROR! ***
1485  MMX    - dequant4_intra 18.330 usec       crc=193340  MMX    -   quant_mpeg_inter 7.078 usec       crc=13247
1486  MMX    - dequant4_inter 19.181 usec       crc=116483  *** CRC ERROR! ***
1487  MMX    -    quant_intra 7.124 usec       crc=56885  MMX    - dequant_mpeg_intra 3.455 usec       crc=24052
1488  MMX    -    quant_inter 6.861 usec       crc=58056  MMX    - dequant_mpeg_inter 4.483 usec       crc=63847
1489  MMX    -  dequant_intra 9.048 usec       crc=-7936  MMX    -   quant_h263_intra 2.597 usec       crc=25662
1490  MMX    -  dequant_inter 8.203 usec       crc=-33217  MMX    -   quant_h263_inter 2.151 usec       crc=23972
1491   ---  MMX    - dequant_h263_intra 2.684 usec       crc=49900
1492  MMXEXT -   quant4_intra 9.045 usec       crc=55827  MMX    - dequant_h263_inter 2.647 usec       crc=48899
1493  MMXEXT -   quant4_inter 8.232 usec       crc=58201   ---
1494  MMXEXT - dequant4_intra 18.250 usec       crc=193340  MMXEXT -   quant_mpeg_intra 3.878 usec       crc=29809
1495  MMXEXT - dequant4_inter 19.256 usec       crc=116483  MMXEXT -   quant_mpeg_inter 4.112 usec       crc=12574
1496  MMXEXT -    quant_intra 7.121 usec       crc=56885  MMXEXT - dequant_mpeg_intra 3.452 usec       crc=24052
1497  MMXEXT -    quant_inter 6.855 usec       crc=58056  MMXEXT - dequant_mpeg_inter 4.473 usec       crc=63847
1498  MMXEXT -  dequant_intra 9.034 usec       crc=-7936  MMXEXT -   quant_h263_intra 2.608 usec       crc=25662
1499  MMXEXT -  dequant_inter 8.202 usec       crc=-33217  MMXEXT -   quant_h263_inter 2.145 usec       crc=23972
1500    MMXEXT - dequant_h263_intra 2.478 usec       crc=49900
1501    MMXEXT - dequant_h263_inter 2.450 usec       crc=48899
1502     ---
1503    3DNOW  -   quant_mpeg_intra 66.051 usec       crc=29809
1504    3DNOW  -   quant_mpeg_inter 73.494 usec       crc=12574
1505    3DNOW  - dequant_mpeg_intra 20.374 usec       crc=24052
1506    3DNOW  - dequant_mpeg_inter 23.645 usec       crc=63847
1507    3DNOW  -   quant_h263_intra 16.292 usec       crc=25662
1508    3DNOW  -   quant_h263_inter 14.322 usec       crc=23972
1509    3DNOW  - dequant_h263_intra 16.613 usec       crc=49900
1510    3DNOW  - dequant_h263_inter 18.382 usec       crc=48899
1511     ---
1512    3DNOWE -   quant_mpeg_intra 66.140 usec       crc=29809
1513    3DNOWE -   quant_mpeg_inter 68.454 usec       crc=12574
1514    3DNOWE - dequant_mpeg_intra 2.881 usec       crc=24052
1515    3DNOWE - dequant_mpeg_inter 4.155 usec       crc=63847
1516    3DNOWE -   quant_h263_intra 1.451 usec       crc=25662
1517    3DNOWE -   quant_h263_inter 1.849 usec       crc=23972
1518    3DNOWE - dequant_h263_intra 2.101 usec       crc=49900
1519    3DNOWE - dequant_h263_inter 2.109 usec       crc=48899
1520   ---   ---
1521    
1522   =====  test cbp =====   =====  test cbp =====
1523  PLAINC -   calc_cbp#1 0.545 usec       cbp=0x15  PLAINC -   calc_cbp#1 0.090 usec       cbp=0x15
1524  PLAINC -   calc_cbp#2 0.540 usec       cbp=0x38  PLAINC -   calc_cbp#2 0.086 usec       cbp=0x38
1525  PLAINC -   calc_cbp#3 0.477 usec       cbp=0xf  PLAINC -   calc_cbp#3 0.087 usec       cbp=0xf
1526  PLAINC -   calc_cbp#4 0.739 usec       cbp=0x5  PLAINC -   calc_cbp#4 0.114 usec       cbp=0x5
1527   ---   ---
1528  MMX    -   calc_cbp#1 0.136 usec       cbp=0x15  MMX    -   calc_cbp#1 0.061 usec       cbp=0x15
1529  MMX    -   calc_cbp#2 0.131 usec       cbp=0x38  MMX    -   calc_cbp#2 0.063 usec       cbp=0x38
1530  MMX    -   calc_cbp#3 0.132 usec       cbp=0xf  MMX    -   calc_cbp#3 0.061 usec       cbp=0xf
1531  MMX    -   calc_cbp#4 0.135 usec       cbp=0x5  MMX    -   calc_cbp#4 0.060 usec       cbp=0x5
1532   ---   ---
1533  SSE2   -   calc_cbp#1 0.135 usec       cbp=0x15  MMXEXT -   calc_cbp#1 0.062 usec       cbp=0x15
1534  SSE2   -   calc_cbp#2 0.131 usec       cbp=0x38  MMXEXT -   calc_cbp#2 0.060 usec       cbp=0x38
1535  SSE2   -   calc_cbp#3 0.134 usec       cbp=0xf  MMXEXT -   calc_cbp#3 0.062 usec       cbp=0xf
1536  SSE2   -   calc_cbp#4 0.136 usec       cbp=0x5  MMXEXT -   calc_cbp#4 0.061 usec       cbp=0x5
1537   ---   ---
1538    3DNOW  -   calc_cbp#1 0.089 usec       cbp=0x15
1539    3DNOW  -   calc_cbp#2 0.087 usec       cbp=0x38
1540    3DNOW  -   calc_cbp#3 0.087 usec       cbp=0xf
1541    3DNOW  -   calc_cbp#4 0.116 usec       cbp=0x5
1542     ---
1543    3DNOWE -   calc_cbp#1 0.050 usec       cbp=0x15
1544    3DNOWE -   calc_cbp#2 0.051 usec       cbp=0x38
1545    3DNOWE -   calc_cbp#3 0.050 usec       cbp=0xf
1546    3DNOWE -   calc_cbp#4 0.049 usec       cbp=0x5
1547     ---
1548    
1549  */  */

Legend:
Removed from v.257  
changed lines
  Added in v.1220

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