When running on a 64 bit kernel, /proc/cpuinfo does not list
the cpu features that aren't optional on such CPUs.

A 32 bit binary which runs on such a kernel, that tries to parse
/proc/cpuinfo to find the relevant cpu features at runtime, won't
thus detect those features, unless it is assumed that CPU architecture
>= 8 implies a set of features.

The kernel does list these features properly if they are queried
via /proc/self/auxv though - however this file is not always readable
(e.g. on most android systems).

This is similar to what the android cpufeatures library will do
starting from the next release. See [1] for details.

It has been suggested to include the non-optional features in
/proc/cpuinfo as well, but that suggested patch never was merged.
See [2] for the discussion around this suggestion.

[1] https://android-review.googlesource.com/91380
[2] http://marc.info/?l=linux-arm-kernel&m=139087240101974

---
This is untested in practice due to the lack of a real ARMv8
device.
---
 libavutil/arm/cpu.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavutil/arm/cpu.c b/libavutil/arm/cpu.c
index 85ea662..5644ffe 100644
--- a/libavutil/arm/cpu.c
+++ b/libavutil/arm/cpu.c
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stdlib.h>
+
 #include "libavutil/cpu.h"
 #include "libavutil/cpu_internal.h"
 #include "config.h"
@@ -92,7 +94,19 @@ static int get_cpuinfo(uint32_t *hwcap)
                 *hwcap |= HWCAP_VFPv3;
             if (strstr(buf, " neon "))
                 *hwcap |= HWCAP_NEON;
-            break;
+        } else if (av_strstart(buf, "CPU architecture", NULL)) {
+            char *sep = strchr(buf, ':');
+            if (sep) {
+                char *val = sep + 1;
+                int arch;
+                val += strspn(val, " \t");
+                arch = atoi(val);
+                if (arch >= 8) {
+                    /* These features are non-optional in ARMv8, and aren't
+                     * listed in cpuinfo on 64 bit kernels. */
+                    *hwcap |= HWCAP_VFP | HWCAP_VFPv3 | HWCAP_NEON;
+                }
+            }
         }
     }
     fclose(f);
-- 
1.8.5.2 (Apple Git-48)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to