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

src/arch/simddetect.cpp: fix NEON detection on FreeBSD #3782

Merged
merged 6 commits into from
May 29, 2022
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
13 changes: 12 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ case "${host_cpu}" in

;;

aarch64)
aarch64|arm64)
clausecker marked this conversation as resolved.
Show resolved Hide resolved

# ARMv8 always has NEON and does not need special compiler flags.
AM_CONDITIONAL([HAVE_NEON], true)
Expand All @@ -178,6 +178,7 @@ case "${host_cpu}" in
AC_DEFINE([HAVE_NEON], [1], [Enable NEON instructions])
NEON_CXXFLAGS="-mfpu=neon"
AC_SUBST([NEON_CXXFLAGS])
check_for_neon=1
clausecker marked this conversation as resolved.
Show resolved Hide resolved
fi

;;
Expand All @@ -191,6 +192,16 @@ esac
# check whether feenableexcept is supported. some C libraries (e.g. uclibc) don't.
AC_CHECK_FUNCS([feenableexcept])

# additional checks for NEON targets
if test x$check_for_neon = x1; then
AC_MSG_NOTICE([checking how to detect NEON availability])
AC_CHECK_FUNCS([getauxval elf_aux_info android_getCpuFamily])

if test $ac_cv_func_getauxval = no && test $ac_cv_func_elf_aux_info = no && test $ac_cv_func_android_getCpuFamily = no; then
AC_MSG_WARN([NEON is available, but we don't know how to check for it. Will not be able to use NEON.])
fi
fi

AX_CHECK_COMPILE_FLAG([-fopenmp-simd], [openmp_simd=true], [openmp_simd=false], [$WERROR])
AM_CONDITIONAL([OPENMP_SIMD], $openmp_simd)

Expand Down
17 changes: 11 additions & 6 deletions src/arch/simddetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
#endif

#if defined(HAVE_NEON) && !defined(__aarch64__)
# ifdef ANDROID
# if defined(HAVE_ANDROID_GETCPUFAMILY)
# include <cpu-features.h>
# else
/* Assume linux */
# elif defined(HAVE_GETAUXVAL)
# include <asm/hwcap.h>
# include <sys/auxv.h>
# elif defined(HAVE_ELF_AUX_INFO)
# include <sys/auxv.h>
# include <sys/elf.h>
# endif
#endif

Expand Down Expand Up @@ -210,15 +212,18 @@ SIMDDetect::SIMDDetect() {
#endif

#if defined(HAVE_NEON) && !defined(__aarch64__)
# ifdef ANDROID
# if defined(HAVE_ANDROID_GETCPUFAMILY)
{
AndroidCpuFamily family = android_getCpuFamily();
if (family == ANDROID_CPU_FAMILY_ARM)
neon_available_ = (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON);
}
# else
/* Assume linux */
# elif defined(HAVE_GETAUXVAL)
neon_available_ = getauxval(AT_HWCAP) & HWCAP_NEON;
# elif defined(HAVE_ELF_AUX_INFO)
unsigned long hwcap = 0;
elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
neon_available_ = hwcap & HWCAP_NEON;
# endif
#endif

Expand Down