blob: 88402ac0ae27a44402e7eccfca0fbccf4c198ba3 (
plain) (
tree)
|
|
- Implement NEON runtime detection on FreeBSD 11.* armv6
--- src/platform.c.orig 2019-08-16 20:55:07 UTC
+++ src/platform.c
@@ -41,8 +41,36 @@
#include <asm/hwcap.h>
#include <sys/auxv.h>
#elif defined(__FreeBSD__) && defined(__arm__)
+#if __FreeBSD__ >= 12
#include <sys/auxv.h>
+#else
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <elf.h>
+#include <errno.h>
+#include <unistd.h>
+
+static unsigned long getauxval(unsigned long type) {
+ Elf_Auxinfo auxv[AT_COUNT];
+ size_t len = sizeof(auxv);
+ int mib[] = {
+ CTL_KERN,
+ KERN_PROC,
+ KERN_PROC_AUXV,
+ getpid(),
+ };
+
+ if (sysctl(mib, nitems(mib), auxv, &len, NULL, 0) != -1) {
+ for (size_t i = 0; i < nitems(auxv); i++)
+ if ((unsigned long)auxv[i].a_type == type)
+ return auxv[i].a_un.a_val;
+
+ errno = ENOENT;
+ }
+ return 0;
+}
#endif
+#endif
#if defined(__linux__)
/* memfd_create was introduced in glibc 2.27 */
@@ -82,9 +110,13 @@ bool neon_available(void)
#if defined(__linux__) && defined(__arm__)
return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0;
#elif defined(__FreeBSD__) && defined(__arm__)
+#if __FreeBSD__ < 12
+ return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0;
+#else
unsigned long hwcap = 0;
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
return (hwcap & HWCAP_NEON) != 0;
+#endif
#endif
return true;
}
|