Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect the presence of getauxval and elf_aux_info #1835

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ config.h:
echo '#define HAVE_ATTRIBUTE_TARGET 1' >> $@
echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@
echo '#endif' >> $@
echo '#if defined __linux__' >> $@
echo '#define HAVE_GETAUXVAL' >> $@
echo '#elif defined __FreeBSD__' >> $@
echo '#define HAVE_ELF_AUX_INFO' >> $@
echo '#elif defined __OpenBSD__' >> $@
echo '// Enable extra OpenBSD checks (see simd.c)' >> $@
echo '#define HAVE_OPENBSD' >> $@
echo '#endif' >> $@

# And similarly for htslib.pc.tmp ("pkg-config template"). No dependency
# on htslib.pc.in listed, as if that file is newer the usual way to regenerate
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ HTS_HIDE_DYNAMIC_SYMBOLS

dnl FIXME This pulls in dozens of standard header checks
AC_FUNC_MMAP
AC_CHECK_FUNCS([gmtime_r fsync drand48 srand48_deterministic])
AC_CHECK_FUNCS([gmtime_r fsync drand48 srand48_deterministic getauxval elf_aux_info])

# Darwin has a dubious fdatasync() symbol, but no declaration in <unistd.h>
AC_CHECK_DECL([fdatasync(int)], [AC_CHECK_FUNCS(fdatasync)])
Expand Down
24 changes: 18 additions & 6 deletions simd.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ DEALINGS IN THE SOFTWARE. */

#if defined __arm__ || defined __aarch64__

#if defined __linux__ || defined __FreeBSD__
#ifdef HAVE_OPENBSD
/*
* Extra check for elf_aux_info() on configure-less OpenBSD builds. Once
* version 7.5 has dropped off support, this can be changed to an assumption
* that the function exists in the Makefile-generated config.h.
*/
#include <sys/param.h>
#if OpenBSD >= 202409
#define HAVE_ELF_AUX_INFO
#endif
#endif

#if defined HAVE_GETAUXVAL || defined HAVE_ELF_AUX_INFO
#include <sys/auxv.h>
#elif defined __APPLE__
#include <sys/types.h>
Expand All @@ -61,23 +73,23 @@ DEALINGS IN THE SOFTWARE. */
#endif

static inline int cpu_supports_neon(void) {
#if defined __linux__ && defined __arm__ && defined HWCAP_NEON
#if defined HAVE_GETAUXVAL && defined __arm__ && defined HWCAP_NEON
return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0;
#elif defined __linux__ && defined __arm__ && defined HWCAP_ARM_NEON
#elif defined HAVE_GETAUXVAL && defined __arm__ && defined HWCAP_ARM_NEON
return (getauxval(AT_HWCAP) & HWCAP_ARM_NEON) != 0;
#elif defined __linux__ && defined __aarch64__ && defined HWCAP_ASIMD
#elif defined HAVE_GETAUXVAL && defined __aarch64__ && defined HWCAP_ASIMD
return (getauxval(AT_HWCAP) & HWCAP_ASIMD) != 0;
#elif defined __APPLE__ && defined __aarch64__
int32_t ctl;
size_t ctlsize = sizeof ctl;
if (sysctlbyname("hw.optional.AdvSIMD", &ctl, &ctlsize, NULL, 0) != 0) return 0;
if (ctlsize != sizeof ctl) return 0;
return ctl;
#elif defined __FreeBSD__ && defined __arm__ && defined HWCAP_NEON
#elif defined HAVE_ELF_AUX_INFO && defined __arm__ && defined HWCAP_NEON
unsigned long cap;
if (elf_aux_info(AT_HWCAP, &cap, sizeof cap) != 0) return 0;
return (cap & HWCAP_NEON) != 0;
#elif defined __FreeBSD__ && defined __aarch64__ && defined HWCAP_ASIMD
#elif defined HAVE_ELF_AUX_INFO && defined __aarch64__ && defined HWCAP_ASIMD
unsigned long cap;
if (elf_aux_info(AT_HWCAP, &cap, sizeof cap) != 0) return 0;
return (cap & HWCAP_ASIMD) != 0;
Expand Down