PR #20392 opened by yibofang URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20392 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20392.patch
The cbrt table generator previously used a 128 KiB static buffer in .bss. Replace it with a temporary av_malloc()/av_free() buffer used only at init. This saves ~128 KiB permanent bss, which is valuable on resource-constrained platforms. >From ae007d38ba0a8979339803e4db41a732de8d9238 Mon Sep 17 00:00:00 2001 From: YiboFang <[email protected]> Date: Tue, 26 Aug 2025 16:51:58 +0800 Subject: [PATCH] avcodec/cbrt_table: use dynamic buffer instead of static array The cbrt table generator previously used a 128 KiB static buffer in .bss. Replace it with a temporary av_malloc()/av_free() buffer used only at init. This saves ~128 KiB permanent bss, which is valuable on resource-constrained platforms. Build cmd: ./configure --arch=arm --target-os=linux \ --enable-cross-compile \ --cross-prefix=arm-linux-gnueabihf- \ --extra-cflags='-march=armv7-a -mfpu=neon-vfpv3 -mfloat-abi=hard -fPIC' On ARM cross build (armv7-a, NEON): before: text=15445946, data=750736, bss=23495660 after : text=15446058 (+112 B), data=750736, bss=23364588 (-128 KiB) overall image size reduced by ~128 KiB. Signed-off-by: Yibo Fang <[email protected]> Signed-off-by: YiboFang <[email protected]> --- libavcodec/cbrt_tablegen.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libavcodec/cbrt_tablegen.h b/libavcodec/cbrt_tablegen.h index 9af18d8ab5..70eccd8a73 100644 --- a/libavcodec/cbrt_tablegen.h +++ b/libavcodec/cbrt_tablegen.h @@ -25,6 +25,8 @@ #include <stdint.h> #include <math.h> +#include "libavutil/log.h" +#include "libavutil/mem.h" #include "libavutil/attributes.h" #include "libavutil/intfloat.h" #include "libavcodec/aac_defines.h" @@ -39,11 +41,18 @@ uint32_t AAC_RENAME(ff_cbrt_tab)[1 << 13]; av_cold void AAC_RENAME(ff_cbrt_tableinit)(void) { - static double cbrt_tab_dbl[1 << 13]; if (!AAC_RENAME(ff_cbrt_tab)[(1<<13) - 1]) { + double *cbrt_tab_dbl; int i, j, k; double cbrt_val; + cbrt_tab_dbl = av_malloc((1 << 13) * sizeof(double)); + if (!cbrt_tab_dbl) { + av_log(NULL, AV_LOG_ERROR, "cbrt_tableinit malloc failed %zu\n", + (1 << 13) * sizeof(double)); + return; + } + for (i = 1; i < 1<<13; i++) cbrt_tab_dbl[i] = 1; @@ -67,6 +76,8 @@ av_cold void AAC_RENAME(ff_cbrt_tableinit)(void) for (i = 0; i < 1<<13; i++) AAC_RENAME(ff_cbrt_tab)[i] = CBRT(cbrt_tab_dbl[i]); + + av_free(cbrt_tab_dbl); } } -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
