Mercurial > mplayer.hg
comparison cpudetect.c @ 8533:9b73b801af55
Ok, here is a better patch, which even adds a fix to compile it on older
NetBSD systems, there was a ; missing.
patch by Bernd Ernesti <mplayer@lists.veego.de>
author | arpi |
---|---|
date | Mon, 23 Dec 2002 01:24:42 +0000 |
parents | 1b2fc92980d9 |
children | 778989dba3a2 |
comparison
equal
deleted
inserted
replaced
8532:9688aa033083 | 8533:9b73b801af55 |
---|---|
14 #include <stdio.h> | 14 #include <stdio.h> |
15 #include <string.h> | 15 #include <string.h> |
16 | 16 |
17 #ifdef __NetBSD__ | 17 #ifdef __NetBSD__ |
18 #include <sys/param.h> | 18 #include <sys/param.h> |
19 #include <setjmp.h> | 19 #include <sys/sysctl.h> |
20 #include <machine/cpu.h> | |
20 #endif | 21 #endif |
21 | 22 |
22 #ifdef __FreeBSD__ | 23 #ifdef __FreeBSD__ |
23 #include <sys/types.h> | 24 #include <sys/types.h> |
24 #include <sys/sysctl.h> | 25 #include <sys/sysctl.h> |
240 #undef CPUID_FAMILY | 241 #undef CPUID_FAMILY |
241 #undef CPUID_MODEL | 242 #undef CPUID_MODEL |
242 #undef CPUID_STEPPING | 243 #undef CPUID_STEPPING |
243 | 244 |
244 | 245 |
245 #ifdef __NetBSD__ | |
246 jmp_buf sseCheckEnv; | |
247 | |
248 void sseCheckHandler(int i) | |
249 { | |
250 longjmp(sseCheckEnv, 1); | |
251 } | |
252 #endif | |
253 | |
254 #if defined(__linux__) && defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC) | 246 #if defined(__linux__) && defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC) |
255 static void sigill_handler_sse( int signal, struct sigcontext sc ) | 247 static void sigill_handler_sse( int signal, struct sigcontext sc ) |
256 { | 248 { |
257 mp_msg(MSGT_CPUDETECT,MSGL_V, "SIGILL, " ); | 249 mp_msg(MSGT_CPUDETECT,MSGL_V, "SIGILL, " ); |
258 | 250 |
306 ret = sysctlbyname("hw.instruction_sse", &has_sse, &len, NULL, 0); | 298 ret = sysctlbyname("hw.instruction_sse", &has_sse, &len, NULL, 0); |
307 if (ret || !has_sse) | 299 if (ret || !has_sse) |
308 gCpuCaps.hasSSE=0; | 300 gCpuCaps.hasSSE=0; |
309 | 301 |
310 #elif defined(__NetBSD__) | 302 #elif defined(__NetBSD__) |
311 #if __NetBSD_Version__ >= 105260000 | 303 #if __NetBSD_Version__ >= 105250000 |
312 if ( gCpuCaps.hasSSE ) { | 304 int has_sse, has_sse2, ret, mib[2]; |
313 void (*oldHandler)(int); | 305 size_t varlen; |
314 | 306 |
315 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " ); | 307 mib[0] = CTL_MACHDEP; |
316 | 308 mib[1] = CPU_SSE; |
317 oldHandler = signal(SIGILL, sseCheckHandler); | 309 varlen = sizeof(has_sse); |
318 if (setjmp(sseCheckEnv)) { | 310 |
319 gCpuCaps.hasSSE = 0; | 311 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " ); |
320 } else { | 312 ret = sysctl(mib, 2, &has_sse, &varlen, NULL, 0); |
321 __asm__ __volatile__ ( | 313 if (ret < 0 || !has_sse) { |
322 "subl $0x10, %esp \n" | 314 gCpuCaps.hasSSE=0; |
323 "movups %xmm0, (%esp) \n" | 315 mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" ); |
324 "emms \n" | 316 } else { |
325 "addl $0x10, %esp \n" | 317 gCpuCaps.hasSSE=1; |
326 ); | 318 mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" ); |
327 } | 319 } |
328 signal(SIGILL, oldHandler); | 320 |
329 | 321 mib[1] = CPU_SSE2; |
330 if ( gCpuCaps.hasSSE ) { | 322 varlen = sizeof(has_sse2); |
331 mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" ); | 323 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE2... " ); |
332 } else { | 324 ret = sysctl(mib, 2, &has_sse2, &varlen, NULL, 0); |
333 mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" ); | 325 if (ret < 0 || !has_sse2) { |
334 } | 326 gCpuCaps.hasSSE2=0; |
327 mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" ); | |
328 } else { | |
329 gCpuCaps.hasSSE2=1; | |
330 mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" ); | |
335 } | 331 } |
336 #else | 332 #else |
337 gCpuCaps.hasSSE = 0 | 333 gCpuCaps.hasSSE = 0; |
338 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "No OS support for SSE, disabling to be safe.\n" ); | 334 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "No OS support for SSE, disabling to be safe.\n" ); |
339 #endif | 335 #endif |
340 #elif defined(__linux__) | 336 #elif defined(__linux__) |
341 #if defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC) | 337 #if defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC) |
342 struct sigaction saved_sigill; | 338 struct sigaction saved_sigill; |