[Mesa-dev] [PATCH v2 1/2] gallium: Enable ARM NEON/VFP CPU detection.
Grazvydas Ignotas
notasas at gmail.com
Fri Apr 14 09:16:02 UTC 2017
On Fri, Apr 14, 2017 at 12:08 AM, Eric Anholt <eric at anholt.net> wrote:
> I wrote this code with reference to pixman, though I've only decided to
> cover Linux (what I'm testing) and Android (seems obvious enough). Linux
> has getauxval() as a cleaner interface to the /proc entry, but it's more
> glibc-specific and I didn't want to add detection for that.
>
But now you have to worry about running out of file descriptors and
forking. Mesa already does checks like
#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) &&
(__GLIBC_MINOR__ >= 19)))
but it's up to you I guess.
> This will be used to enable NEON at runtime on ARMv6 builds of vc4.
>
> v2: Actually initialize the temp vars in the Android path (noticed by
> daniels)
> ---
> src/gallium/auxiliary/util/u_cpu_detect.c | 46
> +++++++++++++++++++++++++++++++
> src/gallium/auxiliary/util/u_cpu_detect.h | 2 ++
> 2 files changed, 48 insertions(+)
>
> diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c
> b/src/gallium/auxiliary/util/u_cpu_detect.c
> index 845fc6b34d5c..c9083fed63af 100644
> --- a/src/gallium/auxiliary/util/u_cpu_detect.c
> +++ b/src/gallium/auxiliary/util/u_cpu_detect.c
> @@ -59,12 +59,18 @@
>
> #if defined(PIPE_OS_LINUX)
> #include <signal.h>
> +#include <fcntl.h>
> +#include <elf.h>
> #endif
>
> #ifdef PIPE_OS_UNIX
> #include <unistd.h>
> #endif
>
> +#if defined(PIPE_OS_ANDROID)
> +#include <cpu-features.h>
> +#endif
> +
> #if defined(PIPE_OS_WINDOWS)
> #include <windows.h>
> #if defined(PIPE_CC_MSVC)
> @@ -294,6 +300,40 @@ PIPE_ALIGN_STACK static inline boolean
> sse2_has_daz(void)
>
> #endif /* X86 or X86_64 */
>
> +#if defined(PIPE_ARCH_ARM)
> +static void
> +check_os_arm_support(void)
> +{
> +#if defined(PIPE_OS_ANDROID)
> + AndroidCpuFamily cpu_family = android_getCpuFamily();
> + uint64_t cpu_features = android_getCpuFeatures();
> +
> + if (cpu_family == ANDROID_CPU_FAMILY_ARM) {
> + if (cpu_features & ANDROID_CPU_ARM_FEATURE_VFPv3)
> + util_cpu_caps.has_vfp = 1;
> + if (cpu_features & ANDROID_CPU_ARM_FEATURE_NEON)
> + util_cpu_caps.has_neon = 1;
> + }
> +#elif defined(PIPE_OS_LINUX)
> + Elf32_auxv_t aux;
> + int fd;
> +
> + fd = open("/proc/self/auxv", O_RDONLY);
>
O_CLOEXEC?
> + if (fd >= 0) {
> + while (read(fd, &aux, sizeof(Elf32_auxv_t)) ==
> sizeof(Elf32_auxv_t)) {
> + if (aux.a_type == AT_HWCAP) {
> + uint32_t hwcap = aux.a_un.a_val;
> +
> + util_cpu_caps.has_vfp = (hwcap >> 6) & 1;
> + util_cpu_caps.has_neon = (hwcap >> 12) & 1;
>
break;
> + }
> + }
> + close (fd);
> + }
> +#endif /* PIPE_OS_LINUX */
> +}
> +#endif /* PIPE_ARCH_ARM */
> +
>
GraÅžvydas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170414/cf230edc/attachment.html>
More information about the mesa-dev
mailing list