[MPlayer-dev-eng] [PATCH] Remove duplicated CPU detection in libmpeg2

jserv at linux2.cc.ntu.edu.tw jserv at linux2.cc.ntu.edu.tw
Thu Jun 15 08:35:32 CEST 2006


Hello list,

  While implementing SSE2-optimized idct and motion compensation
routines for libmpeg2 in MPlayer, I found that there is a duplicated cpu
detection routine in function arch_accel of libmpeg2/cpu_accel.c when
arch = x86 or x86_64. The attachment contains a small patch to use
MPlayer's cpu capability property instead of hand-coded assembly. Also,
the patch added MPEG2_ACCEL_X86_SSE2 definition for identification of
Intel SSE2 instructions.

  Please take a look over that. Thanks!

Best Regards,
Jim Huang (jserv)
http://jserv.sayya.org/
-------------- next part --------------
Index: libmpeg2/cpu_accel.c
===================================================================
--- libmpeg2/cpu_accel.c	(revision 18717)
+++ libmpeg2/cpu_accel.c	(working copy)
@@ -26,6 +26,7 @@
  */
 
 #include "config.h"
+#include "cpudetect.h"
 
 #include <inttypes.h>
 
@@ -37,6 +38,7 @@
 #if defined(ARCH_X86) || defined(ARCH_X86_64)
 static inline uint32_t arch_accel (void)
 {
+#if 0 /* MPlayer has its own CPU detection mechanisms */
     uint32_t eax, ebx, ecx, edx;
     int AMD;
     uint32_t caps;
@@ -109,6 +111,27 @@ static inline uint32_t arch_accel (void)
 	caps |= MPEG2_ACCEL_X86_MMXEXT;
 
     return caps;
+#else /* Use MPlayer's cpu capability property */
+
+#if defined(HAVE_SSE2)
+    if (gCpuCaps.hasSSE2) {
+	return MPEG2_ACCEL_X86_MMX | MPEG2_ACCEL_X86_MMXEXT | MPEG2_ACCEL_X86_SSE2;
+    }
+#endif
+#if defined(HAVE_MMX2) || defined(HAVE_SSE)
+    if (gCpuCaps.hasSSE || gCpuCaps.hasMMX2)
+	return MPEG2_ACCEL_X86_MMX | MPEG2_ACCEL_X86_MMXEXT;
+    }
+#endif
+#if defined(HAVE_MMX)
+    if (gCpuCaps.hasMMX || gCpuCaps.has3DNow || gCpuCaps.has3DNowExt)
+	return MPEG2_ACCEL_X86_MMX;
+    }
+#endif
+    /* No acceleration instructions */
+    return 0;
+
+#endif /* End of cpu detection */
 }
 #endif /* ARCH_X86 || ARCH_X86_64 */
 
Index: libmpeg2/mpeg2.h
===================================================================
--- libmpeg2/mpeg2.h	(revision 18717)
+++ libmpeg2/mpeg2.h	(working copy)
@@ -159,6 +159,7 @@ void mpeg2_custom_fbuf (mpeg2dec_t * mpe
 #define MPEG2_ACCEL_X86_MMX 1
 #define MPEG2_ACCEL_X86_3DNOW 2
 #define MPEG2_ACCEL_X86_MMXEXT 4
+#define MPEG2_ACCEL_X86_SSE2 8
 #define MPEG2_ACCEL_PPC_ALTIVEC 1
 #define MPEG2_ACCEL_ALPHA 1
 #define MPEG2_ACCEL_ALPHA_MVI 2


More information about the MPlayer-dev-eng mailing list