[Flac-dev] FreeBSD 4.x problem resolved

Christian Weisgerber naddy at mips.inka.de
Sat Jan 15 08:55:34 PST 2005

Bryan Levin reported a problem of the FreeBSD flac port dumping
core on FreeBSD 4.x:


It turns out that the port enabled SSE support, but FreeBSD 4.x
does not support SSE by default.  (FreeBSD 5.x and later do.)  I
have added a small patch to the port to check at runtime whether
the system handles SSE.

(The semantics of hw.instruction_sse are that a value of 1 means
that the kernel includes SSE handling *and* the CPU supports SSE.
A value of 0 means that the kernel will not handle SSE so it can't
be used, although the system CPU may or may not support it.)

--- src/libFLAC/cpu.c.orig
+++ src/libFLAC/cpu.c
@@ -25,6 +25,11 @@
 #include <config.h>
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
 const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
 const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
 const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
@@ -52,6 +57,15 @@
 #ifndef FLAC__SSE_OS
 		info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = false;
+#if defined(__FreeBSD__)
+		{
+			int sse;
+			size_t len = sizeof(sse);
+			if (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) || !sse)
+				info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = false;
+		}
 #ifdef FLAC__USE_3DNOW
Christian "naddy" Weisgerber                          naddy at mips.inka.de

More information about the Flac-dev mailing list