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


>From 515b501a88f745440fabf582d012aeb159efccc3 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 30 Mar 2026 10:25:11 +0200
Subject: [PATCH 1/2] avcodec/x86/mpegvideoenc_template: Avoid indirect call

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/x86/mpegvideoenc_template.c |  5 +++++
 libavcodec/x86/mpegvideoencdsp.h       | 29 ++++++++++++++++++++++++++
 libavcodec/x86/mpegvideoencdsp_init.c  |  3 +--
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/x86/mpegvideoencdsp.h

diff --git a/libavcodec/x86/mpegvideoenc_template.c 
b/libavcodec/x86/mpegvideoenc_template.c
index e6ce791347..d6ff4f68a0 100644
--- a/libavcodec/x86/mpegvideoenc_template.c
+++ b/libavcodec/x86/mpegvideoenc_template.c
@@ -29,6 +29,7 @@
 #include "libavcodec/mpegutils.h"
 #include "libavcodec/mpegvideoenc.h"
 #include "fdct.h"
+#include "mpegvideoencdsp.h"
 
 #undef SPREADW
 #undef PMAXW
@@ -79,7 +80,11 @@ static int RENAME(dct_quantize)(MPVEncContext *const s,
     if (s->dct_error_sum) {
         const int intra = s->c.mb_intra;
         s->dct_count[intra]++;
+#if HAVE_SSE2_EXTERNAL
+        ff_mpv_denoise_dct_sse2(block, s->dct_error_sum[intra], 
s->dct_offset[intra]);
+#else
         s->mpvencdsp.denoise_dct(block, s->dct_error_sum[intra], 
s->dct_offset[intra]);
+#endif
     }
 
     if (s->c.mb_intra) {
diff --git a/libavcodec/x86/mpegvideoencdsp.h b/libavcodec/x86/mpegvideoencdsp.h
new file mode 100644
index 0000000000..2463534e0e
--- /dev/null
+++ b/libavcodec/x86/mpegvideoencdsp.h
@@ -0,0 +1,29 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_X86_MPEGVIDEOENCDSP_H
+#define AVCODEC_X86_MPEGVIDEOENCDSP_H
+
+#include <stdint.h>
+
+#include "libavutil/attributes_internal.h"
+
+EXTERN void ff_mpv_denoise_dct_sse2(int16_t block[64], int dct_error_sum[64],
+                                    const uint16_t dct_offset[64]);
+
+#endif /* AVCODEC_X86_MPEGVIDEOENCDSP_H */
diff --git a/libavcodec/x86/mpegvideoencdsp_init.c 
b/libavcodec/x86/mpegvideoencdsp_init.c
index 1b6c75e9e5..5cad7d38ea 100644
--- a/libavcodec/x86/mpegvideoencdsp_init.c
+++ b/libavcodec/x86/mpegvideoencdsp_init.c
@@ -26,9 +26,8 @@
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/mpegvideoencdsp.h"
+#include "mpegvideoencdsp.h"
 
-void ff_mpv_denoise_dct_sse2(int16_t block[64], int dct_error_sum[64],
-                             const uint16_t dct_offset[64]);
 int ff_pix_sum16_sse2(const uint8_t *pix, ptrdiff_t line_size);
 int ff_pix_sum16_xop(const uint8_t *pix, ptrdiff_t line_size);
 int ff_pix_norm1_sse2(const uint8_t *pix, ptrdiff_t line_size);
-- 
2.52.0


>From 44467a598d5c334c5e063fd204f55b7f1dff514b Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 30 Mar 2026 10:56:43 +0200
Subject: [PATCH 2/2] avcodec/mpegvideoencdsp: Add restrict to shrink

Makes GCC avoid creating the aliasing fallback path
and saves 1280B of .text here.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/mpegvideoencdsp.c | 16 ++++++++--------
 libavcodec/mpegvideoencdsp.h |  5 +++--
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/libavcodec/mpegvideoencdsp.c b/libavcodec/mpegvideoencdsp.c
index 3b4a57d58a..a9a905c8bb 100644
--- a/libavcodec/mpegvideoencdsp.c
+++ b/libavcodec/mpegvideoencdsp.c
@@ -179,16 +179,16 @@ static void draw_edges_8_c(uint8_t *buf, ptrdiff_t wrap, 
int width, int height,
 
 /* This wrapper function only serves to convert the stride parameters
  * from ptrdiff_t to int for av_image_copy_plane(). */
-static void copy_plane_wrapper(uint8_t *dst, ptrdiff_t dst_wrap,
-                               const uint8_t *src, ptrdiff_t src_wrap,
+static void copy_plane_wrapper(uint8_t *restrict dst, ptrdiff_t dst_wrap,
+                               const uint8_t *restrict src, ptrdiff_t src_wrap,
                                int width, int height)
 {
     av_image_copy_plane(dst, dst_wrap, src, src_wrap, width, height);
 }
 
 /* 2x2 -> 1x1 */
-static void shrink22(uint8_t *dst, ptrdiff_t dst_wrap,
-                     const uint8_t *src, ptrdiff_t src_wrap,
+static void shrink22(uint8_t *restrict dst, ptrdiff_t dst_wrap,
+                     const uint8_t *restrict src, ptrdiff_t src_wrap,
                      int width, int height)
 {
     int w;
@@ -220,8 +220,8 @@ static void shrink22(uint8_t *dst, ptrdiff_t dst_wrap,
 }
 
 /* 4x4 -> 1x1 */
-static void shrink44(uint8_t *dst, ptrdiff_t dst_wrap,
-                     const uint8_t *src, ptrdiff_t src_wrap,
+static void shrink44(uint8_t *restrict dst, ptrdiff_t dst_wrap,
+                     const uint8_t *restrict src, ptrdiff_t src_wrap,
                      int width, int height)
 {
     int w;
@@ -251,8 +251,8 @@ static void shrink44(uint8_t *dst, ptrdiff_t dst_wrap,
 }
 
 /* 8x8 -> 1x1 */
-static void shrink88(uint8_t *dst, ptrdiff_t dst_wrap,
-                     const uint8_t *src, ptrdiff_t src_wrap,
+static void shrink88(uint8_t *restrict dst, ptrdiff_t dst_wrap,
+                     const uint8_t *restrict src, ptrdiff_t src_wrap,
                      int width, int height)
 {
     int w, i;
diff --git a/libavcodec/mpegvideoencdsp.h b/libavcodec/mpegvideoencdsp.h
index 989503f25f..4d205e1f9a 100644
--- a/libavcodec/mpegvideoencdsp.h
+++ b/libavcodec/mpegvideoencdsp.h
@@ -40,8 +40,9 @@ typedef struct MpegvideoEncDSPContext {
     int (*pix_sum)(const uint8_t *pix, ptrdiff_t line_size);
     int (*pix_norm1)(const uint8_t *pix, ptrdiff_t line_size);
 
-    void (*shrink[4])(uint8_t *dst, ptrdiff_t dst_wrap, const uint8_t *src,
-                      ptrdiff_t src_wrap, int width, int height);
+    void (*shrink[4])(uint8_t *restrict dst, ptrdiff_t dst_wrap,
+                      const uint8_t *restrict src, ptrdiff_t src_wrap,
+                      int width, int height);
 
     void (*draw_edges)(uint8_t *buf, ptrdiff_t wrap, int width, int height,
                        int w, int h, int sides);
-- 
2.52.0

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

Reply via email to