[2/2] golomb: Optimize get_interleaved_ue_golomb

Message ID 1491923186-20000-2-git-send-email-diego@biurrun.de
State New
Headers show

Commit Message

Diego Biurrun April 11, 2017, 3:06 p.m.
From: Alexandra Hájková <alexandra@khirnov.net>

Do not prefetch data too often for short codes.
---
 libavcodec/golomb.h | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Luca Barbato April 11, 2017, 3:36 p.m. | #1
On 11/04/2017 17:06, Diego Biurrun wrote:
> From: Alexandra Hájková <alexandra@khirnov.net>
> 
> Do not prefetch data too often for short codes.
> ---
>  libavcodec/golomb.h | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)

Probably Ok.

Patch

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index cbb5d12..2daedf6 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -105,18 +105,19 @@  static inline unsigned get_interleaved_ue_golomb(BitstreamContext *bc)
 {
     uint32_t buf;
 
-    buf = bitstream_peek(bc, 32);
+    buf = bitstream_peek(bc, 9);
 
-    if (buf & 0xAA800000) {
-        buf >>= 32 - 8;
+    if (buf & 0x155) {
+        buf >>= 1;
         bitstream_skip(bc, ff_interleaved_golomb_vlc_len[buf]);
 
         return ff_interleaved_ue_golomb_vlc_code[buf];
     } else {
-        unsigned ret = 1;
+        unsigned ret = (1 << 4) | ff_interleaved_dirac_golomb_vlc_code[buf >> 1];
 
+        bitstream_skip(bc, 8);
+        buf = bitstream_peek(bc, 8);
         do {
-            buf >>= 32 - 8;
             bitstream_skip(bc, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
 
             if (ff_interleaved_golomb_vlc_len[buf] != 9) {
@@ -125,7 +126,7 @@  static inline unsigned get_interleaved_ue_golomb(BitstreamContext *bc)
                 break;
             }
             ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
-            buf = bitstream_peek(bc, 32);
+            buf = bitstream_peek(bc, 8);
         } while (bitstream_bits_left(bc) > 0);
 
         return ret - 1;