Merge remote-tracking branch 'x264/master'
authorPhillip Blucas <pblucas@gmail.com>
Tue, 7 May 2013 22:44:30 +0000 (17:44 -0500)
committerPhillip Blucas <pblucas@gmail.com>
Tue, 7 May 2013 22:44:30 +0000 (17:44 -0500)
Conflicts:
Makefile
common/bitstream.h
common/common.c
common/common.h
common/mc.c
common/mc.h
configure
encoder/encoder.c
encoder/me.c

30 files changed:
1  2 
.gitignore
Makefile
common/bitstream.c
common/bitstream.h
common/common.c
common/common.h
common/dct.c
common/frame.c
common/frame.h
common/macroblock.c
common/mc.c
common/mc.h
common/pixel.c
common/quant.c
common/set.c
common/x86/predict-a.asm
common/x86/predict.h
common/x86/quant-a.asm
configure
encoder/analyse.c
encoder/encoder.c
encoder/macroblock.c
encoder/macroblock.h
encoder/me.c
encoder/ratecontrol.c
encoder/rdo.c
encoder/slicetype.c
tools/checkasm.c
x264.c
x264.h

diff --cc .gitignore
Simple merge
diff --cc Makefile
+++ b/Makefile
@@@ -176,19 -200,10 +207,19 @@@ x264: x264$(EXE
  checkasm: checkasm$(EXE)
  endif
  
- x264$(EXE): .depend $(OBJCLI) $(CLI_LIBX264)
+ x264$(EXE): $(GENERATED) .depend $(OBJCLI) $(CLI_LIBX264)
        $(LD)$@ $(OBJCLI) $(CLI_LIBX264) $(LDFLAGSCLI) $(LDFLAGS)
  
- checkasm$(EXE): .depend $(OBJCHK) $(LIBX264)
 +ifeq ($(HAVE_MPEG2),1)
 +ifneq ($(EXE),)
 +.PHONY: x262$(EXE)
 +x262: x262$(EXE)
 +endif
 +x262$(EXE): x264
 +      ln -sf x264$(EXE) x262$(EXE)
 +endif
 +
+ checkasm$(EXE): $(GENERATED) .depend $(OBJCHK) $(LIBX264)
        $(LD)$@ $(OBJCHK) $(LIBX264) $(LDFLAGS)
  
  $(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK): .depend
@@@ -249,8 -261,8 +280,8 @@@ fprofiled
  endif
  
  clean:
 -      rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(SONAME) *.a *.lib *.exp *.pdb x264 x264.exe .depend TAGS
 +      rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(SONAME) *.a *.lib *.exp *.pdb x264 x264.exe x262 x262.exe .depend TAGS
-       rm -f checkasm checkasm.exe $(OBJCHK)
+       rm -f checkasm checkasm.exe $(OBJCHK) $(GENERATED) x264_lookahead.clbin
        rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock
  
  distclean: clean
Simple merge
@@@ -55,10 -55,9 +55,10 @@@ typedef struct bs_
  
  typedef struct
  {
-     int     last;
-     int     mask;
-     dctcoef level[64];
+     int32_t last;
+     int32_t mask;
 -    ALIGNED_16( dctcoef level[18] );
++    ALIGNED_16( dctcoef level[64] );
 +    uint8_t run[64];
  } x264_run_level_t;
  
  extern const vlc_t x264_coeff0_token[6];
diff --cc common/common.c
@@@ -198,19 -171,10 +198,23 @@@ void x264_param_default( x264_param_t *
      param->b_pic_struct = 0;
      param->b_fake_interlaced = 0;
      param->i_frame_packing = -1;
+     param->b_opencl = 0;
+     param->i_opencl_device = 0;
+     param->opencl_device_id = NULL;
+     param->psz_clbin_file = NULL;
 +    param->b_mpeg2 = 0;
 +}
 +
 +void x264_param_default_mpeg2( x264_param_t *param )
 +{
 +    x264_param_default( param );
 +    x264_param_force_mpeg2( param );
 +
 +    param->pf_log = x264_log_mpeg2;
 +    param->i_intra_dc_precision = X264_INTRA_DC_8_BIT;
 +    param->b_nonlinear_quant = 1;
 +    param->b_alt_intra_vlc = 1;
 +    param->b_alternate_scan = 0;
  }
  
  static int x264_param_apply_preset( x264_param_t *param, const char *preset )
@@@ -900,20 -782,12 +904,24 @@@ int x264_param_parse( x264_param_t *p, 
          p->i_slice_max_size = atoi(value);
      OPT("slice-max-mbs")
          p->i_slice_max_mbs = atoi(value);
+     OPT("slice-min-mbs")
+         p->i_slice_min_mbs = atoi(value);
      OPT("slices")
          p->i_slice_count = atoi(value);
+     OPT("slices-max")
+         p->i_slice_count_max = atoi(value);
 +#if HAVE_MPEG2
 +    OPT("mpeg2")
 +        p->b_mpeg2 = atobool(value);
 +    OPT("dc")
 +        p->i_intra_dc_precision = atoi(value) - 8;
 +    OPT("altscan")
 +        p->b_alternate_scan = atobool(value);
 +    OPT("linear-quant")
 +        p->b_nonlinear_quant = !atobool(value);
 +    OPT("altintra")
 +        p->b_alt_intra_vlc = atobool(value);
 +#endif
      OPT("cabac")
          p->b_cabac = atobool(value);
      OPT("cabac-idc")
@@@ -1440,9 -1292,10 +1451,11 @@@ char *x264_param2string( x264_param_t *
          s += sprintf( s, "bitdepth=%d ", BIT_DEPTH );
      }
  
-     s += sprintf( s, "cabac=%d", p->b_cabac );
+     if( p->b_opencl )
+         s += sprintf( s, "opencl=%d", p->b_opencl );
+     s += sprintf( s, " cabac=%d", p->b_cabac );
      s += sprintf( s, " ref=%d", p->i_frame_reference );
 +    s += sprintf( s, " mpeg2=%d", p->b_mpeg2 );
      s += sprintf( s, " deblock=%d:%d:%d", p->b_deblocking_filter,
                    p->i_deblocking_filter_alphac0, p->i_deblocking_filter_beta );
      s += sprintf( s, " analyse=%#x:%#x", p->analyse.intra, p->analyse.inter );
diff --cc common/common.h
@@@ -99,25 -96,18 +102,29 @@@ do {
  #include <assert.h>
  #include <limits.h>
  
+ #if HAVE_OPENCL
+ #include "opencl.h"
+ #endif
 +/* MPEG-2 Support */
 +#if HAVE_MPEG2
 +#   define MPEG2 h->param.b_mpeg2
 +#else
 +#   define MPEG2 0
 +#endif
 +
  #if HAVE_INTERLACED
  #   define MB_INTERLACED h->mb.b_interlaced
 -#   define SLICE_MBAFF h->sh.b_mbaff
  #   define PARAM_INTERLACED h->param.b_interlaced
 +#   define SLICE_MBAFF h->sh.b_mbaff
 +#   define MPEG2_MBAFF (PARAM_INTERLACED & MPEG2)
 +#   define PLANE_MBAFF (SLICE_MBAFF | MPEG2_MBAFF)
  #else
  #   define MB_INTERLACED 0
 -#   define SLICE_MBAFF 0
  #   define PARAM_INTERLACED 0
 +#   define SLICE_MBAFF 0
 +#   define MPEG2_MBAFF 0
 +#   define PLANE_MBAFF 0
  #endif
  
  #ifdef CHROMA_FORMAT
@@@ -670,12 -610,11 +677,12 @@@ struct x264_
      /* Current MB DCT coeffs */
      struct
      {
-         ALIGNED_16( dctcoef luma16x16_dc[3][16] );
+         ALIGNED_N( dctcoef luma16x16_dc[3][16] );
          ALIGNED_16( dctcoef chroma_dc[2][8] );
          // FIXME share memory?
-         ALIGNED_16( dctcoef luma8x8[12][64] );
-         ALIGNED_16( dctcoef luma4x4[16*3][16] );
-         ALIGNED_16( dctcoef mpeg2_8x8[8][64] );
+         ALIGNED_N( dctcoef luma8x8[12][64] );
+         ALIGNED_N( dctcoef luma4x4[16*3][16] );
++        ALIGNED_N( dctcoef mpeg2_8x8[8][64] );
      } dct;
  
      /* MB table and cache for current frame/mb */
diff --cc common/dct.c
@@@ -1422,10 -1035,12 +1433,16 @@@ void x264_zigzag_init( int cpu, x264_zi
          pf_interlaced->interleave_8x8_cavlc =
          pf_progressive->interleave_8x8_cavlc = x264_zigzag_interleave_8x8_cavlc_avx;
      }
+     if( cpu&X264_CPU_AVX2 )
+     {
+         pf_interlaced->interleave_8x8_cavlc =
+         pf_progressive->interleave_8x8_cavlc = x264_zigzag_interleave_8x8_cavlc_avx2;
+     }
  #endif // HIGH_BIT_DEPTH
  #endif
 +
 +    /* MPEG-2 TODO: Write SIMD */
 +    if( b_mpeg2 )
 +        pf_interlaced->scan_8x8 = zigzag_scan_8x8_field_mpeg2;
  }
diff --cc common/frame.c
Simple merge
diff --cc common/frame.h
Simple merge
@@@ -119,12 -118,12 +119,12 @@@ static NOINLINE void x264_mb_mc_01xywh
      int weight = h->mb.bipred_weight[i_ref0][i_ref1];
      int mvx0   = x264_clip3( h->mb.cache.mv[0][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
      int mvx1   = x264_clip3( h->mb.cache.mv[1][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] ) + 4*4*x;
 -    int mvy0   = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
 -    int mvy1   = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y;
 +    int mvy0   = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y*(!MPEG2);
 +    int mvy1   = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] ) + 4*4*y*(!MPEG2);
      int i_mode = x264_size2pixel[height][width];
      intptr_t i_stride0 = 16, i_stride1 = 16;
-     ALIGNED_ARRAY_16( pixel, tmp0,[16*16] );
-     ALIGNED_ARRAY_16( pixel, tmp1,[16*16] );
+     ALIGNED_ARRAY_N( pixel, tmp0,[16*16] );
+     ALIGNED_ARRAY_N( pixel, tmp1,[16*16] );
      pixel *src0, *src1;
  
      MC_LUMA_BI( 0 );
diff --cc common/mc.c
@@@ -660,7 -469,7 +660,7 @@@ static void mbtree_propagate_cost( int 
      }
  }
  
- void x264_mc_init( int cpu, x264_mc_functions_t *pf, int b_mpeg2 )
 -void x264_mc_init( int cpu, x264_mc_functions_t *pf, int cpu_independent )
++void x264_mc_init( int cpu, x264_mc_functions_t *pf, int cpu_independent, int b_mpeg2 )
  {
      pf->mc_luma   = mc_luma;
      pf->get_ref   = get_ref;
      x264_mc_init_arm( cpu, pf );
  #endif
  
 +    // override any simd for the time being
 +    if( b_mpeg2 )
 +    {
 +        pf->mc_luma   = mc_luma_mpeg2;
 +        pf->mc_chroma = mc_chroma_mpeg2;
 +        pf->get_ref   = get_ref_mpeg2;
 +        pf->hpel_filter = NULL;
 +        pf->frame_init_lowres_core = frame_init_lowres_core_mpeg2;
 +    }
++
+     if( cpu_independent )
+         pf->mbtree_propagate_cost = mbtree_propagate_cost;
  }
  
  void x264_frame_filter( x264_t *h, x264_frame_t *frame, int mb_y, int b_end )
diff --cc common/mc.h
@@@ -123,6 -123,6 +123,6 @@@ typedef struc
                                     uint16_t *inter_costs, uint16_t *inv_qscales, float *fps_factor, int len );
  } x264_mc_functions_t;
  
- void x264_mc_init( int cpu, x264_mc_functions_t *pf, int b_mpeg2 );
 -void x264_mc_init( int cpu, x264_mc_functions_t *pf, int cpu_independent );
++void x264_mc_init( int cpu, x264_mc_functions_t *pf, int cpu_independent, int b_mpeg2 );
  
  #endif
diff --cc common/pixel.c
Simple merge
diff --cc common/quant.c
Simple merge
diff --cc common/set.c
Simple merge
@@@ -2162,36 -2183,29 +2183,44 @@@ cglobal predict_16x16_dc_core, 2,2,
      RET
  
  cglobal predict_16x16_dc_top, 1,2
-     PRED16x16_DC_SSE2 [pw_8], 4
+     PRED16x16_DC [pw_8], 4
      RET
  
- INIT_XMM sse2
- %if HIGH_BIT_DEPTH
  cglobal predict_16x16_dc_left_core, 1,2
-     movd       m0, r1m
-     SPLATW     m0, m0
-     STORE16x16_SSE2 m0, m0
-     RET
- %else ; !HIGH_BIT_DEPTH
- cglobal predict_16x16_dc_left_core, 1,1
-     movd       m0, r1m
-     SPLATW     m0, m0
+     movd      xm0, r1m
+     SPLATW     m0, xm0
+ %if HIGH_BIT_DEPTH && mmsize == 16
+     STORE16    m0, m0
+ %else
+ %if HIGH_BIT_DEPTH == 0
      packuswb   m0, m0
-     STORE16x16_SSE2 m0
+ %endif
+     STORE16    m0
+ %endif
      RET
+ %endmacro
+ INIT_XMM sse2
+ PREDICT_16x16_DC_CORE
+ %if HIGH_BIT_DEPTH
+ INIT_YMM avx2
+ PREDICT_16x16_DC_CORE
+ %else
+ INIT_XMM avx2
+ PREDICT_16x16_DC_CORE
  %endif
-     STORE8x8   m0, m0
 +
 +;-----------------------------------------------------------------------------
 +; void predict_8x8_mpeg2( uint8_t *src, int predicted_dc )
 +;-----------------------------------------------------------------------------
 +%macro PREDICT_8x8_MPEG2 0
 +cglobal predict_8x8_mpeg2, 2,2
 +    movd       m0, r1d
 +    punpcklbw  m0, m0
 +    SPLATW     m0, m0
++    STORE8     m0
 +    RET
 +%endmacro
 +
 +INIT_MMX mmx2
 +PREDICT_8x8_MPEG2
Simple merge
@@@ -1401,6 -1591,13 +1591,13 @@@ cglobal coeff_last64, 1,
  ; int coeff_level_run( dctcoef *dct, run_level_t *runlevel )
  ;-----------------------------------------------------------------------------
  
 -    .level: resw 16
+ struc levelrun
+     .last: resd 1
+     .mask: resd 1
+     align 16, resb 1
++    .level: resw 64
+ endstruc
  ; t6 = eax for return, t3 = ecx for shift, t[01] = r[01] for x86_64 args
  %if WIN64
      DECLARE_REG_TMP 3,1,2,0,4,5,6
diff --cc configure
+++ b/configure
  if [ "$bit_depth" -gt "8" ]; then
      define HIGH_BIT_DEPTH
      ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH=1"
+     opencl="no"
 +    mpeg2="no"
  else
      ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH=0"
  fi
@@@ -1218,8 -1260,7 +1276,8 @@@ shared:        $share
  static:        $static
  asm:           $asm
  interlaced:    $interlaced
- avs:           $avstype
 +mpeg2:         $mpeg2
+ avs:           $avs
  lavf:          $lavf
  ffms:          $ffms
  gpac:          $gpac
Simple merge
@@@ -1143,10 -1068,8 +1187,11 @@@ static int x264_validate_parameters( x2
      BOOLIFY( b_fake_interlaced );
      BOOLIFY( b_open_gop );
      BOOLIFY( b_bluray_compat );
 +    BOOLIFY( b_nonlinear_quant );
 +    BOOLIFY( b_alt_intra_vlc );
 +    BOOLIFY( b_alternate_scan );
      BOOLIFY( b_full_recon );
+     BOOLIFY( b_opencl );
      BOOLIFY( analyse.b_transform_8x8 );
      BOOLIFY( analyse.b_weighted_bipred );
      BOOLIFY( analyse.b_chroma_me );
@@@ -1433,15 -1304,11 +1478,15 @@@ x264_t *x264_encoder_open( x264_param_
      x264_predict_8x16c_init( h->param.cpu, h->predict_8x16c );
      x264_predict_8x8_init( h->param.cpu, h->predict_8x8, &h->predict_8x8_filter );
      x264_predict_4x4_init( h->param.cpu, h->predict_4x4 );
 +    x264_predict_8x8_mpeg2_init( h->param.cpu, &h->predict_8x8_mpeg2 );
      x264_pixel_init( h->param.cpu, &h->pixf );
 -    x264_dct_init( h->param.cpu, &h->dctf );
 -    x264_zigzag_init( h->param.cpu, &h->zigzagf_progressive, &h->zigzagf_interlaced );
 -    memcpy( &h->zigzagf, PARAM_INTERLACED ? &h->zigzagf_interlaced : &h->zigzagf_progressive, sizeof(h->zigzagf) );
 -    x264_mc_init( h->param.cpu, &h->mc, h->param.b_cpu_independent );
 +    x264_dct_init( h->param.cpu, &h->dctf, MPEG2 );
 +    x264_zigzag_init( h->param.cpu, &h->zigzagf_progressive, &h->zigzagf_interlaced, MPEG2 );
 +    if( MPEG2 )
 +        memcpy( &h->zigzagf, h->param.b_alternate_scan ? &h->zigzagf_interlaced : &h->zigzagf_progressive, sizeof(h->zigzagf) );
 +    else
 +        memcpy( &h->zigzagf, PARAM_INTERLACED ? &h->zigzagf_interlaced : &h->zigzagf_progressive, sizeof(h->zigzagf) );
-     x264_mc_init( h->param.cpu, &h->mc, MPEG2 );
++    x264_mc_init( h->param.cpu, &h->mc, h->param.b_cpu_independent, MPEG2 );
      x264_quant_init( h, h->param.cpu, &h->quantf );
      x264_deblock_init( h->param.cpu, &h->loopf, PARAM_INTERLACED );
      x264_bitstream_init( h->param.cpu, &h->bsf );
@@@ -2536,17 -2383,12 +2595,21 @@@ static int x264_slice_write( x264_t *h 
          }
  
          if( !(i_mb_y & SLICE_MBAFF) && back_up_bitstream )
-             x264_bitstream_backup( h, &bs_bak[0], i_skip, 0 );
+         {
+             x264_bitstream_backup( h, &bs_bak[BS_BAK_SLICE_MAX_SIZE], i_skip, 0 );
+             if( slice_max_size && (thread_last_mb+1-mb_xy) == h->param.i_slice_min_mbs )
+                 x264_bitstream_backup( h, &bs_bak[BS_BAK_SLICE_MIN_MBS], i_skip, 0 );
+         }
  
 +        if( MPEG2 && ( i_skip || i_mb_x == 0 || !IS_INTRA( h->mb.i_type ) ) )
 +            x264_reset_intra_dc_mpeg2( h );
 +
 +        if( MPEG2 && i_mb_x == 0 )
 +        {
 +            i_skip = 0;
 +            x264_reset_mv_predictor_mpeg2( h );
 +        }
 +
          if( PARAM_INTERLACED )
          {
              if( h->mb.b_adaptive_mbaff )
@@@ -2806,15 -2628,11 +2893,18 @@@ cont
          {
              i_mb_y++;
              i_mb_x = 0;
 +            if( MPEG2 )
 +            {
 +                bs_align_0( &h->out.bs );
 +                /* end the MPEG-2 slice at the end of the row */
 +                if( x264_nal_end( h ) )
 +                    return -1;
 +            }
          }
      }
+     if( h->sh.i_last_mb < h->sh.i_first_mb )
+         return 0;
      h->out.nal[h->out.i_nal].i_last_mb = h->sh.i_last_mb;
  
      if( h->param.b_cabac )
Simple merge
Simple merge
diff --cc encoder/me.c
@@@ -876,7 -874,8 +876,8 @@@ static void refine_subpel( x264_t *h, x
      int chroma_v_shift = CHROMA_V_SHIFT;
      int mvy_offset = chroma_v_shift & MB_INTERLACED & m->i_ref ? (h->mb.i_mb_y & 1)*4 - 2 : 0;
  
-     ALIGNED_ARRAY_16( pixel, pix,[64*18] ); // really 17x17x2, but round up for alignment
+     ALIGNED_ARRAY_N( pixel, pix,[64*18] ); // really 17x17x2, but round up for alignment
 -    ALIGNED_ARRAY_16( int, costs,[4] );
++    ALIGNED_ARRAY_N( int, costs,[4] );
  
      int bmx = m->mv[0];
      int bmy = m->mv[1];
Simple merge
diff --cc encoder/rdo.c
Simple merge
@@@ -36,16 -36,22 +36,28 @@@ static int x264_slicetype_frame_cost( x
                                        x264_frame_t **frames, int p0, int p1, int b,
                                        int b_intra_penalty );
  
+ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int b_lookahead );
+ #if HAVE_OPENCL
+ int x264_opencl_lowres_init( x264_t *h, x264_frame_t *fenc, int lambda );
+ int x264_opencl_motionsearch( x264_t *h, x264_frame_t **frames, int b, int ref, int b_islist1, int lambda, const x264_weight_t *w );
+ int x264_opencl_finalize_cost( x264_t *h, int lambda, x264_frame_t **frames, int p0, int p1, int b, int dist_scale_factor );
+ int x264_opencl_precalculate_frame_cost( x264_t *h, x264_frame_t **frames, int lambda, int p0, int p1, int b );
+ void x264_opencl_flush( x264_t *h );
+ void x264_opencl_slicetype_prep( x264_t *h, x264_frame_t **frames, int num_frames, int lambda );
+ void x264_opencl_slicetype_end( x264_t *h );
+ #endif
  static void x264_lowres_context_init( x264_t *h, x264_mb_analysis_t *a )
  {
 +    const uint16_t *lambda_tab;
 +    if( MPEG2 )
 +        lambda_tab = h->param.b_nonlinear_quant ? x264_lambda_tab_exp_mpeg2 :
 +                                                  x264_lambda_tab_lin_mpeg2;
 +    else
 +        lambda_tab = x264_lambda_tab;
      a->i_qp = X264_LOOKAHEAD_QP;
 -    a->i_lambda = x264_lambda_tab[ a->i_qp ];
 +    a->i_lambda = lambda_tab[ a->i_qp ];
      x264_mb_analyse_load_costs( h, a );
      if( h->param.analyse.i_subpel_refine > 1 )
      {
@@@ -1083,12 -1082,12 +1083,12 @@@ static int check_dct( int cpu_ref, int 
          } \
      }
  
 -    x264_zigzag_init( 0, &zigzag_c[0], &zigzag_c[1] );
 -    x264_zigzag_init( cpu_ref, &zigzag_ref[0], &zigzag_ref[1] );
 -    x264_zigzag_init( cpu_new, &zigzag_asm[0], &zigzag_asm[1] );
 +    x264_zigzag_init( 0, &zigzag_c[0], &zigzag_c[1], 0 );
 +    x264_zigzag_init( cpu_ref, &zigzag_ref[0], &zigzag_ref[1], 0 );
 +    x264_zigzag_init( cpu_new, &zigzag_asm[0], &zigzag_asm[1], 0 );
  
      ok = 1; used_asm = 0;
-     TEST_INTERLEAVE( interleave_8x8_cavlc, level1, level2, dct1[0], 64 );
+     TEST_INTERLEAVE( interleave_8x8_cavlc, level1, level2, dct8[0], 64 );
      report( "zigzag_interleave :" );
  
      for( interlace = 0; interlace <= 1; interlace++ )
@@@ -1121,9 -1120,9 +1121,9 @@@ static int check_mc( int cpu_ref, int c
  
      int ret = 0, ok, used_asm;
  
--    x264_mc_init( 0, &mc_c, 0 );
--    x264_mc_init( cpu_ref, &mc_ref, 0 );
--    x264_mc_init( cpu_new, &mc_a, 0 );
++    x264_mc_init( 0, &mc_c, 0, 0 );
++    x264_mc_init( cpu_ref, &mc_ref, 0, 0 );
++    x264_mc_init( cpu_new, &mc_a, 0, 0 );
      x264_pixel_init( 0, &pixf );
  
  #define MC_TEST_LUMA( w, h ) \
@@@ -2118,8 -2122,7 +2123,7 @@@ static int check_quant( int cpu_ref, in
              int result_a = call_a( qf_a.lastname, dct1+ac, &runlevel_a ); \
              if( result_c != result_a || runlevel_c.last != runlevel_a.last || \
                  runlevel_c.mask != runlevel_a.mask || \
-                 memcmp(runlevel_c.level, runlevel_a.level, sizeof(dctcoef)*result_c) || \
-                 memcmp(runlevel_c.run, runlevel_a.run, sizeof(uint8_t)*(result_c-1)) ) \
 -                memcmp(runlevel_c.level, runlevel_a.level, sizeof(dctcoef)*result_c)) \
++                memcmp(runlevel_c.level, runlevel_a.level, sizeof(dctcoef)*result_c) ) \
              { \
                  ok = 0; \
                  fprintf( stderr, #name ": [FAILED]\n" ); \
      return ret;
  }
  
-                 INIT_QUANT8(1) \
 +static int check_quant_mpeg2( int cpu_ref, int cpu_new )
 +{
 +    x264_quant_function_t qf_c;
 +    x264_quant_function_t qf_ref;
 +    x264_quant_function_t qf_a;
 +    ALIGNED_16( dctcoef dct1[64] );
 +    ALIGNED_16( dctcoef dct2[64] );
 +    ALIGNED_16( uint8_t cqm_buf[64] );
 +    int ret = 0, ok = 1, used_asm = 0;
 +    x264_t h_buf;
 +    x264_t *h = &h_buf;
 +    memset( h, 0, sizeof(*h) );
 +    h->sps->i_chroma_format_idc = 1;
 +    h->param.b_mpeg2 = 1;
 +    x264_param_default( &h->param );
 +    x264_param_apply_profile( &h->param, "high" );
 +
 +    for( int i_cqm = 0; i_cqm < 4 && ok; i_cqm++ )
 +    {
 +        if( i_cqm == 0 )
 +        {
 +            for( int i = 0; i < 8; i++ )
 +                h->pps->scaling_list[i] = x264_cqm_flat16;
 +            h->pps->scaling_list[CQM_8IY] = x264_cqm_intra_mpeg2;
 +            h->pps->scaling_list[CQM_8IC] = x264_cqm_intra_mpeg2;
 +            h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_FLAT;
 +        }
 +        else if( i_cqm == 1 )
 +        {
 +            for( int i = 0; i < 4; i++ )
 +                h->pps->scaling_list[i] = x264_cqm_jvt[i+4];
 +            h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_JVT;
 +        }
 +        else
 +        {
 +            if( i_cqm == 2 )
 +                for( int i = 0; i < 64; i++ )
 +                    cqm_buf[i] = 4 + rand() % 252;
 +            else
 +                for( int i = 0; i < 64; i++ )
 +                    cqm_buf[i] = 4;
 +            for( int i = 0; i < 6; i++ )
 +                h->pps->scaling_list[i] = cqm_buf;
 +            h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_CUSTOM;
 +        }
 +
 +        x264_quant_init( h, 0, &qf_c );
 +        x264_quant_init( h, cpu_ref, &qf_ref );
 +        x264_quant_init( h, cpu_new, &qf_a );
 +
 +#define TEST_DEQUANT_MPEG2_INTRA( qname, dqname, block ) \
 +        if( qf_a.dqname != qf_ref.dqname ) \
 +        { \
 +            set_func_name( "%s_%s", #dqname, i_cqm?"cqm":"flat" ); \
 +            used_asm = 1; \
 +            for( int qp = 31; qp > 0; qp-- ) \
 +           { \
-                 INIT_QUANT8(1) \
++                INIT_QUANT8(1, 8) \
 +                qf_c.qname( dct1, h->quant8_mf[block][qp], h->quant8_bias[block][qp] ); \
 +                memcpy( dct2, dct1, 64*sizeof(dctcoef) ); \
 +                call_c1( qf_c.dqname, dct1, h->dequant8_mf[block][qp], h->param.i_intra_dc_precision ); \
 +                call_a1( qf_a.dqname, dct2, h->dequant8_mf[block][qp], h->param.i_intra_dc_precision ); \
 +                if( memcmp( dct1, dct2, 64*sizeof(dctcoef) ) ) \
 +                { \
 +                    ok = 0; \
 +                    fprintf( stderr, #dqname "(qp=%d, cqm=%d, block="#block"): [FAILED]\n", qp, i_cqm ); \
 +                    for (int r = 0; r < 64; r++) fprintf( stderr, "%d ", dct2[r] ); \
 +                    fprintf( stderr, "\n" ); \
 +                    for (int r = 0; r < 64; r++) fprintf( stderr, "%d ", dct1[r] ); \
 +                    fprintf( stderr, "\n" ); \
 +                    break; \
 +                } \
 +                call_c2( qf_c.dqname, dct1, h->dequant8_mf[block][qp], h->param.i_intra_dc_precision ); \
 +                call_a2( qf_a.dqname, dct2, h->dequant8_mf[block][qp], h->param.i_intra_dc_precision ); \
 +            } \
 +        }
 +
 +        for( int precision = 0; precision < 4; precision++ )
 +        {
 +            h->param.i_intra_dc_precision = precision;
 +            x264_cqm_init_mpeg2( h );
 +            TEST_DEQUANT_MPEG2_INTRA( quant_8x8, dequant_mpeg2_intra, CQM_8IY );
 +            x264_cqm_delete( h );
 +        }
 +
 +        x264_cqm_init_mpeg2( h );
 +
 +#define TEST_DEQUANT_MPEG2_INTER( qname, dqname, block ) \
 +        if( qf_a.dqname != qf_ref.dqname ) \
 +        { \
 +            set_func_name( "%s_%s", #dqname, i_cqm?"cqm":"flat" ); \
 +            used_asm = 1; \
 +            for( int qp = 31; qp > 0; qp-- ) \
 +           { \
++                INIT_QUANT8(1, 8) \
 +                qf_c.qname( dct1, h->quant8_mf[block][qp], h->quant8_bias[block][qp] ); \
 +                memcpy( dct2, dct1, 64*sizeof(dctcoef) ); \
 +                call_c1( qf_c.dqname, dct1, h->dequant8_mf[block][qp] ); \
 +                call_a1( qf_a.dqname, dct2, h->dequant8_mf[block][qp] ); \
 +                if( memcmp( dct1, dct2, 64*sizeof(dctcoef) ) ) \
 +                { \
 +                    ok = 0; \
 +                    fprintf( stderr, #dqname "(qp=%d, cqm=%d, block="#block"): [FAILED]\n", qp, i_cqm ); \
 +                    for (int r = 0; r < 64; r++) fprintf( stderr, "%d ", dct2[r] ); \
 +                    fprintf( stderr, "\n" ); \
 +                    for (int r = 0; r < 64; r++) fprintf( stderr, "%d ", dct1[r] ); \
 +                    fprintf( stderr, "\n" ); \
 +                    break; \
 +                } \
 +                call_c2( qf_c.dqname, dct1, h->dequant8_mf[block][qp] ); \
 +                call_a2( qf_a.dqname, dct2, h->dequant8_mf[block][qp] ); \
 +            } \
 +        }
 +
 +        TEST_DEQUANT_MPEG2_INTER( quant_8x8, dequant_mpeg2_inter, CQM_8PY );
 +
 +        x264_cqm_delete( h );
 +    }
 +
 +    report( "dequant mpeg2 :" );
 +
 +    return ret;
 +}
 +
  static int check_intra( int cpu_ref, int cpu_new )
  {
      int ret = 0, ok = 1, used_asm = 0;
diff --cc x264.c
Simple merge
diff --cc x264.h
Simple merge