diff options
author | Daniel Kolesa <[email protected]> | 2019-08-27 21:47:48 +0200 |
---|---|---|
committer | Matt Turner <[email protected]> | 2019-08-27 14:55:37 -0700 |
commit | 1b9fce56c4f28a092dd1cd6a1dbe8921c442824e (patch) | |
tree | 115f74d2b6509e4903d25706bea48bed94a1017c /src/util | |
parent | 23f42f8dcfe7ca275ff3cbb5586b5a07ce8df778 (diff) |
util: add auxv based PowerPC AltiVec/VSX detection
At least on Linux, we can use the ELF auxiliary vector to
detect the presence of AltiVec, VSX and other CPU features
without having to go through handling SIGILL, which has
various problems of its own.
A similar thing is already being done for ARM to detect NEON.
Reviewed-by: Matt Turner <[email protected]>
Signed-off-by: Daniel Kolesa <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/u_cpu_detect.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/util/u_cpu_detect.c b/src/util/u_cpu_detect.c index 4df10c62ef5..abfea65b24d 100644 --- a/src/util/u_cpu_detect.c +++ b/src/util/u_cpu_detect.c @@ -92,7 +92,7 @@ static int has_cpuid(void); #endif -#if defined(PIPE_ARCH_PPC) && !defined(PIPE_OS_APPLE) +#if defined(PIPE_ARCH_PPC) && !defined(PIPE_OS_APPLE) && !defined(PIPE_OS_LINUX) static jmp_buf __lv_powerpc_jmpbuf; static volatile sig_atomic_t __lv_powerpc_canjump = 0; @@ -126,8 +126,29 @@ check_os_altivec_support(void) util_cpu_caps.has_altivec = 1; } } -#else /* !PIPE_OS_APPLE */ - /* not on Apple/Darwin, do it the brute-force way */ +#elif defined(PIPE_OS_LINUX) /* !PIPE_OS_APPLE */ +#if defined(PIPE_ARCH_PPC_64) + Elf64_auxv_t aux; +#else + Elf32_auxv_t aux; +#endif + int fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC); + if (fd >= 0) { + while (read(fd, &aux, sizeof(aux)) == sizeof(aux)) { + if (aux.a_type == AT_HWCAP) { + char *env_vsx = getenv("GALLIVM_VSX"); + uint64_t hwcap = aux.a_un.a_val; + util_cpu_caps.has_altivec = (hwcap >> 28) & 1; + if (!env_vsx || env_vsx[0] != '0') { + util_cpu_caps.has_vsx = (hwcap >> 7) & 1; + } + break; + } + } + close(fd); + } +#else /* !PIPE_OS_APPLE && !PIPE_OS_LINUX */ + /* not on Apple/Darwin or Linux, do it the brute-force way */ /* this is borrowed from the libmpeg2 library */ signal(SIGILL, sigill_handler); if (setjmp(__lv_powerpc_jmpbuf)) { @@ -171,7 +192,7 @@ check_os_altivec_support(void) util_cpu_caps.has_altivec = 0; } } -#endif /* !PIPE_OS_APPLE */ +#endif /* !PIPE_OS_APPLE && !PIPE_OS_LINUX */ } #endif /* PIPE_ARCH_PPC */ |