diff mbox

[FFmpeg-devel] libavcodec: Reduce the size of some arrays

Message ID 20190619023947.15222-1-andreas.rheinhardt@gmail.com
State Accepted
Commit a1a8815220fcb844b645ce32cb1593e744798419
Headers show

Commit Message

Andreas Rheinhardt June 19, 2019, 2:39 a.m. UTC
This commit uses smaller types for some static const arrays to reduce
their size in case the entries can be represented in the smaller type.
The biggest savings came from inv_map_table in vp9.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/a64multienc.c              |  6 +++---
 libavcodec/ac3enc.c                   |  2 +-
 libavcodec/adpcm.c                    |  8 ++++----
 libavcodec/aic.c                      |  4 ++--
 libavcodec/atrac3plus.c               | 12 ++++++------
 libavcodec/atrac3plusdsp.c            |  4 ++--
 libavcodec/atrac9dec.c                |  2 +-
 libavcodec/cbs_h264_syntax_template.c |  2 +-
 libavcodec/cbs_vp9_syntax_template.c  |  4 ++--
 libavcodec/vp9.c                      |  2 +-
 10 files changed, 23 insertions(+), 23 deletions(-)

Comments

Michael Niedermayer June 19, 2019, 7:08 p.m. UTC | #1
On Wed, Jun 19, 2019 at 04:39:47AM +0200, Andreas Rheinhardt wrote:
> This commit uses smaller types for some static const arrays to reduce
> their size in case the entries can be represented in the smaller type.
> The biggest savings came from inv_map_table in vp9.c.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/a64multienc.c              |  6 +++---
>  libavcodec/ac3enc.c                   |  2 +-
>  libavcodec/adpcm.c                    |  8 ++++----
>  libavcodec/aic.c                      |  4 ++--
>  libavcodec/atrac3plus.c               | 12 ++++++------
>  libavcodec/atrac3plusdsp.c            |  4 ++--
>  libavcodec/atrac9dec.c                |  2 +-
>  libavcodec/cbs_h264_syntax_template.c |  2 +-
>  libavcodec/cbs_vp9_syntax_template.c  |  4 ++--
>  libavcodec/vp9.c                      |  2 +-
>  10 files changed, 23 insertions(+), 23 deletions(-)

should be ok

thanks

[...]
James Almer June 20, 2019, 5:59 p.m. UTC | #2
On 6/19/2019 4:08 PM, Michael Niedermayer wrote:
> On Wed, Jun 19, 2019 at 04:39:47AM +0200, Andreas Rheinhardt wrote:
>> This commit uses smaller types for some static const arrays to reduce
>> their size in case the entries can be represented in the smaller type.
>> The biggest savings came from inv_map_table in vp9.c.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
>> ---
>>  libavcodec/a64multienc.c              |  6 +++---
>>  libavcodec/ac3enc.c                   |  2 +-
>>  libavcodec/adpcm.c                    |  8 ++++----
>>  libavcodec/aic.c                      |  4 ++--
>>  libavcodec/atrac3plus.c               | 12 ++++++------
>>  libavcodec/atrac3plusdsp.c            |  4 ++--
>>  libavcodec/atrac9dec.c                |  2 +-
>>  libavcodec/cbs_h264_syntax_template.c |  2 +-
>>  libavcodec/cbs_vp9_syntax_template.c  |  4 ++--
>>  libavcodec/vp9.c                      |  2 +-
>>  10 files changed, 23 insertions(+), 23 deletions(-)
> 
> should be ok
> 
> thanks

Pushed.
diff mbox

Patch

diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index 91aac0933f..38f25020f5 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -60,11 +60,11 @@  typedef struct A64Context {
 } A64Context;
 
 /* gray gradient */
-static const int mc_colors[5]={0x0,0xb,0xc,0xf,0x1};
+static const uint8_t mc_colors[5]={0x0,0xb,0xc,0xf,0x1};
 
 /* other possible gradients - to be tested */
-//static const int mc_colors[5]={0x0,0x8,0xa,0xf,0x7};
-//static const int mc_colors[5]={0x0,0x9,0x8,0xa,0x3};
+//static const uint8_t mc_colors[5]={0x0,0x8,0xa,0xf,0x7};
+//static const uint8_t mc_colors[5]={0x0,0x9,0x8,0xa,0x3};
 
 static void to_meta_with_crop(AVCodecContext *avctx,
                               const AVFrame *p, int *dest)
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index e7e18af92d..f1c95ce877 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -652,7 +652,7 @@  void ff_ac3_process_exponents(AC3EncodeContext *s)
  */
 static void count_frame_bits_fixed(AC3EncodeContext *s)
 {
-    static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
+    static const uint8_t frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
     int blk;
     int frame_bits;
 
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index ede0130bf1..e194764374 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -57,7 +57,7 @@ 
  */
 
 /* These are for CD-ROM XA ADPCM */
-static const int xa_adpcm_table[5][2] = {
+static const int8_t xa_adpcm_table[5][2] = {
     {   0,   0 },
     {  60,   0 },
     { 115, -52 },
@@ -65,7 +65,7 @@  static const int xa_adpcm_table[5][2] = {
     { 122, -60 }
 };
 
-static const int ea_adpcm_table[] = {
+static const int16_t ea_adpcm_table[] = {
     0,  240,  460,  392,
     0,    0, -208, -220,
     0,    1,    3,    4,
@@ -74,7 +74,7 @@  static const int ea_adpcm_table[] = {
 };
 
 // padded to zero where table size is less then 16
-static const int swf_index_tables[4][16] = {
+static const int8_t swf_index_tables[4][16] = {
     /*2*/ { -1, 2 },
     /*3*/ { -1, -1, 2, 4 },
     /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
@@ -484,7 +484,7 @@  static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_
 {
     ADPCMDecodeContext *c = avctx->priv_data;
     GetBitContext gb;
-    const int *table;
+    const int8_t *table;
     int k0, signmask, nb_bits, count;
     int size = buf_size*8;
     int i;
diff --git a/libavcodec/aic.c b/libavcodec/aic.c
index dc28c83661..956d71fcff 100644
--- a/libavcodec/aic.c
+++ b/libavcodec/aic.c
@@ -42,9 +42,9 @@  enum AICBands {
     NUM_BANDS
 };
 
-static const int aic_num_band_coeffs[NUM_BANDS] = { 64, 32, 192, 96 };
+static const uint8_t aic_num_band_coeffs[NUM_BANDS] = { 64, 32, 192, 96 };
 
-static const int aic_band_off[NUM_BANDS] = { 0, 64, 96, 288 };
+static const uint16_t aic_band_off[NUM_BANDS] = { 0, 64, 96, 288 };
 
 static const uint8_t aic_quant_matrix[64] = {
      8, 16, 19, 22, 22, 26, 26, 27,
diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index 3e3bba801b..9f964efb4d 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -81,8 +81,8 @@  av_cold void ff_atrac3p_init_vlcs(void)
 {
     int i, wl_vlc_offs, ct_vlc_offs, sf_vlc_offs, tab_offset;
 
-    static const int wl_nb_bits[4]  = { 2, 3, 5, 5 };
-    static const int wl_nb_codes[4] = { 3, 5, 8, 8 };
+    static const uint8_t wl_nb_bits[4]  = { 2, 3, 5, 5 };
+    static const uint8_t wl_nb_codes[4] = { 3, 5, 8, 8 };
     static const uint8_t * const wl_bits[4] = {
         atrac3p_wl_huff_bits1, atrac3p_wl_huff_bits2,
         atrac3p_wl_huff_bits3, atrac3p_wl_huff_bits4
@@ -95,8 +95,8 @@  av_cold void ff_atrac3p_init_vlcs(void)
         atrac3p_wl_huff_xlat1, atrac3p_wl_huff_xlat2, NULL, NULL
     };
 
-    static const int ct_nb_bits[4]  = { 3, 4, 4, 4 };
-    static const int ct_nb_codes[4] = { 4, 8, 8, 8 };
+    static const uint8_t ct_nb_bits[4]  = { 3, 4, 4, 4 };
+    static const uint8_t ct_nb_codes[4] = { 4, 8, 8, 8 };
     static const uint8_t * const ct_bits[4]  = {
         atrac3p_ct_huff_bits1, atrac3p_ct_huff_bits2,
         atrac3p_ct_huff_bits2, atrac3p_ct_huff_bits3
@@ -109,8 +109,8 @@  av_cold void ff_atrac3p_init_vlcs(void)
         NULL, NULL, atrac3p_ct_huff_xlat1, NULL
     };
 
-    static const int sf_nb_bits[8]  = {  9,  9,  9,  9,  6,  6,  7,  7 };
-    static const int sf_nb_codes[8] = { 64, 64, 64, 64, 16, 16, 16, 16 };
+    static const uint8_t sf_nb_bits[8]  = {  9,  9,  9,  9,  6,  6,  7,  7 };
+    static const uint8_t sf_nb_codes[8] = { 64, 64, 64, 64, 16, 16, 16, 16 };
     static const uint8_t  * const sf_bits[8]  = {
         atrac3p_sf_huff_bits1, atrac3p_sf_huff_bits1, atrac3p_sf_huff_bits2,
         atrac3p_sf_huff_bits3, atrac3p_sf_huff_bits4, atrac3p_sf_huff_bits4,
diff --git a/libavcodec/atrac3plusdsp.c b/libavcodec/atrac3plusdsp.c
index 96aa402c2b..ca3154e133 100644
--- a/libavcodec/atrac3plusdsp.c
+++ b/libavcodec/atrac3plusdsp.c
@@ -248,7 +248,7 @@  void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *f
         out[i] += wavreg1[i] + wavreg2[i];
 }
 
-static const int subband_to_powgrp[ATRAC3P_SUBBANDS] = {
+static const uint8_t subband_to_powgrp[ATRAC3P_SUBBANDS] = {
     0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4
 };
 
@@ -411,7 +411,7 @@  static const float pwc_levs[16] = {
 };
 
 /** Map subband number to quant unit number. */
-static const int subband_to_qu[17] = {
+static const uint8_t subband_to_qu[17] = {
     0, 8, 12, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
 };
 
diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index 805d46f3b8..894c70c7fc 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -241,7 +241,7 @@  static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
                                     ATRAC9ChannelData *c, GetBitContext *gb,
                                     int channel_idx, int first_in_pkt)
 {
-    static const int mode_map[2][4] = { { 0, 1, 2, 3 }, { 0, 2, 3, 4 } };
+    static const uint8_t mode_map[2][4] = { { 0, 1, 2, 3 }, { 0, 2, 3, 4 } };
     const int mode = mode_map[channel_idx][get_bits(gb, 2)];
 
     memset(c->scalefactors, 0, sizeof(c->scalefactors));
diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
index cdacd79fc4..26be6e590f 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -650,7 +650,7 @@  static int FUNC(sei_pic_timing)(CodedBitstreamContext *ctx, RWContext *rw,
     }
 
     if (sps->vui.pic_struct_present_flag) {
-        static const int num_clock_ts[9] = {
+        static const uint8_t num_clock_ts[9] = {
             1, 1, 1, 2, 2, 3, 3, 2, 3
         };
         int i;
diff --git a/libavcodec/cbs_vp9_syntax_template.c b/libavcodec/cbs_vp9_syntax_template.c
index 898cede329..125eb02589 100644
--- a/libavcodec/cbs_vp9_syntax_template.c
+++ b/libavcodec/cbs_vp9_syntax_template.c
@@ -206,8 +206,8 @@  static int FUNC(quantization_params)(CodedBitstreamContext *ctx, RWContext *rw,
 static int FUNC(segmentation_params)(CodedBitstreamContext *ctx, RWContext *rw,
                                      VP9RawFrameHeader *current)
 {
-    static const int segmentation_feature_bits[VP9_SEG_LVL_MAX]   = { 8, 6, 2, 0 };
-    static const int segmentation_feature_signed[VP9_SEG_LVL_MAX] = { 1, 1, 0, 0 };
+    static const uint8_t segmentation_feature_bits[VP9_SEG_LVL_MAX]   = { 8, 6, 2, 0 };
+    static const uint8_t segmentation_feature_signed[VP9_SEG_LVL_MAX] = { 1, 1, 0, 0 };
 
     int err, i, j;
 
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acf3ffc9e7..f16462b1e9 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -353,7 +353,7 @@  static av_always_inline int inv_recenter_nonneg(int v, int m)
 // differential forward probability updates
 static int update_prob(VP56RangeCoder *c, int p)
 {
-    static const int inv_map_table[255] = {
+    static const uint8_t inv_map_table[255] = {
           7,  20,  33,  46,  59,  72,  85,  98, 111, 124, 137, 150, 163, 176,
         189, 202, 215, 228, 241, 254,   1,   2,   3,   4,   5,   6,   8,   9,
          10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  21,  22,  23,  24,