[cvs] / xvidcore / src / xvid.c Repository:
ViewVC logotype

Diff of /xvidcore/src/xvid.c

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

revision 1.33.2.19, Mon Dec 30 10:49:17 2002 UTC revision 1.47, Wed Jun 11 14:10:55 2003 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Native API implementation  -   *  - Native API implementation  -
5   *   *
  *  This program is an implementation of a part of one or more MPEG-4  
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
  *  
6   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
7   *  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
8   *  the Free Software Foundation ; either version 2 of the License, or   *  the Free Software Foundation ; either version 2 of the License, or
# Line 26  Line 17 
17   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19   *   *
  ****************************************************************************/  
   
 /*****************************************************************************  
  *  
  *  History  
  *  
  *      - 23.06.2002    added XVID_CPU_CHKONLY  
  *  - 17.03.2002        Added interpolate8x8_halfpel_hv_xmm  
  *  - 22.12.2001  API change: added xvid_init() - Isibaar  
  *  - 16.12.2001        inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>  
  *  
20   *  $Id$   *  $Id$
21   *   *
22   ****************************************************************************/   ****************************************************************************/
23    
24    #include <stdio.h>
25    #include <stdlib.h>
26    #include <string.h>
27    #include <time.h>
28    
29  #include "xvid.h"  #include "xvid.h"
30  #include "decoder.h"  #include "decoder.h"
31  #include "encoder.h"  #include "encoder.h"
# Line 60  Line 45 
45  #include "utils/timer.h"  #include "utils/timer.h"
46  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
47    
48  #if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE)  #if defined(ARCH_IS_IA32)
49    
50  #ifdef WIN32  #if defined(_MSC_VER)
51  #include <windows.h>  #include <windows.h>
52  #else  #else
53  #include <signal.h>  #include <signal.h>
54  #include <setjmp.h>  #include <setjmp.h>
 #endif  
   
   
 #ifndef WIN32  
55    
56  static jmp_buf mark;  static jmp_buf mark;
57    
# Line 83  Line 64 
64    
65    
66  /*  /*
67  calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled   * Calls the funcptr, and returns whether SIGILL (illegal instruction) was
68  return values:   * signalled
69  -1 : could not determine   *
70  0  : SIGILL was *not* signalled   * Return values:
71  1  : SIGILL was signalled   *  -1 : could not determine
72     *   0 : SIGILL was *not* signalled
73     *   1 : SIGILL was signalled
74  */  */
75    
76  int  int
77  sigill_check(void (*func)())  sigill_check(void (*func)())
78  {  {
79  #ifdef WIN32  #if defined(_MSC_VER)
80          _try {          _try {
81                  func();                  func();
82          }          }
# Line 127  Line 110 
110  }  }
111  #endif  #endif
112    
113    
114    /* detect cpu flags  */
115    static unsigned int
116    detect_cpu_flags()
117    {
118            /* enable native assembly optimizations by default */
119            unsigned int cpu_flags = XVID_CPU_ASM;
120    
121    #if defined(ARCH_IS_IA32)
122            cpu_flags |= check_cpu_features();
123            if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger))
124                    cpu_flags &= ~XVID_CPU_SSE;
125    
126            if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger))
127                    cpu_flags &= ~XVID_CPU_SSE2;
128    #endif
129    
130    #if defined(ARCH_IS_PPC)
131    #if defined(ARCH_IS_PPC_ALTIVEC)
132            cpu_flags |= XVID_CPU_ALTIVEC;
133    #endif
134    #endif
135    
136            return cpu_flags;
137    }
138    
139    
140  /*****************************************************************************  /*****************************************************************************
141   * XviD Init Entry point   * XviD Init Entry point
142   *   *
# Line 160  Line 170 
170    
171          } else {          } else {
172    
173                  cpu_flags = check_cpu_features();                  cpu_flags = detect_cpu_flags();
   
 #if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE)  
                 if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger))  
                         cpu_flags &= ~XVID_CPU_SSE;  
   
                 if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger))  
                         cpu_flags &= ~XVID_CPU_SSE2;  
 #endif  
174          }          }
175    
176          if ((init_param->cpu_flags & XVID_CPU_CHKONLY))          if ((init_param->cpu_flags & XVID_CPU_CHKONLY))
# Line 209  Line 211 
211          transfer_8to16copy = transfer_8to16copy_c;          transfer_8to16copy = transfer_8to16copy_c;
212          transfer_16to8copy = transfer_16to8copy_c;          transfer_16to8copy = transfer_16to8copy_c;
213          transfer_8to16sub  = transfer_8to16sub_c;          transfer_8to16sub  = transfer_8to16sub_c;
214            transfer_8to16subro  = transfer_8to16subro_c;
215          transfer_8to16sub2 = transfer_8to16sub2_c;          transfer_8to16sub2 = transfer_8to16sub2_c;
216          transfer_16to8add  = transfer_16to8add_c;          transfer_16to8add  = transfer_16to8add_c;
217          transfer8x8_copy   = transfer8x8_copy_c;          transfer8x8_copy   = transfer8x8_copy_c;
# Line 236  Line 239 
239          interpolate8x8_avg4 = interpolate8x8_avg4_c;          interpolate8x8_avg4 = interpolate8x8_avg4_c;
240    
241          /* reduced resoltuion */          /* reduced resoltuion */
   
242          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;
243          add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C;          add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C;
 #ifdef ARCH_X86  
         vfilter_31 = xvid_VFilter_31_x86;  
         hfilter_31 = xvid_HFilter_31_x86;  
 #else  
244          vfilter_31 = xvid_VFilter_31_C;          vfilter_31 = xvid_VFilter_31_C;
245          hfilter_31 = xvid_HFilter_31_C;          hfilter_31 = xvid_HFilter_31_C;
 #endif  
246          filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C;          filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C;
247          filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C;          filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C;
248    
# Line 301  Line 298 
298          dev16    = dev16_c;          dev16    = dev16_c;
299          sad16v   = sad16v_c;          sad16v   = sad16v_c;
300    
301  //      Halfpel8_Refine = Halfpel8_Refine_c;  /*      Halfpel8_Refine = Halfpel8_Refine_c; */
302    
303    #if defined(ARCH_IS_IA32)
304    
305  #ifdef ARCH_X86          if ((cpu_flags & XVID_CPU_ASM))
306            {
307                    vfilter_31 = xvid_VFilter_31_x86;
308                    hfilter_31 = xvid_HFilter_31_x86;
309            }
310    
311          if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) ||          if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) ||
312                  (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) ||                  (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) ||
# Line 313  Line 316 
316                  emms = emms_mmx;                  emms = emms_mmx;
317          }          }
318    
319          if ((cpu_flags & XVID_CPU_MMX) > 0) {          if ((cpu_flags & XVID_CPU_MMX)) {
320    
321                  /* Forward and Inverse Discrete Cosine Transformation functions */                  /* Forward and Inverse Discrete Cosine Transformation functions */
322                  fdct = fdct_mmx;                  fdct = fdct_mmx;
# Line 334  Line 337 
337                  transfer_8to16copy = transfer_8to16copy_mmx;                  transfer_8to16copy = transfer_8to16copy_mmx;
338                  transfer_16to8copy = transfer_16to8copy_mmx;                  transfer_16to8copy = transfer_16to8copy_mmx;
339                  transfer_8to16sub  = transfer_8to16sub_mmx;                  transfer_8to16sub  = transfer_8to16sub_mmx;
340                    transfer_8to16subro  = transfer_8to16subro_mmx;
341                  transfer_8to16sub2 = transfer_8to16sub2_mmx;                  transfer_8to16sub2 = transfer_8to16sub2_mmx;
342                  transfer_16to8add  = transfer_16to8add_mmx;                  transfer_16to8add  = transfer_16to8add_mmx;
343                  transfer8x8_copy   = transfer8x8_copy_mmx;                  transfer8x8_copy   = transfer8x8_copy_mmx;
# Line 383  Line 387 
387                  sad8bi  = sad8bi_mmx;                  sad8bi  = sad8bi_mmx;
388                  dev16    = dev16_mmx;                  dev16    = dev16_mmx;
389                  sad16v   = sad16v_mmx;                  sad16v   = sad16v_mmx;
   
390          }          }
391    
392          /* these 3dnow functions are faster than mmx, but slower than xmm. */          /* these 3dnow functions are faster than mmx, but slower than xmm. */
393          if ((cpu_flags & XVID_CPU_3DNOW) > 0) {          if ((cpu_flags & XVID_CPU_3DNOW)) {
394    
395                    emms = emms_3dn;
396    
397                  /* ME functions */                  /* ME functions */
398                  sad16bi = sad16bi_3dn;                  sad16bi = sad16bi_3dn;
# Line 398  Line 403 
403          }          }
404    
405    
406          if ((cpu_flags & XVID_CPU_MMXEXT) > 0) {          if ((cpu_flags & XVID_CPU_MMXEXT)) {
407    
408                  /* Inverse DCT */                  /* Inverse DCT */
409                  idct = idct_xmm;                  idct = idct_xmm;
# Line 436  Line 441 
441                  sad16v   = sad16v_xmm;                  sad16v   = sad16v_xmm;
442          }          }
443    
444          if ((cpu_flags & XVID_CPU_3DNOW) > 0) {          if ((cpu_flags & XVID_CPU_3DNOW)) {
445    
446                  /* Interpolation */                  /* Interpolation */
447                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
# Line 444  Line 449 
449                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
450          }          }
451    
452          if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) {          if ((cpu_flags & XVID_CPU_3DNOWEXT)) {
453    
454                  /* Inverse DCT */                  /* Inverse DCT */
455                  idct =  idct_3dne;                  idct =  idct_3dne;
# Line 453  Line 458 
458                  transfer_8to16copy =  transfer_8to16copy_3dne;                  transfer_8to16copy =  transfer_8to16copy_3dne;
459                  transfer_16to8copy = transfer_16to8copy_3dne;                  transfer_16to8copy = transfer_16to8copy_3dne;
460                  transfer_8to16sub =  transfer_8to16sub_3dne;                  transfer_8to16sub =  transfer_8to16sub_3dne;
461                    transfer_8to16subro =  transfer_8to16subro_3dne;
462                  transfer_8to16sub2 =  transfer_8to16sub2_3dne;                  transfer_8to16sub2 =  transfer_8to16sub2_3dne;
463                  transfer_16to8add = transfer_16to8add_3dne;                  transfer_16to8add = transfer_16to8add_3dne;
464                  transfer8x8_copy = transfer8x8_copy_3dne;                  transfer8x8_copy = transfer8x8_copy_3dne;
# Line 480  Line 486 
486          }          }
487    
488    
489          if ((cpu_flags & XVID_CPU_SSE2) > 0) {          if ((cpu_flags & XVID_CPU_SSE2)) {
 #ifdef EXPERIMENTAL_SSE2_CODE  
490    
491    #if defined(EXPERIMENTAL_SSE2_CODE) /* many people reported crashes with SSE2 */
492                                                                            /* better deactivate it completely and fix everything */
493                                                                            /* in dev-api-4 */
494                  calc_cbp = calc_cbp_sse2;                  calc_cbp = calc_cbp_sse2;
495    
496                  /* Quantization */                  /* Quantization */
# Line 491  Line 499 
499                  quant_inter   = quant_inter_sse2;                  quant_inter   = quant_inter_sse2;
500                  dequant_inter = dequant_inter_sse2;                  dequant_inter = dequant_inter_sse2;
501    
502                  /* ME */                  /* ME; slower than xmm */
503                  sad16    = sad16_sse2;                  sad16    = sad16_sse2;
504                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
   
                 /* Forward and Inverse DCT */  
                 idct  = idct_sse2;  
                 fdct = fdct_sse2;  
505  #endif  #endif
506                    /* Forward and Inverse DCT */
507                    /* idct  = idct_sse2;
508                    /* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */
509          }          }
   
510  #endif  #endif
511    
512  #ifdef ARCH_IA64  #if defined(ARCH_IS_IA64)
513          if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines?          if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */
514            idct_ia64_init();            idct_ia64_init();
515            fdct = fdct_ia64;            fdct = fdct_ia64;
516            idct = idct_ia64;   //not yet working, crashes            idct = idct_ia64;   /*not yet working, crashes */
517            interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;            interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
518            interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;            interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
519            interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;            interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
# Line 515  Line 521 
521            sad16bi = sad16bi_ia64;            sad16bi = sad16bi_ia64;
522            sad8 = sad8_ia64;            sad8 = sad8_ia64;
523            dev16 = dev16_ia64;            dev16 = dev16_ia64;
524  //        Halfpel8_Refine = Halfpel8_Refine_ia64;  /*        Halfpel8_Refine = Halfpel8_Refine_ia64; */
525            quant_intra = quant_intra_ia64;            quant_intra = quant_intra_ia64;
526            dequant_intra = dequant_intra_ia64;            dequant_intra = dequant_intra_ia64;
527            quant_inter = quant_inter_ia64;            quant_inter = quant_inter_ia64;
# Line 526  Line 532 
532            transfer_8to16sub2 = transfer_8to16sub2_ia64;            transfer_8to16sub2 = transfer_8to16sub2_ia64;
533            transfer_16to8add = transfer_16to8add_ia64;            transfer_16to8add = transfer_16to8add_ia64;
534            transfer8x8_copy = transfer8x8_copy_ia64;            transfer8x8_copy = transfer8x8_copy_ia64;
535            DEBUG("Using IA-64 assembler routines.\n");            DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines.");
536          }          }
537  #endif  #endif
538    
539  #ifdef ARCH_PPC  #if defined(ARCH_IS_PPC)
540  #ifdef ARCH_PPC_ALTIVEC          if ((cpu_flags & XVID_CPU_ASM))
541            {
542                    calc_cbp = calc_cbp_ppc;
543            }
544    
545            if ((cpu_flags & XVID_CPU_ALTIVEC))
546            {
547          calc_cbp = calc_cbp_altivec;          calc_cbp = calc_cbp_altivec;
548          fdct = fdct_altivec;          fdct = fdct_altivec;
549          idct = idct_altivec;          idct = idct_altivec;
# Line 539  Line 551 
551          sad16 = sad16_altivec;          sad16 = sad16_altivec;
552          sad8 = sad8_altivec;          sad8 = sad8_altivec;
553          dev16 = dev16_altivec;          dev16 = dev16_altivec;
554  #else          }
         calc_cbp = calc_cbp_ppc;  
 #endif  
555  #endif  #endif
556    
557          return XVID_ERR_OK;          return XVID_ERR_OK;
# Line 552  Line 562 
562  static int  static int
563  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
564  {  {
565          // const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);  /*
566            const int flip1 =
567                    (convert->input.colorspace & XVID_CSP_VFLIP) ^
568                    (convert->output.colorspace & XVID_CSP_VFLIP);
569    */
570          const int width = convert->width;          const int width = convert->width;
571          const int height = convert->height;          const int height = convert->height;
572          const int width2 = convert->width/2;          const int width2 = convert->width/2;
# Line 621  Line 635 
635          return 0;          return 0;
636  }  }
637    
638    int diff16(const int16_t * blockA, const int16_t * blockB, int size)
639    {
640            int i, diff = 0;
641            for (i = 0; i < size; i++)
642                    diff += ABS(blockA[i]-blockB[i]);
643            return diff;
644    }
645    
646    
647    #define XVID_TEST_RANDOM        0x00000001      /* random input data */
648    #define XVID_TEST_VERBOSE       0x00000002      /* verbose error output */
649    
650  int test_h263_intra(quanth263_intraFunc * funcA, quanth263_intraFunc * funcB,  
651                                                  const char * nameA, const char * nameB,  #define TEST_FORWARD    0x00000001      /* intra */
652                                                  int min, int max)  #define TEST_FDCT  (TEST_FORWARD)
653    #define TEST_IDCT  (0)
654    
655    static int test_transform(void * funcA, void * funcB, const char * nameB,
656                                       int test, int flags)
657  {  {
658          int q,i;          int i;
659          int64_t timeSTART;          int64_t timeSTART;
660          int64_t timeA = 0;          int64_t timeA = 0;
661          int64_t timeB = 0;          int64_t timeB = 0;
         DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);  
662          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
663          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
664            int min, max;
665            int count = 0;
666    
667          for (q = 1; q <= 31; q++)       /* quantizer */          int tmp;
668            int min_error = 0x10000*64;
669            int max_error = 0;
670    
671    
672            if ((test & TEST_FORWARD))      /* forward */
673          {          {
674                  for (i = min; i < max; i++)     /* input coeff */                  min = -256;
675                    max = 255;
676            }else{          /* inverse */
677                    min = -2048;
678                    max = 2047;
679            }
680    
681            for (i = 0; i < 64*64; i++)
682                  {                  {
683                          fill16(arrayX, 64, i);                  if ((flags & XVID_TEST_RANDOM))
684                    {
685                            random16(arrayA, 64, min, max);
686                    }else{
687                            fill16(arrayA, 64, i);
688                    }
689                    memcpy(arrayB, arrayA, 64*sizeof(int16_t));
690    
691                    if ((test & TEST_FORWARD))
692                    {
693                          timeSTART = read_counter();                          timeSTART = read_counter();
694                          funcA(arrayA, arrayX, q, q);                          ((fdctFunc*)funcA)(arrayA);
695                          timeA += read_counter() - timeSTART;                          timeA += read_counter() - timeSTART;
696    
697                          timeSTART = read_counter();                          timeSTART = read_counter();
698                          funcB(arrayB, arrayX, q, q);                          ((fdctFunc*)funcB)(arrayB);
699                          timeB += read_counter() - timeSTART;                          timeB += read_counter() - timeSTART;
   
                         if (compare16(arrayA, arrayB, 64))  
                         {  
                                 printf("%s/%s error: q=%i, i=%i\n", nameA?nameA:"?", nameB?nameB:"?", q, i);  
                                 return 0;  
700                          }                          }
701                    else
702                    {
703                            timeSTART = read_counter();
704                            ((idctFunc*)funcA)(arrayA);
705                            timeA += read_counter() - timeSTART;
706    
707                            timeSTART = read_counter();
708                            ((idctFunc*)funcB)(arrayB);
709                            timeB += read_counter() - timeSTART;
710                  }                  }
711    
712                    tmp = diff16(arrayA, arrayB, 64) / 64;
713                    if (tmp > max_error)
714                            max_error = tmp;
715                    if (tmp < min_error)
716                            min_error = tmp;
717    
718                    count++;
719          }          }
720    
721          if (nameA) printf("%s:\t%I64i\n", nameA, timeA);          /* print the "average difference" of best/worst transforms */
722          if (nameB) printf("%s:\t%I64i\n", nameB, timeB);          printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error);
723    
724          return 0;          return 0;
725  }  }
726    
727  int test_h263_inter(quanth263_interFunc * funcA, quanth263_interFunc * funcB,  
728                                                  const char * nameA, const char * nameB,  #define TEST_QUANT      0x00000001      /* forward quantization */
729                                                  int min, int max)  #define TEST_INTRA      0x00000002      /* intra */
730    #define TEST_QUANT_INTRA        (TEST_QUANT|TEST_INTRA)
731    #define TEST_QUANT_INTER        (TEST_QUANT)
732    #define TEST_DEQUANT_INTRA      (TEST_INTRA)
733    #define TEST_DEQUANT_INTER      (0)
734    
735    static int test_quant(void * funcA, void * funcB, const char * nameB,
736                               int test, int flags)
737  {  {
738          int q,i;          int q,i;
739          int64_t timeSTART;          int64_t timeSTART;
740          int64_t timeA = 0;          int64_t timeA = 0;
741          int64_t timeB = 0;          int64_t timeB = 0;
742            int retA = 0, retB = 0;
743          DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);
744          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
745          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
746            int min, max;
747            int count = 0;
748            int errors = 0;
749    
750            if ((test & TEST_QUANT))        /* quant */
751            {
752                    min = -2048;
753                    max = 2047;
754            }else{          /* dequant */
755                    min = -256;
756                    max = 255;
757            }
758    
759          for (q = 1; q <= 31; q++)       /* quantizer */          for (q = 1; q <= 31; q++)       /* quantizer */
760          {          {
761                  for (i = min; i < max; i++)     /* input coeff */                  for (i = min; i < max; i++)     /* input coeff */
762                  {                  {
763                            if ((flags & XVID_TEST_RANDOM))
764                            {
765                                    random16(arrayX, 64, min, max);
766                            }else{
767                          fill16(arrayX, 64, i);                          fill16(arrayX, 64, i);
768                            }
769    
770                            if ((test & TEST_INTRA))        /* intra */
771                            {
772                          timeSTART = read_counter();                          timeSTART = read_counter();
773                          funcA(arrayA, arrayX, q);                                  ((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q);
774                          timeA += read_counter() - timeSTART;                          timeA += read_counter() - timeSTART;
775    
776                          timeSTART = read_counter();                          timeSTART = read_counter();
777                          funcB(arrayB, arrayX, q);                                  ((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q);
778                          timeB += read_counter() - timeSTART;                          timeB += read_counter() - timeSTART;
779                            }
780                            else    /* inter */
781                            {
782                                    timeSTART = read_counter();
783                                    retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q);
784                                    timeA += read_counter() - timeSTART;
785    
786                                    timeSTART = read_counter();
787                                    retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q);
788                                    timeB += read_counter() - timeSTART;
789                            }
790    
791                          if (compare16(arrayA, arrayB, 64))                          /* compare return value from quant_inter, and compare (de)quantiz'd arrays */
792                            if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) ||
793                                    compare16(arrayA, arrayB, 64))
794                          {                          {
795                                  printf("%s/%s error: q=%i, i=%i\n", nameA?nameA:"?", nameB?nameB:"?", q, i);                                  errors++;
796                                  return 0;                                  if ((flags & XVID_TEST_VERBOSE))
797                                            printf("%s error: q=%i, i=%i\n", nameB, q, i);
798                          }                          }
799    
800                            count++;
801                  }                  }
802          }          }
803    
804          if (nameA) printf("%s:\t%I64i\n", nameA, timeA);          printf("%s:\t%i", nameB, (int)(timeB / count));
805          if (nameB) printf("%s:\t%I64i\n", nameB, timeB);          if (errors>0)
806                    printf("\t(%i errors out of %i)", errors, count);
807            printf("\n");
808    
809          return 0;          return 0;
810  }  }
811    
812    
813    
814  int xvid_init_test()  int xvid_init_test(int flags)
815  {  {
816    #if defined(ARCH_IS_IA32)
817          int cpu_flags;          int cpu_flags;
818    #endif
819    
820          printf("xvid_init_test\n");          printf("XviD tests\n\n");
821    
822  #if defined(ARCH_X86)  #if defined(ARCH_IS_IA32)
823          cpu_flags = check_cpu_features();          cpu_flags = detect_cpu_flags();
824    #endif
825    
826          emms_mmx();          idct_int32_init();
827            emms();
828    
829            srand(time(0));
830    
831            /* fDCT test */
832            printf("--- fdct ---\n");
833                    test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
834    
835    #if defined(ARCH_IS_IA32)
836            if (cpu_flags & XVID_CPU_MMX)
837                    test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
838            if (cpu_flags & XVID_CPU_SSE2)
839                    test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
840    #endif
841    
842          printf("--- quant intra ---\n");          /* iDCT test */
843            printf("\n--- idct ---\n");
844                    test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
845    
846    #if defined(ARCH_IS_IA32)
847          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
848                  test_h263_intra(quant_intra_c, quant_intra_mmx, "c", "mmx", -2048, 2047);                  test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
849            if (cpu_flags & XVID_CPU_MMXEXT)
850                    test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags);
851          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
852                  test_h263_intra(quant_intra_c, quant_intra_3dne, NULL, "3dne", -2048, 2047);                  test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
853          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
854                  test_h263_intra(quant_intra_c, quant_intra_sse2, NULL, "sse2", -2048, 2047);                  test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
855    #endif
856    
857            /* Intra quantization test */
858            printf("\n--- quant intra ---\n");
859                    test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
860    
861    #if defined(ARCH_IS_IA32)
862            if (cpu_flags & XVID_CPU_MMX)
863                    test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
864            if (cpu_flags & XVID_CPU_3DNOWEXT)
865                    test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);
866            if (cpu_flags & XVID_CPU_SSE2)
867                    test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);
868    #endif
869    
870            /* Inter quantization test */
871          printf("\n--- quant inter ---\n");          printf("\n--- quant inter ---\n");
872                    test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
873    
874    #if defined(ARCH_IS_IA32)
875          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
876                  test_h263_inter(quant_inter_c, quant_inter_mmx, "c", "mmx", -2048, 2047);                  test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
877          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
878                  test_h263_inter(quant_inter_c, quant_inter_3dne, NULL, "3dne", -2048, 2047);                  test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags);
879          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
880                  test_h263_inter(quant_inter_c, quant_inter_sse2, NULL, "sse2", -2048, 2047);                  test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags);
881    #endif
882    
883          printf("\n--- dequan intra ---\n");          /* Intra dequantization test */
884            printf("\n--- dequant intra ---\n");
885                    test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
886    
887    #if defined(ARCH_IS_IA32)
888          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
889                  test_h263_intra(dequant_intra_c, dequant_intra_mmx, "c", "mmx", -256, 255);                  test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
890          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
891                  test_h263_intra(dequant_intra_c, dequant_intra_xmm, NULL, "xmm", -256, 255);                  test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags);
892          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
893                  test_h263_intra(dequant_intra_c, dequant_intra_3dne, NULL, "3dne", -256, 255);                  test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
894          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
895                  test_h263_intra(dequant_intra_c, dequant_intra_sse2, NULL, "sse2", -256, 255);                  test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags);
896    #endif
897    
898            /* Inter dequantization test */
899          printf("\n--- dequant inter ---\n");          printf("\n--- dequant inter ---\n");
900          if (cpu_flags & XVID_CPU_MMX)                  test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);
                 test_h263_inter((quanth263_interFunc*)dequant_inter_c,  
                                                 (quanth263_interFunc*)dequant_inter_mmx, "c", "mmx", -256, 255);  
901    
902    #if defined(ARCH_IS_IA32)
903            if (cpu_flags & XVID_CPU_MMX)
904                    test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
905          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
906                  test_h263_inter((quanth263_interFunc*)dequant_inter_c,                  test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags);
                                                 (quanth263_interFunc*)dequant_inter_xmm, NULL, "xmm", -256, 255);  
907          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
908                  test_h263_inter((quanth263_interFunc*)dequant_inter_c,                  test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
                                                 (quanth263_interFunc*)dequant_inter_3dne, NULL, "3dne", -256, 255);  
909          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
910                  test_h263_inter((quanth263_interFunc*)dequant_inter_c,                  test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);
911                                                  (quanth263_interFunc*)dequant_inter_sse2, NULL, "sse2", -256, 255);  #endif
912    
913          printf("\n--- quant4_intra ---\n");          /* Intra quantization test */
914            printf("\n--- quant4 intra ---\n");
915                    test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
916    
917    #if defined(ARCH_IS_IA32)
918          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
919                  test_h263_intra((quanth263_intraFunc*)quant4_intra_c,                  test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
                                                 (quanth263_intraFunc*)quant4_intra_mmx, "c", "mmx", -2048, 2047);  
920          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
921                  test_h263_intra((quanth263_intraFunc*)quant4_intra_c,                  test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);
922                                                  (quanth263_intraFunc*)quant4_intra_xmm, NULL, "xmm", -2048, 2047);  #endif
923    
924          printf("\n--- quant4_inter ---\n");          /* Inter quantization test */
925            printf("\n--- quant4 inter ---\n");
926                    test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
927    
928    #if defined(ARCH_IS_IA32)
929          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
930                  test_h263_inter((quanth263_interFunc*)quant4_inter_c,                  test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
                                                 (quanth263_interFunc*)quant4_inter_mmx, "c", "mmx", -2048, 2047);  
931          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
932                  test_h263_inter((quanth263_interFunc*)quant4_inter_c,                  test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);
933                                                  (quanth263_interFunc*)quant4_inter_xmm, NULL, "xmm", -2048, 2047);  #endif
934    
935            /* Intra dequantization test */
936            printf("\n--- dequant4 intra ---\n");
937                    test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
938    
939          printf("\n--- dequant4_intra ---\n");  #if defined(ARCH_IS_IA32)
940          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
941                  test_h263_intra((quanth263_intraFunc*)dequant4_intra_c,                  test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
                                                 (quanth263_intraFunc*)dequant4_intra_mmx, "c", "mmx", -256, 255);  
942          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
943                  test_h263_intra((quanth263_intraFunc*)dequant4_intra_c,                  test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
944                                                  (quanth263_intraFunc*)dequant4_intra_3dne, NULL, "sse2", -256, 255);  #endif
945    
946            /* Inter dequantization test */
947            printf("\n--- dequant4 inter ---\n");
948                    test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
949    
950          printf("\n--- dequant4_inter ---\n");  #if defined(ARCH_IS_IA32)
951          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
952                  test_h263_inter((quanth263_interFunc*)dequant4_inter_c,                  test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
                                                 (quanth263_interFunc*)dequant4_inter_mmx, "c", "mmx", -256, 255);  
953          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
954                  test_h263_inter((quanth263_interFunc*)dequant4_inter_c,                  test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
                                                 (quanth263_interFunc*)dequant4_inter_3dne, NULL, "sse2", -256, 255);  
   
         emms_mmx();  
   
955  #endif  #endif
956    
957            emms();
958    
959          return XVID_ERR_OK;          return XVID_ERR_OK;
960  }  }
961    
# Line 813  Line 975 
975                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
976    
977                  case XVID_INIT_TEST :                  case XVID_INIT_TEST :
978                          return xvid_init_test();                  {
979                            ptr_t flags = (ptr_t)param1;
980                            return xvid_init_test((int)flags);
981                    }
982                  default :                  default :
983                          return XVID_ERR_FAIL;                          return XVID_ERR_FAIL;
984          }          }
# Line 872  Line 1036 
1036          case XVID_ENC_ENCODE:          case XVID_ENC_ENCODE:
1037    
1038                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)
1039                  return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1,                          return encoder_encode_bframes((Encoder *) handle,
1040                                                                                      (XVID_ENC_FRAME *) param1,
1041                                                            (XVID_ENC_STATS *) param2);                                                            (XVID_ENC_STATS *) param2);
1042                  else                  else
1043                  return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1,                          return encoder_encode((Encoder *) handle,
1044                                                                      (XVID_ENC_FRAME *) param1,
1045                                                            (XVID_ENC_STATS *) param2);                                                            (XVID_ENC_STATS *) param2);
1046    
1047          case XVID_ENC_CREATE:          case XVID_ENC_CREATE:

Legend:
Removed from v.1.33.2.19  
changed lines
  Added in v.1.47

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