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

Fixes issue #22333.
Note: These functions have been removed in commit
61e851381f3c039dd8c06073f22da12fcc7409b0, so the issue
only affects releases 7.0 and older.


>From 5e6c584b98cea9b9d78b037728b915887758666d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Sun, 1 Mar 2026 14:57:21 +0100
Subject: [PATCH] swscale/x86/yuv2rgb_template: Add emms to MMX(EXT) functions

Fixes issue #22333.
Note: These functions have been removed in commit
61e851381f3c039dd8c06073f22da12fcc7409b0, so the issue
only affects releases 7.0 and older.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libswscale/x86/yuv2rgb_template.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/libswscale/x86/yuv2rgb_template.c 
b/libswscale/x86/yuv2rgb_template.c
index 596943bb73..c841509a47 100644
--- a/libswscale/x86/yuv2rgb_template.c
+++ b/libswscale/x86/yuv2rgb_template.c
@@ -26,6 +26,23 @@
 #include "libavutil/x86/asm.h"
 #include "libswscale/swscale_internal.h"
 
+#undef EMMS_IF_MMX
+
+#if defined(COMPILE_TEMPLATE_MMX) || defined(COMPILE_TEMPLATE_MMXEXT)
+// Don't use emms_c() directly as it may entail an av_get_cpu_flags() call.
+#if HAVE_MMX_INLINE
+#   define EMMS_IF_MMX __asm__ volatile ("emms" ::: "memory");
+#elif HAVE_MM_EMPTY
+#   include <mmintrin.h>
+#   define EMMS_IF_MMX _mm_empty();
+#else
+#   include "libavutil/emms.h"
+#   define EMMS_IF_MMX emms_c();
+#endif
+#else
+#define EMMS_IF_MMX
+#endif
+
 #define YUV2RGB_LOOP(depth)                                          \
     h_size = (c->dstW + 7) & ~7;                                     \
     if (h_size * depth > FFABS(dstStride[0]))                        \
@@ -84,6 +101,7 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, const 
uint8_t *src[],
 
         RENAME(ff_yuv_420_rgb15)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 
@@ -104,6 +122,7 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, const 
uint8_t *src[],
 
         RENAME(ff_yuv_420_rgb16)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 
@@ -118,6 +137,7 @@ static inline int RENAME(yuv420_rgb32)(SwsContext *c, const 
uint8_t *src[],
 
         RENAME(ff_yuv_420_rgb32)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 
@@ -132,6 +152,7 @@ static inline int RENAME(yuv420_bgr32)(SwsContext *c, const 
uint8_t *src[],
 
         RENAME(ff_yuv_420_bgr32)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 
@@ -146,6 +167,7 @@ static inline int RENAME(yuva420_rgb32)(SwsContext *c, 
const uint8_t *src[],
         const uint8_t *pa = src[3] + y * srcStride[3];
         RENAME(ff_yuva_420_rgb32)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index, pa - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 
@@ -161,6 +183,7 @@ static inline int RENAME(yuva420_bgr32)(SwsContext *c, 
const uint8_t *src[],
         const uint8_t *pa = src[3] + y * srcStride[3];
         RENAME(ff_yuva_420_bgr32)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index, pa - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 #endif
@@ -177,6 +200,7 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, const 
uint8_t *src[],
 
         RENAME(ff_yuv_420_rgb24)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 
@@ -191,6 +215,7 @@ static inline int RENAME(yuv420_bgr24)(SwsContext *c, const 
uint8_t *src[],
 
         RENAME(ff_yuv_420_bgr24)(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
     }
+    EMMS_IF_MMX
     return srcSliceH;
 }
 #endif
-- 
2.52.0

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

Reply via email to