[x264-devel] CABAC/CAVLC: use the new bit-iterating macro here too
Jason Garrett-Glaser
git at videolan.org
Wed Feb 27 00:18:07 CET 2013
x264 | branch: master | Jason Garrett-Glaser <jason at x264.com> | Thu Feb 14 15:00:48 2013 -0800| [e82cf2c8e3bc0d7623f3e8ed9a4684bc3dc40b91] | committer: Jason Garrett-Glaser
CABAC/CAVLC: use the new bit-iterating macro here too
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=e82cf2c8e3bc0d7623f3e8ed9a4684bc3dc40b91
---
encoder/cabac.c | 16 +++++++---------
encoder/cavlc.c | 33 +++++++++++++++++++++++----------
2 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/encoder/cabac.c b/encoder/cabac.c
index 8bd86f7..5fcc4ff 100644
--- a/encoder/cabac.c
+++ b/encoder/cabac.c
@@ -1052,25 +1052,23 @@ if( (h->mb.i_neighbour & MB_TOP) && !h->mb.mb_transform_size[h->mb.i_mb_top_xy]
MUNGE_8x8_NNZ( BACKUP )
for( int p = 0; p < 3; p++ )
- for( int i = 0; i < 4; i++ )
- if( h->mb.i_cbp_luma & ( 1 << i ) )
- x264_cabac_block_residual_8x8_cbf( h, cb, ctx_cat_plane[DCT_LUMA_8x8][p], i*4+p*16, h->dct.luma8x8[i+p*4], b_intra );
+ FOREACH_BIT( i, 0, h->mb.i_cbp_luma )
+ x264_cabac_block_residual_8x8_cbf( h, cb, ctx_cat_plane[DCT_LUMA_8x8][p], i*4+p*16, h->dct.luma8x8[i+p*4], b_intra );
MUNGE_8x8_NNZ( RESTORE )
}
else
{
- for( int i = 0; i < 4; i++ )
- if( h->mb.i_cbp_luma & ( 1 << i ) )
- x264_cabac_block_residual_8x8( h, cb, DCT_LUMA_8x8, h->dct.luma8x8[i] );
+ FOREACH_BIT( i, 0, h->mb.i_cbp_luma )
+ x264_cabac_block_residual_8x8( h, cb, DCT_LUMA_8x8, h->dct.luma8x8[i] );
}
}
else
{
for( int p = 0; p < plane_count; p++ )
- for( int i = 0; i < 16; i++ )
- if( h->mb.i_cbp_luma & ( 1 << ( i >> 2 ) ) )
- x264_cabac_block_residual_cbf( h, cb, ctx_cat_plane[DCT_LUMA_4x4][p], i+p*16, h->dct.luma4x4[i+p*16], b_intra );
+ FOREACH_BIT( i8x8, 0, h->mb.i_cbp_luma )
+ for( int i = 0; i < 4; i++ )
+ x264_cabac_block_residual_cbf( h, cb, ctx_cat_plane[DCT_LUMA_4x4][p], i+i8x8*4+p*16, h->dct.luma4x4[i+i8x8*4+p*16], b_intra );
}
if( chroma && h->mb.i_cbp_chroma ) /* Chroma DC residual present */
diff --git a/encoder/cavlc.c b/encoder/cavlc.c
index 270531e..e0434f3 100644
--- a/encoder/cavlc.c
+++ b/encoder/cavlc.c
@@ -268,20 +268,33 @@ static inline void x264_cavlc_8x8_mvd( x264_t *h, int i )
}
}
-static inline void x264_cavlc_macroblock_luma_residual( x264_t *h, int i8start, int i8end )
+static ALWAYS_INLINE void x264_cavlc_macroblock_luma_residual( x264_t *h, int plane_count )
{
if( h->mb.b_transform_8x8 )
{
/* shuffle 8x8 dct coeffs into 4x4 lists */
- for( int i8 = i8start; i8 <= i8end; i8++ )
- if( h->mb.cache.non_zero_count[x264_scan8[i8*4]] )
- h->zigzagf.interleave_8x8_cavlc( h->dct.luma4x4[i8*4], h->dct.luma8x8[i8], &h->mb.cache.non_zero_count[x264_scan8[i8*4]] );
+ for( int p = 0; p < plane_count; p++ )
+ for( int i8 = 0; i8 < 4; i8++ )
+ if( h->mb.cache.non_zero_count[x264_scan8[p*16+i8*4]] )
+ h->zigzagf.interleave_8x8_cavlc( h->dct.luma4x4[p*16+i8*4], h->dct.luma8x8[p*4+i8],
+ &h->mb.cache.non_zero_count[x264_scan8[p*16+i8*4]] );
}
- for( int i8 = i8start; i8 <= i8end; i8++ )
- if( h->mb.i_cbp_luma & (1 << (i8&3)) )
+ for( int p = 0; p < plane_count; p++ )
+ FOREACH_BIT( i8, 0, h->mb.i_cbp_luma )
for( int i4 = 0; i4 < 4; i4++ )
- x264_cavlc_block_residual( h, DCT_LUMA_4x4, i4+i8*4, h->dct.luma4x4[i4+i8*4] );
+ x264_cavlc_block_residual( h, DCT_LUMA_4x4, i4+i8*4+p*16, h->dct.luma4x4[i4+i8*4+p*16] );
+}
+
+static ALWAYS_INLINE void x264_cavlc_partition_luma_residual( x264_t *h, int i8, int p )
+{
+ if( h->mb.b_transform_8x8 && h->mb.cache.non_zero_count[x264_scan8[i8*4]] )
+ h->zigzagf.interleave_8x8_cavlc( h->dct.luma4x4[i8*4+p*16], h->dct.luma8x8[i8+p*4],
+ &h->mb.cache.non_zero_count[x264_scan8[i8*4+p*16]] );
+
+ if( h->mb.i_cbp_luma & (1 << i8) )
+ for( int i4 = 0; i4 < 4; i4++ )
+ x264_cavlc_block_residual( h, DCT_LUMA_4x4, i4+i8*4+p*16, h->dct.luma4x4[i4+i8*4+p*16] );
}
static void x264_cavlc_mb_header_i( x264_t *h, int i_mb_type, int i_mb_i_offset, int chroma )
@@ -552,7 +565,7 @@ void x264_macroblock_write_cavlc( x264_t *h )
else if( h->mb.i_cbp_luma | h->mb.i_cbp_chroma )
{
x264_cavlc_qp_delta( h );
- x264_cavlc_macroblock_luma_residual( h, 0, plane_count*4-1 );
+ x264_cavlc_macroblock_luma_residual( h, plane_count );
}
if( h->mb.i_cbp_chroma )
{
@@ -612,7 +625,7 @@ static int x264_partition_size_cavlc( x264_t *h, int i8, int i_pixel )
for( j = (i_pixel < PIXEL_8x8); j >= 0; j-- )
{
for( int p = 0; p < plane_count; p++ )
- x264_cavlc_macroblock_luma_residual( h, p*4+i8, p*4+i8 );
+ x264_cavlc_partition_luma_residual( h, i8, p );
if( h->mb.i_cbp_chroma )
{
if( CHROMA_FORMAT == CHROMA_422 )
@@ -665,7 +678,7 @@ static int x264_partition_i8x8_size_cavlc( x264_t *h, int i8, int i_mode )
h->out.bs.i_bits_encoded = x264_cavlc_intra4x4_pred_size( h, 4*i8, i_mode );
bs_write_ue( &h->out.bs, cbp_to_golomb[!CHROMA444][1][(h->mb.i_cbp_chroma << 4)|h->mb.i_cbp_luma] );
for( int p = 0; p < plane_count; p++ )
- x264_cavlc_macroblock_luma_residual( h, p*4+i8, p*4+i8 );
+ x264_cavlc_partition_luma_residual( h, i8, p );
return h->out.bs.i_bits_encoded;
}
More information about the x264-devel
mailing list