PR #24119 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24119 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24119.patch
Saves 18760B of .text here. >From 14d4c89606c8e1afa0d0f1dba472b687f8d80341 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 13 Aug 2026 03:02:46 +0200 Subject: [PATCH] avcodec/h264qpel: Deduplicate >8 bit fpel functions Saves 18760B of .text here. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/h264qpel.c | 32 +++++++++++++++++++------------- libavcodec/h264qpel_template.c | 30 ++++++++++++++++++++---------- libavcodec/snow.c | 2 +- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/libavcodec/h264qpel.c b/libavcodec/h264qpel.c index c64d35b73d..cf49c35f33 100644 --- a/libavcodec/h264qpel.c +++ b/libavcodec/h264qpel.c @@ -53,7 +53,6 @@ av_cold void ff_h264qpel_init(H264QpelContext *c, int bit_depth) #define FUNCC(f, depth) f ## _ ## depth ## _c #define dspfunc2(PFX, IDX, NUM, depth) \ - c->PFX ## _pixels_tab[IDX][ 0] = FUNCC(PFX ## NUM ## _mc00, depth); \ c->PFX ## _pixels_tab[IDX][ 1] = FUNCC(PFX ## NUM ## _mc10, depth); \ c->PFX ## _pixels_tab[IDX][ 2] = FUNCC(PFX ## NUM ## _mc20, depth); \ c->PFX ## _pixels_tab[IDX][ 3] = FUNCC(PFX ## NUM ## _mc30, depth); \ @@ -70,29 +69,36 @@ av_cold void ff_h264qpel_init(H264QpelContext *c, int bit_depth) c->PFX ## _pixels_tab[IDX][14] = FUNCC(PFX ## NUM ## _mc23, depth); \ c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth) -#define SET_QPEL(depth) \ - dspfunc2(put_h264_qpel, 0, 16, depth); \ - dspfunc2(put_h264_qpel, 1, 8, depth); \ - dspfunc2(put_h264_qpel, 2, 4, depth); \ - dspfunc2(avg_h264_qpel, 0, 16, depth); \ - dspfunc2(avg_h264_qpel, 1, 8, depth); \ - dspfunc2(avg_h264_qpel, 2, 4, depth) +#define SET_QPEL(M, depth) \ + M(put_h264_qpel, 0, 16, depth); \ + M(put_h264_qpel, 1, 8, depth); \ + M(put_h264_qpel, 2, 4, depth); \ + M(avg_h264_qpel, 0, 16, depth); \ + M(avg_h264_qpel, 1, 8, depth); \ + M(avg_h264_qpel, 2, 4, depth) + +#define FPEL(PFX, IDX, NUM, depth) c->PFX ## _pixels_tab[IDX][0] = FUNCC(PFX ## NUM ## _mc00, depth); + if (bit_depth <= 8) { + SET_QPEL(FPEL, 8); + } else { + SET_QPEL(FPEL, 16); + } switch (bit_depth) { default: - SET_QPEL(8); + SET_QPEL(dspfunc2, 8); break; case 9: - SET_QPEL(9); + SET_QPEL(dspfunc2, 9); break; case 10: - SET_QPEL(10); + SET_QPEL(dspfunc2, 10); break; case 12: - SET_QPEL(12); + SET_QPEL(dspfunc2, 12); break; case 14: - SET_QPEL(14); + SET_QPEL(dspfunc2, 14); break; } diff --git a/libavcodec/h264qpel_template.c b/libavcodec/h264qpel_template.c index 33df05475e..c3bc09fd7b 100644 --- a/libavcodec/h264qpel_template.c +++ b/libavcodec/h264qpel_template.c @@ -304,12 +304,13 @@ static void FUNC(OPNAME ## h264_qpel16_hv_lowpass)(uint8_t *dst, pixeltmp *tmp, FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst+8*sizeof(pixel), tmp+8, src+8*sizeof(pixel), dstStride, tmpStride, srcStride);\ }\ -#define H264_MC(OPNAME, NAME, SIZE) \ -static void FUNCC(OPNAME ## NAME ## _qpel ## SIZE ## _mc00)(uint8_t *dst, const uint8_t *restrict src, ptrdiff_t stride)\ +#define H264_FPEL(OPNAME, NAME, SIZE) \ +static void FUNCC2(OPNAME ## NAME ## _qpel ## SIZE ## _mc00)(uint8_t *dst, const uint8_t *restrict src, ptrdiff_t stride)\ {\ FUNCC(OPNAME ## pixels ## SIZE)(dst, src, stride, SIZE);\ -}\ -\ +} + +#define H264_MC(OPNAME, NAME, SIZE) \ static void FUNCC(OPNAME ## NAME ## _qpel ## SIZE ## _mc10)(uint8_t *dst, const uint8_t *restrict src, ptrdiff_t stride)\ {\ uint8_t half[SIZE*SIZE*sizeof(pixel)];\ @@ -463,15 +464,24 @@ static void FUNCC(OPNAME ## NAME ## _qpel ## SIZE ## _mc32)(uint8_t *dst, const #define op2_avg(a, b) a = (((a)+CLIP(((b) + 512)>>10)+1)>>1) #define op2_put(a, b) a = CLIP(((b) + 512)>>10) +#undef H264_QPEL +#if BIT_DEPTH == 8 || BIT_DEPTH == 9 +#define H264_QPEL(OPNAME, NAME, SIZE) \ + H264_MC(OPNAME, NAME, SIZE) \ + H264_FPEL(OPNAME, NAME, SIZE) +#else +#define H264_QPEL(OPNAME, NAME, SIZE) H264_MC(OPNAME, NAME, SIZE) +#endif + #ifndef SNOW H264_LOWPASS(put_ , op_put, op2_put) H264_LOWPASS(avg_ , op_avg, op2_avg) -H264_MC(put_, h264, 4) -H264_MC(put_, h264, 8) -H264_MC(put_, h264, 16) -H264_MC(avg_, h264, 4) -H264_MC(avg_, h264, 8) -H264_MC(avg_, h264, 16) +H264_QPEL(put_, h264, 4) +H264_QPEL(put_, h264, 8) +H264_QPEL(put_, h264, 16) +H264_QPEL(avg_, h264, 4) +H264_QPEL(avg_, h264, 8) +H264_QPEL(avg_, h264, 16) #endif #undef op_avg diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 38570645b7..ecacf0a751 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -90,7 +90,7 @@ static void put_snow_qpel2_hv_lowpass_8(uint8_t *dst, pixeltmp *tmp, const uint8 } } -H264_MC(put_, snow, 2) +H264_QPEL(put_, snow, 2) static av_cold void init_qpel(SnowContext *const s) { -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
