Added
Link Here
|
1 |
- Detect NEON/AltiVec/VSX on FreeBSD |
2 |
|
3 |
--- src/util/u_cpu_detect.c.orig 2019-01-17 11:26:23 UTC |
4 |
+++ src/util/u_cpu_detect.c |
5 |
@@ -47,16 +47,18 @@ |
6 |
#endif |
7 |
#endif |
8 |
|
9 |
-#if defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD) |
10 |
+#if defined(PIPE_OS_BSD) |
11 |
#include <sys/param.h> |
12 |
#include <sys/sysctl.h> |
13 |
#include <machine/cpu.h> |
14 |
#endif |
15 |
|
16 |
-#if defined(PIPE_OS_FREEBSD) || defined(PIPE_OS_DRAGONFLY) |
17 |
-#include <sys/types.h> |
18 |
-#include <sys/sysctl.h> |
19 |
+#if defined(PIPE_OS_FREEBSD) |
20 |
+#if __has_include(<sys/auxv.h>) |
21 |
+#include <sys/auxv.h> |
22 |
+#define HAVE_ELF_AUX_INFO |
23 |
#endif |
24 |
+#endif |
25 |
|
26 |
#if defined(PIPE_OS_LINUX) |
27 |
#include <signal.h> |
28 |
@@ -92,7 +94,7 @@ static int has_cpuid(void); |
29 |
#endif |
30 |
|
31 |
|
32 |
-#if defined(PIPE_ARCH_PPC) && !defined(PIPE_OS_APPLE) |
33 |
+#if defined(PIPE_ARCH_PPC) && !defined(PIPE_OS_APPLE) && !defined(PIPE_OS_BSD) |
34 |
static jmp_buf __lv_powerpc_jmpbuf; |
35 |
static volatile sig_atomic_t __lv_powerpc_canjump = 0; |
36 |
|
37 |
@@ -113,8 +115,20 @@ sigill_handler(int sig) |
38 |
static void |
39 |
check_os_altivec_support(void) |
40 |
{ |
41 |
-#if defined(PIPE_OS_APPLE) |
42 |
+#if defined(__ALTIVEC__) |
43 |
+ util_cpu_caps.has_altivec = 1; |
44 |
+#endif |
45 |
+#if defined(__VSX__) |
46 |
+ util_cpu_caps.has_vsx = 1; |
47 |
+#endif |
48 |
+#if defined(__ALTIVEC__) && defined(__VSX__) |
49 |
+/* Do nothing */ |
50 |
+#elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD) |
51 |
+#ifdef HW_VECTORUNIT |
52 |
int sels[2] = {CTL_HW, HW_VECTORUNIT}; |
53 |
+#else |
54 |
+ int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC}; |
55 |
+#endif |
56 |
int has_vu = 0; |
57 |
int len = sizeof (has_vu); |
58 |
int err; |
59 |
@@ -126,7 +140,19 @@ check_os_altivec_support(void) |
60 |
util_cpu_caps.has_altivec = 1; |
61 |
} |
62 |
} |
63 |
-#else /* !PIPE_OS_APPLE */ |
64 |
+#elif defined(PIPE_OS_FREEBSD) /* !PIPE_OS_APPLE && !PIPE_OS_NETBSD && !PIPE_OS_OPENBSD */ |
65 |
+ unsigned long hwcap = 0; |
66 |
+#ifdef HAVE_ELF_AUX_INFO |
67 |
+ elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); |
68 |
+#else |
69 |
+ size_t len = sizeof(hwcap); |
70 |
+ sysctlbyname("hw.cpu_features", &hwcap, &len, NULL, 0); |
71 |
+#endif |
72 |
+ if (hwcap & PPC_FEATURE_HAS_ALTIVEC) |
73 |
+ util_cpu_caps.has_altivec = 1; |
74 |
+ if (hwcap & PPC_FEATURE_HAS_VSX) |
75 |
+ util_cpu_caps.has_vsx = 1; |
76 |
+#else /* !PIPE_OS_APPLE && !PIPE_OS_BSD */ |
77 |
/* not on Apple/Darwin, do it the brute-force way */ |
78 |
/* this is borrowed from the libmpeg2 library */ |
79 |
signal(SIGILL, sigill_handler); |
80 |
@@ -339,7 +365,14 @@ check_os_arm_support(void) |
81 |
* used. Because of this we cannot use PIPE_OS_ANDROID here, but rather |
82 |
* have a separate macro that only gets enabled from respective Android.mk. |
83 |
*/ |
84 |
-#if defined(HAS_ANDROID_CPUFEATURES) |
85 |
+#if defined(__ARM_NEON) || defined(__ARM_NEON__) |
86 |
+ util_cpu_caps.has_neon = 1; |
87 |
+#elif defined(PIPE_OS_FREEBSD) && defined(HAVE_ELF_AUX_INFO) |
88 |
+ unsigned long hwcap = 0; |
89 |
+ elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); |
90 |
+ if (hwcap & HWCAP_NEON) |
91 |
+ util_cpu_caps.has_neon = 1; |
92 |
+#elif defined(HAS_ANDROID_CPUFEATURES) |
93 |
AndroidCpuFamily cpu_family = android_getCpuFamily(); |
94 |
uint64_t cpu_features = android_getCpuFeatures(); |
95 |
|