diff mbox series

[FFmpeg-devel,12/12] avcodec/vlc: Use union of uint8_t and uint16_t in VLC_MULTI_ELEM

Message ID GV1P250MB0737E32B852E134D3134D6188F392@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,1/5] avcodec/ppc/hpeldsp_altivec: Fix left-shift of negative number | expand

Checks

Context Check Description
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_fate_x86 success Make fate finished
yinshiyou/make_loongarch64 warning New warnings during build
andriy/make_x86 warning New warnings during build

Commit Message

Andreas Rheinhardt March 30, 2024, 3:15 a.m. UTC
It is more natural and simplifies writing these arrays.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/bitstream_template.h | 2 +-
 libavcodec/vlc.c                | 8 ++++----
 libavcodec/vlc.h                | 5 ++++-
 3 files changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h
index c8e4a5131e..bbb8dfa555 100644
--- a/libavcodec/bitstream_template.h
+++ b/libavcodec/bitstream_template.h
@@ -542,7 +542,7 @@  static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8],
     unsigned idx = BS_FUNC(peek)(bc, bits);
     int ret, nb_bits, code, n = Jtable[idx].len;
     if (Jtable[idx].num) {
-        AV_COPY64U(dst, Jtable[idx].val);
+        AV_COPY64U(dst, Jtable[idx].val8);
         ret = Jtable[idx].num;
     } else {
         code = table[idx].sym;
diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index e01cc41689..e89866e869 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -440,8 +440,8 @@  static void add_level(VLC_MULTI_ELEM *table, const int is16bit,
             code = curcode + (buf[t].code >> curlen);
             newlimit = curlimit - l;
             l  += curlen;
-            if (is16bit) AV_WN16(info.val+2*curlevel, sym);
-            else info.val[curlevel] = sym&0xFF;
+            if (is16bit) info.val16[curlevel] = sym;
+            else info.val8[curlevel] = sym&0xFF;
 
             if (curlevel) { // let's not add single entries
                 uint32_t val = code >> (32 - numbits);
@@ -500,9 +500,9 @@  static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC *single,
         table[j].len = single->table[j].len;
         table[j].num = single->table[j].len > 0 ? 1 : 0;
         if (is16bit)
-            AV_WN16(table[j].val, single->table[j].sym);
+            table[j].val16[0] = single->table[j].sym;
         else
-            table[j].val[0] = single->table[j].sym;
+            table[j].val8[0]  = single->table[j].sym;
     }
 
     add_level(table, is16bit, nb_codes, numbits, buf,
diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h
index 0cc106c499..bf7b0e65b4 100644
--- a/libavcodec/vlc.h
+++ b/libavcodec/vlc.h
@@ -40,7 +40,10 @@  typedef struct VLC {
 } VLC;
 
 typedef struct VLC_MULTI_ELEM {
-    uint8_t val[VLC_MULTI_MAX_SYMBOLS];
+    union {
+        uint8_t   val8[VLC_MULTI_MAX_SYMBOLS];
+        uint16_t val16[VLC_MULTI_MAX_SYMBOLS / 2];
+    };
     int8_t len; // -31,32
     uint8_t num;
 } VLC_MULTI_ELEM;