Browse Source

inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...

Originally committed as revision 31 to svn://svn.ffmpeg.org/ffmpeg/trunk
tags/v0.5
Arpi 24 years ago
parent
commit
2931ecb90f
2 changed files with 29 additions and 14 deletions
  1. +9
    -9
      libavcodec/common.c
  2. +20
    -5
      libavcodec/common.h

+ 9
- 9
libavcodec/common.c View File

@@ -199,26 +199,26 @@ void init_get_bits(GetBitContext *s,
} }


/* n must be >= 1 and <= 32 */ /* 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; unsigned int val;
int bit_cnt; int bit_cnt;
unsigned int bit_buf; unsigned int bit_buf;
UINT8 *buf_ptr;


#ifdef STATS #ifdef STATS
st_bit_counts[st_current_index] += n; st_bit_counts[st_current_index] += n;
#endif #endif


bit_cnt = s->bit_cnt;
bit_buf = s->bit_buf; 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); val = bit_buf >> (32 - n);
buf_ptr = s->buf_ptr; buf_ptr = s->buf_ptr;
buf_ptr += 4; buf_ptr += 4;


+ 20
- 5
libavcodec/common.h View File

@@ -25,9 +25,9 @@ struct PutBitContext;
typedef void (*WriteDataFunc)(void *, UINT8 *, int); typedef void (*WriteDataFunc)(void *, UINT8 *, int);


typedef struct PutBitContext { typedef struct PutBitContext {
UINT8 *buf, *buf_ptr, *buf_end;
int bit_cnt;
UINT32 bit_buf; UINT32 bit_buf;
int bit_cnt;
UINT8 *buf, *buf_ptr, *buf_end;
long long data_out_size; /* in bytes */ long long data_out_size; /* in bytes */
void *opaque; void *opaque;
WriteDataFunc write_data; WriteDataFunc write_data;
@@ -49,9 +49,9 @@ void jflush_put_bits(PutBitContext *s);
/* bit input */ /* bit input */


typedef struct GetBitContext { typedef struct GetBitContext {
UINT8 *buf, *buf_ptr, *buf_end;
int bit_cnt;
UINT32 bit_buf; UINT32 bit_buf;
int bit_cnt;
UINT8 *buf, *buf_ptr, *buf_end;
} GetBitContext; } GetBitContext;


typedef struct VLC { typedef struct VLC {
@@ -64,7 +64,22 @@ typedef struct VLC {
void init_get_bits(GetBitContext *s, void init_get_bits(GetBitContext *s,
UINT8 *buffer, int buffer_size); 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); void align_get_bits(GetBitContext *s);
int init_vlc(VLC *vlc, int nb_bits, int nb_codes, int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
const void *bits, int bits_wrap, int bits_size, const void *bits, int bits_wrap, int bits_size,


Loading…
Cancel
Save