[svn] / trunk / xvidcore / examples / xvid_bench.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/examples/xvid_bench.c

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

revision 1746, Wed Nov 1 07:12:26 2006 UTC revision 1839, Tue Dec 2 13:44:55 2008 UTC
# Line 19  Line 19 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: xvid_bench.c,v 1.34 2006-11-01 07:12:26 Skal Exp $   * $Id: xvid_bench.c,v 1.39 2008-12-02 13:44:55 Isibaar Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 47  Line 47 
47  #include "xvid.h"  #include "xvid.h"
48    
49  // inner guts  // inner guts
50    #include "portab.h"
51  #include "dct/idct.h"  #include "dct/idct.h"
52  #include "dct/fdct.h"  #include "dct/fdct.h"
53  #include "image/colorspace.h"  #include "image/colorspace.h"
# Line 115  Line 116 
116    
117  CPU cpu_list[] = {  CPU cpu_list[] = {
118          { "PLAINC ", 0 },          { "PLAINC ", 0 },
119  #ifdef ARCH_IS_IA32  #if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)
120          { "MMX    ", XVID_CPU_MMX },          { "MMX    ", XVID_CPU_MMX },
121          { "MMXEXT ", XVID_CPU_MMXEXT | XVID_CPU_MMX },          { "MMXEXT ", XVID_CPU_MMXEXT | XVID_CPU_MMX },
122          { "SSE2   ", XVID_CPU_SSE2 | XVID_CPU_MMX },          { "SSE2   ", XVID_CPU_SSE2 | XVID_CPU_MMX },
123            { "SSE3   ", XVID_CPU_SSE3 | XVID_CPU_SSE2 | XVID_CPU_MMX },
124            { "SSE41  ", XVID_CPU_SSE41| XVID_CPU_SSE3 | XVID_CPU_SSE2 | XVID_CPU_MMX },
125          { "3DNOW  ", XVID_CPU_3DNOW },          { "3DNOW  ", XVID_CPU_3DNOW },
126          { "3DNOWE ", XVID_CPU_3DNOW | XVID_CPU_3DNOWEXT },          { "3DNOWE ", XVID_CPU_3DNOW | XVID_CPU_3DNOWEXT },
127  #endif  #endif
128  #ifdef ARCH_IS_PPC  #ifdef ARCH_IS_PPC
129          { "ALTIVEC", XVID_CPU_ALTIVEC },          { "ALTIVEC", XVID_CPU_ALTIVEC },
130  #endif  #endif
 #ifdef ARCH_IS_X86_64  
         { "X86_64 ", XVID_CPU_ASM},  
 #endif  
131  #ifdef ARCH_IS_IA64  #ifdef ARCH_IS_IA64
132  //      { "IA64   ", XVID_CPU_IA64 },  //      { "IA64   ", XVID_CPU_IA64 },
133  #endif  #endif
# Line 414  Line 414 
414    
415                  t = gettime_usec();                  t = gettime_usec();
416                  emms();                  emms();
417                    for(tst=0; tst<nb_tests; ++tst) s = sad8bi(Cur, Ref1, Ref2, 8);
418                    emms();
419                    t = (gettime_usec() - t) / nb_tests;
420                    printf( "%s - sad8bi %.3f usec       sad=%d %s\n",
421                                    cpu->name, t, s,
422                                    (s!=4002)?"| ERROR": "" );
423    
424                    t = gettime_usec();
425                    emms();
426                  for(tst=0; tst<nb_tests; ++tst) s = dev16(Cur, 16);                  for(tst=0; tst<nb_tests; ++tst) s = dev16(Cur, 16);
427                  emms();                  emms();
428                  t = (gettime_usec() - t) / nb_tests;                  t = (gettime_usec() - t) / nb_tests;
# Line 731  Line 740 
740    set_intra_matrix( mpeg_quant_matrices, Quant );                \    set_intra_matrix( mpeg_quant_matrices, Quant );                \
741    emms();                                   \    emms();                                   \
742    for(q=1; q<=max_Q; ++q) {                 \    for(q=1; q<=max_Q; ++q) {                 \
743            init_intra_matrix( mpeg_quant_matrices, q ); \
744          for(tst=0; tst<nb_tests; ++tst)         \          for(tst=0; tst<nb_tests; ++tst)         \
745            (FUNC)((DST), (SRC), q, q, mpeg_quant_matrices);           \            (FUNC)((DST), (SRC), q, q, mpeg_quant_matrices);           \
746          byte_swap((uint8_t*)(DST), 64*sizeof((DST)[0]), sizeof((DST)[0]));  \          byte_swap((uint8_t*)(DST), 64*sizeof((DST)[0]), sizeof((DST)[0]));  \
# Line 741  Line 751 
751  t = (gettime_usec()-t-overhead)/nb_tests/qm  t = (gettime_usec()-t-overhead)/nb_tests/qm
752    
753  #define TEST_INTRA(REFFUNC, NEWFUNC, RANGE)              \  #define TEST_INTRA(REFFUNC, NEWFUNC, RANGE)              \
754  { int i,q,s;\  { int32_t i,q,s;\
755          DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16); \          DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16); \
756    DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16); \    DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16); \
757    DECLARE_ALIGNED_MATRIX(Dst2,8, 8, int16_t, 16); \    DECLARE_ALIGNED_MATRIX(Dst2,8, 8, int16_t, 16); \
# Line 773  Line 783 
783    
784  void test_quant()  void test_quant()
785  {  {
786          const int nb_tests = 1*speed_ref;          const int32_t nb_tests = 1*speed_ref;
787          const int max_Q = 31;          const int32_t max_Q = 31;
788          DECLARE_ALIGNED_MATRIX(mpeg_quant_matrices, 8, 64, uint16_t, 16);          DECLARE_ALIGNED_MATRIX(mpeg_quant_matrices, 8, 64, uint16_t, 16);
789    
790          int i, qm;          int32_t i, qm;
791          CPU *cpu;          CPU *cpu;
792          DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16);          DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16);
793          DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16);          DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16);
# Line 796  Line 806 
806          for(cpu = cpu_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
807          {          {
808                  double t, overhead;                  double t, overhead;
809                  int tst, q;                  int32_t tst, q;
810                  uint32_t s;                  uint32_t s;
811    
812                  if (!init_cpu(cpu))                  if (!init_cpu(cpu))
# Line 820  Line 830 
830                  TEST_QUANT2(quant_mpeg_intra, Dst, Src);                  TEST_QUANT2(quant_mpeg_intra, Dst, Src);
831                  printf("%s -   quant_mpeg_intra %.3f usec       crc32=0x%08x %s\n",                  printf("%s -   quant_mpeg_intra %.3f usec       crc32=0x%08x %s\n",
832                             cpu->name, t, s,                             cpu->name, t, s,
833                             (s!=0xfd6a21a4)? "| ERROR": "");                             (s!=0x3b999af6)? "| ERROR": "");
834    
835                  TEST_QUANT(quant_mpeg_inter, Dst, Src);                  TEST_QUANT(quant_mpeg_inter, Dst, Src);
836                  printf("%s -   quant_mpeg_inter %.3f usec       crc32=0x%08x %s\n",                  printf("%s -   quant_mpeg_inter %.3f usec       crc32=0x%08x %s\n",
# Line 1721  Line 1731 
1731  t = (gettime_usec() - t) / nb_tests;  \  t = (gettime_usec() - t) / nb_tests;  \
1732          iCrc = calc_crc((uint8_t*)Dst0, sizeof(Dst0), CRC32_INITIAL)          iCrc = calc_crc((uint8_t*)Dst0, sizeof(Dst0), CRC32_INITIAL)
1733    
1734  #define TEST_YUYV(FUNC, S)                \  #define TEST_YUYV(FUNC, S, FLIP)                \
1735  ENTER                               \  ENTER                               \
1736  for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst0[0], S*WIDTH, Src0[0], Src0[1], Src0[2], WIDTH, WIDTH/2, WIDTH, HEIGHT, 0); \  for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst0[0], S*WIDTH, Src0[0], Src0[1], Src0[2], WIDTH, WIDTH/2, WIDTH, HEIGHT, (FLIP)); \
1737  LEAVE  LEAVE
1738    
1739    static const int yuv_CRCs[6][2] = {
1740            {0x0f4fb96b,0x780b6a68}
1741    ,       {0xa986b289,0x65e49b76}
1742    ,       {0x7f19c152,0xd539b86e}
1743    ,       {0x0f4fb96b,0x780b6a68}
1744    ,       {0xa986b289,0x65e49b76}
1745    ,       {0x36ab8b57,0x1cd92fee}
1746    };
1747    
1748  #define WIDTH 128  #define WIDTH 128
1749  #define HEIGHT 32  #define HEIGHT 32
1750  void test_yuv()  void test_yuv()
# Line 1734  Line 1753 
1753          CPU *cpu;          CPU *cpu;
1754          uint8_t Src0[3][WIDTH*HEIGHT];          uint8_t Src0[3][WIDTH*HEIGHT];
1755          uint8_t Dst0[4][WIDTH*HEIGHT];          uint8_t Dst0[4][WIDTH*HEIGHT];
1756          int i, j;          int i, j, with_flip;
1757          double t;          double t;
1758          int tst, iCrc;          int tst, iCrc;
1759    
# Line 1745  Line 1764 
1764    
1765          printf( "\n ===  test YUV ===\n" );          printf( "\n ===  test YUV ===\n" );
1766    
1767            for(with_flip=0; with_flip<=1; ++with_flip) {
1768    
1769          init_cpu(&cpu_list[0]);          init_cpu(&cpu_list[0]);
1770          TEST_YUYV(yv12_to_yuyv_c, 4);                  TEST_YUYV(yv12_to_yuyv_c, 4, with_flip);
1771          printf(" yv12_to_yuyv_c %.3f usec       crc32=0x%08x %s\n",          printf(" yv12_to_yuyv_c %.3f usec       crc32=0x%08x %s\n",
1772                     t, iCrc, (iCrc!=0xeb1a0b0a)?"| ERROR": "" );                             t, iCrc, (iCrc!=yuv_CRCs[0][with_flip])?"| ERROR": "" );
1773          TEST_YUYV(yv12_to_uyvy_c, 4);                  TEST_YUYV(yv12_to_uyvy_c, 4, with_flip);
1774          printf(" yv12_to_uyvy_c %.3f usec       crc32=0x%08x %s\n",          printf(" yv12_to_uyvy_c %.3f usec       crc32=0x%08x %s\n",
1775                     t, iCrc, (iCrc!=0x6e82f55b)?"| ERROR": "" );                          t, iCrc, (iCrc!=yuv_CRCs[1][with_flip])?"| ERROR": "" );
1776    
1777                    TEST_YUYV(yv12_to_bgra_c, 4, with_flip);
1778                    printf(" yv12_to_bgra_c %.3f usec       crc32=0x%08x %s\n",
1779                            t, iCrc, (iCrc!=yuv_CRCs[2][with_flip])?"| ERROR": "" );
1780    
1781  #ifdef ARCH_IS_IA32  #if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)
1782          init_cpu(&cpu_list[1]);          init_cpu(&cpu_list[1]);
1783          TEST_YUYV(yv12_to_yuyv_mmx, 4);                  TEST_YUYV(yv12_to_yuyv_mmx, 4, with_flip);
1784          printf(" yv12_to_yuyv_mmx %.3f usec       crc32=0x%08x %s\n",          printf(" yv12_to_yuyv_mmx %.3f usec       crc32=0x%08x %s\n",
1785                  t, iCrc, (iCrc!=0xeb1a0b0a)?"| ERROR": "" );                          t, iCrc, (iCrc!=yuv_CRCs[3][with_flip])?"| ERROR": "" );
1786    
1787          TEST_YUYV(yv12_to_uyvy_mmx, 4);                  TEST_YUYV(yv12_to_uyvy_mmx, 4, with_flip);
1788          printf(" yv12_to_uyvy_mmx %.3f usec       crc32=0x%08x %s\n",          printf(" yv12_to_uyvy_mmx %.3f usec       crc32=0x%08x %s\n",
1789                  t, iCrc, (iCrc!=0x6e82f55b)?"| ERROR": "" );                          t, iCrc, (iCrc!=yuv_CRCs[4][with_flip])?"| ERROR": "" );
1790    
1791                    TEST_YUYV(yv12_to_bgra_mmx, 4, with_flip);
1792                    printf(" yv12_to_bgra_mmx %.3f usec       crc32=0x%08x %s\n",
1793                            t, iCrc, (iCrc!=yuv_CRCs[5][with_flip])?"| ERROR": "" );
1794    
1795  #endif  #endif
1796    
1797  #ifdef ARCH_IS_PPC  #ifdef ARCH_IS_PPC
1798          init_cpu(&cpu_list[1]);          init_cpu(&cpu_list[1]);
1799          TEST_YUYV(yv12_to_yuyv_altivec_c, 4);                  TEST_YUYV(yv12_to_yuyv_altivec_c, 4, with_flip);
1800          printf(" yv12_to_yuyv_altivec_c %.3f usec       crc32=0x%08x %s\n",          printf(" yv12_to_yuyv_altivec_c %.3f usec       crc32=0x%08x %s\n",
1801                  t, iCrc, (iCrc!=0xeb1a0b0a)?"| ERROR": "" );                          t, iCrc, (iCrc!=yuv_CRCs[3][with_flip])?"| ERROR": "" );
1802    
1803          TEST_YUYV(yv12_to_uyvy_altivec_c, 4);                  TEST_YUYV(yv12_to_uyvy_altivec_c, 4, with_flip);
1804          printf(" yv12_to_uyvy_altivec_c %.3f usec       crc32=0x%08x %s\n",          printf(" yv12_to_uyvy_altivec_c %.3f usec       crc32=0x%08x %s\n",
1805                  t, iCrc, (iCrc!=0x6e82f55b)?"| ERROR": "" );                          t, iCrc, (iCrc!=yuv_CRCs[4][with_flip])?"| ERROR": "" );
1806    
1807                    TEST_YUYV(yv12_to_bgra_altivec_c, 4, with_flip);
1808                    printf(" yv12_to_bgra_altivec_c %.3f usec       crc32=0x%08x %s\n",
1809                            t, iCrc, (iCrc!=yuv_CRCs[5][with_flip])?"| ERROR": "" );
1810  #endif  #endif
1811            }
1812          printf( " --- \n" );          printf( " --- \n" );
1813  }  }
1814    
# Line 1822  Line 1857 
1857                                  t, iCrc, (iCrc!=yv12_CRCs[with_flip][with_uv])?"| ERROR": "" );                                  t, iCrc, (iCrc!=yv12_CRCs[with_flip][with_uv])?"| ERROR": "" );
1858                          /* if (!with_uv) PRINT_NxN(Dst0[1], WIDTH/2, HEIGHT/2, WIDTH ); */                          /* if (!with_uv) PRINT_NxN(Dst0[1], WIDTH/2, HEIGHT/2, WIDTH ); */
1859    
1860  #ifdef ARCH_IS_IA32  #if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)
1861                          init_cpu(&cpu_list[1]);                          init_cpu(&cpu_list[1]);
1862                          TEST_YV2(yv12_to_yv12_mmx, with_uv, with_flip);                          TEST_YV2(yv12_to_yv12_mmx, with_uv, with_flip);
1863                          printf(" yv12_to_yv12_mmx %.3f usec     \tcrc32=0x%08x %s\n",                          printf(" yv12_to_yv12_mmx %.3f usec     \tcrc32=0x%08x %s\n",
# Line 2060  Line 2095 
2095                  lum8x8 = lum_8x8_c;                  lum8x8 = lum_8x8_c;
2096                  lum2x8 = lum_2x8_c;                  lum2x8 = lum_2x8_c;
2097                  csim   = consim_c;                  csim   = consim_c;
2098    #if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)
2099                  if (cpu->cpu & XVID_CPU_MMX){                  if (cpu->cpu & XVID_CPU_MMX){
2100                          lum8x8 = lum_8x8_mmx;                          lum8x8 = lum_8x8_mmx;
2101                          csim = consim_mmx;                          csim = consim_mmx;
# Line 2067  Line 2103 
2103                  if (cpu->cpu & XVID_CPU_MMX){                  if (cpu->cpu & XVID_CPU_MMX){
2104                          csim = consim_sse2;                          csim = consim_sse2;
2105                  }                  }
2106    #endif
2107                  t = gettime_usec();                  t = gettime_usec();
2108                  emms();                  emms();
2109                  for(tst=0; tst<nb_tests; ++tst) m = lum8x8(Ref1, 16);                  for(tst=0; tst<nb_tests; ++tst) m = lum8x8(Ref1, 16);
# Line 2170  Line 2206 
2206          int width, height;          int width, height;
2207          uint32_t chksum = 0;          uint32_t chksum = 0;
2208          const char * test_bitstream = 0;          const char * test_bitstream = 0;
2209    #if defined(WIN32) && defined(ARCH_IS_X86_64)
2210            DECLARE_ALIGNED_MATRIX(xmm_save, 2, 4, uint64_t, 16);
2211            // assumes xmm6 and xmm7 won't be falsely preserved by C code
2212            for(c=0;c<4;c++)
2213                    xmm_save[c] = read_counter();
2214            prime_xmm(xmm_save);
2215    #endif
2216    
2217          cpu_mask = 0;  // default => will use autodectect          cpu_mask = 0;  // default => will use autodectect
2218          for(c=1; c<argc; ++c)          for(c=1; c<argc; ++c)
# Line 2179  Line 2222 
2222            else if (!strcmp(argv[c], "-mmx"))    cpu_mask = XVID_CPU_MMX    | XVID_CPU_FORCE;            else if (!strcmp(argv[c], "-mmx"))    cpu_mask = XVID_CPU_MMX    | XVID_CPU_FORCE;
2223            else if (!strcmp(argv[c], "-mmxext")) cpu_mask = XVID_CPU_MMXEXT | XVID_CPU_MMX | XVID_CPU_FORCE;            else if (!strcmp(argv[c], "-mmxext")) cpu_mask = XVID_CPU_MMXEXT | XVID_CPU_MMX | XVID_CPU_FORCE;
2224            else if (!strcmp(argv[c], "-sse2"))   cpu_mask = XVID_CPU_SSE2   | XVID_CPU_MMXEXT | XVID_CPU_MMX | XVID_CPU_FORCE;            else if (!strcmp(argv[c], "-sse2"))   cpu_mask = XVID_CPU_SSE2   | XVID_CPU_MMXEXT | XVID_CPU_MMX | XVID_CPU_FORCE;
2225              else if (!strcmp(argv[c], "-sse3"))   cpu_mask = XVID_CPU_SSE3   | XVID_CPU_SSE2 | XVID_CPU_MMXEXT | XVID_CPU_MMX | XVID_CPU_FORCE;
2226              else if (!strcmp(argv[c], "-sse4"))   cpu_mask = XVID_CPU_SSE41  | XVID_CPU_SSE3 | XVID_CPU_SSE2 | XVID_CPU_MMXEXT | XVID_CPU_MMX | XVID_CPU_FORCE;
2227            else if (!strcmp(argv[c], "-3dnow"))  cpu_mask = XVID_CPU_3DNOW  | XVID_CPU_FORCE;            else if (!strcmp(argv[c], "-3dnow"))  cpu_mask = XVID_CPU_3DNOW  | XVID_CPU_FORCE;
2228            else if (!strcmp(argv[c], "-3dnowe")) cpu_mask = XVID_CPU_3DNOW  | XVID_CPU_3DNOWEXT | XVID_CPU_FORCE;            else if (!strcmp(argv[c], "-3dnowe")) cpu_mask = XVID_CPU_3DNOW  | XVID_CPU_3DNOWEXT | XVID_CPU_FORCE;
2229            else if (!strcmp(argv[c], "-altivec")) cpu_mask = XVID_CPU_ALTIVEC | XVID_CPU_FORCE;            else if (!strcmp(argv[c], "-altivec")) cpu_mask = XVID_CPU_ALTIVEC | XVID_CPU_FORCE;
# Line 2247  Line 2292 
2292          if (what==-2)          if (what==-2)
2293                  test_quant_bug();                  test_quant_bug();
2294    
2295    #if defined(WIN32) && defined(ARCH_IS_X86_64)
2296            get_xmm(xmm_save+4);
2297            if (memcmp(xmm_save, xmm_save+4, 4*sizeof(int64_t))) {
2298                    printf("\nWIN64 ERROR: XMM6 and XMM7 contents not preserved!\n"
2299                           "        XMM6                             XMM7\n"
2300                           "Before: %.16I64X%.16I64X %.16I64X%.16I64X\n"
2301                           "After:  %.16I64X%.16I64X %.16I64X%.16I64X",
2302                            xmm_save[0],xmm_save[1],xmm_save[2],xmm_save[3],
2303                            xmm_save[4],xmm_save[5],xmm_save[6],xmm_save[7]);
2304            } else {
2305                    printf("\nWIN64: XMM6 and XMM7 contents preserved correctly.\n");
2306            }
2307    #endif
2308    
2309          if ((what >= 0 && what <= 6) || what == 10) {          if ((what >= 0 && what <= 6) || what == 10) {
2310                  printf("\n\n"                  printf("\n\n"
2311                             "NB: If a function isn't optimised for a specific set of intructions,\n"                             "NB: If a function isn't optimised for a specific set of intructions,\n"
# Line 2254  Line 2313 
2313                             "    may appear to be slow.\n");                             "    may appear to be slow.\n");
2314          }          }
2315    
2316  #ifdef ARCH_IS_IA32  #if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)
2317          if (what == 0 || what == 5) {          if (what == 0 || what == 5) {
2318                  printf("\n"                  printf("\n"
2319                             "NB: MMX mpeg4 quantization is known to have very small errors (+/-1 magnitude)\n"                             "NB: MMX mpeg4 quantization is known to have very small errors (+/-1 magnitude)\n"

Legend:
Removed from v.1746  
changed lines
  Added in v.1839

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