[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 1199, Mon Nov 3 19:58:16 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.7 2003-11-03 19:58:16 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 445  Line 490 
490      s = 0; for(i=0; i<8*32; ++i) { s += (Src8[i]-Ref1[i])&i; }      s = 0; for(i=0; i<8*32; ++i) { s += (Src8[i]-Ref1[i])&i; }
491      printf( "crc2=%d\n", s);      printf( "crc2=%d\n", s);
492      if (s!=16256) printf( "*** CRC ERROR! ***\n" );      if (s!=16256) printf( "*** CRC ERROR! ***\n" );
493    #if 1
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!=20384) printf( "*** CRC ERROR! ***\n" );
497    //    for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]);
498    //    printf("\n");
499    #endif
500      printf( " --- \n" );      printf( " --- \n" );
501    }    }
502  }  }
# Line 460  Line 507 
507    
508  #define TEST_QUANT(FUNC, DST, SRC)            \  #define TEST_QUANT(FUNC, DST, SRC)            \
509      t = gettime_usec();                       \      t = gettime_usec();                       \
510    for(s=0,qm=1; qm<=255; ++qm) {              \
511      for(i=0; i<8*8; ++i) Quant[i] = qm;       \
512      set_inter_matrix( Quant );                \
513      emms();                                   \      emms();                                   \
514      for(q=1; q<=max_Q; ++q) {                 \
515      for(tst=0; tst<nb_tests; ++tst)           \      for(tst=0; tst<nb_tests; ++tst)           \
       for(s=0, q=1; q<=max_Q; ++q) {          \  
516          (FUNC)((DST), (SRC), q);              \          (FUNC)((DST), (SRC), q);              \
517          for(i=0; i<64; ++i) s+=(DST)[i]^i;    \          for(i=0; i<64; ++i) s+=(DST)[i]^i^qm;   \
518        }                                       \        }                                       \
519      emms();                                   \      emms();                                   \
520      t = (gettime_usec()-t-overhead)/nb_tests;  }                                           \
521    t = (gettime_usec()-t-overhead)/nb_tests/qm;\
522    s = (s&0xffff)^(s>>16)
523    
524  #define TEST_QUANT2(FUNC, DST, SRC, MULT)     \  #define TEST_QUANT2(FUNC, DST, SRC)             \
525      t = gettime_usec();                       \      t = gettime_usec();                       \
526    for(s=0,qm=1; qm<=255; ++qm) {              \
527      for(i=0; i<8*8; ++i) Quant[i] = qm;       \
528      set_intra_matrix( Quant );                \
529      emms();                                   \      emms();                                   \
530      for(q=1; q<=max_Q; ++q) {                 \
531      for(tst=0; tst<nb_tests; ++tst)           \      for(tst=0; tst<nb_tests; ++tst)           \
532        for(s=0, q=1; q<=max_Q; ++q) {          \            (FUNC)((DST), (SRC), q, q);           \
533          (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;    \  
534        }                                       \        }                                       \
535      emms();                                   \      emms();                                   \
536      t = (gettime_usec()-t-overhead)/nb_tests;  }                                           \
537    t = (gettime_usec()-t-overhead)/nb_tests/qm;\
538    s = (s&0xffff)^(s>>16)
539    
540  void test_quant()  void test_quant()
541  {  {
542    const int nb_tests = 150*speed_ref;          const int nb_tests = 1*speed_ref;
543    const int max_Q = 31;    const int max_Q = 31;
544    int i;          int i, qm;
545    CPU *cpu;    CPU *cpu;
546    int16_t  Src[8*8], Dst[8*8];    int16_t  Src[8*8], Dst[8*8];
547            uint8_t Quant[8*8];
548    
549    printf( "\n =====  test quant =====\n" );    printf( "\n =====  test quant =====\n" );
550    
551    /* we deliberately enfringe the norm's specified range [-127,127], */
552    /* to test the robustness of the iquant module */
553    for(i=0; i<64; ++i) {    for(i=0; i<64; ++i) {
554      Src[i] = i-32;                  Src[i] = 1 + (i-32) * (i&6);
555      Dst[i] = 0;      Dst[i] = 0;
556    }    }
557    
558            for(cpu = cpu_list; cpu->name!=0; ++cpu)
   for(cpu = cpu_short_list; cpu->name!=0; ++cpu)  
559    {    {
560      double t, overhead;      double t, overhead;
561      int tst, s, q;                  int tst, q;
562                    uint32_t s;
563    
564      if (!init_cpu(cpu))      if (!init_cpu(cpu))
565        continue;        continue;
566    
     set_inter_matrix( get_default_inter_matrix() );  
     set_intra_matrix( get_default_intra_matrix() );  
567      overhead = -gettime_usec();      overhead = -gettime_usec();
568      for(tst=0; tst<nb_tests; ++tst)                  for(s=0,qm=1; qm<=255; ++qm) {
569        for(s=0, q=1; q<=max_Q; ++q)                          for(i=0; i<8*8; ++i) Quant[i] = qm;
570          for(i=0; i<64; ++i) s+=Dst[i]^i;                          set_inter_matrix( Quant );
571                            for(q=1; q<=max_Q; ++q)
572                                    for(i=0; i<64; ++i) s+=Dst[i]^i^qm;
573                    }
574      overhead += gettime_usec();      overhead += gettime_usec();
575    
576      TEST_QUANT2(quant4_intra, Dst, Src, 7);  #if 1
577      printf( "%s -   quant4_intra %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT2(quant_mpeg_intra, Dst, Src);
578      if (s!=55827) printf( "*** CRC ERROR! ***\n" );                  printf( "%s -   quant_mpeg_intra %.3f usec       crc=%d\n", cpu->name, t, s );
579                    if (s!=29809) printf( "*** CRC ERROR! ***\n" );
580      TEST_QUANT(quant4_inter, Dst, Src);  
581      printf( "%s -   quant4_inter %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT(quant_mpeg_inter, Dst, Src);
582      if (s!=58201) printf( "*** CRC ERROR! ***\n" );                  printf( "%s -   quant_mpeg_inter %.3f usec       crc=%d\n", cpu->name, t, s );
583                    if (s!=12574) printf( "*** CRC ERROR! ***\n" );
584    #endif
585      TEST_QUANT2(dequant4_intra, Dst, Src, 7);  #if 1
586      printf( "%s - dequant4_intra %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT2(dequant_mpeg_intra, Dst, Src);
587      if (s!=193340) printf( "*** CRC ERROR! ***\n" );                  printf( "%s - dequant_mpeg_intra %.3f usec       crc=%d\n", cpu->name, t, s );
588                    if (s!=24052) printf( "*** CRC ERROR! ***\n" );
589      TEST_QUANT(dequant4_inter, Dst, Src);  
590      printf( "%s - dequant4_inter %.3f usec       crc=%d\n", cpu->name, t, s );                  TEST_QUANT(dequant_mpeg_inter, Dst, Src);
591      if (s!=116483) printf( "*** CRC ERROR! ***\n" );                  printf( "%s - dequant_mpeg_inter %.3f usec       crc=%d\n", cpu->name, t, s );
592                    if (s!=63847) printf( "*** CRC ERROR! ***\n" );
593      TEST_QUANT2(quant_intra, Dst, Src, 7);  #endif
594      printf( "%s -    quant_intra %.3f usec       crc=%d\n", cpu->name, t, s );  #if 1
595      if (s!=56885) printf( "*** CRC ERROR! ***\n" );                  TEST_QUANT2(quant_h263_intra, Dst, Src);
596                    printf( "%s -   quant_h263_intra %.3f usec       crc=%d\n", cpu->name, t, s );
597      TEST_QUANT(quant_inter, Dst, Src);                  if (s!=25662) printf( "*** CRC ERROR! ***\n" );
598      printf( "%s -    quant_inter %.3f usec       crc=%d\n", cpu->name, t, s );  
599      if (s!=58056) printf( "*** CRC ERROR! ***\n" );                  TEST_QUANT(quant_h263_inter, Dst, Src);
600                    printf( "%s -   quant_h263_inter %.3f usec       crc=%d\n", cpu->name, t, s );
601      TEST_QUANT2(dequant_intra, Dst, Src, 7);                  if (s!=23972) printf( "*** CRC ERROR! ***\n" );
602      printf( "%s -  dequant_intra %.3f usec       crc=%d\n", cpu->name, t, s );  #endif
603      if (s!=-7936) printf( "*** CRC ERROR! ***\n" );  #if 1
604                    TEST_QUANT2(dequant_h263_intra, Dst, Src);
605      TEST_QUANT(dequant_inter, Dst, Src);                  printf( "%s - dequant_h263_intra %.3f usec       crc=%d\n", cpu->name, t, s );
606      printf( "%s -  dequant_inter %.3f usec       crc=%d\n", cpu->name, t, s );                  if (s!=49900) printf( "*** CRC ERROR! ***\n" );
607  //    { int k,l; for(k=0; k<8; ++k) { for(l=0; l<8; ++l) printf( "[%.4d]", Dst[k*8+l]); printf("\n"); } }  
608      if (s!=-33217) printf( "*** CRC ERROR! ***\n" );                  TEST_QUANT(dequant_h263_inter, Dst, Src);
609                    printf( "%s - dequant_h263_inter %.3f usec       crc=%d\n", cpu->name, t, s );
610                    if (s!=48899) printf( "*** CRC ERROR! ***\n" );
611    #endif
612      printf( " --- \n" );      printf( " --- \n" );
613    }    }
614  }  }
# Line 573  Line 636 
636    printf( "\n =====  test cbp =====\n" );    printf( "\n =====  test cbp =====\n" );
637    
638    for(i=0; i<6*64; ++i) {    for(i=0; i<6*64; ++i) {
639      Src1[i] = (i*i*3/8192)&(i/64)&1;  // 'random'                  Src1[i] = (i*i*3/8192)&(i/64)&1;  /* 'random' */
640      Src2[i] = (i<3*64);               // half-full                  Src2[i] = (i<3*64);               /* half-full */
641      Src3[i] = ((i+32)>3*64);      Src3[i] = ((i+32)>3*64);
642      Src4[i] = (i==(3*64+2) || i==(5*64+9));      Src4[i] = (i==(3*64+2) || i==(5*64+9));
643    }    }
644    
645    for(cpu = cpu_short_list2; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
646    {    {
647      double t;      double t;
648      int tst, cbp;      int tst, cbp;
# Line 604  Line 667 
667  }  }
668    
669  /*********************************************************************  /*********************************************************************
670     * fdct/idct IEEE1180 compliance
671     *********************************************************************/
672    
673    typedef struct {
674            long Errors[64];
675            long Sqr_Errors[64];
676            long Max_Errors[64];
677            long Nb;
678    } STATS_8x8;
679    
680    void init_stats(STATS_8x8 *S)
681    {
682            int i;
683            for(i=0; i<64; ++i) {
684                    S->Errors[i]     = 0;
685                    S->Sqr_Errors[i] = 0;
686                    S->Max_Errors[i] = 0;
687            }
688            S->Nb = 0;
689    }
690    
691    void store_stats(STATS_8x8 *S, short Blk[64], short Ref[64])
692    {
693            int i;
694            for(i=0; i<64; ++i)
695            {
696                    short Err = Blk[i] - Ref[i];
697                    S->Errors[i] += Err;
698                    S->Sqr_Errors[i] += Err * Err;
699                    if (Err<0) Err = -Err;
700                    if (S->Max_Errors[i]<Err)
701                            S->Max_Errors[i] = Err;
702            }
703            S->Nb++;
704    }
705    
706    void print_stats(STATS_8x8 *S)
707    {
708            int i;
709            double Norm;
710    
711            assert(S->Nb>0);
712            Norm = 1. / (double)S->Nb;
713            printf("\n== Max absolute values of errors ==\n");
714            for(i=0; i<64; i++) {
715                    printf("  %4ld", S->Max_Errors[i]);
716                    if ((i&7)==7) printf("\n");
717            }
718    
719            printf("\n== Mean square errors ==\n");
720            for(i=0; i<64; i++)
721            {
722                    double Err = Norm * (double)S->Sqr_Errors[i];
723                    printf(" %.3f", Err);
724                    if ((i&7)==7) printf("\n");
725            }
726    
727            printf("\n== Mean errors ==\n");
728            for(i=0; i<64; i++)
729            {
730                    double Err = Norm * (double)S->Errors[i];
731                    printf(" %.3f", Err);
732                    if ((i&7)==7) printf("\n");
733            }
734            printf("\n");
735    }
736    
737    static const char *CHECK(double v, double l) {
738            if (fabs(v)<=l) return "ok";
739            else return "FAIL!";
740    }
741    
742    void report_stats(STATS_8x8 *S, const double *Limits)
743    {
744            int i;
745            double Norm, PE, PMSE, OMSE, PME, OME;
746    
747            assert(S->Nb>0);
748            Norm = 1. / (double)S->Nb;
749            PE = 0.;
750            for(i=0; i<64; i++) {
751                    if (PE<S->Max_Errors[i])
752                            PE = S->Max_Errors[i];
753            }
754    
755            PMSE = 0.;
756            OMSE = 0.;
757            for(i=0; i<64; i++)
758            {
759                    double Err = Norm * (double)S->Sqr_Errors[i];
760                    OMSE += Err;
761                    if (PMSE < Err) PMSE = Err;
762            }
763            OMSE /= 64.;
764    
765            PME = 0.;
766            OME = 0.;
767            for(i=0; i<64; i++)
768            {
769                    double Err = Norm * (double)S->Errors[i];
770                    OME += Err;
771                    Err = fabs(Err);
772                    if (PME < Err) PME = Err;
773            }
774            OME /= 64.;
775    
776            printf( "Peak error:   %4.4f\n", PE );
777            printf( "Peak MSE:     %4.4f\n", PMSE );
778            printf( "Overall MSE:  %4.4f\n", OMSE );
779            printf( "Peak ME:      %4.4f\n", PME );
780            printf( "Overall ME:   %4.4f\n", OME );
781    
782            if (Limits!=0)
783            {
784                    printf( "[PE<=%.4f %s]  ", Limits[0], CHECK(PE,   Limits[0]) );
785                    printf( "\n" );
786                    printf( "[PMSE<=%.4f %s]", Limits[1], CHECK(PMSE, Limits[1]) );
787                    printf( "[OMSE<=%.4f %s]", Limits[2], CHECK(OMSE, Limits[2]) );
788                    printf( "\n" );
789                    printf( "[PME<=%.4f %s] ", Limits[3], CHECK(PME , Limits[3]) );
790                    printf( "[OME<=%.4f %s] ", Limits[4], CHECK(OME , Limits[4]) );
791                    printf( "\n" );
792            }
793    }
794    
795    ///* ////////////////////////////////////////////////////// */
796    /* Pseudo-random generator specified by IEEE 1180 */
797    
798    static long ieee_seed = 1;
799    static void ieee_reseed(long s) {
800            ieee_seed = s;
801    }
802    static long ieee_rand(int Min, int Max)
803    {
804            static double z = (double) 0x7fffffff;
805    
806            long i,j;
807            double x;
808    
809            ieee_seed = (ieee_seed * 1103515245) + 12345;
810            i = ieee_seed & 0x7ffffffe;
811            x = ((double) i) / z;
812            x *= (Max-Min+1);
813            j = (long)x;
814            j = j + Min;
815            assert(j>=Min && j<=Max);
816            return (short)j;
817    }
818    
819    #define CLAMP(x, M)   (x) = ((x)<-(M)) ? (-(M)) : ((x)>=(M) ? ((M)-1) : (x))
820    
821    static double Cos[8][8];
822    static void init_ref_dct()
823    {
824            int i, j;
825            for(i=0; i<8; i++)
826            {
827                    double scale = (i == 0) ? sqrt(0.125) : 0.5;
828                    for (j=0; j<8; j++)
829                            Cos[i][j] = scale*cos( (M_PI/8.0)*i*(j + 0.5) );
830            }
831    }
832    
833    void ref_idct(short *M)
834    {
835            int i, j, k;
836            double Tmp[8][8];
837    
838            for(i=0; i<8; i++) {
839                    for(j=0; j<8; j++)
840                    {
841                            double Sum = 0.0;
842                            for (k=0; k<8; k++) Sum += Cos[k][j]*M[8*i+k];
843                            Tmp[i][j] = Sum;
844                    }
845            }
846            for(i=0; i<8; i++) {
847                    for(j=0; j<8; j++) {
848                            double Sum = 0.0;
849                            for (k=0; k<8; k++) Sum += Cos[k][i]*Tmp[k][j];
850                            M[8*i+j] = (short)floor(Sum + .5);
851                    }
852            }
853    }
854    
855    void ref_fdct(short *M)
856    {
857            int i, j, k;
858            double Tmp[8][8];
859    
860            for(i=0; i<8; i++) {
861                    for(j=0; j<8; j++)
862                    {
863                            double Sum = 0.0;
864                            for (k=0; k<8; k++) Sum += Cos[j][k]*M[8*i+k];
865                            Tmp[i][j] = Sum;
866                    }
867            }
868            for(i=0; i<8; i++) {
869                    for(j=0; j<8; j++) {
870                            double Sum = 0.0;
871                            for (k=0; k<8; k++) Sum += Cos[i][k]*Tmp[k][j];
872                            M[8*i+j] = (short)floor(Sum + 0.5);
873                    }
874            }
875    }
876    
877    void test_IEEE1180_compliance(int Min, int Max, int Sign)
878    {
879            static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 };
880            int Loops = 10000;
881            int i, m, n;
882            DECLARE_ALIGNED_MATRIX(Blk0, 8, 8, short, 16); /* reference */
883            DECLARE_ALIGNED_MATRIX(Blk,  8, 8, short, 16);
884            DECLARE_ALIGNED_MATRIX(iBlk, 8, 8, short, 16);
885            DECLARE_ALIGNED_MATRIX(Ref_FDCT, 8, 8, short, 16);
886            DECLARE_ALIGNED_MATRIX(Ref_IDCT, 8, 8, short, 16);
887    
888            STATS_8x8 FStats; /* forward dct stats */
889            STATS_8x8 IStats; /* inverse dct stats */
890    
891            CPU *cpu;
892    
893            init_ref_dct();
894    
895            for(cpu = cpu_list; cpu->name!=0; ++cpu)
896            {
897                    if (!init_cpu(cpu))
898                            continue;
899    
900                    printf( "\n===== IEEE test for %s ==== (Min=%d Max=%d Sign=%d Loops=%d)\n",
901                                    cpu->name, Min, Max, Sign, Loops);
902    
903                    init_stats(&IStats);
904                    init_stats(&FStats);
905    
906                    ieee_reseed(1);
907                    for(n=0; n<Loops; ++n)
908                    {
909                            for(i=0; i<64; ++i)
910                                    Blk0[i] = (short)ieee_rand(Min,Max) * Sign;
911    
912                            /* hmm, I'm not quite sure this is exactly */
913                            /* the tests described in the norm. check... */
914    
915                            memcpy(Ref_FDCT, Blk0, 64*sizeof(short));
916                            ref_fdct(Ref_FDCT);
917                            for(i=0; i<64; i++) CLAMP( Ref_FDCT[i], 2048 );
918    
919                            memcpy(Blk, Blk0, 64*sizeof(short));
920                            emms(); fdct(Blk); emms();
921                            for(i=0; i<64; i++) CLAMP( Blk[i], 2048 );
922    
923                            store_stats(&FStats, Blk, Ref_FDCT);
924    
925    
926                            memcpy(Ref_IDCT, Ref_FDCT, 64*sizeof(short));
927                            ref_idct(Ref_IDCT);
928                            for (i=0; i<64; i++) CLAMP( Ref_IDCT[i], 256 );
929    
930                            memcpy(iBlk, Ref_FDCT, 64*sizeof(short));
931                            emms(); idct(iBlk); emms();
932                            for(i=0; i<64; i++) CLAMP( iBlk[i], 256 );
933    
934                            store_stats(&IStats, iBlk, Ref_IDCT);
935                    }
936    
937    
938                    printf( "\n  -- FDCT report --\n" );
939    //    print_stats(&FStats);
940                    report_stats(&FStats, 0); /* so far I know, IEEE1180 says nothing for fdct */
941    
942                    for(i=0; i<64; i++) Blk[i] = 0;
943                    emms(); fdct(Blk); emms();
944                    for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;
945                    printf( "FDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );
946    
947                    printf( "\n  -- IDCT report --\n" );
948    //    print_stats(&IStats);
949                    report_stats(&IStats, ILimits);
950    
951    
952                    for(i=0; i<64; i++) Blk[i] = 0;
953                    emms(); idct(Blk); emms();
954                    for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;
955                    printf( "IDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );
956            }
957    }
958    
959    
960    void test_dct_saturation(int Min, int Max)
961    {
962    /* test behaviour on input range fringe */
963    
964            int i, n, p;
965            CPU *cpu;
966    //  const short IDCT_MAX =  2047;  /* 12bits input */
967    //  const short IDCT_MIN = -2048;
968    //  const short IDCT_OUT =   256;  /* 9bits ouput */
969            const int Partitions = 4;
970            const int Loops = 10000 / Partitions;
971    
972            init_ref_dct();
973    
974            for(cpu = cpu_list; cpu->name!=0; ++cpu)
975            {
976                    short Blk0[64], Blk[64];
977                    STATS_8x8 Stats;
978    
979                    if (!init_cpu(cpu))
980                            continue;
981    
982                    printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n",
983                                    cpu->name, Min, Max );
984    
985                    /* FDCT tests // */
986    
987                    init_stats(&Stats);
988    
989                    /* test each computation channels separately */
990                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0;
991                    ref_fdct(Blk0);
992                    emms(); fdct(Blk); emms();
993                    store_stats(&Stats, Blk, Blk0);
994    
995                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Min : 0;
996                    ref_fdct(Blk0);
997                    emms(); fdct(Blk); emms();
998                    store_stats(&Stats, Blk, Blk0);
999    
1000                    /* randomly saturated inputs */
1001                    for(p=0; p<Partitions; ++p)
1002                    {
1003                            for(n=0; n<Loops; ++n)
1004                            {
1005                                    for(i=0; i<64; ++i)
1006                                            Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? Max : Min;
1007                                    ref_fdct(Blk0);
1008                                    emms(); fdct(Blk); emms();
1009                                    store_stats(&Stats, Blk, Blk0);
1010                            }
1011                    }
1012                    printf( "\n  -- FDCT saturation report --\n" );
1013                    report_stats(&Stats, 0);
1014    
1015    
1016                    /* IDCT tests // */
1017    #if 0
1018                    /* no finished yet */
1019    
1020                    init_stats(&Stats);
1021    
1022    /* test each computation channel separately */
1023                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0;
1024                    ref_idct(Blk0);
1025                    emms(); idct(Blk); emms();
1026                    for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }
1027                    store_stats(&Stats, Blk, Blk0);
1028    
1029                    for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MIN : 0;
1030                    ref_idct(Blk0);
1031                    emms(); idct(Blk); emms();
1032                    for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }
1033                    store_stats(&Stats, Blk, Blk0);
1034    
1035                    /* randomly saturated inputs */
1036                    for(p=0; p<Partitions; ++p)
1037                    {
1038                            for(n=0; n<Loops; ++n)
1039                            {
1040                                    for(i=0; i<64; ++i)
1041                                            Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? IDCT_MAX : IDCT_MIN;
1042                                    ref_idct(Blk0);
1043                                    emms(); idct(Blk); emms();
1044                                    for(i=0; i<64; i++) { CLAMP(Blk0[i],IDCT_OUT); CLAMP(Blk[i],IDCT_OUT); }
1045                                    store_stats(&Stats, Blk, Blk0);
1046                            }
1047                    }
1048    
1049                    printf( "\n  -- IDCT saturation report --\n" );
1050                    print_stats(&Stats);
1051                    report_stats(&Stats, 0);
1052    #endif
1053            }
1054    }
1055    
1056    /*********************************************************************
1057   * measure raw decoding speed   * measure raw decoding speed
1058   *********************************************************************/   *********************************************************************/
1059    
# Line 612  Line 1062 
1062    FILE *f = 0;    FILE *f = 0;
1063    void *dechandle = 0;    void *dechandle = 0;
1064    int xerr;    int xerr;
1065          XVID_INIT_PARAM xinit;          xvid_gbl_init_t xinit;
1066          XVID_DEC_PARAM xparam;          xvid_dec_create_t xparam;
1067          XVID_DEC_FRAME xframe;          xvid_dec_frame_t xframe;
1068          double t = 0.;          double t = 0.;
1069          int nb = 0;          int nb = 0;
1070    uint8_t *buf = 0;    uint8_t *buf = 0;
# Line 622  Line 1072 
1072    int buf_size, pos;    int buf_size, pos;
1073    uint32_t chksum = 0;    uint32_t chksum = 0;
1074    
1075          xinit.cpu_flags = 0;          memset(&xinit, 0, sizeof(xinit));
1076          xvid_init(NULL, 0, &xinit, NULL);          xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;
1077          printf( "API version: %d, core build:%d\n", xinit.api_version, xinit.core_build);          xinit.version = XVID_VERSION;
1078            xvid_global(NULL, 0, &xinit, NULL);
1079    
1080            memset(&xparam, 0, sizeof(xparam));
1081          xparam.width = width;          xparam.width = width;
1082          xparam.height = height;          xparam.height = height;
1083            xparam.version = XVID_VERSION;
1084          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);
1085          if (xerr!=XVID_ERR_OK) {          if (xerr==XVID_ERR_FAIL) {
1086            printf("can't init decoder (err=%d)\n", xerr);            printf("can't init decoder (err=%d)\n", xerr);
1087            return;            return;
1088          }          }
# Line 651  Line 1103 
1103    }    }
1104    else printf( "Input size: %d\n", buf_size);    else printf( "Input size: %d\n", buf_size);
1105    
1106    buf = malloc(buf_size); // should be enuf'          buf = malloc(buf_size); /* should be enuf' */
1107    rgb_out = calloc(4, width*height);  // <-room for _RGB24          rgb_out = calloc(4, width*height);  /* <-room for _RGB24 */
1108    if (buf==0 || rgb_out==0) {    if (buf==0 || rgb_out==0) {
1109      printf( "malloc failed!\n" );      printf( "malloc failed!\n" );
1110      goto End;      goto End;
# Line 667  Line 1119 
1119    pos = 0;    pos = 0;
1120    t = -gettime_usec();    t = -gettime_usec();
1121    while(1) {    while(1) {
1122                    memset(&xframe, 0, sizeof(xframe));
1123                    xframe.version = XVID_VERSION;
1124      xframe.bitstream = buf + pos;      xframe.bitstream = buf + pos;
1125      xframe.length = buf_size - pos;      xframe.length = buf_size - pos;
1126      xframe.image = rgb_out;                  xframe.output.plane[0] = rgb_out;
1127      xframe.stride = width;                  xframe.output.stride[0] = width;
1128      xframe.colorspace = XVID_CSP_RGB24;                  xframe.output.csp = XVID_CSP_BGR;
1129      xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);      xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);
1130      nb++;      nb++;
1131      pos += xframe.length;      pos += xframe.length;
# Line 682  Line 1136 
1136      }      }
1137      if (pos==buf_size)      if (pos==buf_size)
1138        break;        break;
1139      if (xerr!=XVID_ERR_OK) {                  if (xerr==XVID_ERR_FAIL) {
1140            printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);            printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);
1141            break;            break;
1142          }          }
# Line 698  Line 1152 
1152    if (buf!=0) free(buf);    if (buf!=0) free(buf);
1153    if (dechandle!=0) {    if (dechandle!=0) {
1154      xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);      xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);
1155      if (xerr!=XVID_ERR_OK)                  if (xerr==XVID_ERR_FAIL)
1156              printf("destroy-decoder failed (err=%d)!\n", xerr);              printf("destroy-decoder failed (err=%d)!\n", xerr);
1157    }    }
1158    if (f!=0) fclose(f);    if (f!=0) fclose(f);
# Line 714  Line 1168 
1168    
1169    printf( "\n =====  (de)quant4_intra saturation bug? =====\n" );    printf( "\n =====  (de)quant4_intra saturation bug? =====\n" );
1170    
1171    for(cpu = cpu_short_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
1172    {    {
1173      int i;      int i;
1174      int16_t  Src[8*8], Dst[8*8];      int16_t  Src[8*8], Dst[8*8];
# Line 724  Line 1178 
1178    
1179      for(i=0; i<64; ++i) Src[i] = i-32;      for(i=0; i<64; ++i) Src[i] = i-32;
1180      set_intra_matrix( get_default_intra_matrix() );      set_intra_matrix( get_default_intra_matrix() );
1181      dequant4_intra(Dst, Src, 32, 5);                  dequant_mpeg_intra(Dst, Src, 31, 5);
1182      printf( "dequant4_intra with CPU=%s:  ", cpu->name);                  printf( "dequant_mpeg_intra with CPU=%s:  ", cpu->name);
1183      printf( "  Out[]= " );      printf( "  Out[]= " );
1184      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
1185      printf( "\n" );      printf( "\n" );
# Line 733  Line 1187 
1187    
1188    printf( "\n =====  (de)quant4_inter saturation bug? =====\n" );    printf( "\n =====  (de)quant4_inter saturation bug? =====\n" );
1189    
1190    for(cpu = cpu_short_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
1191    {    {
1192      int i;      int i;
1193      int16_t  Src[8*8], Dst[8*8];      int16_t  Src[8*8], Dst[8*8];
# Line 743  Line 1197 
1197    
1198      for(i=0; i<64; ++i) Src[i] = i-32;      for(i=0; i<64; ++i) Src[i] = i-32;
1199      set_inter_matrix( get_default_inter_matrix() );      set_inter_matrix( get_default_inter_matrix() );
1200      dequant4_inter(Dst, Src, 32);                  dequant_mpeg_inter(Dst, Src, 31);
1201      printf( "dequant4_inter with CPU=%s:  ", cpu->name);                  printf( "dequant_mpeg_inter with CPU=%s:  ", cpu->name);
1202      printf( "  Out[]= " );      printf( "  Out[]= " );
1203      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);      for(i=0; i<64; ++i) printf( "[%d]", Dst[i]);
1204      printf( "\n" );      printf( "\n" );
# Line 756  Line 1210 
1210    CPU *cpu;    CPU *cpu;
1211    short Blk[8*8], Blk0[8*8];    short Blk[8*8], Blk0[8*8];
1212    
1213    printf( "\n =====  fdct/idct saturation diffs =====\n" );          printf( "\n =====  fdct/idct precision diffs =====\n" );
1214    
1215    for(cpu = cpu_short_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
1216    {    {
1217      int i;      int i;
1218    
# Line 782  Line 1236 
1236    }    }
1237  }  }
1238    
1239    void test_quant_bug()
1240    {
1241            const int max_Q = 31;
1242            int i, n, qm, q;
1243            CPU *cpu;
1244            int16_t  Src[8*8], Dst[8*8];
1245            uint8_t Quant[8*8];
1246            CPU cpu_bug_list[] = { { "PLAINC", 0 }, { "MMX   ", XVID_CPU_MMX }, {0,0} };
1247            uint16_t Crcs_Inter[2][32];
1248            uint16_t Crcs_Intra[2][32];
1249            printf( "\n =====  test MPEG4-quantize bug =====\n" );
1250    
1251            for(i=0; i<64; ++i) Src[i] = 2048*(i-32)/32;
1252    
1253    #if 1
1254            for(qm=1; qm<=255; ++qm)
1255            {
1256                    for(i=0; i<8*8; ++i) Quant[i] = qm;
1257                    set_inter_matrix( Quant );
1258    
1259                    for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n)
1260                    {
1261                            uint16_t s;
1262    
1263                            if (!init_cpu(cpu))
1264                                    continue;
1265    
1266                            for(q=1; q<=max_Q; ++q) {
1267                                    emms();
1268                                    quant_mpeg_inter( Dst, Src, q );
1269                                    emms();
1270                                    for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i;
1271                                    Crcs_Inter[n][q] = s;
1272                            }
1273                    }
1274    
1275                    for(q=1; q<=max_Q; ++q)
1276                            for(i=0; i<n-1; ++i)
1277                                    if (Crcs_Inter[i][q]!=Crcs_Inter[i+1][q])
1278                                            printf( "Discrepancy Inter: qm=%d, q=%d  -> %d/%d !\n",
1279                                                            qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]);
1280            }
1281    #endif
1282    
1283    #if 1
1284            for(qm=1; qm<=255; ++qm)
1285            {
1286                    for(i=0; i<8*8; ++i) Quant[i] = qm;
1287                    set_intra_matrix( Quant );
1288    
1289                    for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n)
1290                    {
1291                            uint16_t s;
1292    
1293                            if (!init_cpu(cpu))
1294                                    continue;
1295    
1296                            for(q=1; q<=max_Q; ++q) {
1297                                    emms();
1298                                    quant_mpeg_intra( Dst, Src, q, q);
1299                                    emms();
1300                                    for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i;
1301                                    Crcs_Intra[n][q] = s;
1302                            }
1303                    }
1304    
1305                    for(q=1; q<=max_Q; ++q)
1306                            for(i=0; i<n-1; ++i)
1307                                    if (Crcs_Intra[i][q]!=Crcs_Intra[i+1][q])
1308                                            printf( "Discrepancy Intra: qm=%d, q=%d  -> %d/%d!\n",
1309                                                            qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]);
1310            }
1311    #endif
1312    }
1313    
1314  /*********************************************************************  /*********************************************************************
1315   * main   * main
# Line 798  Line 1326 
1326    if (what==0 || what==5) test_quant();    if (what==0 || what==5) test_quant();
1327    if (what==0 || what==6) test_cbp();    if (what==0 || what==6) test_cbp();
1328    
1329    if (what==8) {          if (what==7) {
1330                    test_IEEE1180_compliance(-256, 255, 1);
1331                    test_IEEE1180_compliance(-256, 255,-1);
1332                    test_IEEE1180_compliance(  -5,   5, 1);
1333                    test_IEEE1180_compliance(  -5,   5,-1);
1334                    test_IEEE1180_compliance(-300, 300, 1);
1335                    test_IEEE1180_compliance(-300, 300,-1);
1336            }
1337            if (what==8) test_dct_saturation(-256, 255);
1338    
1339            if (what==9) {
1340      int width, height;      int width, height;
1341      if (argc<5) {      if (argc<5) {
1342        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 1348 
1348    }    }
1349    
1350    if (what==-1) {    if (what==-1) {
     test_bugs1();  
1351      test_dct_precision_diffs();      test_dct_precision_diffs();
1352                    test_bugs1();
1353    }    }
1354            if (what==-2)
1355                    test_quant_bug();
1356    
1357    return 0;    return 0;
1358  }  }
1359    
1360  /*********************************************************************  /*********************************************************************
1361   * 'Reference' output (except for timing) on a PIII 1.13Ghz/linux   * 'Reference' output (except for timing) on a PIII 1.13Ghz/linux
1362   *********************************************************************/   *********************************************************************/
1363    
1364    /* as of 07/01/2002, there's a problem with mpeg4-quantization */
1365  /*  /*
1366    
1367   ===== test fdct/idct =====   ===== test fdct/idct =====
1368  PLAINC -  2.631 usec       iCrc=3  fCrc=-85  PLAINC -  3.312 usec       PSNR=13.291  MSE=3.000
1369  MMX    -  0.596 usec       iCrc=3  fCrc=-67  MMX    -  0.591 usec       PSNR=13.291  MSE=3.000
1370  MMXEXT -  0.608 usec       iCrc=3  fCrc=-67  MMXEXT -  0.577 usec       PSNR=13.291  MSE=3.000
1371  SSE2   -  0.605 usec       iCrc=3  fCrc=-67  SSE2   -  0.588 usec       PSNR=13.291  MSE=3.000
1372  3DNOW  - skipped...  3DNOW  - skipped...
1373  3DNOWE - skipped...  3DNOWE - skipped...
1374    
1375   ===  test block motion ===   ===  test block motion ===
1376  PLAINC - interp- h-round0 1.031 usec       iCrc=8107  PLAINC - interp- h-round0 0.911 usec       iCrc=8107
1377  PLAINC -           round1 1.022 usec       iCrc=8100  PLAINC -           round1 0.863 usec       iCrc=8100
1378  PLAINC - interp- v-round0 1.002 usec       iCrc=8108  PLAINC - interp- v-round0 0.860 usec       iCrc=8108
1379  PLAINC -           round1 1.011 usec       iCrc=8105  PLAINC -           round1 0.857 usec       iCrc=8105
1380  PLAINC - interp-hv-round0 1.623 usec       iCrc=8112  PLAINC - interp-hv-round0 2.103 usec       iCrc=8112
1381  PLAINC -           round1 1.621 usec       iCrc=8103  PLAINC -           round1 2.050 usec       iCrc=8103
 PLAINC - interpolate8x8_c 0.229 usec       iCrc=8107  
1382   ---   ---
1383  MMX    - interp- h-round0 0.105 usec       iCrc=8107  MMX    - interp- h-round0 0.105 usec       iCrc=8107
1384  MMX    -           round1 0.105 usec       iCrc=8100  MMX    -           round1 0.106 usec       iCrc=8100
1385  MMX    - interp- v-round0 0.106 usec       iCrc=8108  MMX    - interp- v-round0 0.106 usec       iCrc=8108
1386  MMX    -           round1 0.107 usec       iCrc=8105  MMX    -           round1 0.106 usec       iCrc=8105
1387  MMX    - interp-hv-round0 0.145 usec       iCrc=8112  MMX    - interp-hv-round0 0.145 usec       iCrc=8112
1388  MMX    -           round1 0.145 usec       iCrc=8103  MMX    -           round1 0.145 usec       iCrc=8103
 MMX    - interpolate8x8_c 0.229 usec       iCrc=8107  
1389   ---   ---
1390  MMXEXT - interp- h-round0 0.027 usec       iCrc=8107  MMXEXT - interp- h-round0 0.028 usec       iCrc=8107
1391  MMXEXT -           round1 0.041 usec       iCrc=8100  MMXEXT -           round1 0.041 usec       iCrc=8100
1392  MMXEXT - interp- v-round0 0.027 usec       iCrc=8108  MMXEXT - interp- v-round0 0.027 usec       iCrc=8108
1393  MMXEXT -           round1 0.040 usec       iCrc=8105  MMXEXT -           round1 0.041 usec       iCrc=8105
1394  MMXEXT - interp-hv-round0 0.070 usec       iCrc=8112  MMXEXT - interp-hv-round0 0.066 usec       iCrc=8112
1395  MMXEXT -           round1 0.066 usec       iCrc=8103  MMXEXT -           round1 0.065 usec       iCrc=8103
 MMXEXT - interpolate8x8_c 0.027 usec       iCrc=8107  
1396   ---   ---
1397  SSE2   - interp- h-round0 0.106 usec       iCrc=8107  SSE2   - interp- h-round0 0.109 usec       iCrc=8107
1398  SSE2   -           round1 0.105 usec       iCrc=8100  SSE2   -           round1 0.105 usec       iCrc=8100
1399  SSE2   - interp- v-round0 0.106 usec       iCrc=8108  SSE2   - interp- v-round0 0.106 usec       iCrc=8108
1400  SSE2   -           round1 0.106 usec       iCrc=8105  SSE2   -           round1 0.109 usec       iCrc=8105
1401  SSE2   - interp-hv-round0 0.145 usec       iCrc=8112  SSE2   - interp-hv-round0 0.145 usec       iCrc=8112
1402  SSE2   -           round1 0.145 usec       iCrc=8103  SSE2   -           round1 0.145 usec       iCrc=8103
 SSE2   - interpolate8x8_c 0.237 usec       iCrc=8107  
1403   ---   ---
1404  3DNOW  - skipped...  3DNOW  - skipped...
1405  3DNOWE - skipped...  3DNOWE - skipped...
1406    
1407   ======  test SAD ======   ======  test SAD ======
1408  PLAINC - sad8    0.296 usec       sad=3776  PLAINC - sad8    0.251 usec       sad=3776
1409  PLAINC - sad16   1.599 usec       sad=27214  PLAINC - sad16   1.601 usec       sad=27214
1410  PLAINC - sad16bi 2.350 usec       sad=26274  PLAINC - sad16bi 2.371 usec       sad=26274
1411  PLAINC - dev16   1.610 usec       sad=3344  PLAINC - dev16   1.564 usec       sad=3344
1412   ---   ---
1413  MMX    - sad8    0.057 usec       sad=3776  MMX    - sad8    0.057 usec       sad=3776
1414  MMX    - sad16   0.178 usec       sad=27214  MMX    - sad16   0.182 usec       sad=27214
1415  MMX    - sad16bi 2.381 usec       sad=26274  MMX    - sad16bi 2.462 usec       sad=26274
1416  MMX    - dev16   0.312 usec       sad=3344  MMX    - dev16   0.311 usec       sad=3344
1417   ---   ---
1418  MMXEXT - sad8    0.036 usec       sad=3776  MMXEXT - sad8    0.036 usec       sad=3776
1419  MMXEXT - sad16   0.106 usec       sad=27214  MMXEXT - sad16   0.109 usec       sad=27214
1420  MMXEXT - sad16bi 0.182 usec       sad=26274  MMXEXT - sad16bi 0.143 usec       sad=26274
1421  MMXEXT - dev16   0.193 usec       sad=3344  MMXEXT - dev16   0.192 usec       sad=3344
1422   ---   ---
1423  SSE2   - sad8    0.057 usec       sad=3776  SSE2   - sad8    0.057 usec       sad=3776
1424  SSE2   - sad16   0.178 usec       sad=27214  SSE2   - sad16   0.179 usec       sad=27214
1425  SSE2   - sad16bi 2.427 usec       sad=26274  SSE2   - sad16bi 2.456 usec       sad=26274
1426  SSE2   - dev16   0.313 usec       sad=3344  SSE2   - dev16   0.321 usec       sad=3344
1427   ---   ---
1428  3DNOW  - skipped...  3DNOW  - skipped...
1429  3DNOWE - skipped...  3DNOWE - skipped...
1430    
1431   ===  test transfer ===   ===  test transfer ===
1432  PLAINC - 8to16     0.124 usec       crc=28288  PLAINC - 8to16     0.151 usec       crc=28288
1433  PLAINC - 16to8     0.753 usec       crc=28288  PLAINC - 16to8     1.113 usec       crc=28288
1434  PLAINC - 8to8      0.041 usec       crc=20352  PLAINC - 8to8      0.043 usec       crc=20352
1435  PLAINC - 16to8add  0.916 usec       crc=25536  PLAINC - 16to8add  1.069 usec       crc=25536
1436  PLAINC - 8to16sub  0.812 usec       crc1=28064 crc2=16256  PLAINC - 8to16sub  0.631 usec       crc1=28064 crc2=16256
1437  PLAINC - 8to16sub2 0.954 usec       crc=20384  PLAINC - 8to16sub2 0.597 usec       crc=20384
1438   ---  ---
1439  MMX    - 8to16     0.037 usec       crc=28288  MMX    - 8to16     0.032 usec       crc=28288
1440  MMX    - 16to8     0.016 usec       crc=28288  MMX    - 16to8     0.024 usec       crc=28288
1441  MMX    - 8to8      0.018 usec       crc=20352  MMX    - 8to8      0.020 usec       crc=20352
1442  MMX    - 16to8add  0.044 usec       crc=25536  MMX    - 16to8add  0.043 usec       crc=25536
1443  MMX    - 8to16sub  0.065 usec       crc1=28064 crc2=16256  MMX    - 8to16sub  0.066 usec       crc1=28064 crc2=16256
1444  MMX    - 8to16sub2 0.110 usec       crc=20384  MMX    - 8to16sub2 0.111 usec       crc=20384
  ---  
 MMXEXT - 8to16     0.032 usec       crc=28288  
 MMXEXT - 16to8     0.023 usec       crc=28288  
 MMXEXT - 8to8      0.018 usec       crc=20352  
 MMXEXT - 16to8add  0.041 usec       crc=25536  
 MMXEXT - 8to16sub  0.065 usec       crc1=28064 crc2=16256  
 MMXEXT - 8to16sub2 0.069 usec       crc=20384  
1445   ---   ---
1446    
1447   =====  test quant =====   =====  test quant =====
1448  PLAINC -   quant4_intra 78.889 usec       crc=55827  PLAINC -   quant4_intra 74.248 usec       crc=29809
1449  PLAINC -   quant4_inter 71.957 usec       crc=58201  PLAINC -   quant4_inter 70.850 usec       crc=12574
1450  PLAINC - dequant4_intra 34.968 usec       crc=193340  PLAINC - dequant4_intra 40.628 usec       crc=24052
1451  PLAINC - dequant4_inter 40.792 usec       crc=116483  PLAINC - dequant4_inter 45.691 usec       crc=63847
1452  PLAINC -    quant_intra 30.845 usec       crc=56885  PLAINC -    quant_intra 43.357 usec       crc=25662
1453  PLAINC -    quant_inter 34.842 usec       crc=58056  PLAINC -    quant_inter 33.410 usec       crc=23972
1454  PLAINC -  dequant_intra 33.211 usec       crc=-7936  PLAINC -  dequant_intra 36.384 usec       crc=49900
1455  PLAINC -  dequant_inter 45.486 usec       crc=-33217  PLAINC -  dequant_inter 48.930 usec       crc=48899
1456   ---  ---
1457  MMX    -   quant4_intra 9.030 usec       crc=55827  MMX    -   quant4_intra 7.445 usec       crc=3459
1458  MMX    -   quant4_inter 8.234 usec       crc=58201  *** CRC ERROR! ***
1459  MMX    - dequant4_intra 18.330 usec       crc=193340  MMX    -   quant4_inter 5.384 usec       crc=51072
1460  MMX    - dequant4_inter 19.181 usec       crc=116483  *** CRC ERROR! ***
1461  MMX    -    quant_intra 7.124 usec       crc=56885  MMX    - dequant4_intra 5.515 usec       crc=24052
1462  MMX    -    quant_inter 6.861 usec       crc=58056  MMX    - dequant4_inter 7.745 usec       crc=63847
1463  MMX    -  dequant_intra 9.048 usec       crc=-7936  MMX    -    quant_intra 4.661 usec       crc=25662
1464  MMX    -  dequant_inter 8.203 usec       crc=-33217  MMX    -    quant_inter 4.406 usec       crc=23972
1465   ---  MMX    -  dequant_intra 4.928 usec       crc=49900
1466  MMXEXT -   quant4_intra 9.045 usec       crc=55827  MMX    -  dequant_inter 4.532 usec       crc=48899
 MMXEXT -   quant4_inter 8.232 usec       crc=58201  
 MMXEXT - dequant4_intra 18.250 usec       crc=193340  
 MMXEXT - dequant4_inter 19.256 usec       crc=116483  
 MMXEXT -    quant_intra 7.121 usec       crc=56885  
 MMXEXT -    quant_inter 6.855 usec       crc=58056  
 MMXEXT -  dequant_intra 9.034 usec       crc=-7936  
 MMXEXT -  dequant_inter 8.202 usec       crc=-33217  
1467   ---   ---
1468    
1469   =====  test cbp =====   =====  test cbp =====
1470  PLAINC -   calc_cbp#1 0.545 usec       cbp=0x15  PLAINC -   calc_cbp#1 0.371 usec       cbp=0x15
1471  PLAINC -   calc_cbp#2 0.540 usec       cbp=0x38  PLAINC -   calc_cbp#2 0.432 usec       cbp=0x38
1472  PLAINC -   calc_cbp#3 0.477 usec       cbp=0xf  PLAINC -   calc_cbp#3 0.339 usec       cbp=0xf
1473  PLAINC -   calc_cbp#4 0.739 usec       cbp=0x5  PLAINC -   calc_cbp#4 0.506 usec       cbp=0x5
1474   ---   ---
1475  MMX    -   calc_cbp#1 0.136 usec       cbp=0x15  MMX    -   calc_cbp#1 0.136 usec       cbp=0x15
1476  MMX    -   calc_cbp#2 0.131 usec       cbp=0x38  MMX    -   calc_cbp#2 0.134 usec       cbp=0x38
1477  MMX    -   calc_cbp#3 0.132 usec       cbp=0xf  MMX    -   calc_cbp#3 0.138 usec       cbp=0xf
1478  MMX    -   calc_cbp#4 0.135 usec       cbp=0x5  MMX    -   calc_cbp#4 0.135 usec       cbp=0x5
1479   ---   ---
1480  SSE2   -   calc_cbp#1 0.135 usec       cbp=0x15  SSE2   -   calc_cbp#1 0.136 usec       cbp=0x15
1481  SSE2   -   calc_cbp#2 0.131 usec       cbp=0x38  SSE2   -   calc_cbp#2 0.133 usec       cbp=0x38
1482  SSE2   -   calc_cbp#3 0.134 usec       cbp=0xf  SSE2   -   calc_cbp#3 0.133 usec       cbp=0xf
1483  SSE2   -   calc_cbp#4 0.136 usec       cbp=0x5  SSE2   -   calc_cbp#4 0.141 usec       cbp=0x5
1484   ---   ---
1485    
1486  */  */

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

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