From 2d3776b8cc97e605883b1352f6e798791e54cf06 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 9 Mar 2026 12:36:05 +0100 Subject: [PATCH] avutil/x86/emms: Unavpriv avpriv_emms_asm() This fallback function is used if external MMX is available, while inline MMX and intrinsics for emitting emms are unavailable. It is implemented as an avpriv function, which has several drawbacks for shared builds: 1. The function is so small (3 bytes; 16 with padding) that the overhead of exporting and importing it dwarfs the gains from code deduplication. 2. A call to an external library has more overhead than a library-internal one. 3. It may cause linking failures when a libavutil not exporting avpriv_emms_asm() is paired with a library needing it (if inline assembly and intrinsics were unavailable when building the dependent library). I am not aware of this ever happening. 4. We would be forced to keep avpriv_emms_asm() around for ABI stability even after it is no longer needed. This commit therefore uses the STLIBOBJS, SHLIBOBJS approach to duplicating it into each library on its own if needed. Signed-off-by: Andreas Rheinhardt --- libavcodec/x86/Makefile | 4 ++++ libavcodec/x86/emms.asm | 19 +++++++++++++++++++ libavfilter/x86/Makefile | 4 ++++ libavfilter/x86/emms.asm | 19 +++++++++++++++++++ libavutil/emms.h | 5 ++--- libavutil/x86/Makefile | 3 ++- libavutil/x86/emms.asm | 4 ++-- libswscale/x86/Makefile | 4 ++++ libswscale/x86/emms.asm | 19 +++++++++++++++++++ 9 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 libavcodec/x86/emms.asm create mode 100644 libavfilter/x86/emms.asm create mode 100644 libswscale/x86/emms.asm diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile index e87cb750f4..890ac15f2a 100644 --- a/libavcodec/x86/Makefile +++ b/libavcodec/x86/Makefile @@ -1,5 +1,9 @@ OBJS += x86/constants.o \ +EMMS_OBJS_$(HAVE_MMX_INLINE)_$(HAVE_MMX_EXTERNAL)_$(HAVE_MM_EMPTY) = x86/emms.o +# Add internal copy of ff_emms() to lavc for shared builds (if needed). +SHLIBOBJS += $(EMMS_OBJS__yes_) + # subsystems X86ASM-OBJS-$(CONFIG_AC3DSP) += x86/ac3dsp_init.o X86ASM-OBJS-$(CONFIG_AUDIODSP) += x86/audiodsp_init.o diff --git a/libavcodec/x86/emms.asm b/libavcodec/x86/emms.asm new file mode 100644 index 0000000000..513a0e9fd8 --- /dev/null +++ b/libavcodec/x86/emms.asm @@ -0,0 +1,19 @@ +;***************************************************************************** +;* 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 +;****************************************************************************** + +%include "libavutil/x86/emms.asm" diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile index ade0efc9ae..cfbed4317c 100644 --- a/libavfilter/x86/Makefile +++ b/libavfilter/x86/Makefile @@ -1,6 +1,10 @@ OBJS-$(CONFIG_NOISE_FILTER) += x86/vf_noise.o OBJS-$(CONFIG_SPP_FILTER) += x86/vf_spp.o +EMMS_OBJS_$(HAVE_MMX_INLINE)_$(HAVE_MMX_EXTERNAL)_$(HAVE_MM_EMPTY) = x86/emms.o +# Add internal copy of ff_emms() to libavfilter for shared builds (if needed). +SHLIBOBJS-$(CONFIG_FSPP_FILTER) += $(EMMS_OBJS__yes_) + X86ASM-OBJS-$(CONFIG_SCENE_SAD) += x86/scene_sad.o x86/scene_sad_init.o X86ASM-OBJS-$(CONFIG_AFIR_FILTER) += x86/af_afir.o x86/af_afir_init.o diff --git a/libavfilter/x86/emms.asm b/libavfilter/x86/emms.asm new file mode 100644 index 0000000000..513a0e9fd8 --- /dev/null +++ b/libavfilter/x86/emms.asm @@ -0,0 +1,19 @@ +;***************************************************************************** +;* 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 +;****************************************************************************** + +%include "libavutil/x86/emms.asm" diff --git a/libavutil/emms.h b/libavutil/emms.h index 2b9a456223..bad0bdbd9c 100644 --- a/libavutil/emms.h +++ b/libavutil/emms.h @@ -28,8 +28,6 @@ #if ARCH_X86 -void avpriv_emms_asm(void); - #if HAVE_MMX_INLINE #ifndef __MMX__ #include "libavutil/cpu.h" @@ -80,7 +78,8 @@ static inline void ff_assert0_fpu(const char *file, int line_number) # include # define emms_c _mm_empty #elif HAVE_MMX_EXTERNAL -# define emms_c avpriv_emms_asm +void ff_emms_asm(void); +# define emms_c ff_emms_asm #endif /* HAVE_MMX_INLINE */ #endif /* ARCH_X86 */ diff --git a/libavutil/x86/Makefile b/libavutil/x86/Makefile index 590758ce78..a305503c0f 100644 --- a/libavutil/x86/Makefile +++ b/libavutil/x86/Makefile @@ -1,10 +1,11 @@ OBJS += x86/cpu.o \ EMMS_OBJS_$(HAVE_MMX_INLINE)_$(HAVE_MMX_EXTERNAL)_$(HAVE_MM_EMPTY) = x86/emms.o +# For static builds, libavutil provides ff_emms for all libraries (if needed). +STLIBOBJS += $(EMMS_OBJS__yes_) X86ASM-OBJS += x86/cpuid.o \ x86/crc.o \ - $(EMMS_OBJS__yes_) \ x86/fixed_dsp.o x86/fixed_dsp_init.o \ x86/float_dsp.o x86/float_dsp_init.o \ x86/imgutils.o x86/imgutils_init.o \ diff --git a/libavutil/x86/emms.asm b/libavutil/x86/emms.asm index df84f2221b..485fba4557 100644 --- a/libavutil/x86/emms.asm +++ b/libavutil/x86/emms.asm @@ -23,8 +23,8 @@ SECTION .text ;----------------------------------------------------------------------------- -; void avpriv_emms_asm(void) +; void ff_emms_asm(void) ;----------------------------------------------------------------------------- -cvisible emms_asm, 0, 0 +cglobal emms_asm, 0, 0 emms RET diff --git a/libswscale/x86/Makefile b/libswscale/x86/Makefile index 2eeb2b2627..0f7a3dbf2d 100644 --- a/libswscale/x86/Makefile +++ b/libswscale/x86/Makefile @@ -6,6 +6,10 @@ OBJS-$(HAVE_MMXEXT_INLINE) += x86/hscale_fast_bilinear_simd.o \ OBJS-$(CONFIG_XMM_CLOBBER_TEST) += x86/w64xmmtest.o +EMMS_OBJS_$(HAVE_MMX_INLINE)_$(HAVE_MMX_EXTERNAL)_$(HAVE_MM_EMPTY) = x86/emms.o +# Add internal copy of ff_emms() to swscale for shared builds (if needed). +SHLIBOBJS += $(EMMS_OBJS__yes_) + X86ASM-OBJS += x86/input.o \ x86/output.o \ x86/scale.o \ diff --git a/libswscale/x86/emms.asm b/libswscale/x86/emms.asm new file mode 100644 index 0000000000..513a0e9fd8 --- /dev/null +++ b/libswscale/x86/emms.asm @@ -0,0 +1,19 @@ +;***************************************************************************** +;* 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 +;****************************************************************************** + +%include "libavutil/x86/emms.asm"