[x264-devel] Allow x264 to detect AltiVec and the # of CPUs on OpenBSD.
Brad
brad at comstyle.com
Sat Jan 17 16:42:09 CET 2009
On Sat, Jan 17, 2009 at 03:28:50PM +0000, Loren Merritt wrote:
> On Sat, 17 Jan 2009, Guillaume POIRIER wrote:
>
> > 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.
>
> doesn't need two separate consecutive #ifdef SYS_OPENBSD
Looks a bit better.
--- common/cpu.c.orig Wed Jan 7 16:45:07 2009
+++ common/cpu.c Sat Jan 17 07:11:13 2009
@@ -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,15 @@ 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;
size_t length = sizeof( numberOfCPUs );
+#ifdef SYS_OPENBSD
+ int mib[2] = { CTL_HW, HW_NCPU };
+ 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