From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] avcodec/vc2enc: Simplify writing dirac golomb codes Date: Sat, 8 Mar 2025 16:28:02 +0100 Message-ID: <DU0P250MB07470AB13A6D81A0C825E2D48FD42@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM> (raw) [-- Attachment #1: Type: text/plain, Size: 27 bytes --] Patch attached. - Andreas [-- Attachment #2: 0001-avcodec-vc2enc-Simplify-writing-dirac-golomb-codes.patch --] [-- Type: text/x-patch, Size: 1954 bytes --] From 4e50b2adb6de16754b629eaf18fc92d67ecdf1ca Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Sat, 8 Mar 2025 15:45:24 +0100 Subject: [PATCH] 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> --- libavcodec/vc2enc.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c index b82370a753..8e68d7a89d 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() */ -- 2.45.2 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2025-03-08 15:28 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-03-08 15:28 Andreas Rheinhardt [this message] 2025-03-08 18:31 ` Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=DU0P250MB07470AB13A6D81A0C825E2D48FD42@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git