[x264-devel] commit: faster cabac_encode_ue_bypass (Loren Merritt )

git version control git at videolan.org
Mon Mar 24 10:12:37 CET 2008


x264 | branch: master | Loren Merritt <pengvado at akuvian.org> | Mon Mar 24 01:56:31 2008 -0600| [1035c63eb9ef354670c3c16f23fd3ac2bb88ec19]

faster cabac_encode_ue_bypass

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

 common/cabac.c  |   19 +++++++++++++++++++
 common/cabac.h  |    1 +
 encoder/cabac.c |   17 -----------------
 encoder/rdo.c   |    1 +
 4 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/common/cabac.c b/common/cabac.c
index 6ecb9a5..ad5d203 100644
--- a/common/cabac.c
+++ b/common/cabac.c
@@ -919,6 +919,25 @@ void x264_cabac_encode_bypass( x264_cabac_t *cb, int b )
     x264_cabac_putbyte( cb );
 }
 
+void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val )
+{
+    int k, i;
+    uint32_t x;
+    for( k = exp_bits; val >= (1<<k); k++ )
+        val -= 1<<k;
+    x = (((1<<(k-exp_bits))-1)<<(k+1))+val;
+    k = 2*k+1-exp_bits;
+    i = ((k-1)&7)+1;
+    do {
+        k -= i;
+        cb->i_low <<= i;
+        cb->i_low += ((x>>k)&0xff) * cb->i_range;
+        cb->i_queue += i;
+        x264_cabac_putbyte( cb );
+        i = 8;
+    } while( k > 0 );
+}
+
 void x264_cabac_encode_terminal( x264_cabac_t *cb )
 {
     cb->i_range -= 2;
diff --git a/common/cabac.h b/common/cabac.h
index c0a2e18..709c516 100644
--- a/common/cabac.h
+++ b/common/cabac.h
@@ -55,6 +55,7 @@ void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int
 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, int b );
 void x264_cabac_encode_bypass( x264_cabac_t *cb, int b );
+void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val );
 void x264_cabac_encode_terminal( x264_cabac_t *cb );
 void x264_cabac_encode_flush( x264_t *h, x264_cabac_t *cb );
 
diff --git a/encoder/cabac.c b/encoder/cabac.c
index bccb4eb..e150cb0 100644
--- a/encoder/cabac.c
+++ b/encoder/cabac.c
@@ -24,23 +24,6 @@
 #include "common/common.h"
 #include "macroblock.h"
 
-static inline void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val )
-{
-#ifdef RDO_SKIP_BS
-    cb->f8_bits_encoded += ( bs_size_ue( val + (1<<exp_bits)-1 ) - exp_bits ) << 8;
-#else
-    int k;
-    for( k = exp_bits; val >= (1<<k); k++ )
-    {
-        x264_cabac_encode_bypass( cb, 1 );
-        val -= 1 << k;
-    }
-    x264_cabac_encode_bypass( cb, 0 );
-    while( k-- )
-        x264_cabac_encode_bypass( cb, (val >> k)&0x01 );
-#endif
-}
-
 static inline void x264_cabac_mb_type_intra( x264_t *h, x264_cabac_t *cb, int i_mb_type,
                     int ctx0, int ctx1, int ctx2, int ctx3, int ctx4, int ctx5 )
 {
diff --git a/encoder/rdo.c b/encoder/rdo.c
index c34fac3..7f29af7 100644
--- a/encoder/rdo.c
+++ b/encoder/rdo.c
@@ -44,6 +44,7 @@ static int cabac_prefix_size[15][128];
 #define x264_cabac_encode_decision(c,x,v) x264_cabac_size_decision(c,x,v)
 #define x264_cabac_encode_terminal(c)     x264_cabac_size_decision(c,276,0)
 #define x264_cabac_encode_bypass(c,v)     ((c)->f8_bits_encoded += 256)
+#define x264_cabac_encode_ue_bypass(c,e,v) ((c)->f8_bits_encoded += (bs_size_ue(v+(1<<e)-1)-e)<<8)
 #define x264_cabac_encode_flush(h,c)
 #define x264_macroblock_write_cabac  x264_macroblock_size_cabac
 #include "cabac.c"



More information about the x264-devel mailing list