-
Notifications
You must be signed in to change notification settings - Fork 76
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
base: master
Are you sure you want to change the base?
Conversation
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.
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
Would this code work on Android and iOS? |
I actually don’t know, I don’t have any such device available so I only tested on Linux. According to Android’s documentation it should, but I couldn’t find anything similar for iOS. Edit: this codepath is only used on Linux anyway, we could extend it to Android but it doesn’t make sense for iOS it seems. |
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
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
Linux and Android. Android defines linux as well |
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
#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 |
There was a problem hiding this comment.
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.
#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 |
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
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 has been tested on a Nintendo Switch running ArchLinuxARM, on both AArch64 and AArch32.