diff mbox

[FFmpeg-devel] avcodec/vp3data: combine eob_run_base and eob_run_get_bits tables

Message ID b718bb0c9383b4b332eb943324a3e4568437c1e1.1558749041.git.pross@xvid.org
State Accepted
Commit b6ca032adebe05573d9fe9c3a2625240f55b33b0
Headers show

Commit Message

Peter Ross May 25, 2019, 2:04 a.m. UTC
---
This provides a small readability improvement.
I observe no performance change on x86_64 or arm6.

 libavcodec/vp3.c     | 6 +++---
 libavcodec/vp3data.h | 9 ++++-----
 2 files changed, 7 insertions(+), 8 deletions(-)

Comments

Reimar Döffinger May 26, 2019, 7:27 p.m. UTC | #1
On Sat, May 25, 2019 at 12:04:49PM +1000, Peter Ross wrote:
> ---
> This provides a small readability improvement.
> I observe no performance change on x86_64 or arm6.

Looks good to me, but probably the maintainer should decide.
I guess I'd be very mildly curious to know if the asm code
the compiler generates looks (slightly) better with this change
as I expect, but if I'm honest it's not really relevant.
Peter Ross May 27, 2019, 7:07 a.m. UTC | #2
On Sun, May 26, 2019 at 09:27:55PM +0200, Reimar Döffinger wrote:
> On Sat, May 25, 2019 at 12:04:49PM +1000, Peter Ross wrote:
> > ---
> > This provides a small readability improvement.
> > I observe no performance change on x86_64 or arm6.
> 
> Looks good to me, but probably the maintainer should decide.
> I guess I'd be very mildly curious to know if the asm code
> the compiler generates looks (slightly) better with this change
> as I expect, but if I'm honest it's not really relevant.

ok.

x86_64:

-before patch
+after patch

+       leaq    eob_run_table(%rip), %rcx
        movslq  %edx, %rdx
-       leaq    eob_run_base(%rip), %rcx
-       movzbl  (%rcx,%rdx), %edi
+       movzbl  (%rcx,%rdx,2), %edi
 .LVL540:
-       leaq    eob_run_get_bits(%rip), %rcx
-       movzbl  (%rcx,%rdx), %edx
+       movzbl  1(%rcx,%rdx,2), %edx

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
diff mbox

Patch

diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index b248c90413..63f60c9109 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -988,9 +988,9 @@  static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
         token = get_vlc2(gb, vlc_table, 11, 3);
         /* use the token to get a zero run, a coefficient, and an eob run */
         if ((unsigned) token <= 6U) {
-            eob_run = eob_run_base[token];
-            if (eob_run_get_bits[token])
-                eob_run += get_bits(gb, eob_run_get_bits[token]);
+            eob_run = eob_run_table[token].base;
+            if (eob_run_table[token].bits)
+                eob_run += get_bits(gb, eob_run_table[token].bits);
 
             if (!eob_run)
                 eob_run = INT_MAX;
diff --git a/libavcodec/vp3data.h b/libavcodec/vp3data.h
index c82b1b3a86..d520a10c76 100644
--- a/libavcodec/vp3data.h
+++ b/libavcodec/vp3data.h
@@ -198,11 +198,10 @@  static const int8_t fixed_motion_vector_table[64] = {
 };
 
 /* only tokens 0..6 indicate eob runs */
-static const uint8_t eob_run_base[7] = {
-    1, 2, 3, 4, 8, 16, 0
-};
-static const uint8_t eob_run_get_bits[7] = {
-    0, 0, 0, 2, 3, 4, 12
+static const struct {
+    uint8_t base, bits;
+} eob_run_table[7] = {
+    {1, 0}, {2, 0}, {3, 0}, {4, 2}, {8, 3}, {16, 4}, {0, 12}
 };
 
 static const uint8_t zero_run_base[32] = {