Commit 4f9e958b authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/put_bits: Implement put_bits32() in a single pass instead of 2 passes writing 16bits each

820 cpu cycles -> 660 cpu cycles for 100 put_bits32()
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent db93fd74
......@@ -209,15 +209,37 @@ static inline void put_sbits(PutBitContext *pb, int n, int32_t value)
*/
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
{
int lo = value & 0xffff;
int hi = value >> 16;
unsigned int bit_buf;
int bit_left;
bit_buf = s->bit_buf;
bit_left = s->bit_left;
#ifdef BITSTREAM_WRITER_LE
put_bits(s, 16, lo);
put_bits(s, 16, hi);
bit_buf |= value << (32 - bit_left);
if (3 < s->buf_end - s->buf_ptr) {
AV_WL32(s->buf_ptr, bit_buf);
s->buf_ptr += 4;
} else {
av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too small\n");
av_assert2(0);
}
bit_buf = (uint64_t)value >> bit_left;
#else
put_bits(s, 16, hi);
put_bits(s, 16, lo);
bit_buf = (uint64_t)bit_buf << bit_left;
bit_buf |= value >> (32 - bit_left);
if (3 < s->buf_end - s->buf_ptr) {
AV_WB32(s->buf_ptr, bit_buf);
s->buf_ptr += 4;
} else {
av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too small\n");
av_assert2(0);
}
bit_buf = value;
#endif
s->bit_buf = bit_buf;
s->bit_left = bit_left;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment