- 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 #include #elif defined(__FreeBSD__) && defined(__arm__) +#if __FreeBSD__ >= 12 #include +#else +#include +#include +#include +#include +#include + +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; }