Subject: Re: Font handling in the mplayer package and enable-runtime-cpudetection (was: CVS commit: pkgsrc/graphics/mplayer-share)
To: Thomas Klausner <wiz@netbsd.org>
From: Bernd Ernesti <netbsd@lists.veego.de>
List: tech-pkg
Date: 12/22/2002 19:38:13
--EVF5PPMfhYS0aIcm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Dec 22, 2002 at 07:33:15PM +0100, Bernd Ernesti wrote:
> On Fri, Dec 06, 2002 at 04:21:47PM +0200, Thomas Klausner wrote:
[..]
> And the turning on the --enable-runtime-cpudetection without any way to
> disable it, better only enable it if a flag is set, is also a performance
> thing which should not be done.

Oh, and i forgot one thing about that. It should be converted to use sysctl.

I made a patch to the current cvs version of mplayer, but didn't had the time to test
it.

If someone could do that today, then it could be integrated in the next release
candidate of mplayer.

Bernd


--EVF5PPMfhYS0aIcm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="cpudetect.diff"

--- ../main/cpudetect.c	Sat Dec  7 21:40:22 2002
+++ cpudetect.c	Sun Dec  8 23:20:14 2002
@@ -16,7 +16,8 @@
 
 #ifdef __NetBSD__
 #include <sys/param.h>
-#include <setjmp.h>
+#include <sys/sysctl.h>
+#include <machine/cpu.h>
 #endif
 
 #ifdef __FreeBSD__
@@ -242,15 +243,6 @@
 #undef CPUID_STEPPING
 
 
-#ifdef __NetBSD__
-jmp_buf sseCheckEnv;
-
-void sseCheckHandler(int i)
-{
-        longjmp(sseCheckEnv, 1);
-}
-#endif
-
 #if defined(__linux__) && defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC)
 static void sigill_handler_sse( int signal, struct sigcontext sc )
 {
@@ -308,30 +300,34 @@
       gCpuCaps.hasSSE=0;
 
 #elif defined(__NetBSD__)
-#if __NetBSD_Version__ >= 105260000
-   if ( gCpuCaps.hasSSE ) {
-      void (*oldHandler)(int);
-
-      mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
-
-      oldHandler = signal(SIGILL, sseCheckHandler);
-      if (setjmp(sseCheckEnv)) {
-        gCpuCaps.hasSSE = 0;
-      } else {
-         __asm__ __volatile__ (
-               "subl $0x10, %esp     \n"
-               "movups %xmm0, (%esp) \n"
-               "emms                 \n"
-               "addl $0x10, %esp     \n"
-           );
-      }
-      signal(SIGILL, oldHandler);
-
-      if ( gCpuCaps.hasSSE ) {
-	mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
-      } else {
-	mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" );
-      }
+#if __NetBSD_Version__ >= 105250000
+   int has_sse, has_sse2, ret, mib[2];
+   size_t varlen;
+
+   mib[0] = CTL_MACHDEP;
+   mib[1] = CPU_SSE;
+   varlen = sizeof(has_sse);
+
+   mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
+   ret = sysctl(mib, 2, &has_sse, &varlen, NULL, 0);
+   if (ret < 0 || !has_sse) {
+      gCpuCaps.hasSSE=0;
+      mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
+   } else {
+      gCpuCaps.hasSSE=1;
+      mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" );
+   }
+
+   mib[1] = CPU_SSE2;
+   varlen = sizeof(has_sse2);
+   mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE2... " );
+   ret = sysctl(mib, 2, &has_sse2, &varlen, NULL, 0);
+   if (ret < 0 || !has_sse2) {
+      gCpuCaps.hasSSE2=0;
+      mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
+   } else {
+      gCpuCaps.hasSSE2=1;
+      mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" );
    }
 #else
    gCpuCaps.hasSSE = 0

--EVF5PPMfhYS0aIcm--