ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Sat Mar  8 15:45:24 2025 +0100| [512e597932dfe05cf5665192efbe2c93c2e36af2] | 
committer: Andreas Rheinhardt

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.rheinha...@outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=512e597932dfe05cf5665192efbe2c93c2e36af2
---

 libavcodec/vc2enc.c | 30 +++---------------------------
 1 file changed, 3 insertions(+), 27 deletions(-)

diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index aa1ec40f3d..4611c3977b 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -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() */

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to