shithub: dav1d

Download patch

ref: 7b61d4ec0df53b9d07c03a609a5af0ce79e983a8
parent: 2689dfb5e8e79e22fb3723874893c08381e10afb
author: Janne Grunau <janne-vlc@jannau.net>
date: Wed Oct 31 17:29:52 EDT 2018

arm: add cpu flag detection

For Linux (and Android) use getauxval(). For ios and windows on arm
assume NEON is available.

--- a/meson.build
+++ b/meson.build
@@ -132,6 +132,12 @@
     cdata.set('HAVE_ALIGNED_MALLOC', 1)
 endif
 
+if (host_machine.cpu_family() == 'aarch64' or
+    host_machine.cpu_family().startswith('arm'))
+    if cc.has_function('getauxval', prefix : '#include <sys/auxv.h>', args : test_args)
+        cdata.set('HAVE_GETAUXVAL', 1)
+    endif
+endif
 
 # Compiler flag tests
 
--- a/src/arm/cpu.c
+++ b/src/arm/cpu.c
@@ -25,8 +25,30 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "config.h"
+
 #include "src/arm/cpu.h"
 
+#if HAVE_GETAUXVAL
+#include <sys/auxv.h>
+
+#if ARCH_AARCH64
+#define NEON_HWCAP HWCAP_ASIMD
+#elif ARCH_ARM
+#define NEON_HWCAP HWCAP_ARM_NEON
+#endif
+#endif
+
 unsigned dav1d_get_cpu_flags_arm(void) {
-    return DAV1D_ARM_CPU_FLAG_NEON;
+    unsigned flags = 0;
+#if HAVE_GETAUXVAL
+    unsigned long hw_cap = getauxval(AT_HWCAP);
+    flags |= (hw_cap & NEON_HWCAP) ? DAV1D_ARM_CPU_FLAG_NEON : 0;
+#elif __APPLE__
+    flags |= DAV1D_ARM_CPU_FLAG_NEON;
+#elif defined(_WIN32)
+    flags |= DAV1D_ARM_CPU_FLAG_NEON;
+#endif
+
+    return flags;
 }