From da59f288c6245b7c22deb65cbd527a5d625aece2 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Thu, 2 Apr 2026 13:20:01 +0200 Subject: [PATCH] avcodec/hevc/dsp_template: Add restrict to add_residual functions Allows the compiler to optimize the the aliasing checks away and saves 5376B here (GCC 15, -O3). Also, avoid converting the stride to uint16_t for >8bpp: stride /= sizeof(pixel) will use an unsigned division (i.e. a logical right shift)*, which is not what is intended here. *: If size_t is the corresponding unsigned type to ptrdiff_t Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc/dsp_template.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/hevc/dsp_template.c b/libavcodec/hevc/dsp_template.c index f703f6d071..e7b21127ba 100644 --- a/libavcodec/hevc/dsp_template.c +++ b/libavcodec/hevc/dsp_template.c @@ -43,20 +43,18 @@ static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height } } -static av_always_inline void FUNC(add_residual)(uint8_t *_dst, const int16_t *res, +static av_always_inline void FUNC(add_residual)(uint8_t *restrict dst8, const int16_t *restrict res, ptrdiff_t stride, int size) { int x, y; - pixel *dst = (pixel *)_dst; - - stride /= sizeof(pixel); for (y = 0; y < size; y++) { + pixel *restrict dst = (pixel *)dst8; for (x = 0; x < size; x++) { dst[x] = av_clip_pixel(dst[x] + *res); res++; } - dst += stride; + dst8 += stride; } }