[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 11:54:48 CEST 2006


On Thu, Jun 15, 2006 at 05:49:49PM +0800, jserv at linux2.cc.ntu.edu.tw wrote:
> On Thu, Jun 15, 2006 at 11:29:40AM +0200, Michael Niedermayer wrote:
> > Hi
> > 
> > On Thu, Jun 15, 2006 at 02:35:32PM +0800, jserv at linux2.cc.ntu.edu.tw wrote:
> > [...]
> > 
> > 3DNOW is ignored by this patch
> 
> hi Michael,
> 
>   Thanks for remanding me of 3DNow! detection, and I have updated my
> patch in attachment.

Hello list,

I am sorry that I sent the wrong attachment, and this one is correct
though.

Regards,
Jim Huang (jserv)
http://jserv.sayya.org/
-------------- next part --------------
Index: libmpeg2/cpu_accel.c
===================================================================
--- libmpeg2/cpu_accel.c	(revision 18722)
+++ libmpeg2/cpu_accel.c	(working copy)
@@ -26,6 +26,7 @@
  */
 
 #include "config.h"
+#include "cpudetect.h"
 
 #include <inttypes.h>
 
@@ -35,8 +36,16 @@
 
 #ifdef ACCEL_DETECT
 #if defined(ARCH_X86) || defined(ARCH_X86_64)
+
+/* MPlayer imports libmpeg2 as decoder, which detects MMX / 3DNow! 
+ * instructions via assembly. However, it is regarded as duplicaed work
+ * in MPlayer, so that we enforce to use MPlayer's implementation.
+ */
+#define USE_MPLAYER_CPUDETECT
+
 static inline uint32_t arch_accel (void)
 {
+#if !defined(USE_MPLAYER_CPUDETECT)
     uint32_t eax, ebx, ecx, edx;
     int AMD;
     uint32_t caps;
@@ -109,6 +118,32 @@ static inline uint32_t arch_accel (void)
 	caps |= MPEG2_ACCEL_X86_MMXEXT;
 
     return caps;
+#else /* USE_MPLAYER_CPUDETECT: 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_3DNOW) || defined(HAVE_3DNOWEX)
+    if (gCpuCaps.has3DNowExt || gCpuCaps.has3DNow)
+	return MPEG2_ACCEL_X86_3DNOW;
+    }
+#endif
+#if defined(HAVE_MMX)
+    if (gCpuCaps.hasMMX || gCpuCaps.has3DNow || gCpuCaps.has3DNowExt)
+	return MPEG2_ACCEL_X86_MMX;
+    }
+#endif
+    /* No acceleration instructions */
+    return 0;
+
+#endif /* USE_MPLAYER_CPUDETECT */
 }
 #endif /* ARCH_X86 || ARCH_X86_64 */
 
Index: libmpeg2/mpeg2.h
===================================================================
--- libmpeg2/mpeg2.h	(revision 18722)
+++ 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