Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/multimedia/aom/files/patch-aom__ports_ppc__cpudetect.c
18157 views
1
- Implement VSX detection on FreeBSD
2
3
--- aom_ports/ppc_cpudetect.c.orig 2025-09-02 20:59:58 UTC
4
+++ aom_ports/ppc_cpudetect.c
5
@@ -9,18 +9,11 @@
6
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
7
*/
8
9
-#include <fcntl.h>
10
-#include <unistd.h>
11
-#include <stdint.h>
12
-
13
#include "config/aom_config.h"
14
15
#include "aom_ports/ppc.h"
16
17
#if CONFIG_RUNTIME_CPU_DETECT
18
-#include <asm/cputable.h>
19
-#include <linux/auxvec.h>
20
-
21
static int cpu_env_flags(int *flags) {
22
char *env;
23
env = getenv("AOM_SIMD_CAPS");
24
@@ -38,6 +31,13 @@ static int cpu_env_mask(void) {
25
return env && *env ? (int)strtol(env, NULL, 0) : ~0;
26
}
27
28
+#if defined(__linux__)
29
+#include <fcntl.h>
30
+#include <unistd.h>
31
+#include <stdint.h>
32
+#include <asm/cputable.h>
33
+#include <linux/auxvec.h>
34
+
35
int ppc_simd_caps(void) {
36
int flags;
37
int mask;
38
@@ -76,7 +76,35 @@ out_close:
39
close(fd);
40
return flags & mask;
41
}
42
+#elif defined(__FreeBSD__)
43
+#include <sys/auxv.h>
44
+#include <machine/cpu.h>
45
+
46
+int ppc_simd_caps(void) {
47
+ int flags;
48
+ int mask;
49
+ u_long hwcap = 0;
50
+
51
+ // If AOM_SIMD_CAPS is set then allow only those capabilities.
52
+ if (!cpu_env_flags(&flags)) {
53
+ return flags;
54
+ }
55
+
56
+ mask = cpu_env_mask();
57
+
58
+ elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
59
+#if HAVE_VSX
60
+ if (hwcap & PPC_FEATURE_HAS_VSX) flags |= HAS_VSX;
61
+#endif
62
+
63
+ return flags & mask;
64
+}
65
#else
66
+#error \
67
+ "--enable-runtime-cpu-detect selected, but no CPU detection method " \
68
+"available for your platform. Reconfigure with --disable-runtime-cpu-detect."
69
+#endif /* end __FreeBSD__ */
70
+#else
71
// If there is no RTCD the function pointers are not used and can not be
72
// changed.
73
int ppc_simd_caps(void) { return 0; }
74
75