diff options
author | Eric Anholt <anholt@FreeBSD.org> | 2005-10-17 23:36:47 +0000 |
---|---|---|
committer | Eric Anholt <anholt@FreeBSD.org> | 2005-10-17 23:36:47 +0000 |
commit | cd41364d4678a0c9c07f9312783c738dc25d690c (patch) | |
tree | a19dc2fede6901a96d33edc6aed2f05585955eb9 | |
parent | 3d5f945c06a296c6cbb6fb06a4e0322f53db2cff (diff) | |
download | liboil-cd41364d4678a0c9c07f9312783c738dc25d690c.tar.gz |
Disable SSE on versions of FreeBSD with no kernel support for it. On
non-FreeBSD, non-Linux kernels, disable it until we learn to check
whether the operating system supports SSE.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | liboil/liboilcpu.c | 38 |
2 files changed, 46 insertions, 0 deletions
@@ -1,5 +1,13 @@ 2005-10-17 Eric Anholt <anholt@FreeBSD.org> + * liboil/liboilcpu.c: (oil_cpu_i386_kernel_restrict_flags), + (oil_cpu_i386_getflags): + Disable SSE on versions of FreeBSD with no kernel support for it. On + non-FreeBSD, non-Linux kernels, disable it until we learn to check + whether the operating system supports SSE. + +2005-10-17 Eric Anholt <anholt@FreeBSD.org> + * liboil/powerpc/Makefile.am: Don't attempt to build powerpc files on non-powerpcs, where the altivec flags break the compile. diff --git a/liboil/liboilcpu.c b/liboil/liboilcpu.c index 666b746..5ef0077 100644 --- a/liboil/liboilcpu.c +++ b/liboil/liboilcpu.c @@ -40,6 +40,11 @@ #include <setjmp.h> #include <signal.h> +#if defined(__FreeBSD__) +#include <sys/types.h> +#include <sys/sysctl.h> +#endif + #if defined(__i386__) static char * get_cpuinfo_flags_string (char *cpuinfo); static char ** strsplit (char *s); @@ -203,6 +208,37 @@ oil_cpu_i386_getflags_cpuid (void) } } +/* Reduce the set of CPU capabilities detected by whatever detection mechanism + * was chosen, according to kernel limitations. SSE requires kernel support for + * use. + * + * This function might also want to grow a check for the old RedHat + Linux 2.2 + * unmasked SSE FPU exception bug. Other than that, if /proc/cpuinfo reported + * SSE, then it's safe. + */ +static void +oil_cpu_i386_kernel_restrict_flags(void) +{ +#ifdef __FreeBSD__ + int ret, enabled; + unsigned int len; + + len = sizeof(enabled); + ret = sysctlbyname("hw.instruction_sse", &enabled, &len, NULL, 0); + if (ret || !enabled) { + oil_cpu_flags &= ~(OIL_IMPL_FLAG_SSE | OIL_IMPL_FLAG_SSE2 | + OIL_IMPL_FLAG_MMXEXT | OIL_IMPL_FLAG_SSE3); + } +#endif +#if !defined(__linux__) && !defined(__FreeBSD__) + /* If we don't know that the operating system supports SSE, don't trust that + * it will properly support it. + */ + oil_cpu_flags &= ~(OIL_IMPL_FLAG_SSE | OIL_IMPL_FLAG_SSE2 | + OIL_IMPL_FLAG_MMXEXT | OIL_IMPL_FLAG_SSE3); +#endif +} + static void oil_cpu_i386_getflags(void) { @@ -214,6 +250,8 @@ oil_cpu_i386_getflags(void) } else { oil_cpu_i386_getflags_cpuid(); } + + oil_cpu_i386_kernel_restrict_flags(); } #endif |