]> git.sesse.net Git - x264/blobdiff - common/quant.c
Remove explicit run calculation from coeff_level_run
[x264] / common / quant.c
index db9d57a8d8098291c51d57344b51d2baf4218ef7..0ba71d3941940bfa19ea23ac1070740a3e24694f 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * quant.c: quantization and level-run
  *****************************************************************************
- * Copyright (C) 2005-2011 x264 project
+ * Copyright (C) 2005-2012 x264 project
  *
  * Authors: Loren Merritt <lorenm@u.washington.edu>
  *          Fiona Glaser <fiona@x264.com>
@@ -373,14 +373,14 @@ static int x264_coeff_level_run##num( dctcoef *dct, x264_run_level_t *runlevel )
 {\
     int i_last = runlevel->last = x264_coeff_last##num(dct);\
     int i_total = 0;\
+    int mask = 0;\
     do\
     {\
-        int r = 0;\
-        runlevel->level[i_total] = dct[i_last];\
-        while( --i_last >= 0 && dct[i_last] == 0 )\
-            r++;\
-        runlevel->run[i_total++] = r;\
+        runlevel->level[i_total++] = dct[i_last];\
+        mask |= 1 << (i_last);\
+        while( --i_last >= 0 && dct[i_last] == 0 );\
     } while( i_last >= 0 );\
+    runlevel->mask = mask;\
     return i_total;\
 }
 
@@ -389,6 +389,18 @@ level_run(8)
 level_run(15)
 level_run(16)
 
+#if ARCH_X86_64
+#define INIT_TRELLIS(cpu)\
+    pf->trellis_cabac_4x4 = x264_trellis_cabac_4x4_##cpu;\
+    pf->trellis_cabac_8x8 = x264_trellis_cabac_8x8_##cpu;\
+    pf->trellis_cabac_4x4_psy = x264_trellis_cabac_4x4_psy_##cpu;\
+    pf->trellis_cabac_8x8_psy = x264_trellis_cabac_8x8_psy_##cpu;\
+    pf->trellis_cabac_dc = x264_trellis_cabac_dc_##cpu;\
+    pf->trellis_cabac_chroma_422_dc = x264_trellis_cabac_chroma_422_dc_##cpu;
+#else
+#define INIT_TRELLIS(...)
+#endif
+
 void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
 {
     pf->quant_8x8 = quant_8x8;
@@ -423,6 +435,7 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
 
 #if HIGH_BIT_DEPTH
 #if HAVE_MMX
+    INIT_TRELLIS( sse2 );
     if( cpu&X264_CPU_MMX2 )
     {
 #if ARCH_X86
@@ -435,13 +448,15 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
             pf->decimate_score16 = x264_decimate_score16_mmx2_slowctz;
         }
         pf->decimate_score64 = x264_decimate_score64_mmx2;
-        pf->coeff_last4 = x264_coeff_last4_mmx2;
+        pf->coeff_last8 = x264_coeff_last8_mmx2;
         pf->coeff_last[  DCT_LUMA_AC] = x264_coeff_last15_mmx2;
         pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2;
         pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2;
+        pf->coeff_level_run8 = x264_coeff_level_run8_mmx2;
         pf->coeff_level_run[  DCT_LUMA_AC] = x264_coeff_level_run15_mmx2;
         pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
 #endif
+        pf->coeff_last4 = x264_coeff_last4_mmx2;
         pf->coeff_level_run4 = x264_coeff_level_run4_mmx2;
         if( cpu&X264_CPU_LZCNT )
             pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt;
@@ -464,17 +479,21 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
             pf->decimate_score15 = x264_decimate_score15_sse2_slowctz;
             pf->decimate_score16 = x264_decimate_score16_sse2_slowctz;
         }
+        pf->coeff_last8 = x264_coeff_last8_sse2;
         pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2;
         pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2;
         pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2;
+        pf->coeff_level_run8 = x264_coeff_level_run8_sse2;
         pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2;
         pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
         if( cpu&X264_CPU_LZCNT )
         {
             pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt;
+            pf->coeff_last8 = x264_coeff_last8_sse2_lzcnt;
             pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
             pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
             pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
+            pf->coeff_level_run8 = x264_coeff_level_run8_sse2_lzcnt;
             pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt;
             pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt;
         }
@@ -494,6 +513,7 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
             pf->decimate_score16 = x264_decimate_score16_ssse3_slowctz;
         }
         pf->decimate_score64 = x264_decimate_score64_ssse3;
+        INIT_TRELLIS( ssse3 );
     }
     if( cpu&X264_CPU_SSE4 )
     {
@@ -506,9 +526,19 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
     {
         pf->denoise_dct = x264_denoise_dct_avx;
     }
+    if( cpu&X264_CPU_XOP )
+    {
+        pf->dequant_4x4_dc = x264_dequant_4x4dc_xop;
+        if( h->param.i_cqm_preset != X264_CQM_FLAT )
+        {
+            pf->dequant_4x4 = x264_dequant_4x4_xop;
+            pf->dequant_8x8 = x264_dequant_8x8_xop;
+        }
+    }
 #endif // HAVE_MMX
 #else // !HIGH_BIT_DEPTH
 #if HAVE_MMX
+    INIT_TRELLIS( sse2 );
     if( cpu&X264_CPU_MMX )
     {
 #if ARCH_X86
@@ -546,11 +576,15 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
         pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
 #endif
         pf->coeff_last4 = x264_coeff_last4_mmx2;
+        pf->coeff_last8 = x264_coeff_last8_mmx2;
         pf->coeff_level_run4 = x264_coeff_level_run4_mmx2;
+        pf->coeff_level_run8 = x264_coeff_level_run8_mmx2;
         if( cpu&X264_CPU_LZCNT )
         {
             pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt;
+            pf->coeff_last8 = x264_coeff_last8_mmx2_lzcnt;
             pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt;
+            pf->coeff_level_run8 = x264_coeff_level_run8_mmx2_lzcnt;
         }
     }
 
@@ -608,6 +642,7 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
             pf->decimate_score16 = x264_decimate_score16_ssse3_slowctz;
         }
         pf->decimate_score64 = x264_decimate_score64_ssse3;
+        INIT_TRELLIS( ssse3 );
     }
 
     if( cpu&X264_CPU_SSE4 )
@@ -629,6 +664,15 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
         pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_avx;
         pf->denoise_dct = x264_denoise_dct_avx;
     }
+
+    if( cpu&X264_CPU_XOP )
+    {
+        if( h->param.i_cqm_preset != X264_CQM_FLAT )
+        {
+            pf->dequant_4x4 = x264_dequant_4x4_xop;
+            pf->dequant_8x8 = x264_dequant_8x8_xop;
+        }
+    }
 #endif // HAVE_MMX
 
 #if HAVE_ALTIVEC