[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.45.4.1, Sat May 3 23:23: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 59  Line 44 
44  #include "utils/emms.h"  #include "utils/emms.h"
45  #include "utils/timer.h"  #include "utils/timer.h"
46  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
47    #include "image/qpel.h"
48    
49  #if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE)  #if defined(ARCH_IS_IA32)
50    
51  #ifdef WIN32  #if defined(_MSC_VER)
52  #include <windows.h>  #include <windows.h>
53  #else  #else
54  #include <signal.h>  #include <signal.h>
55  #include <setjmp.h>  #include <setjmp.h>
 #endif  
   
   
 #ifndef WIN32  
56    
57  static jmp_buf mark;  static jmp_buf mark;
58    
# Line 83  Line 65 
65    
66    
67  /*  /*
68  calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled   * Calls the funcptr, and returns whether SIGILL (illegal instruction) was
69  return values:   * signalled
70  -1 : could not determine   *
71  0  : SIGILL was *not* signalled   * Return values:
72  1  : SIGILL was signalled   *  -1 : could not determine
73     *   0 : SIGILL was *not* signalled
74     *   1 : SIGILL was signalled
75  */  */
76    
77  int  int
78  sigill_check(void (*func)())  sigill_check(void (*func)())
79  {  {
80  #ifdef WIN32  #if defined(_MSC_VER)
81          _try {          _try {
82                  func();                  func();
83          }          }
# Line 127  Line 111 
111  }  }
112  #endif  #endif
113    
114    
115    /* detect cpu flags  */
116    static unsigned int
117    detect_cpu_flags()
118    {
119            /* enable native assembly optimizations by default */
120            unsigned int cpu_flags = XVID_CPU_ASM;
121    
122    #if defined(ARCH_IS_IA32)
123            cpu_flags |= check_cpu_features();
124            if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger))
125                    cpu_flags &= ~XVID_CPU_SSE;
126    
127            if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger))
128                    cpu_flags &= ~XVID_CPU_SSE2;
129    #endif
130    
131    #if defined(ARCH_IS_PPC)
132    #if defined(ARCH_IS_PPC_ALTIVEC)
133            cpu_flags |= XVID_CPU_ALTIVEC;
134    #endif
135    #endif
136    
137            return cpu_flags;
138    }
139    
140    
141  /*****************************************************************************  /*****************************************************************************
142   * XviD Init Entry point   * XviD Init Entry point
143   *   *
# Line 160  Line 171 
171    
172          } else {          } else {
173    
174                  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  
175          }          }
176    
177          if ((init_param->cpu_flags & XVID_CPU_CHKONLY))          if ((init_param->cpu_flags & XVID_CPU_CHKONLY))
# Line 179  Line 182 
182    
183          init_param->cpu_flags = cpu_flags;          init_param->cpu_flags = cpu_flags;
184    
185            /* Qpel stuff */
186            xvid_QP_Funcs = &xvid_QP_Funcs_C;
187            xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C;
188            xvid_Init_QP_mmx();
189    
190          /* Initialize the function pointers */          /* Initialize the function pointers */
191          idct_int32_init();          idct_int32_init();
# Line 209  Line 216 
216          transfer_8to16copy = transfer_8to16copy_c;          transfer_8to16copy = transfer_8to16copy_c;
217          transfer_16to8copy = transfer_16to8copy_c;          transfer_16to8copy = transfer_16to8copy_c;
218          transfer_8to16sub  = transfer_8to16sub_c;          transfer_8to16sub  = transfer_8to16sub_c;
219            transfer_8to16subro  = transfer_8to16subro_c;
220          transfer_8to16sub2 = transfer_8to16sub2_c;          transfer_8to16sub2 = transfer_8to16sub2_c;
221          transfer_16to8add  = transfer_16to8add_c;          transfer_16to8add  = transfer_16to8add_c;
222          transfer8x8_copy   = transfer8x8_copy_c;          transfer8x8_copy   = transfer8x8_copy_c;
# Line 236  Line 244 
244          interpolate8x8_avg4 = interpolate8x8_avg4_c;          interpolate8x8_avg4 = interpolate8x8_avg4_c;
245    
246          /* reduced resoltuion */          /* reduced resoltuion */
   
247          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;
248          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  
249          vfilter_31 = xvid_VFilter_31_C;          vfilter_31 = xvid_VFilter_31_C;
250          hfilter_31 = xvid_HFilter_31_C;          hfilter_31 = xvid_HFilter_31_C;
 #endif  
251          filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C;          filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C;
252          filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C;          filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C;
253    
# Line 301  Line 303 
303          dev16    = dev16_c;          dev16    = dev16_c;
304          sad16v   = sad16v_c;          sad16v   = sad16v_c;
305    
306  //      Halfpel8_Refine = Halfpel8_Refine_c;  /*      Halfpel8_Refine = Halfpel8_Refine_c; */
307    
308    #if defined(ARCH_IS_IA32)
309    
310  #ifdef ARCH_X86          if ((cpu_flags & XVID_CPU_ASM))
311            {
312                    vfilter_31 = xvid_VFilter_31_x86;
313                    hfilter_31 = xvid_HFilter_31_x86;
314            }
315    
316          if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) ||          if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) ||
317                  (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) ||                  (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) ||
# Line 313  Line 321 
321                  emms = emms_mmx;                  emms = emms_mmx;
322          }          }
323    
324          if ((cpu_flags & XVID_CPU_MMX) > 0) {          if ((cpu_flags & XVID_CPU_MMX)) {
325    
326                    /* Qpel stuff */
327                    xvid_QP_Funcs = &xvid_QP_Funcs_mmx;
328                    xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx;
329                    xvid_Init_QP_mmx();
330    
331                  /* Forward and Inverse Discrete Cosine Transformation functions */                  /* Forward and Inverse Discrete Cosine Transformation functions */
332                  fdct = fdct_mmx;                  fdct = fdct_mmx;
# Line 334  Line 347 
347                  transfer_8to16copy = transfer_8to16copy_mmx;                  transfer_8to16copy = transfer_8to16copy_mmx;
348                  transfer_16to8copy = transfer_16to8copy_mmx;                  transfer_16to8copy = transfer_16to8copy_mmx;
349                  transfer_8to16sub  = transfer_8to16sub_mmx;                  transfer_8to16sub  = transfer_8to16sub_mmx;
350                    transfer_8to16subro  = transfer_8to16subro_mmx;
351                  transfer_8to16sub2 = transfer_8to16sub2_mmx;                  transfer_8to16sub2 = transfer_8to16sub2_mmx;
352                  transfer_16to8add  = transfer_16to8add_mmx;                  transfer_16to8add  = transfer_16to8add_mmx;
353                  transfer8x8_copy   = transfer8x8_copy_mmx;                  transfer8x8_copy   = transfer8x8_copy_mmx;
# Line 383  Line 397 
397                  sad8bi  = sad8bi_mmx;                  sad8bi  = sad8bi_mmx;
398                  dev16    = dev16_mmx;                  dev16    = dev16_mmx;
399                  sad16v   = sad16v_mmx;                  sad16v   = sad16v_mmx;
   
400          }          }
401    
402          /* these 3dnow functions are faster than mmx, but slower than xmm. */          /* these 3dnow functions are faster than mmx, but slower than xmm. */
403          if ((cpu_flags & XVID_CPU_3DNOW) > 0) {          if ((cpu_flags & XVID_CPU_3DNOW)) {
404    
405                    emms = emms_3dn;
406    
407                  /* ME functions */                  /* ME functions */
408                  sad16bi = sad16bi_3dn;                  sad16bi = sad16bi_3dn;
# Line 398  Line 413 
413          }          }
414    
415    
416          if ((cpu_flags & XVID_CPU_MMXEXT) > 0) {          if ((cpu_flags & XVID_CPU_MMXEXT)) {
417    
418                  /* Inverse DCT */                  /* Inverse DCT */
419                  idct = idct_xmm;                  idct = idct_xmm;
# Line 436  Line 451 
451                  sad16v   = sad16v_xmm;                  sad16v   = sad16v_xmm;
452          }          }
453    
454          if ((cpu_flags & XVID_CPU_3DNOW) > 0) {          if ((cpu_flags & XVID_CPU_3DNOW)) {
455    
456                  /* Interpolation */                  /* Interpolation */
457                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
# Line 444  Line 459 
459                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
460          }          }
461    
462          if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) {          if ((cpu_flags & XVID_CPU_3DNOWEXT)) {
463    
464                  /* Inverse DCT */                  /* Inverse DCT */
465                  idct =  idct_3dne;                  idct =  idct_3dne;
# Line 453  Line 468 
468                  transfer_8to16copy =  transfer_8to16copy_3dne;                  transfer_8to16copy =  transfer_8to16copy_3dne;
469                  transfer_16to8copy = transfer_16to8copy_3dne;                  transfer_16to8copy = transfer_16to8copy_3dne;
470                  transfer_8to16sub =  transfer_8to16sub_3dne;                  transfer_8to16sub =  transfer_8to16sub_3dne;
471                    transfer_8to16subro =  transfer_8to16subro_3dne;
472                  transfer_8to16sub2 =  transfer_8to16sub2_3dne;                  transfer_8to16sub2 =  transfer_8to16sub2_3dne;
473                  transfer_16to8add = transfer_16to8add_3dne;                  transfer_16to8add = transfer_16to8add_3dne;
474                  transfer8x8_copy = transfer8x8_copy_3dne;                  transfer8x8_copy = transfer8x8_copy_3dne;
# Line 480  Line 496 
496          }          }
497    
498    
499          if ((cpu_flags & XVID_CPU_SSE2) > 0) {          if ((cpu_flags & XVID_CPU_SSE2)) {
 #ifdef EXPERIMENTAL_SSE2_CODE  
500    
501                  calc_cbp = calc_cbp_sse2;                  calc_cbp = calc_cbp_sse2;
502    
# Line 491  Line 506 
506                  quant_inter   = quant_inter_sse2;                  quant_inter   = quant_inter_sse2;
507                  dequant_inter = dequant_inter_sse2;                  dequant_inter = dequant_inter_sse2;
508    
509                  /* ME */  #if defined(EXPERIMENTAL_SSE2_CODE)
510                    /* ME; slower than xmm */
511                  sad16    = sad16_sse2;                  sad16    = sad16_sse2;
512                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
513    #endif
514                  /* Forward and Inverse DCT */                  /* Forward and Inverse DCT */
515                  idct  = idct_sse2;                  idct  = idct_sse2;
516                  fdct = fdct_sse2;                  fdct = fdct_sse2;
 #endif  
517          }          }
   
518  #endif  #endif
519    
520  #ifdef ARCH_IA64  #if defined(ARCH_IS_IA64)
521          if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines?          if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */
522            idct_ia64_init();            idct_ia64_init();
523            fdct = fdct_ia64;            fdct = fdct_ia64;
524            idct = idct_ia64;   //not yet working, crashes            idct = idct_ia64;   /*not yet working, crashes */
525            interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;            interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
526            interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;            interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
527            interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;            interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
# Line 515  Line 529 
529            sad16bi = sad16bi_ia64;            sad16bi = sad16bi_ia64;
530            sad8 = sad8_ia64;            sad8 = sad8_ia64;
531            dev16 = dev16_ia64;            dev16 = dev16_ia64;
532  //        Halfpel8_Refine = Halfpel8_Refine_ia64;  /*        Halfpel8_Refine = Halfpel8_Refine_ia64; */
533            quant_intra = quant_intra_ia64;            quant_intra = quant_intra_ia64;
534            dequant_intra = dequant_intra_ia64;            dequant_intra = dequant_intra_ia64;
535            quant_inter = quant_inter_ia64;            quant_inter = quant_inter_ia64;
# Line 526  Line 540 
540            transfer_8to16sub2 = transfer_8to16sub2_ia64;            transfer_8to16sub2 = transfer_8to16sub2_ia64;
541            transfer_16to8add = transfer_16to8add_ia64;            transfer_16to8add = transfer_16to8add_ia64;
542            transfer8x8_copy = transfer8x8_copy_ia64;            transfer8x8_copy = transfer8x8_copy_ia64;
543            DEBUG("Using IA-64 assembler routines.\n");            DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines.");
544          }          }
545  #endif  #endif
546    
547  #ifdef ARCH_PPC  #if defined(ARCH_IS_PPC)
548  #ifdef ARCH_PPC_ALTIVEC          if ((cpu_flags & XVID_CPU_ASM))
549            {
550                    calc_cbp = calc_cbp_ppc;
551            }
552    
553            if ((cpu_flags & XVID_CPU_ALTIVEC))
554            {
555          calc_cbp = calc_cbp_altivec;          calc_cbp = calc_cbp_altivec;
556          fdct = fdct_altivec;          fdct = fdct_altivec;
557          idct = idct_altivec;          idct = idct_altivec;
# Line 539  Line 559 
559          sad16 = sad16_altivec;          sad16 = sad16_altivec;
560          sad8 = sad8_altivec;          sad8 = sad8_altivec;
561          dev16 = dev16_altivec;          dev16 = dev16_altivec;
562  #else          }
         calc_cbp = calc_cbp_ppc;  
 #endif  
563  #endif  #endif
564    
565          return XVID_ERR_OK;          return XVID_ERR_OK;
# Line 552  Line 570 
570  static int  static int
571  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
572  {  {
573          // const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);  /*
574            const int flip1 =
575                    (convert->input.colorspace & XVID_CSP_VFLIP) ^
576                    (convert->output.colorspace & XVID_CSP_VFLIP);
577    */
578          const int width = convert->width;          const int width = convert->width;
579          const int height = convert->height;          const int height = convert->height;
580          const int width2 = convert->width/2;          const int width2 = convert->width/2;
# Line 621  Line 643 
643          return 0;          return 0;
644  }  }
645    
646    int diff16(const int16_t * blockA, const int16_t * blockB, int size)
647    {
648            int i, diff = 0;
649            for (i = 0; i < size; i++)
650                    diff += ABS(blockA[i]-blockB[i]);
651            return diff;
652    }
653    
654    
655    #define XVID_TEST_RANDOM        0x00000001      /* random input data */
656    #define XVID_TEST_VERBOSE       0x00000002      /* verbose error output */
657    
658  int test_h263_intra(quanth263_intraFunc * funcA, quanth263_intraFunc * funcB,  
659                                                  const char * nameA, const char * nameB,  #define TEST_FORWARD    0x00000001      /* intra */
660                                                  int min, int max)  #define TEST_FDCT  (TEST_FORWARD)
661    #define TEST_IDCT  (0)
662    
663    static int test_transform(void * funcA, void * funcB, const char * nameB,
664                                       int test, int flags)
665  {  {
666          int q,i;          int i;
667          int64_t timeSTART;          int64_t timeSTART;
668          int64_t timeA = 0;          int64_t timeA = 0;
669          int64_t timeB = 0;          int64_t timeB = 0;
         DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);  
670          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
671          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
672            int min, max;
673            int count = 0;
674    
675          for (q = 1; q <= 31; q++)       /* quantizer */          int tmp;
676            int min_error = 0x10000*64;
677            int max_error = 0;
678    
679    
680            if ((test & TEST_FORWARD))      /* forward */
681          {          {
682                  for (i = min; i < max; i++)     /* input coeff */                  min = -256;
683                    max = 255;
684            }else{          /* inverse */
685                    min = -2048;
686                    max = 2047;
687            }
688    
689            for (i = 0; i < 64*64; i++)
690                  {                  {
691                          fill16(arrayX, 64, i);                  if ((flags & XVID_TEST_RANDOM))
692                    {
693                            random16(arrayA, 64, min, max);
694                    }else{
695                            fill16(arrayA, 64, i);
696                    }
697                    memcpy(arrayB, arrayA, 64*sizeof(int16_t));
698    
699                    if ((test & TEST_FORWARD))
700                    {
701                          timeSTART = read_counter();                          timeSTART = read_counter();
702                          funcA(arrayA, arrayX, q, q);                          ((fdctFunc*)funcA)(arrayA);
703                          timeA += read_counter() - timeSTART;                          timeA += read_counter() - timeSTART;
704    
705                          timeSTART = read_counter();                          timeSTART = read_counter();
706                          funcB(arrayB, arrayX, q, q);                          ((fdctFunc*)funcB)(arrayB);
707                          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;  
708                          }                          }
709                    else
710                    {
711                            timeSTART = read_counter();
712                            ((idctFunc*)funcA)(arrayA);
713                            timeA += read_counter() - timeSTART;
714    
715                            timeSTART = read_counter();
716                            ((idctFunc*)funcB)(arrayB);
717                            timeB += read_counter() - timeSTART;
718                  }                  }
719    
720                    tmp = diff16(arrayA, arrayB, 64) / 64;
721                    if (tmp > max_error)
722                            max_error = tmp;
723                    if (tmp < min_error)
724                            min_error = tmp;
725    
726                    count++;
727          }          }
728    
729          if (nameA) printf("%s:\t%I64i\n", nameA, timeA);          /* print the "average difference" of best/worst transforms */
730          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);
731    
732          return 0;          return 0;
733  }  }
734    
735  int test_h263_inter(quanth263_interFunc * funcA, quanth263_interFunc * funcB,  
736                                                  const char * nameA, const char * nameB,  #define TEST_QUANT      0x00000001      /* forward quantization */
737                                                  int min, int max)  #define TEST_INTRA      0x00000002      /* intra */
738    #define TEST_QUANT_INTRA        (TEST_QUANT|TEST_INTRA)
739    #define TEST_QUANT_INTER        (TEST_QUANT)
740    #define TEST_DEQUANT_INTRA      (TEST_INTRA)
741    #define TEST_DEQUANT_INTER      (0)
742    
743    static int test_quant(void * funcA, void * funcB, const char * nameB,
744                               int test, int flags)
745  {  {
746          int q,i;          int q,i;
747          int64_t timeSTART;          int64_t timeSTART;
748          int64_t timeA = 0;          int64_t timeA = 0;
749          int64_t timeB = 0;          int64_t timeB = 0;
750            int retA = 0, retB = 0;
751          DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);
752          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
753          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
754            int min, max;
755            int count = 0;
756            int errors = 0;
757    
758            if ((test & TEST_QUANT))        /* quant */
759            {
760                    min = -2048;
761                    max = 2047;
762            }else{          /* dequant */
763                    min = -256;
764                    max = 255;
765            }
766    
767          for (q = 1; q <= 31; q++)       /* quantizer */          for (q = 1; q <= 31; q++)       /* quantizer */
768          {          {
769                  for (i = min; i < max; i++)     /* input coeff */                  for (i = min; i < max; i++)     /* input coeff */
770                  {                  {
771                            if ((flags & XVID_TEST_RANDOM))
772                            {
773                                    random16(arrayX, 64, min, max);
774                            }else{
775                          fill16(arrayX, 64, i);                          fill16(arrayX, 64, i);
776                            }
777    
778                            if ((test & TEST_INTRA))        /* intra */
779                            {
780                          timeSTART = read_counter();                          timeSTART = read_counter();
781                          funcA(arrayA, arrayX, q);                                  ((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q);
782                          timeA += read_counter() - timeSTART;                          timeA += read_counter() - timeSTART;
783    
784                          timeSTART = read_counter();                          timeSTART = read_counter();
785                          funcB(arrayB, arrayX, q);                                  ((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q);
786                          timeB += read_counter() - timeSTART;                          timeB += read_counter() - timeSTART;
787                            }
788                            else    /* inter */
789                            {
790                                    timeSTART = read_counter();
791                                    retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q);
792                                    timeA += read_counter() - timeSTART;
793    
794                                    timeSTART = read_counter();
795                                    retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q);
796                                    timeB += read_counter() - timeSTART;
797                            }
798    
799                          if (compare16(arrayA, arrayB, 64))                          /* compare return value from quant_inter, and compare (de)quantiz'd arrays */
800                            if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) ||
801                                    compare16(arrayA, arrayB, 64))
802                          {                          {
803                                  printf("%s/%s error: q=%i, i=%i\n", nameA?nameA:"?", nameB?nameB:"?", q, i);                                  errors++;
804                                  return 0;                                  if ((flags & XVID_TEST_VERBOSE))
805                                            printf("%s error: q=%i, i=%i\n", nameB, q, i);
806                          }                          }
807    
808                            count++;
809                  }                  }
810          }          }
811    
812          if (nameA) printf("%s:\t%I64i\n", nameA, timeA);          printf("%s:\t%i", nameB, (int)(timeB / count));
813          if (nameB) printf("%s:\t%I64i\n", nameB, timeB);          if (errors>0)
814                    printf("\t(%i errors out of %i)", errors, count);
815            printf("\n");
816    
817          return 0;          return 0;
818  }  }
819    
820    
821    
822  int xvid_init_test()  int xvid_init_test(int flags)
823  {  {
824    #if defined(ARCH_IS_IA32)
825          int cpu_flags;          int cpu_flags;
826    #endif
827    
828          printf("xvid_init_test\n");          printf("XviD tests\n\n");
829    
830  #if defined(ARCH_X86)  #if defined(ARCH_IS_IA32)
831          cpu_flags = check_cpu_features();          cpu_flags = detect_cpu_flags();
832    #endif
833    
834          emms_mmx();          idct_int32_init();
835            emms();
836    
837            srand(time(0));
838    
839            /* fDCT test */
840            printf("--- fdct ---\n");
841                    test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
842    
843    #if defined(ARCH_IS_IA32)
844            if (cpu_flags & XVID_CPU_MMX)
845                    test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
846            if (cpu_flags & XVID_CPU_SSE2)
847                    test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
848    #endif
849    
850          printf("--- quant intra ---\n");          /* iDCT test */
851            printf("\n--- idct ---\n");
852                    test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
853    
854    #if defined(ARCH_IS_IA32)
855          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
856                  test_h263_intra(quant_intra_c, quant_intra_mmx, "c", "mmx", -2048, 2047);                  test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
857            if (cpu_flags & XVID_CPU_MMXEXT)
858                    test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags);
859          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
860                  test_h263_intra(quant_intra_c, quant_intra_3dne, NULL, "3dne", -2048, 2047);                  test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
861          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
862                  test_h263_intra(quant_intra_c, quant_intra_sse2, NULL, "sse2", -2048, 2047);                  test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
863    #endif
864    
865            /* Intra quantization test */
866            printf("\n--- quant intra ---\n");
867                    test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
868    
869    #if defined(ARCH_IS_IA32)
870            if (cpu_flags & XVID_CPU_MMX)
871                    test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
872            if (cpu_flags & XVID_CPU_3DNOWEXT)
873                    test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);
874            if (cpu_flags & XVID_CPU_SSE2)
875                    test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);
876    #endif
877    
878            /* Inter quantization test */
879          printf("\n--- quant inter ---\n");          printf("\n--- quant inter ---\n");
880                    test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
881    
882    #if defined(ARCH_IS_IA32)
883          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
884                  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);
885          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
886                  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);
887          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
888                  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);
889    #endif
890    
891          printf("\n--- dequan intra ---\n");          /* Intra dequantization test */
892            printf("\n--- dequant intra ---\n");
893                    test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
894    
895    #if defined(ARCH_IS_IA32)
896          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
897                  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);
898          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
899                  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);
900          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
901                  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);
902          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
903                  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);
904    #endif
905    
906            /* Inter dequantization test */
907          printf("\n--- dequant inter ---\n");          printf("\n--- dequant inter ---\n");
908          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);  
909    
910    #if defined(ARCH_IS_IA32)
911            if (cpu_flags & XVID_CPU_MMX)
912                    test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
913          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
914                  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);  
915          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
916                  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);  
917          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
918                  test_h263_inter((quanth263_interFunc*)dequant_inter_c,                  test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);
919                                                  (quanth263_interFunc*)dequant_inter_sse2, NULL, "sse2", -256, 255);  #endif
920    
921          printf("\n--- quant4_intra ---\n");          /* Intra quantization test */
922            printf("\n--- quant4 intra ---\n");
923                    test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
924    
925    #if defined(ARCH_IS_IA32)
926          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
927                  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);  
928          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
929                  test_h263_intra((quanth263_intraFunc*)quant4_intra_c,                  test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);
930                                                  (quanth263_intraFunc*)quant4_intra_xmm, NULL, "xmm", -2048, 2047);  #endif
931    
932          printf("\n--- quant4_inter ---\n");          /* Inter quantization test */
933            printf("\n--- quant4 inter ---\n");
934                    test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
935    
936    #if defined(ARCH_IS_IA32)
937          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
938                  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);  
939          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
940                  test_h263_inter((quanth263_interFunc*)quant4_inter_c,                  test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);
941                                                  (quanth263_interFunc*)quant4_inter_xmm, NULL, "xmm", -2048, 2047);  #endif
942    
943            /* Intra dequantization test */
944            printf("\n--- dequant4 intra ---\n");
945                    test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
946    
947          printf("\n--- dequant4_intra ---\n");  #if defined(ARCH_IS_IA32)
948          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
949                  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);  
950          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
951                  test_h263_intra((quanth263_intraFunc*)dequant4_intra_c,                  test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
952                                                  (quanth263_intraFunc*)dequant4_intra_3dne, NULL, "sse2", -256, 255);  #endif
953    
954            /* Inter dequantization test */
955            printf("\n--- dequant4 inter ---\n");
956                    test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
957    
958          printf("\n--- dequant4_inter ---\n");  #if defined(ARCH_IS_IA32)
959          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
960                  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);  
961          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
962                  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();  
   
963  #endif  #endif
964    
965            emms();
966    
967          return XVID_ERR_OK;          return XVID_ERR_OK;
968  }  }
969    
# Line 813  Line 983 
983                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
984    
985                  case XVID_INIT_TEST :                  case XVID_INIT_TEST :
986                          return xvid_init_test();                  {
987                            ptr_t flags = (ptr_t)param1;
988                            return xvid_init_test((int)flags);
989                    }
990                  default :                  default :
991                          return XVID_ERR_FAIL;                          return XVID_ERR_FAIL;
992          }          }
# Line 872  Line 1044 
1044          case XVID_ENC_ENCODE:          case XVID_ENC_ENCODE:
1045    
1046                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)
1047                  return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1,                          return encoder_encode_bframes((Encoder *) handle,
1048                                                                                      (XVID_ENC_FRAME *) param1,
1049                                                            (XVID_ENC_STATS *) param2);                                                            (XVID_ENC_STATS *) param2);
1050                  else                  else
1051                  return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1,                          return encoder_encode((Encoder *) handle,
1052                                                                      (XVID_ENC_FRAME *) param1,
1053                                                            (XVID_ENC_STATS *) param2);                                                            (XVID_ENC_STATS *) param2);
1054    
1055          case XVID_ENC_CREATE:          case XVID_ENC_CREATE:

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

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