~abreu-alexandre/oxide/add-ua-to-downloadrequested

« back to all changes in this revision

Viewing changes to patches/implement-webrtc-get-cpu-features-arm.patch

  • Committer: Chris Coulson
  • Date: 2015-05-29 15:18:09 UTC
  • Revision ID: chris.coulson@canonical.com-20150529151809-nnai6owq6s7jq7do
Enable run-time NEON detection in components that support it (eg, skia)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Description: Implement WebRtc_GetCPUFeaturesARM on non-Android arm,
 
2
#  so that it can be built with arm_neon_optional and NEON run-time
 
3
#  detection works
 
4
# Author: Chris Coulson <chris.coulson@canonical.com>
 
5
 
 
6
diff --git a/third_party/webrtc/system_wrappers/source/cpu_features.cc b/third_party/webrtc/system_wrappers/source/cpu_features.cc
 
7
--- a/third_party/webrtc/system_wrappers/source/cpu_features.cc
 
8
+++ b/third_party/webrtc/system_wrappers/source/cpu_features.cc
 
9
@@ -65,8 +65,76 @@ static int GetCPUInfo(CPUFeature feature
 
10
 static int GetCPUInfo(CPUFeature feature) {
 
11
   (void)feature;
 
12
   return 0;
 
13
 }
 
14
 #endif
 
15
 
 
16
 WebRtc_CPUInfo WebRtc_GetCPUInfo = GetCPUInfo;
 
17
 WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM = GetCPUInfoNoASM;
 
18
+
 
19
+#if defined(WEBRTC_ARCH_ARM64)
 
20
+
 
21
+uint64_t WebRtc_GetCPUFeaturesARM(void) {
 
22
+  return kCPUFeatureNEON;
 
23
+}
 
24
+
 
25
+#elif defined(WEBRTC_ARCH_ARM)
 
26
+
 
27
+#include <asm/hwcap.h>
 
28
+#include <sys/auxv.h>
 
29
+#include <stdio.h>
 
30
+
 
31
+#if defined(WEBRTC_ARCH_ARM_V7)
 
32
+#define HAVE_ARM_V7 kCPUFeatureARMv7
 
33
+#else
 
34
+#define HAVE_ARM_V7 0
 
35
+#endif
 
36
+#if defined(WEBRTC_ARCH_ARM_NEON)
 
37
+#define HAVE_ARM_NEON kCPUFeatureNEON
 
38
+#else
 
39
+#define HAVE_ARM_NEON 0
 
40
+#endif
 
41
+
 
42
+#define CORE_FLAGS (HAVE_ARM_V7 | HAVE_ARM_NEON)
 
43
+
 
44
+uint64_t WebRtc_GetCPUFeaturesARM(void) {
 
45
+  static bool detected = false;
 
46
+  static uint64_t flags = CORE_FLAGS;
 
47
+
 
48
+  if (detected) {
 
49
+    return flags;
 
50
+  }
 
51
+
 
52
+  detected = true;
 
53
+
 
54
+  struct { uint32_t a_type; uint32_t a_val; } auxv;
 
55
+  FILE *f = fopen("/proc/self/auxv", "r");
 
56
+
 
57
+  bool found_hwcap = false;
 
58
+  uint32_t hwcap = 0;
 
59
+
 
60
+  if (f) {
 
61
+    while (fread(&auxv, sizeof(auxv), 1, f) > 0) {
 
62
+      if (auxv.a_type == AT_HWCAP) {
 
63
+        hwcap = auxv.a_val;
 
64
+        found_hwcap = true;
 
65
+        break;
 
66
+      }
 
67
+    }
 
68
+    fclose(f);
 
69
+  }
 
70
+
 
71
+  if (!found_hwcap) {
 
72
+    return flags;
 
73
+  }
 
74
+
 
75
+  if (hwcap & HWCAP_VFPv3) {
 
76
+    flags |= kCPUFeatureVFPv3;
 
77
+  }
 
78
+  if (hwcap & HWCAP_NEON) {
 
79
+    flags |= kCPUFeatureNEON;
 
80
+  }
 
81
+
 
82
+  return flags;
 
83
+}
 
84
+
 
85
+#endif