From 31f0749cd44dfbf9f970df412e7fac596c133dfb Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 10 Oct 2025 15:49:04 +0200 Subject: [PATCH] avcodec/vp3: Optimize alignment check away when possible Check only on arches that need said check. (Btw: I do not see how h_loop_filter benefits from alignment at all and why h_loop_filter_unaligned exists.) Signed-off-by: Andreas Rheinhardt --- libavcodec/vp3.c | 2 +- libavcodec/vp3dsp.h | 4 ++++ tests/checkasm/vp3dsp.c | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 406c4f499b..0613254c14 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -2031,7 +2031,7 @@ static int vp4_mc_loop_filter(Vp3DecodeContext *s, int plane, int motion_x, int plane_height); #define safe_loop_filter(name, ptr, stride, bounding_values) \ - if ((uintptr_t)(ptr) & 7) \ + if (VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT && (uintptr_t)(ptr) & 7) \ s->vp3dsp.name##_unaligned(ptr, stride, bounding_values); \ else \ s->vp3dsp.name(ptr, stride, bounding_values); diff --git a/libavcodec/vp3dsp.h b/libavcodec/vp3dsp.h index 1d5dd4b738..7512676379 100644 --- a/libavcodec/vp3dsp.h +++ b/libavcodec/vp3dsp.h @@ -22,6 +22,10 @@ #include #include +// If this is one, {v,h}_loop_filter expect src to be aligned on eight bytes; +// otherwise they don't have any alignment requirements for src. +#define VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT (ARCH_ARM || ARCH_MIPS) + typedef struct VP3DSPContext { /** * Copy 8xH pixels from source to destination buffer using a bilinear diff --git a/tests/checkasm/vp3dsp.c b/tests/checkasm/vp3dsp.c index 81f096dc2a..4f985ae62a 100644 --- a/tests/checkasm/vp3dsp.c +++ b/tests/checkasm/vp3dsp.c @@ -68,8 +68,8 @@ static void vp3_check_loop_filter(void) #define TEST(NAME) .name = #NAME, .offset = offsetof(VP3DSPContext, NAME) { TEST(v_loop_filter_unaligned), 2, 1, 0, 7, 1, 0 }, { TEST(h_loop_filter_unaligned), 0, 7, 2, 1, 1, 1 }, - { TEST(v_loop_filter), 2, 1, 0, 7, 8, 0 }, - { TEST(h_loop_filter), 0, 7, 2, 1, 8, 1 }, + { TEST(v_loop_filter), 2, 1, 0, 7, VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT ? 8 : 1, 0 }, + { TEST(h_loop_filter), 0, 7, 2, 1, VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT ? 8 : 1, 1 }, }; declare_func(void, uint8_t *src, ptrdiff_t stride, int *bounding_values);