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

Unified · Split

libavcodec/vc2enc.c+3−27
@@ -189,23 +189,10 @@ typedef struct VC2EncContext { · 188 unmodified lines
189static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)189static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
190{190{
191 int i;191 int i;
192 int bits = 0;192 int bits = av_log2(++val);
193 unsigned topbit = 1, maxval = 1;193 unsigned topbit = 1 << bits;
194 uint64_t pbits = 0;194 uint64_t pbits = 0;
195 195
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
209 for (i = 0; i < bits; i++) {196 for (i = 0; i < bits; i++) {
210 topbit >>= 1;197 topbit >>= 1;
211 av_assert2(pbits <= UINT64_MAX>>3);198 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
219 206
220static av_always_inline int count_vc2_ue_uint(uint32_t val)207static av_always_inline int count_vc2_ue_uint(uint32_t val)
221{208{
222 int topbit = 1, maxval = 1;209 return 2 * av_log2(val + 1) + 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;
234}210}
235 211
236/* VC-2 10.4 - parse_info() */212/* 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