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 <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2026-03-09 12:36:05 +01:00
parent fff992a5bc
commit 2d3776b8cc
9 changed files with 75 additions and 6 deletions
+4
View File
@@ -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
+19
View File
@@ -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"
+4
View File
@@ -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
+19
View File
@@ -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"
+2 -3
View File
@@ -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 <mmintrin.h>
# 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 */
+2 -1
View File
@@ -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 \
+2 -2
View File
@@ -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
+4
View File
@@ -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 \
+19
View File
@@ -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"