Mercurial > libavcodec.hg
changeset 1875:45a1592dadca libavcodec
* moving some of the commonly used bit reading/writing functions
from common.c -> common.h so that they can be inlined.
+ performace gain ~1% (measured with DV decoding)
+ code bloat 0.05%
Looks like a win-win solution.
author | romansh |
---|---|
date | Fri, 12 Mar 2004 23:39:38 +0000 |
parents | fab737b59790 |
children | 72ac356803ea |
files | common.c common.h dv.c |
diffstat | 3 files changed, 99 insertions(+), 113 deletions(-) [+] |
line wrap: on
line diff
--- a/common.c Thu Mar 11 13:22:39 2004 +0000 +++ b/common.c Fri Mar 12 23:39:38 2004 +0000 @@ -45,34 +45,6 @@ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }; -void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) -{ - s->buf = buffer; - s->buf_end = s->buf + buffer_size; -#ifdef ALT_BITSTREAM_WRITER - s->index=0; - ((uint32_t*)(s->buf))[0]=0; -// memset(buffer, 0, buffer_size); -#else - s->buf_ptr = s->buf; - s->bit_left=32; - s->bit_buf=0; -#endif -} - -//#ifdef CONFIG_ENCODERS -#if 1 - -/* return the number of bits output */ -int put_bits_count(PutBitContext *s) -{ -#ifdef ALT_BITSTREAM_WRITER - return s->index; -#else - return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; -#endif -} - void align_put_bits(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER @@ -82,28 +54,6 @@ #endif } -#endif //CONFIG_ENCODERS - -/* pad the end of the output stream with zeros */ -void flush_put_bits(PutBitContext *s) -{ -#ifdef ALT_BITSTREAM_WRITER - align_put_bits(s); -#else - s->bit_buf<<= s->bit_left; - while (s->bit_left < 32) { - /* XXX: should test end of buffer */ - *s->buf_ptr++=s->bit_buf >> 24; - s->bit_buf<<=8; - s->bit_left+=8; - } - s->bit_left=32; - s->bit_buf=0; -#endif -} - -#ifdef CONFIG_ENCODERS - void put_string(PutBitContext * pbc, char *s, int put_zero) { while(*s){ @@ -116,55 +66,6 @@ /* bit input functions */ -#endif //CONFIG_ENCODERS - -/** - * init GetBitContext. - * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits - * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end - * @param bit_size the size of the buffer in bits - */ -void init_get_bits(GetBitContext *s, - const uint8_t *buffer, int bit_size) -{ - const int buffer_size= (bit_size+7)>>3; - - s->buffer= buffer; - s->size_in_bits= bit_size; - s->buffer_end= buffer + buffer_size; -#ifdef ALT_BITSTREAM_READER - s->index=0; -#elif defined LIBMPEG2_BITSTREAM_READER -#ifdef LIBMPEG2_BITSTREAM_READER_HACK - if ((int)buffer&1) { - /* word alignment */ - s->cache = (*buffer++)<<24; - s->buffer_ptr = buffer; - s->bit_count = 16-8; - } else -#endif - { - s->buffer_ptr = buffer; - s->bit_count = 16; - s->cache = 0; - } -#elif defined A32_BITSTREAM_READER - s->buffer_ptr = (uint32_t*)buffer; - s->bit_count = 32; - s->cache0 = 0; - s->cache1 = 0; -#endif - { - OPEN_READER(re, s) - UPDATE_CACHE(re, s) - UPDATE_CACHE(re, s) - CLOSE_READER(re, s) - } -#ifdef A32_BITSTREAM_READER - s->cache1 = 0; -#endif -} - /** * reads 0-32 bits. */
--- a/common.h Thu Mar 11 13:22:39 2004 +0000 +++ b/common.h Fri Mar 12 23:39:38 2004 +0000 @@ -292,11 +292,55 @@ #endif } PutBitContext; -void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size); +static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) +{ + s->buf = buffer; + s->buf_end = s->buf + buffer_size; +#ifdef ALT_BITSTREAM_WRITER + s->index=0; + ((uint32_t*)(s->buf))[0]=0; +// memset(buffer, 0, buffer_size); +#else + s->buf_ptr = s->buf; + s->bit_left=32; + s->bit_buf=0; +#endif +} + +/* return the number of bits output */ +static inline int put_bits_count(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + return s->index; +#else + return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; +#endif +} -int put_bits_count(PutBitContext *s); +static inline int put_bits_left(PutBitContext* s) +{ + return (s->buf_end - s->buf) * 8 - put_bits_count(s); +} + +/* pad the end of the output stream with zeros */ +static inline void flush_put_bits(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + align_put_bits(s); +#else + s->bit_buf<<= s->bit_left; + while (s->bit_left < 32) { + /* XXX: should test end of buffer */ + *s->buf_ptr++=s->bit_buf >> 24; + s->bit_buf<<=8; + s->bit_left+=8; + } + s->bit_left=32; + s->bit_buf=0; +#endif +} + void align_put_bits(PutBitContext *s); -void flush_put_bits(PutBitContext *s); void put_string(PutBitContext * pbc, char *s, int put_zero); /* bit input */ @@ -318,8 +362,6 @@ int size_in_bits; } GetBitContext; -static inline int get_bits_count(GetBitContext *s); - #define VLC_TYPE int16_t typedef struct VLC { @@ -825,8 +867,57 @@ skip_bits(s, 1); } -void init_get_bits(GetBitContext *s, - const uint8_t *buffer, int buffer_size); +/** + * init GetBitContext. + * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits + * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end + * @param bit_size the size of the buffer in bits + */ +static inline void init_get_bits(GetBitContext *s, + const uint8_t *buffer, int bit_size) +{ + const int buffer_size= (bit_size+7)>>3; + + s->buffer= buffer; + s->size_in_bits= bit_size; + s->buffer_end= buffer + buffer_size; +#ifdef ALT_BITSTREAM_READER + s->index=0; +#elif defined LIBMPEG2_BITSTREAM_READER +#ifdef LIBMPEG2_BITSTREAM_READER_HACK + if ((int)buffer&1) { + /* word alignment */ + s->cache = (*buffer++)<<24; + s->buffer_ptr = buffer; + s->bit_count = 16-8; + } else +#endif + { + s->buffer_ptr = buffer; + s->bit_count = 16; + s->cache = 0; + } +#elif defined A32_BITSTREAM_READER + s->buffer_ptr = (uint32_t*)buffer; + s->bit_count = 32; + s->cache0 = 0; + s->cache1 = 0; +#endif + { + OPEN_READER(re, s) + UPDATE_CACHE(re, s) + UPDATE_CACHE(re, s) + CLOSE_READER(re, s) + } +#ifdef A32_BITSTREAM_READER + s->cache1 = 0; +#endif +} + +static inline int get_bits_left(GetBitContext *s) +{ + return s->size_in_bits - get_bits_count(s); +} int check_marker(GetBitContext *s, const char *msg); void align_get_bits(GetBitContext *s);
--- a/dv.c Thu Mar 11 13:22:39 2004 +0000 +++ b/dv.c Fri Mar 12 23:39:38 2004 +0000 @@ -642,12 +642,6 @@ uint32_t partial_bit_buffer; /* we can't use uint16_t here */ } EncBlockInfo; -static always_inline int dv_bits_left(PutBitContext* s) -{ - return (s->buf_end - s->buf) * 8 - - ((s->buf_ptr - s->buf) * 8 + 32 - (int64_t)s->bit_left); -} - static always_inline void dv_encode_ac(EncBlockInfo* bi, PutBitContext* pb_pool, int pb_size) { @@ -660,7 +654,7 @@ bi->partial_bit_count = bi->partial_bit_buffer = 0; vlc_loop: /* Find suitable storage space */ - for (; size > (bits_left = dv_bits_left(pb)); pb++) { + for (; size > (bits_left = put_bits_left(pb)); pb++) { if (bits_left) { size -= bits_left; put_bits(pb, bits_left, vlc >> size);