1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/vc2enc: Simplify writing dirac golomb codes

The earlier code used a loop to determine the number of bits used
and called ff_log2() on a power of two (and it would be easy to
keep track of the exponent of said power-of-two); neither GCC nor
Clang optimized the loop away or avoided the ff_log2().
This patch replaces the loop and the log2 with a single av_log2().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-03-08 15:45:24 +01:00
parent 27c82af2fe
commit 512e597932

View File

@ -189,23 +189,10 @@ typedef struct VC2EncContext {
static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
{
int i;
int bits = 0;
unsigned topbit = 1, maxval = 1;
int bits = av_log2(++val);
unsigned topbit = 1 << bits;
uint64_t pbits = 0;
if (!val++) {
put_bits(pb, 1, 1);
return;
}
while (val > maxval) {
topbit <<= 1;
maxval <<= 1;
maxval |= 1;
}
bits = ff_log2(topbit);
for (i = 0; i < bits; i++) {
topbit >>= 1;
av_assert2(pbits <= UINT64_MAX>>3);
@ -219,18 +206,7 @@ static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
static av_always_inline int count_vc2_ue_uint(uint32_t val)
{
int topbit = 1, maxval = 1;
if (!val++)
return 1;
while (val > maxval) {
topbit <<= 1;
maxval <<= 1;
maxval |= 1;
}
return ff_log2(topbit)*2 + 1;
return 2 * av_log2(val + 1) + 1;
}
/* VC-2 10.4 - parse_info() */