[mythtv] [patch] calc_cbp redux

Daniel Thor Kristjansson danielk at cat.nyu.edu
Sun Aug 22 10:29:19 EDT 2004


So I just tested the calc_cbp I wrote against the one from the
latest ffmpeg merge. Mine is faster. To test them I put both in a
non-static, non-inlined calc_cbp function so the profiler wouldn't
get confused. This new version should do better when inlined since it
has fewer branches per execution unit.

Calc in current CVS
3662      0.6386  libmythavcodec-0.15.so.0.15.0 calc_cbp
Calc in this patch
2744      0.5681  libmythavcodec-0.15.so.0.15.0 calc_cbp
^samples  ^percent of total time in mythtv

-- Daniel
-------------- next part --------------
Index: libs/libavcodec/xvmcvideo.c
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libavcodec/xvmcvideo.c,v
retrieving revision 1.8
diff -r1.8 xvmcvideo.c
72a73,108
> static inline int calc_cbp(MpegEncContext *s)
> {
>     int cbp, cbp1;
> 
>     cbp   = (s->block_last_index[0] >= 0) ? (1 << (5)) : 0;
>     cbp1  = (s->block_last_index[1] >= 0) ? (1 << (4)) : 0;
>     cbp  |= (s->block_last_index[2] >= 0) ? (1 << (3)) : 0;
>     cbp1 |= (s->block_last_index[3] >= 0) ? (1 << (2)) : 0;
>     cbp  |= cbp1;
> 
>     if (s->flags & CODEC_FLAG_GRAY)
>         return cbp; // 4 block for grayscale one done
> 
>     cbp |= (((s->block_last_index[4] >= 0) ? 1 << (1) : 0) | 
>             ((s->block_last_index[5] >= 0) ? 1 << (0) : 0));
> 
>     if (s->chroma_format >= 2) {
>         if (s->chroma_format == 2)
>         { /* CHROMA_422 */
>             cbp |= (((s->block_last_index[4] >= 0) ? 1 << (6+1) : 0) |
>                     ((s->block_last_index[5] >= 0) ? 1 << (6+0) : 0));
>         }
>         else
>         { /* CHROMA_444 */
>             cbp  |= (s->block_last_index[ 6] >= 0) ? 1 << (6+5) : 0;
>             cbp1  = (s->block_last_index[ 7] >= 0) ? 1 << (6+3) : 0;
>             cbp  |= (s->block_last_index[ 8] >= 0) ? 1 << (6+4) : 0;
>             cbp1 |= (s->block_last_index[ 9] >= 0) ? 1 << (6+2) : 0;
>             cbp  |= (s->block_last_index[10] >= 0) ? 1 << (6+1) : 0;
>             cbp1 |= (s->block_last_index[11] >= 0) ? 1 << (6+0) : 0;
>             cbp  |= cbp1;
>         }
>     }
>     return cbp;
> }
> 
333,343c369
<         cbp = 0;
<         for(i=0; i<blocks_per_mb; i++) {
<             cbp+= cbp;
<             if (s->block_last_index[i] >= 0)
<                 cbp++;
<         }
< 
<         if (s->flags & CODEC_FLAG_GRAY && !s->mb_intra)
<             cbp &= 0xf << (blocks_per_mb - 4);
< 
<         mv_block->coded_block_pattern = cbp;
---
>         mv_block->coded_block_pattern = calc_cbp(s);
346c372,373
<         if (0==cbp) mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;
---
>         if (!mv_block->coded_block_pattern)
> 	    mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;


More information about the mythtv-dev mailing list