[FFmpeg-cvslog] avcodec/speedhqenc: Hardcode table to save space

Andreas Rheinhardt git at videolan.org
Wed May 5 19:27:52 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Thu Dec 10 09:19:08 2020 +0100| [03008c2811ec26cf338780a89b6b2b849b399e3c] | committer: Andreas Rheinhardt

avcodec/speedhqenc: Hardcode table to save space

The SpeedHQ encoder currently reverses the entries of two small tables
and stores them in other tables. These other tables have a size of 48
bytes, yet the code for their initialization takes 135 bytes (GCC 9.3,
x64, O3 albeit in an av_cold function). So remove the runtime
initialization and hardcode the tables.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

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

 libavcodec/speedhqenc.c | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 529df4f5b6..43437223db 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -38,8 +38,13 @@
 extern RLTable ff_rl_speedhq;
 static uint8_t speedhq_static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3];
 
-static uint16_t mpeg12_vlc_dc_lum_code_reversed[12];
-static uint16_t mpeg12_vlc_dc_chroma_code_reversed[12];
+/* Exactly the same as MPEG-2, except little-endian. */
+static const uint16_t mpeg12_vlc_dc_lum_code_reversed[12] = {
+    0x1, 0x0, 0x2, 0x5, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF
+};
+static const uint16_t mpeg12_vlc_dc_chroma_code_reversed[12] = {
+    0x0, 0x2, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF
+};
 
 /* simple include everything table for dc, first byte is bits
  * number next 3 are code */
@@ -48,30 +53,8 @@ static uint32_t speedhq_chr_dc_uni[512];
 
 static uint8_t uni_speedhq_ac_vlc_len[64 * 64 * 2];
 
-static uint32_t reverse(uint32_t num, int bits)
-{
-    return bitswap_32(num) >> (32 - bits);
-}
-
-static void reverse_code(const uint16_t *code, const uint8_t *bits,
-                         uint16_t *reversed_code, int num_entries)
-{
-    for (int i = 0; i < num_entries; i++)
-        reversed_code[i] = reverse(code[i], bits[i]);
-}
-
 static av_cold void speedhq_init_static_data(void)
 {
-    /* Exactly the same as MPEG-2, except little-endian. */
-    reverse_code(ff_mpeg12_vlc_dc_lum_code,
-                 ff_mpeg12_vlc_dc_lum_bits,
-                 mpeg12_vlc_dc_lum_code_reversed,
-                 12);
-    reverse_code(ff_mpeg12_vlc_dc_chroma_code,
-                 ff_mpeg12_vlc_dc_chroma_bits,
-                 mpeg12_vlc_dc_chroma_code_reversed,
-                 12);
-
     ff_rl_init(&ff_rl_speedhq, speedhq_static_rl_table_store);
 
     /* build unified dc encoding tables */



More information about the ffmpeg-cvslog mailing list