<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 14, 2017 at 12:08 AM, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">I wrote this code with reference to pixman, though I've only decided to<br>
cover Linux (what I'm testing) and Android (seems obvious enough). Linux<br>
has getauxval() as a cleaner interface to the /proc entry, but it's more<br>
glibc-specific and I didn't want to add detection for that.<br></span></blockquote><div><br></div><div>But now you have to worry about running out of file descriptors and forking. Mesa already does checks like<br>#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 19)))<br></div><div>but it's up to you I guess.<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
<br>
This will be used to enable NEON at runtime on ARMv6 builds of vc4.<br>
<br>
</span>v2: Actually initialize the temp vars in the Android path (noticed by<br>
daniels)<br>
<span class="gmail-">---<br>
src/gallium/auxiliary/util/u_<wbr>cpu_detect.c | 46 ++++++++++++++++++++++++++++++<wbr>+<br>
src/gallium/auxiliary/util/u_<wbr>cpu_detect.h | 2 ++<br>
2 files changed, 48 insertions(+)<br>
<br>
diff --git a/src/gallium/auxiliary/util/<wbr>u_cpu_detect.c b/src/gallium/auxiliary/util/<wbr>u_cpu_detect.c<br>
</span>index 845fc6b34d5c..c9083fed63af 100644<br>
<div><div class="gmail-h5">--- a/src/gallium/auxiliary/util/<wbr>u_cpu_detect.c<br>
+++ b/src/gallium/auxiliary/util/<wbr>u_cpu_detect.c<br>
@@ -59,12 +59,18 @@<br>
<br>
#if defined(PIPE_OS_LINUX)<br>
#include <signal.h><br>
+#include <fcntl.h><br>
+#include <elf.h><br>
#endif<br>
<br>
#ifdef PIPE_OS_UNIX<br>
#include <unistd.h><br>
#endif<br>
<br>
+#if defined(PIPE_OS_ANDROID)<br>
+#include <cpu-features.h><br>
+#endif<br>
+<br>
#if defined(PIPE_OS_WINDOWS)<br>
#include <windows.h><br>
#if defined(PIPE_CC_MSVC)<br>
@@ -294,6 +300,40 @@ PIPE_ALIGN_STACK static inline boolean sse2_has_daz(void)<br>
<br>
#endif /* X86 or X86_64 */<br>
<br>
+#if defined(PIPE_ARCH_ARM)<br>
+static void<br>
+check_os_arm_support(void)<br>
+{<br>
+#if defined(PIPE_OS_ANDROID)<br>
</div></div>+ AndroidCpuFamily cpu_family = android_getCpuFamily();<br>
+ uint64_t cpu_features = android_getCpuFeatures();<br>
<div class="gmail-HOEnZb"><div class="gmail-h5">+<br>
+ if (cpu_family == ANDROID_CPU_FAMILY_ARM) {<br>
+ if (cpu_features & ANDROID_CPU_ARM_FEATURE_VFPv3)<br>
+ util_cpu_caps.has_vfp = 1;<br>
+ if (cpu_features & ANDROID_CPU_ARM_FEATURE_NEON)<br>
+ util_cpu_caps.has_neon = 1;<br>
+ }<br>
+#elif defined(PIPE_OS_LINUX)<br>
+ Elf32_auxv_t aux;<br>
+ int fd;<br>
+<br>
+ fd = open("/proc/self/auxv", O_RDONLY);<br></div></div></blockquote><div><br></div><div>O_CLOEXEC?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">
+ if (fd >= 0) {<br>
+ while (read(fd, &aux, sizeof(Elf32_auxv_t)) == sizeof(Elf32_auxv_t)) {<br>
+ if (aux.a_type == AT_HWCAP) {<br>
+ uint32_t hwcap = aux.a_un.a_val;<br>
+<br>
+ util_cpu_caps.has_vfp = (hwcap >> 6) & 1;<br>
+ util_cpu_caps.has_neon = (hwcap >> 12) & 1;<br></div></div></blockquote><div><br></div><div>break;<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">
+ }<br>
+ }<br>
+ close (fd);<br>
+ }<br>
+#endif /* PIPE_OS_LINUX */<br>
+}<br>
+#endif /* PIPE_ARCH_ARM */<br>
+<br></div></div></blockquote><div><br clear="all"><div><div class="gmail_signature">Gražvydas<br></div></div><br></div></div><br></div></div>