diff mbox series

[FFmpeg-devel,38/39] avcodec/speedhqenc: Hardcode table to save space

Message ID 20201210111657.2276739-39-andreas.rheinhardt@gmail.com
State New
Headers show
Series Make mpegvideo encoders init-threadsafe
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 10, 2020, 11:16 a.m. UTC
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@gmail.com>
---
 libavcodec/speedhqenc.c | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index dbc638cb82..abad87632f 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 */