[FFmpeg-devel] [PATCH 31/41] avcodec/x86/hpeldsp_init: Disable overridden functions on x64

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Jun 10 02:55:13 EEST 2022


x64 always has MMX, MMXEXT, SSE and SSE2 and this means
that some functions for MMX, MMXEXT, SSE and 3dnow are always
overridden by other functions (unless one e.g. explicitly
disables SSE2). This commit therefore disables
the 3dnow implementation (which is overridden by the MMXEXT
specific implementation) as well as some MMX functions
at compile-time for x64.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/x86/fpel.asm       |  2 ++
 libavcodec/x86/hpeldsp.asm    | 22 +++++++++++++++++++
 libavcodec/x86/hpeldsp_init.c | 40 +++++++++++++++++++++++++----------
 libavcodec/x86/rnd_template.c |  2 ++
 4 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/libavcodec/x86/fpel.asm b/libavcodec/x86/fpel.asm
index d38a1b1035..8c810265c3 100644
--- a/libavcodec/x86/fpel.asm
+++ b/libavcodec/x86/fpel.asm
@@ -91,7 +91,9 @@ cglobal %1_pixels%2, 4,5,4
 INIT_MMX mmx
 OP_PIXELS put, 4
 OP_PIXELS put, 8
+%if ARCH_X86_32
 OP_PIXELS avg, 8
+%endif
 OP_PIXELS put, 16
 OP_PIXELS avg, 16
 
diff --git a/libavcodec/x86/hpeldsp.asm b/libavcodec/x86/hpeldsp.asm
index ce5d7a4e28..97f9f06539 100644
--- a/libavcodec/x86/hpeldsp.asm
+++ b/libavcodec/x86/hpeldsp.asm
@@ -83,8 +83,10 @@ cglobal put_pixels8_x2, 4,5
 
 INIT_MMX mmxext
 PUT_PIXELS8_X2
+%if ARCH_X86_32
 INIT_MMX 3dnow
 PUT_PIXELS8_X2
+%endif
 
 
 ; void ff_put_pixels16_x2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
@@ -127,8 +129,10 @@ cglobal put_pixels16_x2, 4,5
 
 INIT_MMX mmxext
 PUT_PIXELS_16
+%if ARCH_X86_32
 INIT_MMX 3dnow
 PUT_PIXELS_16
+%endif
 ; The 8_X2 macro can easily be used here
 INIT_XMM sse2
 PUT_PIXELS8_X2
@@ -171,8 +175,10 @@ cglobal put_no_rnd_pixels8_x2, 4,5
 
 INIT_MMX mmxext
 PUT_NO_RND_PIXELS8_X2
+%if ARCH_X86_32
 INIT_MMX 3dnow
 PUT_NO_RND_PIXELS8_X2
+%endif
 
 
 ; void ff_put_pixels8_y2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
@@ -209,8 +215,10 @@ cglobal put_pixels8_y2, 4,5
 
 INIT_MMX mmxext
 PUT_PIXELS8_Y2
+%if ARCH_X86_32
 INIT_MMX 3dnow
 PUT_PIXELS8_Y2
+%endif
 ; actually, put_pixels16_y2_sse2
 INIT_XMM sse2
 PUT_PIXELS8_Y2
@@ -249,8 +257,10 @@ cglobal put_no_rnd_pixels8_y2, 4,5
 
 INIT_MMX mmxext
 PUT_NO_RND_PIXELS8_Y2
+%if ARCH_X86_32
 INIT_MMX 3dnow
 PUT_NO_RND_PIXELS8_Y2
+%endif
 
 
 ; void ff_avg_pixels8(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
@@ -279,8 +289,10 @@ cglobal avg_pixels8, 4,5
     REP_RET
 %endmacro
 
+%if ARCH_X86_32
 INIT_MMX 3dnow
 AVG_PIXELS8
+%endif
 
 
 ; void ff_avg_pixels8_x2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
@@ -335,12 +347,16 @@ cglobal avg_pixels8_x2, 4,5
     REP_RET
 %endmacro
 
+%if ARCH_X86_32
 INIT_MMX mmx
 AVG_PIXELS8_X2
+%endif
 INIT_MMX mmxext
 AVG_PIXELS8_X2
+%if ARCH_X86_32
 INIT_MMX 3dnow
 AVG_PIXELS8_X2
+%endif
 ; actually avg_pixels16_x2
 INIT_XMM sse2
 AVG_PIXELS8_X2
@@ -384,8 +400,10 @@ cglobal avg_pixels8_y2, 4,5
 
 INIT_MMX mmxext
 AVG_PIXELS8_Y2
+%if ARCH_X86_32
 INIT_MMX 3dnow
 AVG_PIXELS8_Y2
+%endif
 ; actually avg_pixels16_y2
 INIT_XMM sse2
 AVG_PIXELS8_Y2
@@ -433,8 +451,10 @@ cglobal avg_approx_pixels8_xy2, 4,5
 
 INIT_MMX mmxext
 AVG_APPROX_PIXELS8_XY2
+%if ARCH_X86_32
 INIT_MMX 3dnow
 AVG_APPROX_PIXELS8_XY2
+%endif
 
 
 ; void ff_avg_pixels16_xy2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
@@ -517,8 +537,10 @@ cglobal %1_pixels8_xy2, 4,5
 
 INIT_MMX mmxext
 SET_PIXELS_XY2 avg
+%if ARCH_X86_32
 INIT_MMX 3dnow
 SET_PIXELS_XY2 avg
+%endif
 INIT_XMM sse2
 SET_PIXELS_XY2 put
 SET_PIXELS_XY2 avg
diff --git a/libavcodec/x86/hpeldsp_init.c b/libavcodec/x86/hpeldsp_init.c
index 6336587281..06ba5390d7 100644
--- a/libavcodec/x86/hpeldsp_init.c
+++ b/libavcodec/x86/hpeldsp_init.c
@@ -131,19 +131,25 @@ CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
 #undef DEF
 #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
 #define STATIC
+#if ARCH_X86_64
+#define NO_AVG
+#endif
 
 #include "rnd_template.c"
 
+#undef NO_AVG
 #undef DEF
 #undef SET_RND
 #undef PAVGBP
 #undef PAVGB
 
 #if HAVE_MMX
+#if ARCH_X86_32
 CALL_2X_PIXELS(avg_pixels16_y2_mmx, avg_pixels8_y2_mmx, 8)
 CALL_2X_PIXELS(put_pixels16_y2_mmx, put_pixels8_y2_mmx, 8)
 
 CALL_2X_PIXELS_EXPORT(ff_avg_pixels16_xy2_mmx, ff_avg_pixels8_xy2_mmx, 8)
+#endif
 CALL_2X_PIXELS_EXPORT(ff_put_pixels16_xy2_mmx, ff_put_pixels8_xy2_mmx, 8)
 #endif
 
@@ -162,38 +168,49 @@ CALL_2X_PIXELS_EXPORT(ff_put_pixels16_xy2_mmx, ff_put_pixels8_xy2_mmx, 8)
     CALL_2X_PIXELS(avg_pixels16_xy2       ## CPUEXT, ff_avg_pixels8_xy2       ## CPUEXT, 8) \
     CALL_2X_PIXELS(avg_approx_pixels16_xy2## CPUEXT, ff_avg_approx_pixels8_xy2## CPUEXT, 8)
 
+#if ARCH_X86_32
 HPELDSP_AVG_PIXELS16(_3dnow)
+#endif
 HPELDSP_AVG_PIXELS16(_mmxext)
 
 #endif /* HAVE_X86ASM */
 
 #define SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU)                             \
     if (HAVE_MMX_EXTERNAL)                                                  \
-    c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _     ## CPU;
+        c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU
 
 #if HAVE_MMX_INLINE
-#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)                                     \
+#define SET_HPEL_FUNCS03(PFX, IDX, SIZE, CPU)                                   \
+    do {                                                                        \
+        SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU);                                \
+        c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
+    } while (0)
+#define SET_HPEL_FUNCS12(PFX, IDX, SIZE, CPU)                                   \
     do {                                                                        \
-        SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU)                                 \
         c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_  ## CPU; \
         c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_  ## CPU; \
-        c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
     } while (0)
 #else
+#define SET_HPEL_FUNCS03(PFX, IDX, SIZE, CPU) SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU)
+#define SET_HPEL_FUNCS12(PFX, IDX, SIZE, CPU) ((void)0)
+#endif
 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)                                     \
     do {                                                                        \
-        SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU)                                 \
+        SET_HPEL_FUNCS03(PFX, IDX, SIZE, CPU);                                  \
+        SET_HPEL_FUNCS12(PFX, IDX, SIZE, CPU);                                  \
     } while (0)
-#endif
 
 static void hpeldsp_init_mmx(HpelDSPContext *c, int flags)
 {
-    SET_HPEL_FUNCS(put,        [0], 16, mmx);
+    SET_HPEL_FUNCS03(put,      [0], 16, mmx);
     SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
-    SET_HPEL_FUNCS(avg,        [0], 16, mmx);
     SET_HPEL_FUNCS(avg_no_rnd,    , 16, mmx);
-    SET_HPEL_FUNCS(put,        [1],  8, mmx);
+    SET_HPEL_FUNCS03(put,      [1],  8, mmx);
     SET_HPEL_FUNCS(put_no_rnd, [1],  8, mmx);
+#if ARCH_X86_32
+    SET_HPEL_FUNCS12(put,      [0], 16, mmx);
+    SET_HPEL_FUNCS12(put,      [1],  8, mmx);
+    SET_HPEL_FUNCS(avg,        [0], 16, mmx);
     if (HAVE_MMX_EXTERNAL) {
         c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmx;
         c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmx;
@@ -202,6 +219,7 @@ static void hpeldsp_init_mmx(HpelDSPContext *c, int flags)
     c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
     c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmx;
 #endif
+#endif
 }
 
 static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags)
@@ -237,7 +255,7 @@ static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags)
 
 static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags)
 {
-#if HAVE_AMD3DNOW_EXTERNAL
+#if HAVE_AMD3DNOW_EXTERNAL && ARCH_X86_32
     c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
     c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
 
@@ -263,7 +281,7 @@ static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags)
         c->avg_pixels_tab[0][3] = avg_approx_pixels16_xy2_3dnow;
         c->avg_pixels_tab[1][3] = ff_avg_approx_pixels8_xy2_3dnow;
     }
-#endif /* HAVE_AMD3DNOW_EXTERNAL */
+#endif /* HAVE_AMD3DNOW_EXTERNAL && ARCH_X86_32 */
 }
 
 static void hpeldsp_init_sse2_fast(HpelDSPContext *c, int flags)
diff --git a/libavcodec/x86/rnd_template.c b/libavcodec/x86/rnd_template.c
index 09946bd23f..b825eeba6e 100644
--- a/libavcodec/x86/rnd_template.c
+++ b/libavcodec/x86/rnd_template.c
@@ -97,6 +97,7 @@ av_unused STATIC void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixel
         :FF_REG_a, "memory");
 }
 
+#ifndef NO_AVG
 // avg_pixels
 // this routine is 'slightly' suboptimal but mostly unused
 av_unused STATIC void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels,
@@ -173,3 +174,4 @@ av_unused STATIC void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixel
         :"D"(block), "r"((x86_reg)line_size)
         :FF_REG_a, "memory");
 }
+#endif
-- 
2.34.1



More information about the ffmpeg-devel mailing list