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

Improve ARM runtime feature detection on Linux #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions features/features_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,27 @@ static void arm_enable_runfast_mode(void)
#endif

#if defined(__linux__) && !defined(CPU_X86)
#if __ARM_ARCH
#include <sys/auxv.h>
#endif

static unsigned char check_arm_cpu_feature(const char* feature)
{
#if __ARM_ARCH < 8
uint64_t hwcap = getauxval(AT_HWCAP);
if (!strcmp(feature, "neon"))
return (hwcap & HWCAP_ARM_NEON) != 0;
if (!strcmp(feature, "vfpv3"))
return (hwcap & HWCAP_ARM_VFPv3) != 0;
if (!strcmp(feature, "vfpv4"))
return (hwcap & HWCAP_ARM_VFPv4) != 0;
return 0;
#elif __ARM_ARCH == 8
uint64_t hwcap = getauxval(AT_HWCAP);
if (!strcmp(feature, "asimd"))
return (hwcap & HWCAP_ASIMD) != 0;
return 0;
#else
Comment on lines +340 to +360
Copy link
Contributor

@SpriteOvO SpriteOvO Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR broke builds for architectures other than x86 and ARM.

AT_HWCAP, HWCAP_ARM_NEON, HWCAP_ARM_VFPv3 and HWCAP_ARM_VFPv4 macros are not defined on other architectures.

Suggested change
#if __ARM_ARCH
#include <sys/auxv.h>
#endif
static unsigned char check_arm_cpu_feature(const char* feature)
{
#if __ARM_ARCH < 8
uint64_t hwcap = getauxval(AT_HWCAP);
if (!strcmp(feature, "neon"))
return (hwcap & HWCAP_ARM_NEON) != 0;
if (!strcmp(feature, "vfpv3"))
return (hwcap & HWCAP_ARM_VFPv3) != 0;
if (!strcmp(feature, "vfpv4"))
return (hwcap & HWCAP_ARM_VFPv4) != 0;
return 0;
#elif __ARM_ARCH == 8
uint64_t hwcap = getauxval(AT_HWCAP);
if (!strcmp(feature, "asimd"))
return (hwcap & HWCAP_ASIMD) != 0;
return 0;
#else
#if defined(__ARM_ARCH)
#include <sys/auxv.h>
#endif
static unsigned char check_arm_cpu_feature(const char* feature)
{
#if defined(__ARM_ARCH) && __ARM_ARCH < 8
uint64_t hwcap = getauxval(AT_HWCAP);
if (!strcmp(feature, "neon"))
return (hwcap & HWCAP_ARM_NEON) != 0;
if (!strcmp(feature, "vfpv3"))
return (hwcap & HWCAP_ARM_VFPv3) != 0;
if (!strcmp(feature, "vfpv4"))
return (hwcap & HWCAP_ARM_VFPv4) != 0;
return 0;
#elif defined(__ARM_ARCH) && __ARM_ARCH == 8
uint64_t hwcap = getauxval(AT_HWCAP);
if (!strcmp(feature, "asimd"))
return (hwcap & HWCAP_ASIMD) != 0;
return 0;
#else

char line[1024];
unsigned char status = 0;
RFILE *fp = filestream_open("/proc/cpuinfo",
Expand All @@ -362,6 +381,7 @@ static unsigned char check_arm_cpu_feature(const char* feature)
filestream_close(fp);

return status;
#endif
}

#if !defined(_SC_NPROCESSORS_ONLN)
Expand Down