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

Guillaume POIRIER gpoirier at mplayerhq.hu
Sat Jan 17 14:16:17 CET 2009


On Sat, Jan 17, 2009 at 2:14 PM, Guillaume POIRIER
<gpoirier at mplayerhq.hu> wrote:
> Hello,
>
> On Tue, Jan 6, 2009 at 10:37 AM, Brad <brad at comstyle.com> wrote:
>> 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.
>
> The attached patch does the same with a fewer lines.

Duh! Here it is!

Brad, please give it a try if you can.

Guillaume
-- 
Only a very small fraction of our DNA does anything; the rest is all
comments and ifdefs.

Natalie Wood  - "The only time a woman really succeeds in changing a
man is when he is a baby."
-------------- next part --------------
diff --git a/common/cpu.c b/common/cpu.c
index 56c88cb..53e14f9 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@ -33,6 +33,11 @@
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #endif
+#ifdef SYS_OPENBSD
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <machine/cpu.h>
+#endif
 
 #include "common.h"
 #include "cpu.h"
@@ -194,13 +199,17 @@ uint32_t x264_cpu_detect( void )
 
 #elif defined( ARCH_PPC )
 
-#ifdef SYS_MACOSX
+#if defined(SYS_MACOSX) || defined(SYS_OPENBSD)
 #include <sys/sysctl.h>
 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 +303,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;
     }


More information about the x264-devel mailing list