From 3f77ce4deed82a98be15451b7aa79c899113deaa Mon Sep 17 00:00:00 2001 From: Zuxy Meng Date: Fri, 4 Sep 2026 21:18:41 -0700 Subject: [PATCH] avcodec/ppc/h264dsp: Fix edge cases for bi-weight on ppc S16 saturating sum must be computed dot-product-first. The Altivec code added the offset to the first product before adding the second product, so an intermediate saturation could corrupt the result even when the true sum fits. Swap the two vec_adds to form the dot product first. This fixes bi-weight checkasm test for PPC. Signed-off-by: Zuxy Meng --- libavcodec/ppc/h264dsp.c | 4 ++-- tests/checkasm/h264dsp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/ppc/h264dsp.c b/libavcodec/ppc/h264dsp.c index d832e7f01c..c558dafa0b 100644 --- a/libavcodec/ppc/h264dsp.c +++ b/libavcodec/ppc/h264dsp.c @@ -749,16 +749,16 @@ void biweight_h264_W_altivec(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int h v0 = vec_mladd(v0, vweightd, zero_s16v); v2 = vec_mladd(v2, vweights, zero_s16v); - v0 = vec_adds(v0, voffset); v0 = vec_adds(v0, v2); + v0 = vec_adds(v0, voffset); v0 = vec_sra(v0, vlog2_denom); } if (w == 16 || !dst_aligned) { v1 = vec_mladd(v1, vweightd, zero_s16v); v3 = vec_mladd(v3, vweights, zero_s16v); - v1 = vec_adds(v1, voffset); v1 = vec_adds(v1, v3); + v1 = vec_adds(v1, voffset); v1 = vec_sra(v1, vlog2_denom); } vdst = vec_packsu(v0, v1); diff --git a/tests/checkasm/h264dsp.c b/tests/checkasm/h264dsp.c index a38ee32d9c..61839b13d6 100644 --- a/tests/checkasm/h264dsp.c +++ b/tests/checkasm/h264dsp.c @@ -544,8 +544,8 @@ static void check_weight(void) } } -// only arch that can pass test -#define H264_CHECK_BIWEIGHT ARCH_X86 +// only archs that can pass test +#define H264_CHECK_BIWEIGHT (ARCH_X86 || ARCH_PPC) #if H264_CHECK_BIWEIGHT static void check_biweight(void)