# HG changeset patch # User arpi_esp # Date 996880155 0 # Node ID 907b67420d846cc1b88df574aa96f838318ac529 # Parent 82d4c9be9873720b8325d40ec072aec5f5a2dc14 inlineing common case of get_bits() -> gives 2speedup. more optim coming soon... diff -r 82d4c9be9873 -r 907b67420d84 common.c --- a/common.c Fri Aug 03 18:33:03 2001 +0000 +++ b/common.c Fri Aug 03 23:09:15 2001 +0000 @@ -199,26 +199,26 @@ } /* n must be >= 1 and <= 32 */ -unsigned int get_bits(GetBitContext *s, int n) +/* also true: n > s->bit_cnt */ +unsigned int get_bits_long(GetBitContext *s, int n) { unsigned int val; int bit_cnt; unsigned int bit_buf; - UINT8 *buf_ptr; #ifdef STATS st_bit_counts[st_current_index] += n; #endif - bit_cnt = s->bit_cnt; bit_buf = s->bit_buf; + bit_cnt = s->bit_cnt - n; - bit_cnt -= n; - if (bit_cnt >= 0) { - /* most common case here */ - val = bit_buf >> (32 - n); - bit_buf <<= n; - } else { +// if (bit_cnt >= 0) { +// val = bit_buf >> (32 - n); +// bit_buf <<= n; +// } else + { + UINT8 *buf_ptr; val = bit_buf >> (32 - n); buf_ptr = s->buf_ptr; buf_ptr += 4; diff -r 82d4c9be9873 -r 907b67420d84 common.h --- a/common.h Fri Aug 03 18:33:03 2001 +0000 +++ b/common.h Fri Aug 03 23:09:15 2001 +0000 @@ -25,9 +25,9 @@ typedef void (*WriteDataFunc)(void *, UINT8 *, int); typedef struct PutBitContext { - UINT8 *buf, *buf_ptr, *buf_end; + UINT32 bit_buf; int bit_cnt; - UINT32 bit_buf; + UINT8 *buf, *buf_ptr, *buf_end; long long data_out_size; /* in bytes */ void *opaque; WriteDataFunc write_data; @@ -49,9 +49,9 @@ /* bit input */ typedef struct GetBitContext { - UINT8 *buf, *buf_ptr, *buf_end; + UINT32 bit_buf; int bit_cnt; - UINT32 bit_buf; + UINT8 *buf, *buf_ptr, *buf_end; } GetBitContext; typedef struct VLC { @@ -64,7 +64,22 @@ void init_get_bits(GetBitContext *s, UINT8 *buffer, int buffer_size); -unsigned int get_bits(GetBitContext *s, int n); +unsigned int get_bits_long(GetBitContext *s, int n); + +static inline unsigned int get_bits(GetBitContext *s, int n){ + if(s->bit_cnt>=n){ + /* most common case here */ + unsigned int val = s->bit_buf >> (32 - n); + s->bit_buf <<= n; + s->bit_cnt -= n; +#ifdef STATS + st_bit_counts[st_current_index] += n; +#endif + return val; + } + return get_bits_long(s,n); +} + void align_get_bits(GetBitContext *s); int init_vlc(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size,