From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size
Date: Mon, 19 May 2025 13:54:29 +0200
Message-ID: <AS8P250MB0744DB699C38733CBF0884E68F9CA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20250519114134.338832-1-chenyu202107@gmail.com>
chenyu202107@gmail.com:
> From: chenyu <chenyu202107@gmail.com>
>
> Optimizing 160k code size by converting static array to dynamic malloc memory.
>
> Signed-off-by: chenyu <chenyu202107@gmail.com>
> ---
> libavcodec/mpegaudiodata.h | 4 ++--
> libavcodec/mpegaudiodec_common_tablegen.h | 10 ++++++++--
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h
> index 720c4bee64..6dfb74cd01 100644
> --- a/libavcodec/mpegaudiodata.h
> +++ b/libavcodec/mpegaudiodata.h
> @@ -50,8 +50,8 @@ extern const unsigned char * const ff_mpa_alloc_tables[5];
> extern const int8_t ff_table_4_3_exp [TABLE_4_3_SIZE];
> extern const uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
> #else
> -extern int8_t ff_table_4_3_exp [TABLE_4_3_SIZE];
> -extern uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
> +extern int8_t *ff_table_4_3_exp;
> +extern uint32_t *ff_table_4_3_value;
> #endif
>
> /* VLCs for decoding layer 3 huffman tables */
> diff --git a/libavcodec/mpegaudiodec_common_tablegen.h b/libavcodec/mpegaudiodec_common_tablegen.h
> index bf402c9d84..66e93df27f 100644
> --- a/libavcodec/mpegaudiodec_common_tablegen.h
> +++ b/libavcodec/mpegaudiodec_common_tablegen.h
> @@ -34,9 +34,10 @@
> #else
> #include <math.h>
> #include "libavutil/attributes.h"
> +#include "libavutil/mem.h"
>
> -int8_t ff_table_4_3_exp [TABLE_4_3_SIZE];
> -uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
> +int8_t *ff_table_4_3_exp;
> +uint32_t *ff_table_4_3_value;
>
> #define FRAC_BITS 23
> #define IMDCT_SCALAR 1.759
> @@ -51,6 +52,11 @@ static av_cold void mpegaudiodec_common_tableinit(void)
> };
> double pow43_val = 0;
>
> +#if !CONFIG_HARDCODED_TABLES
> + ff_table_4_3_exp = (int8_t *)av_calloc(TABLE_4_3_SIZE, sizeof(int8_t));
> + ff_table_4_3_value = (uint32_t *)av_calloc(TABLE_4_3_SIZE, sizeof(uint32_t));
> +#endif
> +
> for (int i = 1; i < TABLE_4_3_SIZE; i++) {
> double f, fm;
> int e, m;
This does not improve "code size" at all; after all you are actually
adding code (and an indirection) with your allocation. If one interprets
"code size" as "size of the binary" (instead of just .text), then this
patch still doesn't make sense, because the tables are currently in .bss
which does not increase the size of the binaries (that's at least the
case for common systems, is it different for you?).
And of course you are missing the error check (in fact, you have no way
to return an error from init functions like this).
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-05-19 11:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-19 11:41 chenyu202107
2025-05-19 11:54 ` Andreas Rheinhardt [this message]
2025-05-19 12:15 [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce " chenyu202107
2025-05-19 12:15 ` [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing " chenyu202107
2025-05-21 0:46 ` Michael Niedermayer
2025-05-21 7:40 ` Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8P250MB0744DB699C38733CBF0884E68F9CA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git