Skip to content

Commit

Permalink
Improve ARM runtime feature detection on Linux
Browse files Browse the repository at this point in the history
getauxval(AT_HWCAP) is the best way to check for features on ARM and
AArch64, as it doesn’t require parsing a file, instead it just returns a
value provided by the kernel in our address space.

This commit should be synchronised with
libretro/libretro-common#176
  • Loading branch information
linkmauve authored and Salz committed Jan 5, 2021
1 parent 7d0ef3a commit 6f434fe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions desmume/src/libretro-common/features/features_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,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
char line[1024];
unsigned char status = 0;
RFILE *fp = filestream_open("/proc/cpuinfo", RFILE_MODE_READ_TEXT, -1);
Expand All @@ -334,6 +353,7 @@ static unsigned char check_arm_cpu_feature(const char* feature)
filestream_close(fp);

return status;
#endif
}

#if !defined(_SC_NPROCESSORS_ONLN)
Expand Down

0 comments on commit 6f434fe

Please sign in to comment.