Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/multimedia/aom/files/patch-aom__ports_arm__cpudetect.c
16125 views
1
- Assume NEON is enabled on aarch64
2
- Implement NEON runtime detection on FreeBSD
3
4
--- aom_ports/arm_cpudetect.c.orig 2018-11-16 20:24:20 UTC
5
+++ aom_ports/arm_cpudetect.c
6
@@ -38,7 +38,7 @@ static int arm_cpu_env_mask(void) {
7
return env && *env ? (int)strtol(env, NULL, 0) : ~0;
8
}
9
10
-#if !CONFIG_RUNTIME_CPU_DETECT
11
+#if !CONFIG_RUNTIME_CPU_DETECT || defined(__ARM_NEON)
12
13
int aom_arm_cpu_caps(void) {
14
/* This function should actually be a no-op. There is no way to adjust any of
15
@@ -143,7 +143,57 @@ int aom_arm_cpu_caps(void) {
16
}
17
return flags & mask;
18
}
19
-#else /* end __linux__ */
20
+#elif defined(__FreeBSD__)
21
+
22
+#if __FreeBSD__ < 12
23
+#include <sys/param.h>
24
+#include <sys/sysctl.h>
25
+#include <elf.h>
26
+#include <errno.h>
27
+#include <unistd.h>
28
+
29
+static unsigned long getauxval(unsigned long type) {
30
+ Elf_Auxinfo auxv[AT_COUNT];
31
+ size_t len = sizeof(auxv);
32
+ int mib[] = {
33
+ CTL_KERN,
34
+ KERN_PROC,
35
+ KERN_PROC_AUXV,
36
+ getpid(),
37
+ };
38
+
39
+ if (sysctl(mib, nitems(mib), auxv, &len, NULL, 0) != -1) {
40
+ for (size_t i = 0; i < nitems(auxv); i++)
41
+ if ((unsigned long)auxv[i].a_type == type)
42
+ return auxv[i].a_un.a_val;
43
+
44
+ errno = ENOENT;
45
+ }
46
+ return 0;
47
+}
48
+#else
49
+#include <sys/auxv.h>
50
+#endif
51
+
52
+int aom_arm_cpu_caps(void) {
53
+ int flags;
54
+ int mask;
55
+ u_long hwcap = 0;
56
+ if (!arm_cpu_env_flags(&flags)) {
57
+ return flags;
58
+ }
59
+ mask = arm_cpu_env_mask();
60
+#if __FreeBSD__ < 12
61
+ hwcap = getauxval(AT_HWCAP);
62
+#else
63
+ elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
64
+#endif
65
+#if HAVE_NEON
66
+ if (hwcap & HWCAP_NEON) flags |= HAS_NEON;
67
+#endif
68
+ return flags & mask;
69
+}
70
+#else /* end __FreeBSD__ */
71
#error \
72
"--enable-runtime-cpu-detect selected, but no CPU detection method " \
73
"available for your platform. Reconfigure with --disable-runtime-cpu-detect."
74
75