History

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().

Andreas Rheinhardt committed 1 year ago

Commit 512e5971 parent 27c82af1 file · +3 −27Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/vc2enc.c+3−27
@@ -189,23 +189,10 @@ typedef struct VC2EncContext { · 188 unmodified lines
189189 static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
190190 {
191191 int i;
192− int bits = 0;
193− unsigned topbit = 1, maxval = 1;
192+ int bits = av_log2(++val);
193+ unsigned topbit = 1 << bits;
194194 uint64_t pbits = 0;
195195
196− if (!val++) {
197− put_bits(pb, 1, 1);
198− return;
199− }
200−
201− while (val > maxval) {
202− topbit <<= 1;
203− maxval <<= 1;
204− maxval |= 1;
205− }
206−
207− bits = ff_log2(topbit);
208−
209196 for (i = 0; i < bits; i++) {
210197 topbit >>= 1;
211198 av_assert2(pbits <= UINT64_MAX>>3);
@@ -219,18 +206,7 @@ static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val) · 7 unmodified lines
219206
220207 static av_always_inline int count_vc2_ue_uint(uint32_t val)
221208 {
222− int topbit = 1, maxval = 1;
223−
224− if (!val++)
225− return 1;
226−
227− while (val > maxval) {
228− topbit <<= 1;
229− maxval <<= 1;
230− maxval |= 1;
231− }
232−
233− return ff_log2(topbit)*2 + 1;
209+ return 2 * av_log2(val + 1) + 1;
234210 }
235211
236212 /* VC-2 10.4 - parse_info() */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t