[x264-devel] [PATCH] OpenBSD support

Brad brad at comstyle.com
Sat Sep 6 21:55:19 CEST 2008


On Mon, Sep 01, 2008 at 09:47:28PM -0400, Brad wrote:
> Here are a handful of patches to fix x264 on OpenBSD.
> 
> 
> Switch from using the signals method of AltiVec detection to using
> the machdep.altivec sysctl and add support for detecting the number
> of CPUs in the system using the hw.ncpu sysctl.

Here is another revision of the patch mentioned above. This seems
to be the preferred style or so I've been told based on brief
discussion on the IRC channel..


$OpenBSD: patch-common_cpu_c,v 1.3 2008/08/28 15:23:31 brad Exp $
--- common/cpu.c.orig	Sun Jul 13 16:45:06 2008
+++ common/cpu.c	Sat Sep  6 15:22:29 2008
@@ -32,6 +32,10 @@
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #endif
+#ifdef SYS_OPENBSD
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
 
 #include "common.h"
 #include "cpu.h"
@@ -182,13 +186,20 @@ uint32_t x264_cpu_detect( void )
 
 #elif defined( ARCH_PPC )
 
-#ifdef SYS_MACOSX
+#if defined(SYS_MACOSX) || defined(SYS_OPENBSD)
 #include <sys/sysctl.h>
+#ifdef SYS_OPENBSD
+#include <machine/cpu.h>
+#endif
 uint32_t x264_cpu_detect( void )
 {
     /* Thank you VLC */
     uint32_t cpu = 0;
+#ifdef SYS_OPENBSD
+    int      selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
+#else
     int      selectors[2] = { CTL_HW, HW_VECTORUNIT };
+#endif
     int      has_altivec = 0;
     size_t   length = sizeof( has_altivec );
     int      error = sysctl( selectors, 2, &has_altivec, &length, NULL, 0 );
@@ -286,6 +297,17 @@ int x264_cpu_num_processors( void )
     int numberOfCPUs;
     size_t length = sizeof( numberOfCPUs );
     if( sysctlbyname("hw.ncpu", &numberOfCPUs, &length, NULL, 0) )
+    {
+        numberOfCPUs = 1;
+    }
+    return numberOfCPUs;
+
+#elif defined(SYS_OPENBSD)
+    int numberOfCPUs;
+    int mib[2] = { CTL_HW, HW_NCPU };
+    size_t length = sizeof( numberOfCPUs );
+
+    if( sysctl(mib, 2, &numberOfCPUs, &length, NULL, 0) )
     {
         numberOfCPUs = 1;
     }

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the x264-devel mailing list