PR #24050 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24050
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24050.patch

Also avoid a shuffle in the x86 h263 loopfilter.


>From 4e838cd35d071724e75ec3903a8b05e939472732 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 19:19:19 +0200
Subject: [PATCH 1/3] avcodec/h263dsp: Use ptrdiff_t for stride

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/h263.c                  | 4 ++--
 libavcodec/h263dsp.c               | 4 ++--
 libavcodec/h263dsp.h               | 5 +++--
 libavcodec/mips/h263dsp_mips.h     | 4 ++--
 libavcodec/mips/h263dsp_msa.c      | 8 ++++----
 libavcodec/riscv/h263dsp_init.c    | 4 ++--
 libavcodec/x86/h263_loopfilter.asm | 6 ++----
 libavcodec/x86/h263dsp_init.c      | 5 +++--
 tests/checkasm/h263dsp.c           | 4 ++--
 9 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index 6d2de715ab..61a8fa96b4 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -96,8 +96,8 @@ void ff_h263_update_motion_val(MpegEncContext * s){
 
 void ff_h263_loop_filter(MpegEncContext * s){
     int qp_c;
-    const int linesize  = s->linesize;
-    const int uvlinesize= s->uvlinesize;
+    const ptrdiff_t   linesize = s->linesize;
+    const ptrdiff_t uvlinesize = s->uvlinesize;
     const int xy = s->mb_y * s->mb_stride + s->mb_x;
     uint8_t *dest_y = s->dest[0];
     uint8_t *dest_cb= s->dest[1];
diff --git a/libavcodec/h263dsp.c b/libavcodec/h263dsp.c
index 165174a499..bc54e69c22 100644
--- a/libavcodec/h263dsp.c
+++ b/libavcodec/h263dsp.c
@@ -28,7 +28,7 @@ const uint8_t ff_h263_loop_filter_strength[32] = {
     7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12
 };
 
-static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale)
+static void h263_h_loop_filter_c(uint8_t *src, ptrdiff_t stride, int qscale)
 {
     int y;
     const int strength = ff_h263_loop_filter_strength[qscale];
@@ -71,7 +71,7 @@ static void h263_h_loop_filter_c(uint8_t *src, int stride, 
int qscale)
     }
 }
 
-static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale)
+static void h263_v_loop_filter_c(uint8_t *src, ptrdiff_t stride, int qscale)
 {
     int x;
     const int strength = ff_h263_loop_filter_strength[qscale];
diff --git a/libavcodec/h263dsp.h b/libavcodec/h263dsp.h
index 2dccd23392..d94358d07c 100644
--- a/libavcodec/h263dsp.h
+++ b/libavcodec/h263dsp.h
@@ -19,13 +19,14 @@
 #ifndef AVCODEC_H263DSP_H
 #define AVCODEC_H263DSP_H
 
+#include <stddef.h>
 #include <stdint.h>
 
 extern const uint8_t ff_h263_loop_filter_strength[32];
 
 typedef struct H263DSPContext {
-    void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
-    void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
+    void (*h263_h_loop_filter)(uint8_t *src, ptrdiff_t stride, int qscale);
+    void (*h263_v_loop_filter)(uint8_t *src, ptrdiff_t stride, int qscale);
 } H263DSPContext;
 
 void ff_h263dsp_init(H263DSPContext *ctx);
diff --git a/libavcodec/mips/h263dsp_mips.h b/libavcodec/mips/h263dsp_mips.h
index 5ea9fcbb88..7ae896e11c 100644
--- a/libavcodec/mips/h263dsp_mips.h
+++ b/libavcodec/mips/h263dsp_mips.h
@@ -23,8 +23,8 @@
 
 #include "libavcodec/mpegvideo.h"
 
-void ff_h263_h_loop_filter_msa(uint8_t *src, int stride, int q_scale);
-void ff_h263_v_loop_filter_msa(uint8_t *src, int stride, int q_scale);
+void ff_h263_h_loop_filter_msa(uint8_t *src, ptrdiff_t stride, int q_scale);
+void ff_h263_v_loop_filter_msa(uint8_t *src, ptrdiff_t stride, int q_scale);
 void ff_dct_unquantize_mpeg2_inter_msa(const MPVContext *s, int16_t *block,
                                        int32_t index, int32_t q_scale);
 void ff_dct_unquantize_h263_inter_msa(const MPVContext *s, int16_t *block,
diff --git a/libavcodec/mips/h263dsp_msa.c b/libavcodec/mips/h263dsp_msa.c
index 2e1ca0183d..b1f3a2a8a1 100644
--- a/libavcodec/mips/h263dsp_msa.c
+++ b/libavcodec/mips/h263dsp_msa.c
@@ -26,7 +26,7 @@ static const uint8_t h263_loop_filter_strength_msa[32] = {
     7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12
 };
 
-static void h263_h_loop_filter_msa(uint8_t *src, int32_t stride, int32_t 
qscale)
+static void h263_h_loop_filter_msa(uint8_t *src, ptrdiff_t stride, int32_t 
qscale)
 {
     int32_t strength = h263_loop_filter_strength_msa[qscale];
     v16u8 in0, in1, in2, in3, in4, in5, in6, in7;
@@ -89,7 +89,7 @@ static void h263_h_loop_filter_msa(uint8_t *src, int32_t 
stride, int32_t qscale)
     ST_W8(in0, in3, 0, 1, 2, 3, 0, 1, 2, 3, src, stride);
 }
 
-static void h263_v_loop_filter_msa(uint8_t *src, int32_t stride, int32_t 
qscale)
+static void h263_v_loop_filter_msa(uint8_t *src, ptrdiff_t stride, int32_t 
qscale)
 {
     int32_t strength = h263_loop_filter_strength_msa[qscale];
     uint64_t res0, res1, res2, res3;
@@ -150,12 +150,12 @@ static void h263_v_loop_filter_msa(uint8_t *src, int32_t 
stride, int32_t qscale)
     SD4(res0, res1, res2, res3, src, stride);
 }
 
-void ff_h263_h_loop_filter_msa(uint8_t *src, int32_t stride, int32_t q_scale)
+void ff_h263_h_loop_filter_msa(uint8_t *src, ptrdiff_t stride, int32_t q_scale)
 {
     h263_h_loop_filter_msa(src, stride, q_scale);
 }
 
-void ff_h263_v_loop_filter_msa(uint8_t *src, int32_t stride, int32_t q_scale)
+void ff_h263_v_loop_filter_msa(uint8_t *src, ptrdiff_t stride, int32_t q_scale)
 {
     h263_v_loop_filter_msa(src, stride, q_scale);
 }
diff --git a/libavcodec/riscv/h263dsp_init.c b/libavcodec/riscv/h263dsp_init.c
index 21b536366c..fa4877364f 100644
--- a/libavcodec/riscv/h263dsp_init.c
+++ b/libavcodec/riscv/h263dsp_init.c
@@ -25,8 +25,8 @@
 #include "libavutil/riscv/cpu.h"
 #include "libavcodec/h263dsp.h"
 
-void ff_h263_h_loop_filter_rvv(uint8_t *src, int stride, int q);
-void ff_h263_v_loop_filter_rvv(uint8_t *src, int stride, int q);
+void ff_h263_h_loop_filter_rvv(uint8_t *src, ptrdiff_t stride, int q);
+void ff_h263_v_loop_filter_rvv(uint8_t *src, ptrdiff_t stride, int q);
 
 av_cold void ff_h263dsp_init_riscv(H263DSPContext *c)
 {
diff --git a/libavcodec/x86/h263_loopfilter.asm 
b/libavcodec/x86/h263_loopfilter.asm
index 083537154b..868f843275 100644
--- a/libavcodec/x86/h263_loopfilter.asm
+++ b/libavcodec/x86/h263_loopfilter.asm
@@ -86,9 +86,8 @@ SECTION .text
 %endmacro
 
 INIT_XMM sse2
-; void ff_h263_v_loop_filter_sse2(uint8_t *src, int stride, int qscale)
+; void ff_h263_v_loop_filter_sse2(uint8_t *src, ptrdiff_t stride, int qscale)
 cglobal h263_v_loop_filter, 3,5,8
-    movsxdifnidn r1, r1d
     movsxdifnidn r2, r2d
 
     lea          r3, [h263_loop_filter_strength]
@@ -118,10 +117,9 @@ cglobal h263_v_loop_filter, 3,5,8
 %endmacro
 
 
-; void ff_h263_h_loop_filter_sse2(uint8_t *src, int stride, int qscale)
+; void ff_h263_h_loop_filter_sse2(uint8_t *src, ptrdiff_t stride, int qscale)
 INIT_XMM sse2
 cglobal h263_h_loop_filter, 3,5,8,32
-    movsxdifnidn r1, r1d
     movsxdifnidn r2, r2d
 
     lea          r4, [h263_loop_filter_strength]
diff --git a/libavcodec/x86/h263dsp_init.c b/libavcodec/x86/h263dsp_init.c
index 3dd5d132e5..e0ec75fa7b 100644
--- a/libavcodec/x86/h263dsp_init.c
+++ b/libavcodec/x86/h263dsp_init.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stddef.h>
 #include <stdint.h>
 
 #include "libavutil/attributes.h"
@@ -25,8 +26,8 @@
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/h263dsp.h"
 
-void ff_h263_h_loop_filter_sse2(uint8_t *src, int stride, int qscale);
-void ff_h263_v_loop_filter_sse2(uint8_t *src, int stride, int qscale);
+void ff_h263_h_loop_filter_sse2(uint8_t *src, ptrdiff_t stride, int qscale);
+void ff_h263_v_loop_filter_sse2(uint8_t *src, ptrdiff_t stride, int qscale);
 
 av_cold void ff_h263dsp_init_x86(H263DSPContext *c)
 {
diff --git a/tests/checkasm/h263dsp.c b/tests/checkasm/h263dsp.c
index f99d376adc..5fafa24a9a 100644
--- a/tests/checkasm/h263dsp.c
+++ b/tests/checkasm/h263dsp.c
@@ -26,7 +26,7 @@
 #include "libavutil/mem.h"
 #include "libavutil/mem_internal.h"
 
-typedef void (*filter)(uint8_t *src, int stride, int qscale);
+typedef void (*filter)(uint8_t *src, ptrdiff_t stride, int qscale);
 
 static void check_loop_filter(char dim, filter func)
 {
@@ -34,7 +34,7 @@ static void check_loop_filter(char dim, filter func)
     LOCAL_ALIGNED_16(uint8_t, buf1, [32 * 32]);
     int qscale = rnd() % 32;
 
-    declare_func(void, uint8_t *, int, int);
+    declare_func(void, uint8_t *, ptrdiff_t, int);
 
     for (size_t y = 0; y < 32; y++)
         for (size_t x = 0; x < 32; x++)
-- 
2.52.0


>From 77c491b814852c0dc1fe448cdcf90261e1ad6fb3 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Sat, 8 Aug 2026 01:36:44 +0200
Subject: [PATCH 2/3] avcodec/x86/h263dsp_loopfilter: Avoid shuffle

Also start splatting a bit earlier.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/x86/h263_loopfilter.asm | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavcodec/x86/h263_loopfilter.asm 
b/libavcodec/x86/h263_loopfilter.asm
index 868f843275..3515246de0 100644
--- a/libavcodec/x86/h263_loopfilter.asm
+++ b/libavcodec/x86/h263_loopfilter.asm
@@ -45,18 +45,17 @@ SECTION .text
     punpcklbw    m1, m7
     psubw        m1, m2
     psllw        m1, 2
+    movd         m2, %5
     paddw        m1, m0
     pxor         m6, m6
     pcmpgtw      m6, m1
+    punpcklbw    m2, m2
     pxor         m1, m6
     psubw        m1, m6
     psrlw        m1, 3
     packuswb     m1, m7
+    pshuflw      m2, m2, 0
     packsswb     m6, m7
-    movd         m2, %5
-    punpcklbw    m2, m2
-    punpcklbw    m2, m2
-    punpcklbw    m2, m2
     psubusb      m2, m1
     mova         m7, m2
     psubusb      m7, m1
-- 
2.52.0


>From 43e2698a278991898da7efac45f4d26ed1c54395 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Sat, 8 Aug 2026 02:25:34 +0200
Subject: [PATCH 3/3] avcodec/mpeg4videodsp: Use ptrdiff_t for stride

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/mpeg4videodsp.c     | 4 ++--
 libavcodec/mpeg4videodsp.h     | 7 ++++---
 libavcodec/ppc/mpeg4videodsp.c | 2 +-
 libavcodec/x86/mpeg4videodsp.c | 2 +-
 tests/checkasm/mpeg4videodsp.c | 2 +-
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpeg4videodsp.c b/libavcodec/mpeg4videodsp.c
index 1c5661a076..7067d8e885 100644
--- a/libavcodec/mpeg4videodsp.c
+++ b/libavcodec/mpeg4videodsp.c
@@ -21,7 +21,7 @@
 #include "libavutil/common.h"
 #include "mpeg4videodsp.h"
 
-static void gmc1_c(uint8_t *dst, const uint8_t *src, int stride, int h,
+static void gmc1_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h,
                    int x16, int y16, int rounder)
 {
     const int A = (16 - x16) * (16 - y16);
@@ -44,7 +44,7 @@ static void gmc1_c(uint8_t *dst, const uint8_t *src, int 
stride, int h,
     }
 }
 
-void ff_gmc_c(uint8_t *dst, const uint8_t *src, int stride, int h, int ox, int 
oy,
+void ff_gmc_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int 
ox, int oy,
               int dxx, int dxy, int dyx, int dyy, int shift, int r,
               int width, int height)
 {
diff --git a/libavcodec/mpeg4videodsp.h b/libavcodec/mpeg4videodsp.h
index e1ccb71ce9..05f1ccc8a9 100644
--- a/libavcodec/mpeg4videodsp.h
+++ b/libavcodec/mpeg4videodsp.h
@@ -19,9 +19,10 @@
 #ifndef AVCODEC_MPEG4VIDEODSP_H
 #define AVCODEC_MPEG4VIDEODSP_H
 
+#include <stddef.h>
 #include <stdint.h>
 
-void ff_gmc_c(uint8_t *dst, const uint8_t *src, int stride, int h, int ox, int 
oy,
+void ff_gmc_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int 
ox, int oy,
               int dxx, int dxy, int dyx, int dyy, int shift, int r,
               int width, int height);
 
@@ -30,12 +31,12 @@ typedef struct Mpeg4VideoDSPContext {
      * translational global motion compensation.
      */
     void (*gmc1)(uint8_t *dst /* align 8 */, const uint8_t *src /* align 1 */,
-                 int srcStride, int h, int x16, int y16, int rounder);
+                 ptrdiff_t srcStride, int h, int x16, int y16, int rounder);
     /**
      * global motion compensation.
      */
     void (*gmc)(uint8_t *dst /* align 8 */, const uint8_t *src /* align 1 */,
-                int stride, int h, int ox, int oy,
+                ptrdiff_t stride, int h, int ox, int oy,
                 int dxx, int dxy, int dyx, int dyy,
                 int shift, int r, int width, int height);
 } Mpeg4VideoDSPContext;
diff --git a/libavcodec/ppc/mpeg4videodsp.c b/libavcodec/ppc/mpeg4videodsp.c
index 8b30af4258..79e19ab6eb 100644
--- a/libavcodec/ppc/mpeg4videodsp.c
+++ b/libavcodec/ppc/mpeg4videodsp.c
@@ -32,7 +32,7 @@
 /* AltiVec-enhanced gmc1. ATM this code assumes stride is a multiple of 8
  * to preserve proper dst alignment. */
 static void gmc1_altivec(uint8_t *dst /* align 8 */, const uint8_t *src /* 
align1 */,
-                         int stride, int h, int x16, int y16, int rounder)
+                         ptrdiff_t stride, int h, int x16, int y16, int 
rounder)
 {
     int i;
     const DECLARE_ALIGNED(16, unsigned short, rounder_a) = rounder;
diff --git a/libavcodec/x86/mpeg4videodsp.c b/libavcodec/x86/mpeg4videodsp.c
index d326327f13..337a4b32d7 100644
--- a/libavcodec/x86/mpeg4videodsp.c
+++ b/libavcodec/x86/mpeg4videodsp.c
@@ -37,7 +37,7 @@ typedef struct {
 DECLARE_ASM_CONST(16, xmm_u16, pw_0to7) = { { 0, 1, 2, 3, 4, 5, 6, 7 } };
 
 static void gmc_ssse3(uint8_t *dst, const uint8_t *src,
-                      int stride, int h, int ox, int oy,
+                      ptrdiff_t stride, int h, int ox, int oy,
                       int dxx, int dxy, int dyx, int dyy,
                       int shift, int r, int width, int height)
 {
diff --git a/tests/checkasm/mpeg4videodsp.c b/tests/checkasm/mpeg4videodsp.c
index 49557224f5..a24ef480d8 100644
--- a/tests/checkasm/mpeg4videodsp.c
+++ b/tests/checkasm/mpeg4videodsp.c
@@ -81,7 +81,7 @@ static void checkasm_check_gmc(const Mpeg4VideoDSPContext 
*const mdsp)
     DECLARE_ALIGNED_4(uint8_t, srcbuf)[MAX_STRIDE * MAX_HEIGHT];
 
     declare_func(void, uint8_t *dst, const uint8_t *src,
-                 int stride, int h, int ox, int oy,
+                 ptrdiff_t stride, int h, int ox, int oy,
                  int dxx, int dxy, int dyx, int dyy,
                  int shift, int r, int width, int height);
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to