[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 1617, Mon May 23 09:29:43 2005 UTC revision 1746, Wed Nov 1 07:12:26 2006 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.19 2005-05-23 09:29:43 Skal Exp $   * $Id: xvid_bench.c,v 1.34 2006-11-01 07:12:26 Skal Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 58  Line 58 
58  #include "utils/timer.h"  #include "utils/timer.h"
59  #include "quant/quant_matrix.c"  #include "quant/quant_matrix.c"
60  #include "bitstream/cbp.h"  #include "bitstream/cbp.h"
61    #include "bitstream/bitstream.h"
62    
63  #include <math.h>  #include <math.h>
64    
# Line 112  Line 113 
113          unsigned int cpu;          unsigned int cpu;
114  } CPU;  } CPU;
115    
116  CPU cpu_list[] =  CPU cpu_list[] = {
117  { { "PLAINC", 0 }          { "PLAINC ", 0 },
118  #ifdef ARCH_IS_IA32  #ifdef ARCH_IS_IA32
119    , { "MMX   ", XVID_CPU_MMX }          { "MMX    ", XVID_CPU_MMX },
120    , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }          { "MMXEXT ", XVID_CPU_MMXEXT | XVID_CPU_MMX },
121    , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }          { "SSE2   ", XVID_CPU_SSE2 | XVID_CPU_MMX },
122    , { "3DNOW ", XVID_CPU_3DNOW }          { "3DNOW  ", XVID_CPU_3DNOW },
123    , { "3DNOWE", XVID_CPU_3DNOW | XVID_CPU_3DNOWEXT }          { "3DNOWE ", XVID_CPU_3DNOW | XVID_CPU_3DNOWEXT },
124  #endif  #endif
125  #ifdef ARCH_IS_PPC  #ifdef ARCH_IS_PPC
126    , { "ALTIVEC", XVID_CPU_ALTIVEC }          { "ALTIVEC", XVID_CPU_ALTIVEC },
127  #endif  #endif
128  #ifdef ARCH_IS_X86_64  #ifdef ARCH_IS_X86_64
129    , { "X86_64", XVID_CPU_ASM}          { "X86_64 ", XVID_CPU_ASM},
130  #endif  #endif
131  //, { "IA64  ", XVID_CPU_IA64 }  #ifdef ARCH_IS_IA64
132  //, { "TSC   ", XVID_CPU_TSC }  //      { "IA64   ", XVID_CPU_IA64 },
   , { 0, 0 } };  
   
 CPU  cpu_short_list[] =  
 { { "PLAINC", 0 }  
 #ifdef ARCH_IS_IA32  
   , { "MMX   ", XVID_CPU_MMX }  
 //, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }  
 #endif  
 //, { "IA64  ", XVID_CPU_IA64 }  
   , { 0, 0 } };  
   
 CPU cpu_short_list2[] =  
 { { "PLAINC", 0 }  
 #ifdef ARCH_IS_IA32  
   , { "MMX   ", XVID_CPU_MMX }  
   , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }  
133  #endif  #endif
134    , { 0, 0 } };  //      { "TSC    ", XVID_CPU_TSC },
135            { 0, 0 }
136    };
137    
138    
139  int init_cpu(CPU *cpu)  int init_cpu(CPU *cpu)
# Line 274  Line 261 
261          return crc;          return crc;
262  }  }
263    
264    void byte_swap(uint8_t *mem, int len, int element_size) {
265    #ifdef ARCH_IS_BIG_ENDIAN
266            int i;
267    
268            if(element_size == 1) {
269                    /* No need to swap */
270            } else if(element_size == 2) {
271                    uint8_t temp[2];
272    
273                    for(i=0; i < (len/2); i++ ) {
274                            temp[0] = mem[0];
275                            temp[1] = mem[1];
276                            mem[0] = temp[1];
277                            mem[1] = temp[0];
278    
279                            mem += 2;
280                    }
281            } else if(element_size == 4) {
282                    uint8_t temp[4];
283    
284                    for(i=0; i < (len/4); i++ ) {
285                            temp[0] = mem[0];
286                            temp[1] = mem[1];
287                            temp[2] = mem[2];
288                            temp[3] = mem[3];
289                            mem[0] = temp[3];
290                            mem[1] = temp[2];
291                            mem[2] = temp[1];
292                            mem[3] = temp[0];
293    
294                            mem += 4;
295                    }
296            } else {
297                    printf("ERROR: byte_swap unsupported element_size(%u)\n", element_size);
298            }
299    #endif
300    }
301    
302  /*********************************************************************  /*********************************************************************
303   * test DCT   * test DCT
304   *********************************************************************/   *********************************************************************/
# Line 494  Line 519 
519                             (iCrc!=8107)?"| ERROR": "" );                             (iCrc!=8107)?"| ERROR": "" );
520  #endif  #endif
521    
522        /* New functions for field prediction by CK 1.10.2005 */
523    #pragma NEW8X4
524                    TEST_MB(interpolate8x4_halfpel_h, 0);
525                    printf("%s - interpfield-h -round0 %.3f usec       crc32=0x%08x %s\n",
526                               cpu->name, t, iCrc,
527                               (iCrc!=0x9538d6df)?"| ERROR": "" );
528    
529                    TEST_MB(interpolate8x4_halfpel_h, 1);
530                    printf("%s -                round1 %.3f usec       crc32=0x%08x %s\n",
531                               cpu->name, t, iCrc,
532                               (iCrc!=0xde5f1db4)?"| ERROR": "" );
533    
534    
535                    TEST_MB(interpolate8x4_halfpel_v, 0);
536                    printf("%s - interpfield- v-round0 %.3f usec       crc32=0x%08x %s\n",
537                               cpu->name, t, iCrc,
538                               (iCrc!=0xea5a69ef)?"| ERROR": "" );
539    
540                    TEST_MB(interpolate8x4_halfpel_v, 1);
541                    printf("%s -                round1 %.3f usec       crc32=0x%08x %s\n",
542                               cpu->name, t, iCrc,
543                               (iCrc!=0x4f10ec0f)?"| ERROR": "" );
544    
545    
546                    TEST_MB(interpolate8x4_halfpel_hv, 0);
547                    printf("%s - interpfield-hv-round0 %.3f usec       crc32=0x%08x %s\n",
548                               cpu->name, t, iCrc,
549                               (iCrc!=0xf97ee367)?"| ERROR": "" );
550    
551                    TEST_MB(interpolate8x4_halfpel_hv, 1);
552                    printf("%s -                round1 %.3f usec       crc32=0x%08x %s\n",
553                               cpu->name, t, iCrc,
554                               (iCrc!=0xb6a9f581)?"| ERROR": "" );
555    /* End of 8x4 functions */
556    
557                  printf( " --- \n" );                  printf( " --- \n" );
558          }          }
559  }  }
560    
561    #undef ENTER
562    #undef LEAVE
563    #undef TEST_MB
564    #undef TEST_MB2
565    
566  /*********************************************************************  /*********************************************************************
567   * test transfer   * test transfer
568   *********************************************************************/   *********************************************************************/
# Line 527  Line 592 
592  }                                         \  }                                         \
593  emms();                                   \  emms();                                   \
594  t = (gettime_usec()-t -overhead) / nb_tests;\  t = (gettime_usec()-t -overhead) / nb_tests;\
595  s = calc_crc((uint8_t*)(DST), sizeof((DST)), CRC32_INITIAL)  byte_swap((uint8_t*)(DST), 8*32*sizeof((DST)[0]), sizeof((DST)[0]));  \
596    s = calc_crc((uint8_t*)(DST), 8*32*sizeof((DST)[0]), CRC32_INITIAL)
597    
598  #define TEST_TRANSFER(FUNC, DST, SRC)         \  #define TEST_TRANSFER(FUNC, DST, SRC)         \
599  TEST_TRANSFER_BEGIN(DST);                 \  TEST_TRANSFER_BEGIN(DST);                 \
# Line 553  Line 619 
619  }                                         \  }                                         \
620  emms();                                   \  emms();                                   \
621  t = (gettime_usec()-t -overhead) / nb_tests;\  t = (gettime_usec()-t -overhead) / nb_tests;\
622  s = calc_crc((uint8_t*)(DST), sizeof((DST)), CRC32_INITIAL)  byte_swap((uint8_t*)(DST), 8*32*sizeof((DST)[0]), sizeof((DST)[0]));  \
623    s = calc_crc((uint8_t*)(DST), 8*32*sizeof((DST)[0]), CRC32_INITIAL)
624    
625  #define TEST_TRANSFER2(FUNC, DST, SRC, R1)    \  #define TEST_TRANSFER2(FUNC, DST, SRC, R1)    \
626  TEST_TRANSFER2_BEGIN(DST,SRC);            \  TEST_TRANSFER2_BEGIN(DST,SRC);            \
# Line 570  Line 637 
637          const int nb_tests = 4000*speed_ref;          const int nb_tests = 4000*speed_ref;
638          int i;          int i;
639          CPU *cpu;          CPU *cpu;
640          uint8_t  Src8[8*32], Dst8[8*32], Ref1[8*32], Ref2[8*32];  //      uint8_t  Src8[8*32], Dst8[8*32], Ref1[8*32], Ref2[8*32];
641          int16_t Src16[8*32], Dst16[8*32];  //      int16_t Src16[8*32], Dst16[8*32];
642      DECLARE_ALIGNED_MATRIX(Src8, 8, 32, uint8_t, CACHE_LINE);
643      DECLARE_ALIGNED_MATRIX(Dst8, 8, 32, uint8_t, CACHE_LINE);
644      DECLARE_ALIGNED_MATRIX(Ref1, 8, 32, uint8_t, CACHE_LINE);
645      DECLARE_ALIGNED_MATRIX(Ref2, 8, 32, uint8_t, CACHE_LINE);
646      DECLARE_ALIGNED_MATRIX(Src16, 8, 32, uint16_t, CACHE_LINE);
647      DECLARE_ALIGNED_MATRIX(Dst16, 8, 32, uint16_t, CACHE_LINE);
648    
649          printf( "\n ===  test transfer ===\n" );          printf( "\n ===  test transfer ===\n" );
650    
# Line 593  Line 666 
666                                  cpu->name, t, s,                                  cpu->name, t, s,
667                                  (s!=0xee7ccbb4)?"| ERROR": "");                                  (s!=0xee7ccbb4)?"| ERROR": "");
668    
669        /* New functions for field prediction by CK 1.10.2005 */
670    #pragma NEW8X4
671                    TEST_TRANSFER(transfer8x4_copy, Dst8, Src8);
672                    printf("%s - 8to4      %.3f usec       crc32=0x%08x %s\n",
673                               cpu->name, t, s,
674                               (s!=0xbb9c3db5)?"| ERROR": "");
675    /* End of new functions */
676    
677                  TEST_TRANSFER(transfer8x8_copy, Dst8, Src8);                  TEST_TRANSFER(transfer8x8_copy, Dst8, Src8);
678                  printf("%s - 8to8      %.3f usec       crc32=0x%08x %s\n",                  printf("%s - 8to8      %.3f usec       crc32=0x%08x %s\n",
679                             cpu->name, t, s,                             cpu->name, t, s,
# Line 606  Line 687 
687                  TEST_TRANSFER2(transfer_8to16sub, Dst16, Src8, Ref1);                  TEST_TRANSFER2(transfer_8to16sub, Dst16, Src8, Ref1);
688                  {                  {
689                          int s1, s2;                          int s1, s2;
690                          s1 = calc_crc((uint8_t*)Dst16, sizeof(Dst16), CRC32_INITIAL);                          s1 = calc_crc((uint8_t*)Dst16, 8*32*sizeof(Dst16[0]), CRC32_INITIAL);
691                          s2 = calc_crc((uint8_t*)Src8, sizeof(Src8), CRC32_INITIAL);                          s2 = calc_crc((uint8_t*)Src8, 8*32*sizeof(Src8[0]), CRC32_INITIAL);
692                          printf("%s - 8to16sub  %.3f usec       crc32(1)=0x%08x crc32(2)=0x%08x %s %s\n",                          printf("%s - 8to16sub  %.3f usec       crc32(1)=0x%08x crc32(2)=0x%08x %s %s\n",
693                                     cpu->name, t, s1, s2,                                     cpu->name, t, s1, s2,
694                                     (s1!=0xa1e07163)?"| ERROR1": "",                                     (s1!=0xa1e07163)?"| ERROR1": "",
# Line 636  Line 717 
717    for(q=1; q<=max_Q; ++q) {                 \    for(q=1; q<=max_Q; ++q) {                 \
718          for(tst=0; tst<nb_tests; ++tst)         \          for(tst=0; tst<nb_tests; ++tst)         \
719            (FUNC)((DST), (SRC), q, mpeg_quant_matrices);              \            (FUNC)((DST), (SRC), q, mpeg_quant_matrices);              \
720          s = calc_crc((uint8_t*)(DST), 64*sizeof(int16_t), s); \          byte_swap((uint8_t*)(DST), 64*sizeof((DST)[0]), sizeof((DST)[0]));  \
721            s = calc_crc((uint8_t*)(DST), 64*sizeof((DST)[0]), s); \
722    }                                         \    }                                         \
723    emms();                                   \    emms();                                   \
724  }                                           \  }                                           \
# Line 651  Line 733 
733    for(q=1; q<=max_Q; ++q) {                 \    for(q=1; q<=max_Q; ++q) {                 \
734          for(tst=0; tst<nb_tests; ++tst)         \          for(tst=0; tst<nb_tests; ++tst)         \
735            (FUNC)((DST), (SRC), q, q, mpeg_quant_matrices);           \            (FUNC)((DST), (SRC), q, q, mpeg_quant_matrices);           \
736          s = calc_crc((uint8_t*)(DST), 64*sizeof(int16_t), s); \          byte_swap((uint8_t*)(DST), 64*sizeof((DST)[0]), sizeof((DST)[0]));  \
737            s = calc_crc((uint8_t*)(DST), 64*sizeof((DST)[0]), s); \
738    }                                         \    }                                         \
739    emms();                                   \    emms();                                   \
740  }                                           \  }                                           \
# Line 871  Line 954 
954   * test non-zero AC counting   * test non-zero AC counting
955   *********************************************************************/   *********************************************************************/
956    
957  #define TEST_CBP(FUNC, SRC)               \  #define TEST_CBP(FUNC, SRC, NB)           \
958  t = gettime_usec();                       \  t = gettime_usec();                       \
959  emms();                                   \  emms();                                   \
960  for(tst=0; tst<nb_tests; ++tst) {         \  for(tst=0; tst<NB; ++tst) {         \
961    cbp = (FUNC)((SRC));                    \    cbp = (FUNC)((SRC));                    \
962  }                                         \  }                                         \
963  emms();                                   \  emms();                                   \
# Line 883  Line 966 
966  void test_cbp()  void test_cbp()
967  {  {
968          const int nb_tests = 10000*speed_ref;          const int nb_tests = 10000*speed_ref;
969          int i;          int i, n, m;
970          CPU *cpu;          CPU *cpu;
971          DECLARE_ALIGNED_MATRIX(Src1, 6, 64, int16_t, 16);          DECLARE_ALIGNED_MATRIX(Src1, 6, 64, int16_t, 16);
972          DECLARE_ALIGNED_MATRIX(Src2, 6, 64, int16_t, 16);          DECLARE_ALIGNED_MATRIX(Src2, 6, 64, int16_t, 16);
973          DECLARE_ALIGNED_MATRIX(Src3, 6, 64, int16_t, 16);          DECLARE_ALIGNED_MATRIX(Src3, 6, 64, int16_t, 16);
974          DECLARE_ALIGNED_MATRIX(Src4, 6, 64, int16_t, 16);          DECLARE_ALIGNED_MATRIX(Src4, 6, 64, int16_t, 16);
975      DECLARE_ALIGNED_MATRIX(Src5, 6, 64, int16_t, 16);
976    
977          printf( "\n =====  test cbp =====\n" );          printf( "\n =====  test cbp =====\n" );
978    
# Line 897  Line 981 
981                  Src2[i] = (i<3*64);               /* half-full */                  Src2[i] = (i<3*64);               /* half-full */
982                  Src3[i] = ((i+32)>3*64);                  Src3[i] = ((i+32)>3*64);
983                  Src4[i] = (i==(3*64+2) || i==(5*64+9));                  Src4[i] = (i==(3*64+2) || i==(5*64+9));
984        Src5[i] = ieee_rand(0,1) ? -1 : 1;  /* +/- test */
985          }          }
986    
987          for(cpu = cpu_list; cpu->name!=0; ++cpu)          for(cpu = cpu_list; cpu->name!=0; ++cpu)
# Line 907  Line 992 
992                  if (!init_cpu(cpu))                  if (!init_cpu(cpu))
993                          continue;                          continue;
994    
995                  TEST_CBP(calc_cbp, Src1);                  TEST_CBP(calc_cbp, Src1, nb_tests);
996                  printf("%s -   calc_cbp#1 %.3f usec       cbp=0x%02x %s\n",                  printf("%s -   calc_cbp#1 %.3f usec       cbp=0x%02x %s\n",
997                             cpu->name, t, cbp, (cbp!=0x15)?"| ERROR": "");                             cpu->name, t, cbp, (cbp!=0x15)?"| ERROR": "");
998                  TEST_CBP(calc_cbp, Src2);                  TEST_CBP(calc_cbp, Src2, nb_tests);
999                  printf("%s -   calc_cbp#2 %.3f usec       cbp=0x%02x %s\n",                  printf("%s -   calc_cbp#2 %.3f usec       cbp=0x%02x %s\n",
1000                             cpu->name, t, cbp, (cbp!=0x38)?"| ERROR": "");                             cpu->name, t, cbp, (cbp!=0x38)?"| ERROR": "");
1001                  TEST_CBP(calc_cbp, Src3);                  TEST_CBP(calc_cbp, Src3, nb_tests);
1002                  printf("%s -   calc_cbp#3 %.3f usec       cbp=0x%02x %s\n",                  printf("%s -   calc_cbp#3 %.3f usec       cbp=0x%02x %s\n",
1003                             cpu->name, t, cbp, (cbp!=0x0f)?"| ERROR": "" );                             cpu->name, t, cbp, (cbp!=0x0f)?"| ERROR": "" );
1004                  TEST_CBP(calc_cbp, Src4);                  TEST_CBP(calc_cbp, Src4, nb_tests);
1005                  printf("%s -   calc_cbp#4 %.3f usec       cbp=0x%02x %s\n",                  printf("%s -   calc_cbp#4 %.3f usec       cbp=0x%02x %s\n",
1006                             cpu->name, t, cbp, (cbp!=0x05)?"| ERROR": "" );                             cpu->name, t, cbp, (cbp!=0x05)?"| ERROR": "" );
1007                    TEST_CBP(calc_cbp, Src5, nb_tests);
1008                    printf("%s -   calc_cbp#4 %.3f usec       cbp=0x%02x %s\n",
1009                               cpu->name, t, cbp, (cbp!=0x3f)?"| ERROR": "" );
1010                  printf( " --- \n" );                  printf( " --- \n" );
1011          }          }
1012    
1013            for(cpu = cpu_list; cpu->name!=0; ++cpu)  /* bench suggested by Carlo (carlo dot bramix at libero dot it) */
1014            {
1015                    double t;
1016                    int tst, cbp, err;
1017    
1018                    if (!init_cpu(cpu))
1019                            continue;
1020    
1021        err = 0;
1022        for(n=0; n<6; ++n)
1023        {
1024          for(m=0; m<64; ++m)
1025          {
1026            for(i=0; i<6*64; ++i)
1027              Src1[i] = (i== (m + n*64));
1028    
1029            TEST_CBP(calc_cbp, Src1, 1);
1030            if (cbp!= (((m!=0)<<(5-n))))
1031            {
1032              printf( "%s -   calc_cbp#5: ERROR at pos %d / %d!\n", cpu->name, n, m);
1033              err = 1;
1034              break;
1035            }
1036          }
1037        }
1038        if (!err)
1039          printf( " %s -    calc_cbp#5 : OK\n", cpu->name );
1040    
1041            }
1042  }  }
1043    
1044  /*********************************************************************  /*********************************************************************
# Line 1383  Line 1501 
1501                  xframe.bitstream = buf + pos;                  xframe.bitstream = buf + pos;
1502                  xframe.length = buf_size - pos;                  xframe.length = buf_size - pos;
1503                  xframe.output.plane[0] = (uint8_t*)(((size_t)yuv_out + 15) & ~15);                  xframe.output.plane[0] = (uint8_t*)(((size_t)yuv_out + 15) & ~15);
1504                  xframe.output.plane[1] = xframe.output.plane[0] + bps*height;                  xframe.output.plane[1] = (uint8_t*)xframe.output.plane[0] + bps*height;
1505                  xframe.output.plane[2] = xframe.output.plane[1] + bps/2;                  xframe.output.plane[2] = (uint8_t*)xframe.output.plane[1] + bps/2;
1506                  xframe.output.stride[0] = bps;                  xframe.output.stride[0] = bps;
1507                  xframe.output.stride[1] = bps;                  xframe.output.stride[1] = bps;
1508                  xframe.output.stride[2] = bps;                  xframe.output.stride[2] = bps;
# Line 1402  Line 1520 
1520                  nb++;                  nb++;
1521    
1522      for(y=0; y<height/2; ++y) {      for(y=0; y<height/2; ++y) {
1523                    chksum = calc_crc(xframe.output.plane[0] + (2*y+0)*bps, width, chksum);                    chksum = calc_crc((uint8_t*)xframe.output.plane[0] + (2*y+0)*bps, width, chksum);
1524                          chksum = calc_crc(xframe.output.plane[0] + (2*y+1)*bps, width, chksum);                          chksum = calc_crc((uint8_t*)xframe.output.plane[0] + (2*y+1)*bps, width, chksum);
1525                          chksum = calc_crc(xframe.output.plane[1] + y*bps, width/2, chksum);                          chksum = calc_crc((uint8_t*)xframe.output.plane[1] + y*bps, width/2, chksum);
1526                          chksum = calc_crc(xframe.output.plane[2] + y*bps, width/2, chksum);                          chksum = calc_crc((uint8_t*)xframe.output.plane[2] + y*bps, width/2, chksum);
1527                  }                  }
1528                  if (pos==buf_size)                  if (pos==buf_size)
1529                          break;                          break;
# Line 1588  Line 1706 
1706          }          }
1707  #endif  #endif
1708  }  }
1709    
1710    /*********************************************************************
1711     * test some YUV func
1712     *********************************************************************/
1713    
1714    #define ENTER \
1715    for(i=0; i<(int)sizeof(Dst0); ++i) Dst0[0][i] = 0;   \
1716    t = gettime_usec();                   \
1717    emms();
1718    
1719    #define LEAVE \
1720    emms();                             \
1721    t = (gettime_usec() - t) / nb_tests;  \
1722            iCrc = calc_crc((uint8_t*)Dst0, sizeof(Dst0), CRC32_INITIAL)
1723    
1724    #define TEST_YUYV(FUNC, S)                \
1725    ENTER                               \
1726    for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst0[0], S*WIDTH, Src0[0], Src0[1], Src0[2], WIDTH, WIDTH/2, WIDTH, HEIGHT, 0); \
1727    LEAVE
1728    
1729    #define WIDTH 128
1730    #define HEIGHT 32
1731    void test_yuv()
1732    {
1733            const int nb_tests = 200*speed_ref;
1734            CPU *cpu;
1735            uint8_t Src0[3][WIDTH*HEIGHT];
1736            uint8_t Dst0[4][WIDTH*HEIGHT];
1737            int i, j;
1738            double t;
1739            int tst, iCrc;
1740    
1741            colorspace_init();
1742            ieee_reseed(1);
1743            for(i=0; i<(int)sizeof(Src0); ++i) Src0[0][i] = ieee_rand(0,255);
1744            for(i=0; i<(int)sizeof(Dst0); ++i) Dst0[0][i] = 0x5a;
1745    
1746            printf( "\n ===  test YUV ===\n" );
1747    
1748            init_cpu(&cpu_list[0]);
1749            TEST_YUYV(yv12_to_yuyv_c, 4);
1750            printf(" yv12_to_yuyv_c %.3f usec       crc32=0x%08x %s\n",
1751                       t, iCrc, (iCrc!=0xeb1a0b0a)?"| ERROR": "" );
1752            TEST_YUYV(yv12_to_uyvy_c, 4);
1753            printf(" yv12_to_uyvy_c %.3f usec       crc32=0x%08x %s\n",
1754                       t, iCrc, (iCrc!=0x6e82f55b)?"| ERROR": "" );
1755    
1756    #ifdef ARCH_IS_IA32
1757            init_cpu(&cpu_list[1]);
1758            TEST_YUYV(yv12_to_yuyv_mmx, 4);
1759            printf(" yv12_to_yuyv_mmx %.3f usec       crc32=0x%08x %s\n",
1760                    t, iCrc, (iCrc!=0xeb1a0b0a)?"| ERROR": "" );
1761    
1762            TEST_YUYV(yv12_to_uyvy_mmx, 4);
1763            printf(" yv12_to_uyvy_mmx %.3f usec       crc32=0x%08x %s\n",
1764                    t, iCrc, (iCrc!=0x6e82f55b)?"| ERROR": "" );
1765    #endif
1766    
1767    #ifdef ARCH_IS_PPC
1768            init_cpu(&cpu_list[1]);
1769            TEST_YUYV(yv12_to_yuyv_altivec_c, 4);
1770            printf(" yv12_to_yuyv_altivec_c %.3f usec       crc32=0x%08x %s\n",
1771                    t, iCrc, (iCrc!=0xeb1a0b0a)?"| ERROR": "" );
1772    
1773            TEST_YUYV(yv12_to_uyvy_altivec_c, 4);
1774            printf(" yv12_to_uyvy_altivec_c %.3f usec       crc32=0x%08x %s\n",
1775                    t, iCrc, (iCrc!=0x6e82f55b)?"| ERROR": "" );
1776    #endif
1777            printf( " --- \n" );
1778    }
1779    
1780    #define TEST_YV2(FUNC, WITH_UV, WITH_FLIP)        \
1781    ENTER                               \
1782    for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst0[0], Dst0[1], Dst0[2], WIDTH, WIDTH, \
1783            Src0[0], (WITH_UV) ? Src0[1] : 0, (WITH_UV) ? Src0[2] : 0,  WIDTH, WIDTH, \
1784            WIDTH-2, HEIGHT-2, WITH_FLIP); \
1785    LEAVE
1786    
1787    #define PRINT_NxN(DATA,W,H,STR)   {   \
1788            int i,j; \
1789            for(j=0; j<(H); ++j) { \
1790                    for(i=0; i<(W); ++i) printf( "0x%.2x ", (DATA)[i+j*(STR)] );\
1791                    printf("\n"); \
1792            } \
1793            printf("---\n"); \
1794    }
1795    
1796    static const int yv12_CRCs[2][2] = {
1797            {0x5cab7cf0,0xdab46541}
1798    ,       {0xe8bae865,0x1faf77b7}
1799    };
1800    
1801    void test_yuv2()
1802    {
1803            const int nb_tests = 800*speed_ref;
1804            CPU *cpu;
1805            uint8_t Src0[3][WIDTH*HEIGHT];
1806            uint8_t Dst0[3][WIDTH*HEIGHT];
1807            int with_uv, with_flip;
1808            int i, j;
1809            double t;
1810            int tst, iCrc;
1811    
1812            colorspace_init();
1813            ieee_reseed(1);
1814            for(i=0; i<(int)sizeof(Src0); ++i) Src0[0][i] = ieee_rand(0,255);
1815    
1816            printf( "\n ===  test YV2 ===\n" );
1817            for(with_flip=0; with_flip<=1; ++with_flip) {
1818                    for(with_uv=0; with_uv<=1; ++with_uv) {
1819                            init_cpu(&cpu_list[0]);
1820                            TEST_YV2(yv12_to_yv12_c, with_uv, with_flip);
1821                            printf(" yv12_to_yv12_c   %.3f usec      \tcrc32=0x%08x %s\n",
1822                                    t, iCrc, (iCrc!=yv12_CRCs[with_flip][with_uv])?"| ERROR": "" );
1823                            /* if (!with_uv) PRINT_NxN(Dst0[1], WIDTH/2, HEIGHT/2, WIDTH ); */
1824    
1825    #ifdef ARCH_IS_IA32
1826                            init_cpu(&cpu_list[1]);
1827                            TEST_YV2(yv12_to_yv12_mmx, with_uv, with_flip);
1828                            printf(" yv12_to_yv12_mmx %.3f usec     \tcrc32=0x%08x %s\n",
1829                                    t, iCrc, (iCrc!=yv12_CRCs[with_flip][with_uv])?"| ERROR": "" );
1830                            /* if (!with_uv) PRINT_NxN(Dst0[1], WIDTH/2, HEIGHT/2, WIDTH ); */
1831    
1832                            TEST_YV2(yv12_to_yv12_xmm, with_uv, with_flip);
1833                            printf(" yv12_to_yv12_xmm %.3f usec     \tcrc32=0x%08x %s\n",
1834                                    t, iCrc, (iCrc!=yv12_CRCs[with_flip][with_uv])?"| ERROR": "" );
1835    #endif
1836                    }
1837    
1838                    printf( " --- \n" );
1839            }
1840            printf( " ===== \n" );
1841    }
1842    
1843    #undef WIDTH
1844    #undef HEIGHT
1845    #undef ENTER
1846    #undef LEAVE
1847    
1848  /*********************************************************************/  /*********************************************************************/
1849    
1850  static uint32_t __inline log2bin_v1(uint32_t value)  static uint32_t __inline log2bin_v1(uint32_t value)
# Line 1710  Line 1967 
1967  }  }
1968    
1969  /*********************************************************************  /*********************************************************************
1970     * test compiler
1971     *********************************************************************/
1972    
1973    void test_compiler() {
1974      int nb_err = 0;
1975      int32_t v;
1976      if (sizeof(uint16_t)<2) {
1977        printf( "ERROR: sizeof(uint16_t)<2 !!\n" );
1978        nb_err++;
1979      }
1980      if (sizeof(int16_t)<2) {
1981        printf( "ERROR: sizeof(int16_t)<2 !!\n" );
1982        nb_err++;
1983      }
1984      if (sizeof(uint8_t)!=1) {
1985        printf( "ERROR: sizeof(uint8_t)!=1 !!\n" );
1986        nb_err++;
1987      }
1988      if (sizeof(int8_t)!=1) {
1989        printf( "ERROR: sizeof(int8_t)!=1 !!\n" );
1990        nb_err++;
1991      }
1992      if (sizeof(uint32_t)<4) {
1993        printf( "ERROR: sizeof(uint32_t)<4 !!\n" );
1994        nb_err++;
1995      }
1996      if (sizeof(int32_t)<4) {
1997        printf( "ERROR: sizeof(int32_t)<4 !!\n" );
1998        nb_err++;
1999      }
2000             /* yes, i know, this test is silly. But better be safe than sorry. :) */
2001      for(v=1000; v>=0; v--) {
2002        if ( (v>>2) != v/4)
2003          nb_err++;
2004      }
2005      for(v=-1000; v!=-1; v++) {
2006        if ( (v>>2) != (v/4)-!!(v%4))
2007          nb_err++;
2008      }
2009      if (nb_err!=0) {
2010        printf( "ERROR! please post your platform/compiler specs to xvid-devel@xvid.org !\n" );
2011      }
2012    }
2013    
2014    /*********************************************************************
2015     * test SSIM functions
2016     *********************************************************************/
2017    
2018    typedef int (*lumfunc)(uint8_t* ptr, int stride);
2019    typedef void (*csfunc)(uint8_t* ptro, uint8_t* ptrc, int stride, int lumo, int lumc, int* pdevo, int* pdevc, int* pcorr);
2020    
2021    extern int lum_8x8_c(uint8_t* ptr, int stride);
2022    extern int lum_8x8_mmx(uint8_t* ptr, int stride);
2023    extern int lum_2x8_c(uint8_t* ptr, int stride);
2024    extern void consim_c(uint8_t* ptro, uint8_t* ptrc, int stride, int lumo, int lumc, int* pdevo, int* pdevc, int* pcorr);
2025    extern void consim_mmx(uint8_t* ptro, uint8_t* ptrc, int stride, int lumo, int lumc, int* pdevo, int* pdevc, int* pcorr);
2026    extern void consim_sse2(uint8_t* ptro, uint8_t* ptrc, int stride, int lumo, int lumc, int* pdevo, int* pdevc, int* pcorr);
2027    
2028    void test_SSIM()
2029    {
2030            const int nb_tests = 3000*speed_ref;
2031            int tst;
2032            CPU *cpu;
2033            int i;
2034            int devs[3];
2035            long lumo, lumc;
2036            DECLARE_ALIGNED_MATRIX(Ref1, 16, 16, uint8_t, 16);
2037            DECLARE_ALIGNED_MATRIX(Ref2, 16, 16, uint8_t, 16);
2038            lumfunc lum8x8;
2039            lumfunc lum2x8;
2040            csfunc  csim;
2041    
2042            ieee_reseed(1);
2043            printf( "\n ======  test SSIM ======\n" );
2044            for(i=0; i<16*16;++i) {
2045                    long v1, v2;
2046                    v1 = ieee_rand(-256, 511);
2047                    v2 = ieee_rand(-256, 511);
2048                    Ref1[i] = (v1<0) ? 0 : (v1>255) ? 255 : v1;
2049                    Ref2[i] = (v2<0) ? 0 : (v2>255) ? 255 : v2;
2050            }
2051            lumc = ieee_rand(0, 255);
2052            lumo = ieee_rand(0, 255);
2053    
2054            for(cpu = cpu_list; cpu->name!=0; ++cpu)
2055            {
2056                    double t;
2057                    int m;
2058                    if (!init_cpu(cpu))
2059                            continue;
2060                    lum8x8 = lum_8x8_c;
2061                    lum2x8 = lum_2x8_c;
2062                    csim   = consim_c;
2063                    if (cpu->cpu & XVID_CPU_MMX){
2064                            lum8x8 = lum_8x8_mmx;
2065                            csim = consim_mmx;
2066                    }
2067                    if (cpu->cpu & XVID_CPU_MMX){
2068                            csim = consim_sse2;
2069                    }
2070    
2071                    t = gettime_usec();
2072                    emms();
2073                    for(tst=0; tst<nb_tests; ++tst) m = lum8x8(Ref1, 16);
2074                    emms();
2075                    t = (gettime_usec() - t) / nb_tests;
2076                    printf("%s - ssim-lum8x8    %.3f usec       m=%d %s\n",
2077                               cpu->name, t, m,
2078                               (m!=8230)?"| ERROR": "" );
2079    
2080                    t = gettime_usec();
2081                    emms();
2082                    for(tst=0; tst<nb_tests; ++tst) m = lum2x8(Ref1+8, 16);
2083                    emms();
2084                    t = (gettime_usec() - t) / nb_tests;
2085                    printf("%s - ssim-lum2x8    %.3f usec       m=%d %s\n",
2086                               cpu->name, t, m,
2087                               (m!=681)?"| ERROR": "" );
2088    
2089                    t = gettime_usec();
2090                    emms();
2091                    for(tst=0; tst<nb_tests; ++tst) csim(Ref1, Ref2, 16, lumo, lumc, devs+0, devs+1, devs+2);
2092                    emms();
2093                    t = (gettime_usec() - t) / nb_tests;
2094                    printf("%s - ssim-consim    %.3f usec       devs=[0x%x 0x%x 0x%x] %s\n",
2095                               cpu->name, t, devs[0], devs[1], devs[2],
2096                               (devs[0]!=0x1bdf0f || devs[1]!=0x137258 ||  devs[2]!=0xcdb13)?"| ERROR": "" );
2097                    printf( " --- \n" );
2098            }
2099    }
2100    
2101    /*********************************************************************
2102     * test bitstream functions
2103     *********************************************************************/
2104    
2105    #define BIT_BUF_SIZE 2000
2106    
2107    static void test_bits()
2108    {
2109      const int nb_tests = 50*speed_ref;
2110      int tst;
2111      uint32_t Crc;
2112      uint8_t Buf[BIT_BUF_SIZE];
2113      uint32_t Extracted[BIT_BUF_SIZE*8]; /* worst case: bits read 1 by 1 */
2114      int Lens[BIT_BUF_SIZE*8];
2115      double t1;
2116    
2117    
2118      printf( "\n ===  test bitstream ===\n" );
2119      ieee_reseed(1);
2120      Crc = 0;
2121    
2122      t1 = gettime_usec();
2123      for(tst=0; tst<nb_tests; ++tst) {
2124            Bitstream bs;
2125            int m, m2, l, l2;
2126    
2127            for(l=0; l<BIT_BUF_SIZE; ++l)
2128                    Buf[l] = (uint8_t)ieee_rand(0,255);
2129    
2130            l = BIT_BUF_SIZE - ieee_rand(1,BIT_BUF_SIZE/10);
2131            BitstreamInit(&bs, (void*)(Buf+BIT_BUF_SIZE-l), l);
2132    
2133    
2134            BitstreamReset(&bs);
2135            for(l2=l*8, m=0; l2>0; m++) {
2136                    const int b = ieee_rand(1,32);
2137                    Lens[m] = b;
2138                    l2 -= b;
2139                    if (l2<0) break;
2140                    Extracted[m] = BitstreamShowBits(&bs, b);
2141                    BitstreamSkip(&bs, b);
2142    //              printf( "<= %d: %d 0x%x\n", m, b, Extracted[m]);
2143            }
2144    
2145            BitstreamReset(&bs);
2146            for(m2=0; m2<m; ++m2) {
2147                    const int b = Lens[m2];
2148                    const uint32_t v = BitstreamGetBits(&bs, b);
2149                    Crc |= (v!=Extracted[m2]);
2150    //              printf( "=> %d: %d 0x%x %c\n", m2, b, v, " *"[Crc]);
2151            }
2152      }
2153      t1 = (gettime_usec() - t1) / nb_tests;
2154      printf(" test_bits   %.3f usec   %s\n", t1, (Crc!=0)?"| ERROR": "" );
2155    }
2156    
2157    /*********************************************************************
2158   * main   * main
2159   *********************************************************************/   *********************************************************************/
2160    
# Line 1733  Line 2178 
2178            else if (!strcmp(argv[c], "-c"))      cpu_mask = 0 /* PLAIN_C */ | XVID_CPU_FORCE;            else if (!strcmp(argv[c], "-c"))      cpu_mask = 0 /* PLAIN_C */ | XVID_CPU_FORCE;
2179            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;
2180            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;
2181            else if (!strcmp(argv[c], "-sse2"))   cpu_mask = XVID_CPU_SSE2   | 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;
2182            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;
2183            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;
2184            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 1777  Line 2222 
2222          if (what==0 || what==10) test_sse();          if (what==0 || what==10) test_sse();
2223          if (what==0 || what==11) test_log2bin();          if (what==0 || what==11) test_log2bin();
2224          if (what==0 || what==12) test_gcd();          if (what==0 || what==12) test_gcd();
2225            if (what==0 || what==13) test_compiler();
2226            if (what==0 || what==14) test_yuv();
2227            if (what==0 || what==15) test_SSIM();
2228            if (what==0 || what==16) test_yuv2();
2229            if (what==0 || what==17) test_bits();
2230    
2231          if (what==7) {          if (what==7) {
2232                  test_IEEE1180_compliance(-256, 255, 1);                  test_IEEE1180_compliance(-256, 255, 1);

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

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