diff libmpeg2/cpu_accel.c @ 18727:24b2d27f2407

Use MPlayer's CPU detection module instead of libmpeg2's, initial patch by Jim Huang jserv A linux2¡ëcc¡ëntu¡ëedu¡ëtw, reworked by me according to The Guru's advices ;-) Original thread: Date: Jun 15, 2006 8:35 AM Subject: [MPlayer-dev-eng] [PATCH] Remove duplicated CPU detection in libmpeg2
author gpoirier
date Fri, 16 Jun 2006 13:40:00 +0000
parents 52838f825747
children 0783dd397f74
line wrap: on
line diff
--- a/libmpeg2/cpu_accel.c	Fri Jun 16 11:39:23 2006 +0000
+++ b/libmpeg2/cpu_accel.c	Fri Jun 16 13:40:00 2006 +0000
@@ -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,20 @@
 	caps |= MPEG2_ACCEL_X86_MMXEXT;
 
     return caps;
+#else /* USE_MPLAYER_CPUDETECT: Use MPlayer's cpu capability property */
+    caps = 0;
+    if (gCpuCaps.hasMMX)
+        caps |= MPEG2_ACCEL_X86_MMX;
+    if (gCpuCaps.hasSSE2)
+	caps |= MPEG2_ACCEL_X86_SSE2;
+    if (gCpuCaps.hasMMX2)
+	caps |= MPEG2_ACCEL_X86_MMXEXT;
+    if (gCpuCaps.has3DNow)
+	caps |= MPEG2_ACCEL_X86_3DNOW;
+
+    return caps;
+
+#endif /* USE_MPLAYER_CPUDETECT */
 }
 #endif /* ARCH_X86 || ARCH_X86_64 */