[FFmpeg-cvslog] avcodec/wavpackenc: use ff_clz()

Paul B Mahol git at videolan.org
Thu May 2 16:42:19 EEST 2019


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu May  2 15:35:09 2019 +0200| [bf5d814f1082ea330ba78a591eb426c6c4263c0c] | committer: Paul B Mahol

avcodec/wavpackenc: use ff_clz()

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

 libavcodec/wavpackenc.c | 20 +++-----------------
 libavcodec/wavpackenc.h | 11 -----------
 2 files changed, 3 insertions(+), 28 deletions(-)

diff --git a/libavcodec/wavpackenc.c b/libavcodec/wavpackenc.c
index 979b92165b..95f4b6530c 100644
--- a/libavcodec/wavpackenc.c
+++ b/libavcodec/wavpackenc.c
@@ -637,21 +637,15 @@ static void reverse_mono_decorr(struct Decorr *dpp)
     }
 }
 
+#define count_bits(av) ((av) ? 32 - ff_clz(av) : 0)
+
 static uint32_t log2sample(uint32_t v, int limit, uint32_t *result)
 {
-    uint32_t dbits;
+    uint32_t dbits = count_bits(v);
 
     if ((v += v >> 9) < (1 << 8)) {
-        dbits = nbits_table[v];
         *result += (dbits << 8) + wp_log2_table[(v << (9 - dbits)) & 0xff];
     } else {
-        if (v < (1 << 16))
-            dbits = nbits_table[v >> 8] + 8;
-        else if (v < (1 << 24))
-            dbits = nbits_table[v >> 16] + 16;
-        else
-            dbits = nbits_table[v >> 24] + 24;
-
         *result += dbits = (dbits << 8) + wp_log2_table[(v >> (dbits - 9)) & 0xff];
 
         if (limit && dbits >= limit)
@@ -1969,14 +1963,6 @@ static int wv_stereo(WavPackEncodeContext *s,
     return 0;
 }
 
-#define count_bits(av) ( \
- (av) < (1 << 8) ? nbits_table[av] : \
-  ( \
-   (av) < (1 << 16) ? nbits_table[(av) >> 8] + 8 : \
-   ((av) < (1 << 24) ? nbits_table[(av) >> 16] + 16 : nbits_table[(av) >> 24] + 24) \
-  ) \
-)
-
 static void encode_flush(WavPackEncodeContext *s)
 {
     WavPackWords *w = &s->w;
diff --git a/libavcodec/wavpackenc.h b/libavcodec/wavpackenc.h
index 9dd2a01bbe..11914337cf 100644
--- a/libavcodec/wavpackenc.h
+++ b/libavcodec/wavpackenc.h
@@ -650,15 +650,4 @@ static const uint16_t decorr_filter_sizes[] = {
 
 static const uint8_t decorr_filter_nterms[] = { 2, 5, 10, 16 };
 
-static const int8_t nbits_table[] = {
- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
-};
-
 #endif /* AVCODEC_WAVPACKENC_H */



More information about the ffmpeg-cvslog mailing list