[x264-devel] commit: inline cabac_size_decision (Loren Merritt )

git version control git at videolan.org
Mon Mar 24 08:00:54 CET 2008


x264 | branch: master | Loren Merritt <pengvado at akuvian.org> | Sat Mar 22 20:25:06 2008 -0600| [d4f9f60faf14bd1415f16dd419d1889324db3e1e]

inline cabac_size_decision

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=d4f9f60faf14bd1415f16dd419d1889324db3e1e
---

 common/cabac.c  |   62 ++++++++++++++++++++++++++++++++----------------------
 common/cabac.h  |   31 ++++++++++++++++++++++-----
 encoder/cabac.c |   10 +++++---
 encoder/rdo.c   |    1 -
 4 files changed, 68 insertions(+), 36 deletions(-)

diff --git a/common/cabac.c b/common/cabac.c
index 612eeda..c381cd0 100644
--- a/common/cabac.c
+++ b/common/cabac.c
@@ -715,7 +715,7 @@ static const uint8_t x264_cabac_range_lps[128][4] =
     {   2,   2,   2,   2 },
 };
 
-static const uint8_t x264_cabac_transition[2][128] =
+const uint8_t x264_cabac_transition[2][128] =
 {{
       0,  1,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
      15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
@@ -779,8 +779,8 @@ static const uint8_t x264_cabac_probability[128] =
     FIX8(0.0219), FIX8(0.0208), FIX8(0.0198), FIX8(0.0187)
 };
 /* -ln2(probability) */
-static const uint16_t x264_cabac_entropy[128] =
-{
+const uint16_t x264_cabac_entropy[2][128] =
+{{
     FIX8(0.0273), FIX8(0.0288), FIX8(0.0303), FIX8(0.0320),
     FIX8(0.0337), FIX8(0.0355), FIX8(0.0375), FIX8(0.0395),
     FIX8(0.0416), FIX8(0.0439), FIX8(0.0463), FIX8(0.0488),
@@ -813,7 +813,40 @@ static const uint16_t x264_cabac_entropy[128] =
     FIX8(4.9099), FIX8(4.9851), FIX8(5.0602), FIX8(5.1354),
     FIX8(5.2106), FIX8(5.2859), FIX8(5.3610), FIX8(5.4362),
     FIX8(5.5114), FIX8(5.5866), FIX8(5.6618), FIX8(5.7370)
-};
+},{
+    FIX8(5.7370), FIX8(5.6618), FIX8(5.5866), FIX8(5.5114),
+    FIX8(5.4362), FIX8(5.3610), FIX8(5.2859), FIX8(5.2106),
+    FIX8(5.1354), FIX8(5.0602), FIX8(4.9851), FIX8(4.9099),
+    FIX8(4.8347), FIX8(4.7595), FIX8(4.6843), FIX8(4.6091),
+    FIX8(4.5339), FIX8(4.4588), FIX8(4.3836), FIX8(4.3083),
+    FIX8(4.2332), FIX8(4.1580), FIX8(4.0828), FIX8(4.0076),
+    FIX8(3.9324), FIX8(3.8572), FIX8(3.7820), FIX8(3.7068),
+    FIX8(3.6316), FIX8(3.5565), FIX8(3.4813), FIX8(3.4061),
+    FIX8(3.3309), FIX8(3.2557), FIX8(3.1805), FIX8(3.1053),
+    FIX8(3.0301), FIX8(2.9549), FIX8(2.8797), FIX8(2.8046),
+    FIX8(2.7294), FIX8(2.6542), FIX8(2.5790), FIX8(2.5038),
+    FIX8(2.4286), FIX8(2.3534), FIX8(2.2782), FIX8(2.2030),
+    FIX8(2.1278), FIX8(2.0527), FIX8(1.9775), FIX8(1.9023),
+    FIX8(1.8271), FIX8(1.7519), FIX8(1.6767), FIX8(1.6015),
+    FIX8(1.5263), FIX8(1.4511), FIX8(1.3759), FIX8(1.3008),
+    FIX8(1.2256), FIX8(1.1504), FIX8(1.0752), FIX8(1.0000),
+    FIX8(1.0000), FIX8(0.9285), FIX8(0.8638), FIX8(0.8050),
+    FIX8(0.7513), FIX8(0.7020), FIX8(0.6568), FIX8(0.6152),
+    FIX8(0.5768), FIX8(0.5412), FIX8(0.5082), FIX8(0.4776),
+    FIX8(0.4491), FIX8(0.4226), FIX8(0.3979), FIX8(0.3748),
+    FIX8(0.3532), FIX8(0.3331), FIX8(0.3142), FIX8(0.2964),
+    FIX8(0.2798), FIX8(0.2642), FIX8(0.2496), FIX8(0.2358),
+    FIX8(0.2229), FIX8(0.2107), FIX8(0.1992), FIX8(0.1884),
+    FIX8(0.1782), FIX8(0.1686), FIX8(0.1596), FIX8(0.1510),
+    FIX8(0.1429), FIX8(0.1353), FIX8(0.1282), FIX8(0.1214),
+    FIX8(0.1149), FIX8(0.1089), FIX8(0.1032), FIX8(0.0977),
+    FIX8(0.0926), FIX8(0.0878), FIX8(0.0832), FIX8(0.0788),
+    FIX8(0.0747), FIX8(0.0708), FIX8(0.0671), FIX8(0.0637),
+    FIX8(0.0604), FIX8(0.0572), FIX8(0.0543), FIX8(0.0515),
+    FIX8(0.0488), FIX8(0.0463), FIX8(0.0439), FIX8(0.0416),
+    FIX8(0.0395), FIX8(0.0375), FIX8(0.0355), FIX8(0.0337),
+    FIX8(0.0320), FIX8(0.0303), FIX8(0.0288), FIX8(0.0273)
+}};
 
 
 /*****************************************************************************
@@ -951,24 +984,3 @@ void x264_cabac_encode_flush( x264_t *h, x264_cabac_t *cb )
     }
 }
 
-/*****************************************************************************
- *
- *****************************************************************************/
-void x264_cabac_size_decision( x264_cabac_t *cb, int i_ctx, int b )
-{
-    int i_state = cb->state[i_ctx];
-    cb->state[i_ctx] = x264_cabac_transition[b][i_state];
-    cb->f8_bits_encoded += x264_cabac_entropy[ b ? 127 - i_state : i_state ];
-}
-
-int x264_cabac_size_decision2( uint8_t *state, int b )
-{
-    int i_state = *state;
-    *state = x264_cabac_transition[b][i_state];
-    return x264_cabac_entropy[ b ? 127 - i_state : i_state ];
-}
-
-int x264_cabac_size_decision_noup( uint8_t *state, int b )
-{
-    return x264_cabac_entropy[ b ? 127 - *state : *state ];
-}
diff --git a/common/cabac.h b/common/cabac.h
index 2a86270..9de99b3 100644
--- a/common/cabac.h
+++ b/common/cabac.h
@@ -45,24 +45,43 @@ typedef struct
 
 } x264_cabac_t;
 
+extern const uint8_t x264_cabac_transition[2][128];
+extern const uint16_t x264_cabac_entropy[2][128];
+
 /* init the contexts given i_slice_type, the quantif and the model */
 void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model );
 
 /* encoder only: */
 void x264_cabac_encode_init ( x264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end );
-void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx_idx, int b );
+void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b );
 void x264_cabac_encode_bypass( x264_cabac_t *cb, int b );
 void x264_cabac_encode_terminal( x264_cabac_t *cb );
 void x264_cabac_encode_flush( x264_t *h, x264_cabac_t *cb );
 
-/* internal only. these don't write the bitstream, just calculate bit cost: */
-void x264_cabac_size_decision( x264_cabac_t *cb, int i_ctx, int b );
-int  x264_cabac_size_decision2( uint8_t *state, int b );
-int  x264_cabac_size_decision_noup( uint8_t *state, int b );
-
 static inline int x264_cabac_pos( x264_cabac_t *cb )
 {
     return (cb->p - cb->p_start + cb->i_bytes_outstanding) * 8 + cb->i_queue;
 }
 
+/* internal only. these don't write the bitstream, just calculate bit cost: */
+
+static inline void x264_cabac_size_decision( x264_cabac_t *cb, long i_ctx, long b )
+{
+    int i_state = cb->state[i_ctx];
+    cb->state[i_ctx] = x264_cabac_transition[b][i_state];
+    cb->f8_bits_encoded += x264_cabac_entropy[b][i_state];
+}
+
+static inline int x264_cabac_size_decision2( uint8_t *state, long b )
+{
+    int i_state = *state;
+    *state = x264_cabac_transition[b][i_state];
+    return x264_cabac_entropy[b][i_state];
+}
+
+static inline int x264_cabac_size_decision_noup( uint8_t *state, long b )
+{
+    return x264_cabac_entropy[b][*state];
+}
+
 #endif
diff --git a/encoder/cabac.c b/encoder/cabac.c
index ed7a3f2..bccb4eb 100644
--- a/encoder/cabac.c
+++ b/encoder/cabac.c
@@ -60,7 +60,7 @@ static inline void x264_cabac_mb_type_intra( x264_t *h, x264_cabac_t *cb, int i_
         x264_cabac_encode_decision( cb, ctx0, 1 );
         x264_cabac_encode_terminal( cb );
 
-        x264_cabac_encode_decision( cb, ctx1, ( h->mb.i_cbp_luma == 0 ? 0 : 1 ));
+        x264_cabac_encode_decision( cb, ctx1, !!h->mb.i_cbp_luma );
         if( h->mb.i_cbp_chroma == 0 )
         {
             x264_cabac_encode_decision( cb, ctx2, 0 );
@@ -68,10 +68,10 @@ static inline void x264_cabac_mb_type_intra( x264_t *h, x264_cabac_t *cb, int i_
         else
         {
             x264_cabac_encode_decision( cb, ctx2, 1 );
-            x264_cabac_encode_decision( cb, ctx3, ( h->mb.i_cbp_chroma == 1 ? 0 : 1 ) );
+            x264_cabac_encode_decision( cb, ctx3, h->mb.i_cbp_chroma != 1 );
         }
-        x264_cabac_encode_decision( cb, ctx4, ( (i_pred / 2) ? 1 : 0 ));
-        x264_cabac_encode_decision( cb, ctx5, ( (i_pred % 2) ? 1 : 0 ));
+        x264_cabac_encode_decision( cb, ctx4, i_pred>>1 );
+        x264_cabac_encode_decision( cb, ctx5, i_pred&1 );
     }
 }
 
@@ -381,6 +381,7 @@ static void x264_cabac_mb_qp_delta( x264_t *h, x264_cabac_t *cb )
     x264_cabac_encode_decision( cb, 60 + ctx, 0 );
 }
 
+#ifndef RDO_SKIP_BS
 void x264_cabac_mb_skip( x264_t *h, int b_skip )
 {
     int ctx = 0;
@@ -397,6 +398,7 @@ void x264_cabac_mb_skip( x264_t *h, int b_skip )
     ctx += (h->sh.i_type == SLICE_TYPE_P) ? 11 : 24;
     x264_cabac_encode_decision( &h->cabac, ctx, b_skip );
 }
+#endif
 
 static inline void x264_cabac_mb_sub_p_partition( x264_cabac_t *cb, int i_sub )
 {
diff --git a/encoder/rdo.c b/encoder/rdo.c
index e5c4464..c34fac3 100644
--- a/encoder/rdo.c
+++ b/encoder/rdo.c
@@ -46,7 +46,6 @@ static int cabac_prefix_size[15][128];
 #define x264_cabac_encode_bypass(c,v)     ((c)->f8_bits_encoded += 256)
 #define x264_cabac_encode_flush(h,c)
 #define x264_macroblock_write_cabac  x264_macroblock_size_cabac
-#define x264_cabac_mb_skip  x264_cabac_mb_size_skip_unused
 #include "cabac.c"
 
 



More information about the x264-devel mailing list