shithub: dav1d

Download patch

ref: ed79e075c4788d7f2c4948caa5ee4fa9927cb743
parent: 7b61d4ec0df53b9d07c03a609a5af0ce79e983a8
author: Janne Grunau <[email protected]>
date: Thu Nov 1 06:00:00 EDT 2018

arm: add /proc/cpuinfo based NEON detection for Android J-B

--- a/src/arm/cpu.c
+++ b/src/arm/cpu.c
@@ -37,6 +37,36 @@
 #elif ARCH_ARM
 #define NEON_HWCAP HWCAP_ARM_NEON
 #endif
+
+#elif defined(__ANDROID__)
+#include <stdio.h>
+#include <string.h>
+
+static unsigned parse_proc_cpuinfo(const char *flag) {
+    FILE *file = fopen("/proc/cpuinfo", "r");
+    if (!file)
+        return 0;
+
+    char line_buffer[120];
+    const char *line;
+
+    while ((line = fgets(line_buffer, sizeof(line_buffer), file))) {
+        if (strstr(line, flag)) {
+            fclose(file);
+            return 1;
+        }
+        // if line is incomplete seek back to avoid splitting the search
+        // string into two buffers
+        if (!strchr(line, '\n') && strlen(line) > strlen(flag)) {
+            if (fseek(file, -strlen(flag), SEEK_CUR))
+                break;
+        }
+    }
+
+    fclose(file);
+
+    return 0;
+}
 #endif
 
 unsigned dav1d_get_cpu_flags_arm(void) {
@@ -44,6 +74,8 @@
 #if HAVE_GETAUXVAL
     unsigned long hw_cap = getauxval(AT_HWCAP);
     flags |= (hw_cap & NEON_HWCAP) ? DAV1D_ARM_CPU_FLAG_NEON : 0;
+#elif defined(__ANDROID__)
+    flags |= parse_proc_cpuinfo("neon") ? DAV1D_ARM_CPU_FLAG_NEON : 0;
 #elif __APPLE__
     flags |= DAV1D_ARM_CPU_FLAG_NEON;
 #elif defined(_WIN32)