PR #21688 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21688 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21688.patch
>From cb912667b51ac6701d4991e9e464b9dbdfad343d Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sun, 8 Feb 2026 14:44:54 +0100 Subject: [PATCH 1/9] avutil/avassert: Deprecate av_assert0_fpu() Said function has presumably been added in order to check that we have successfully reset the floating point state after having violated the ABI/calling convention by not issuing emms in our MMX DSP routines. Yet the ability to check this should not have been made public, because there is no external need for it and because the function does not even always achieve what its documentation claims to do: It only works when inline assembly is available. It should have been implemented in emms.h like emms_c() (which is where a replacement should be put if there is still ABI-violating MMX code when av_assert0_fpu() is removed). Signed-off-by: Andreas Rheinhardt <[email protected]> --- doc/APIchanges | 3 +++ libavutil/avassert.h | 12 ++++++++++-- libavutil/utils.c | 3 ++- libavutil/version.h | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index ee3167bb14..8703daa119 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 API changes, most recent first: +2026-02-xx - xxxxxxxxxx - lavu 60.xx.100 - avassert.h + Deprecate av_assert0_fpu() and av_assert2_fpu() without replacement. + 2026-01-xx - xxxxxxxxxx - lavu 60.24.100 - hwcontext_d3d11va.h Add BindFlags and MiscFlags to AVD3D11VADeviceContext diff --git a/libavutil/avassert.h b/libavutil/avassert.h index 209c0d9d17..e316a3c90d 100644 --- a/libavutil/avassert.h +++ b/libavutil/avassert.h @@ -34,6 +34,7 @@ #include "attributes.h" #include "log.h" #include "macros.h" +#include "version.h" /** * assert() equivalent, that is always enabled. @@ -63,18 +64,25 @@ */ #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1 #define av_assert2(cond) av_assert0(cond) -#define av_assert2_fpu() av_assert0_fpu() #else #define av_assert2(cond) ((void)0) -#define av_assert2_fpu() ((void)0) #endif +#if FF_API_ASSERT_FPU +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1 +#define av_assert2_fpu() av_assert0_fpu() +#else +#define av_assert2_fpu() ((void)0) +#endif /** * Assert that floating point operations can be executed. * * This will av_assert0() that the cpu is not in MMX state on X86 + * @deprecated without replacement */ +attribute_deprecated void av_assert0_fpu(void); +#endif /** * Asserts that are used as compiler optimization hints depending diff --git a/libavutil/utils.c b/libavutil/utils.c index 162a4dee26..fc431fdd60 100644 --- a/libavutil/utils.c +++ b/libavutil/utils.c @@ -99,7 +99,7 @@ AVRational av_get_time_base_q(void) { return (AVRational){1, AV_TIME_BASE}; } - +#if FF_API_ASSERT_FPU void av_assert0_fpu(void) { #if HAVE_MMX_INLINE uint16_t state[14]; @@ -112,3 +112,4 @@ void av_assert0_fpu(void) { av_assert0((state[4] & 3) == 3); #endif } +#endif diff --git a/libavutil/version.h b/libavutil/version.h index 9d308ed059..26b1d1d4ee 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -112,6 +112,7 @@ #define FF_API_OPT_PTR (LIBAVUTIL_VERSION_MAJOR < 61) #define FF_API_CPU_FLAG_FORCE (LIBAVUTIL_VERSION_MAJOR < 61) #define FF_API_DOVI_L11_INVALID_PROPS (LIBAVUTIL_VERSION_MAJOR < 61) +#define FF_API_ASSERT_FPU (LIBAVUTIL_VERSION_MAJOR < 61) /** * @} -- 2.52.0 >From 56828742c3b594e8bdd4f993e7a1d07082ed7c35 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 15 Nov 2025 09:40:49 +0100 Subject: [PATCH 2/9] swresample/x86/audio_convert: Remove remnants of MMX Forgotten in 2b94f23b06d9bbab4cd5b5fec9f4e53ff365e5ab. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libswresample/x86/audio_convert.asm | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libswresample/x86/audio_convert.asm b/libswresample/x86/audio_convert.asm index ad65008e23..40778e0823 100644 --- a/libswresample/x86/audio_convert.asm +++ b/libswresample/x86/audio_convert.asm @@ -247,7 +247,6 @@ pack_6ch_%2_to_%1_u_int %+ SUFFIX: mov%3 m3, [srcq+src3q] mov%3 m4, [srcq+src4q] mov%3 m5, [srcq+src5q] -%if cpuflag(sse) SBUTTERFLYPS 0, 1, 6 SBUTTERFLYPS 2, 3, 6 SBUTTERFLYPS 4, 5, 6 @@ -281,18 +280,6 @@ pack_6ch_%2_to_%1_u_int %+ SUFFIX: mov %+ %3 %+ ps [dstq+48], m1 mov %+ %3 %+ ps [dstq+64], m2 mov %+ %3 %+ ps [dstq+80], m5 -%else ; mmx - SBUTTERFLY dq, 0, 1, 6 - SBUTTERFLY dq, 2, 3, 6 - SBUTTERFLY dq, 4, 5, 6 - - movq [dstq ], m0 - movq [dstq+ 8], m2 - movq [dstq+16], m4 - movq [dstq+24], m1 - movq [dstq+32], m3 - movq [dstq+40], m5 -%endif add srcq, mmsize add dstq, mmsize*6 sub lend, mmsize/4 -- 2.52.0 >From c0e1625fb1673afaf35a95e088761a3a977bb74d Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 15 Nov 2025 09:43:31 +0100 Subject: [PATCH 3/9] swresample/{audioconvert,rematrix}: Don't check for HAVE_MMX There are no MMX functions left in all of libswresample, so checking for it makes no sense. Notice that configure currently disables x86asm if mmx is disabled, so the check is also redundant. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libswresample/audioconvert.c | 2 +- libswresample/rematrix.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c index 04108fb966..f8bac98ca5 100644 --- a/libswresample/audioconvert.c +++ b/libswresample/audioconvert.c @@ -176,7 +176,7 @@ AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, } } -#if ARCH_X86 && HAVE_X86ASM && HAVE_MMX +#if ARCH_X86 && HAVE_X86ASM swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels); #elif ARCH_ARM swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels); diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 76681e9229..b725159730 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -552,7 +552,7 @@ av_cold int swri_rematrix_init(SwrContext *s){ s->matrix_ch[i][0]= ch_in; } -#if ARCH_X86 && HAVE_X86ASM && HAVE_MMX +#if ARCH_X86 && HAVE_X86ASM return swri_rematrix_init_x86(s); #endif -- 2.52.0 >From 31c05434c29a82b51b9bd71b444cac0e18714a0c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 15 Nov 2025 09:51:31 +0100 Subject: [PATCH 4/9] doc/optimization: Fix incorrect statement Signed-off-by: Andreas Rheinhardt <[email protected]> --- doc/optimization.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/optimization.txt b/doc/optimization.txt index 40480e4fa9..06ad3ab880 100644 --- a/doc/optimization.txt +++ b/doc/optimization.txt @@ -5,7 +5,7 @@ What to optimize: ----------------- If you plan to do non-x86 architecture specific optimizations (SIMD normally), then take a look in the x86/ directory, as most important functions are -already optimized for MMX. +already optimized for x86. If you want to do x86 optimizations then you can either try to fine-tune the stuff in the x86 directory or find some other functions in the C source to -- 2.52.0 >From c04d5c7081106619cb5936925621c43366a8c993 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 15 Nov 2025 10:09:18 +0100 Subject: [PATCH 5/9] avcodec/x86/dirac_dwt: Remove MMX in comment Forgotten in 5e332fe35cd336a5c7718d5e9a5a93ece0e61a3a. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/dirac_dwt.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/x86/dirac_dwt.asm b/libavcodec/x86/dirac_dwt.asm index 46fb6b2dcf..83fbb15b1f 100644 --- a/libavcodec/x86/dirac_dwt.asm +++ b/libavcodec/x86/dirac_dwt.asm @@ -252,7 +252,7 @@ cglobal horizontal_compose_dd97i_ssse3, 3,6,8, b, tmp, w, x, w2, b_w2 jl .lowpass_loop EDGE_EXTENSION 1, 2, xw - ; leave the last up to 7 (sse) or 3 (mmx) values for C + ; leave the last up to 7 (sse) values for C xor xd, xd and w2d, ~(mmsize/2 - 1) cmp w2d, mmsize/2 -- 2.52.0 >From ffad7d51c52901fbc59b89c13e6e542d48918bb7 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 15 Nov 2025 10:23:01 +0100 Subject: [PATCH 6/9] avcodec/mpegvideoenc: Remove MMX from comment The MMX code has been removed in 5ef613bcb0508f16bd5b190168183326391de9b0 and MMX was not used for most cpus even before then. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/mpegvideoenc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 9003d017e5..3943a284e8 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -117,7 +117,7 @@ typedef struct MPVEncContext { int (*q_intra_matrix)[64]; int (*q_chroma_intra_matrix)[64]; int (*q_inter_matrix)[64]; - /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/ + /** identical to the above but for SSE & these are not permutated, second 64 entries are bias*/ uint16_t (*q_intra_matrix16)[2][64]; uint16_t (*q_chroma_intra_matrix16)[2][64]; uint16_t (*q_inter_matrix16)[2][64]; -- 2.52.0 >From d73fb3d3ec580150e446c2b68f314d361dc9eb2f Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sun, 8 Feb 2026 15:53:12 +0100 Subject: [PATCH 7/9] avcodec/snowenc: Remove redundant emms_c() This emms_c() has been superseded by the one added a few lines above in 2c1d38d1e1c2617f51bbb833bb7fe1298644cd21. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/snowenc.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 68c2bb2ebc..13ee402cbc 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -2057,8 +2057,6 @@ redo_frame: ff_write_pass1_stats(&enc->m); enc->m.last_pict_type = mpv->c.pict_type; - emms_c(); - ff_encode_add_stats_side_data(pkt, s->current_picture->quality, enc->encoding_error, (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0, -- 2.52.0 >From 17ffc307e94215bf98af4017a2f27e508bf86af4 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sun, 8 Feb 2026 16:21:16 +0100 Subject: [PATCH 8/9] avcodec/ratecontrol: Remove unnecessary emms_c() ff_rate_control_init/uninit() are only called during codec init or close and no DSP calls happen in these, so there is no need to reset the floating point state. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/ratecontrol.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 7f89b5b218..a789277c9f 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -533,7 +533,6 @@ av_cold int ff_rate_control_init(MPVMainEncContext *const m) "qp2bits", NULL }; - emms_c(); if (!avctx->rc_max_available_vbv_use && avctx->rc_buffer_size) { if (avctx->rc_max_rate) { @@ -710,8 +709,6 @@ av_cold int ff_rate_control_init(MPVMainEncContext *const m) av_cold void ff_rate_control_uninit(RateControlContext *rcc) { - emms_c(); - // rc_eq is always managed via an AVOption and therefore not freed here. av_expr_free(rcc->rc_eq_eval); rcc->rc_eq_eval = NULL; -- 2.52.0 >From 1920ad0742dd3ed37da54c56c6c53c7e2fec5369 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sun, 8 Feb 2026 21:48:56 +0100 Subject: [PATCH 9/9] avcodec/ratecontrol: Move emms_c() to the only callsite needing it Namely to one of the three callsites in snowenc.c. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/ratecontrol.c | 2 -- libavcodec/snowenc.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index a789277c9f..d48ede909c 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -26,7 +26,6 @@ */ #include "libavutil/attributes.h" -#include "libavutil/emms.h" #include "libavutil/internal.h" #include "libavutil/mem.h" @@ -924,7 +923,6 @@ float ff_rate_estimate_qscale(MPVMainEncContext *const m, int dry_run) double rate_factor; int64_t var; const int pict_type = s->c.pict_type; - emms_c(); get_qminmax(&qmin, &qmax, m, pict_type); diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 13ee402cbc..6ce341d64d 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -1700,6 +1700,7 @@ static int ratecontrol_1pass(SnowEncContext *enc, AVFrame *pict) coef_sum+= abs(buf[x+y*stride]) * qdiv >> 16; } } + emms_c(); /* ugly, ratecontrol just takes a sqrt again */ av_assert0(coef_sum < INT_MAX); -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
