[1/2] golomb: Optimize get_ue/se_golomb

Message ID 1491923186-20000-1-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 | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

Comments

Hendrik Leppkes April 11, 2017, 3:15 p.m. | #1
On Tue, Apr 11, 2017 at 5:06 PM, Diego Biurrun <diego@biurrun.de> wrote:
> From: Alexandra Hájková <alexandra@khirnov.net>
>
> Do not prefetch data too often for short codes.
> ---
>  libavcodec/golomb.h | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
>

Are there any numbers for these changes?

- Hendrik
Luca Barbato April 11, 2017, 3:36 p.m. | #2
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 | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
> 

Seems fine.
Diego Biurrun April 11, 2017, 3:42 p.m. | #3
On Tue, Apr 11, 2017 at 05:15:50PM +0200, Hendrik Leppkes wrote:
> On Tue, Apr 11, 2017 at 5:06 PM, Diego Biurrun <diego@biurrun.de> wrote:
> > From: Alexandra Hájková <alexandra@khirnov.net>
> >
> > Do not prefetch data too often for short codes.
> > ---
> >  libavcodec/golomb.h | 32 ++++++++++++++++----------------
> >  1 file changed, 16 insertions(+), 16 deletions(-)
> 
> Are there any numbers for these changes?

No, I haven't benchmarked these in isolation.

Diego

Patch

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 648f924..cbb5d12 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -54,20 +54,20 @@  static inline int get_ue_golomb(BitstreamContext *bc)
 {
     unsigned int buf;
 
-    buf = bitstream_peek(bc, 32);
+    buf = bitstream_peek(bc, 9);
 
-    if (buf >= (1 << 27)) {
-        buf >>= 32 - 9;
+    if (buf >= (1 << 4)) {
         bitstream_skip(bc, ff_golomb_vlc_len[buf]);
 
         return ff_ue_golomb_vlc_code[buf];
     } else {
-        int log = 2 * av_log2(buf) - 31;
-        buf >>= log;
-        buf--;
+        unsigned int buf2 = bitstream_peek(bc, 32);
+        int log = 2 * av_log2(buf2) - 31;
+        buf2 >>= log;
+        buf2--;
         bitstream_skip(bc, 32 - log);
 
-        return buf;
+        return buf2;
     }
 }
 
@@ -167,25 +167,25 @@  static inline int get_se_golomb(BitstreamContext *bc)
 {
     unsigned int buf;
 
-    buf = bitstream_peek(bc, 32);
+    buf = bitstream_peek(bc, 9);
 
-    if (buf >= (1 << 27)) {
-        buf >>= 32 - 9;
+    if (buf >= (1 << 4)) {
         bitstream_skip(bc, ff_golomb_vlc_len[buf]);
 
         return ff_se_golomb_vlc_code[buf];
     } else {
-        int log = 2 * av_log2(buf) - 31;
-        buf >>= log;
+        unsigned int buf2 = bitstream_peek(bc, 32);
+        int log = 2 * av_log2(buf2) - 31;
+        buf2 >>= log;
 
         bitstream_skip(bc, 32 - log);
 
-        if (buf & 1)
-            buf = -(buf >> 1);
+        if (buf2 & 1)
+            buf2 = -(buf2 >> 1);
         else
-            buf = (buf >> 1);
+            buf2 = (buf2 >> 1);
 
-        return buf;
+        return buf2;
     }
 }