[x264-devel] Allow x264 to detect AltiVec and the # of CPUs on OpenBSD.

Brad brad at comstyle.com
Tue Jan 6 10:37:29 CET 2009


Here is a diff to allow the CPU code in x264 to detect the presence of
AltiVec on OpenBSD/PowerPC systems and the # of CPUs on any architecture
supported by OpenBSD.


--- common/cpu.c.orig	Sat Jan  3 16:45:09 2009
+++ common/cpu.c	Sat Jan  3 23:55:03 2009
@@ -33,6 +33,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"
@@ -194,13 +198,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 );
@@ -294,10 +305,17 @@ int x264_cpu_num_processors( void )
     get_system_info( &info );
     return info.cpu_count;
 
-#elif defined(SYS_MACOSX) || defined(SYS_FREEBSD)
+#elif defined(SYS_MACOSX) || defined(SYS_FREEBSD) || defined(SYS_OPENBSD)
     int numberOfCPUs;
+#ifdef SYS_OPENBSD
+    int mib[2] = { CTL_HW, HW_NCPU };
+#endif
     size_t length = sizeof( numberOfCPUs );
+#ifdef SYS_OPENBSD
+    if( sysctl(mib, 2, &numberOfCPUs, &length, NULL, 0) )
+#else
     if( sysctlbyname("hw.ncpu", &numberOfCPUs, &length, NULL, 0) )
+#endif
     {
         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