From 82486255da7a5a0205337c3a4a4f9571ec858d99 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 1 Apr 2019 12:42:19 +0000 Subject: [PATCH 1/2] Simplify AltiVec detection on Linux --- src/strategyselector.c | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/strategyselector.c b/src/strategyselector.c index 51651ce2..39962b92 100644 --- a/src/strategyselector.c +++ b/src/strategyselector.c @@ -375,39 +375,12 @@ static INLINE int get_cpuid(unsigned level, unsigned sublevel, cpuid_t *cpu_info #if COMPILE_POWERPC # if defined(__linux__) -#include -#include -#include #include +#include -//Source: http://freevec.org/function/altivec_runtime_detection_linux static int altivec_available(void) { - int result = 0; - unsigned long buf[64]; - ssize_t count; - int fd, i; - - fd = open("/proc/self/auxv", O_RDONLY); - if (fd < 0) { - return 0; - } - // loop on reading - do { - count = read(fd, buf, sizeof(buf)); - if (count < 0) - break; - for (i=0; i < (count / sizeof(unsigned long)); i += 2) { - if (buf[i] == AT_HWCAP) { - result = !!(buf[i+1] & PPC_FEATURE_HAS_ALTIVEC); - goto out_close; - } else if (buf[i] == AT_NULL) - goto out_close; - } - } while (count == sizeof(buf)); -out_close: - close(fd); - return result; + return !!(getauxval(AT_HWCAP) & PPC_FEATURE_HAS_ALTIVEC); } # elif defined(__FreeBSD__) #include From 85f46e17a90aed84cf68b67630bd0179d665c6ca Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 1 Apr 2019 12:31:11 +0000 Subject: [PATCH 2/2] Detect AltiVec via elf_aux_info() on FreeBSD 12+ --- src/strategyselector.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/strategyselector.c b/src/strategyselector.c index 39962b92..be3eff93 100644 --- a/src/strategyselector.c +++ b/src/strategyselector.c @@ -374,13 +374,23 @@ static INLINE int get_cpuid(unsigned level, unsigned sublevel, cpuid_t *cpu_info #endif // COMPILE_INTEL #if COMPILE_POWERPC -# if defined(__linux__) +# if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 12) +#ifdef __linux__ #include +#else +#include +#endif #include static int altivec_available(void) { - return !!(getauxval(AT_HWCAP) & PPC_FEATURE_HAS_ALTIVEC); + unsigned long hwcap = 0; +#ifdef __linux__ + hwcap = getauxval(AT_HWCAP); +#else + elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); +#endif + return !!(hwcap & PPC_FEATURE_HAS_ALTIVEC); } # elif defined(__FreeBSD__) #include