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

Conversation

linkmauve
Copy link
Contributor

@linkmauve linkmauve commented Nov 3, 2020

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.

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.
linkmauve added a commit to TASEmulators/desmume that referenced this pull request Nov 4, 2020
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
@inactive123
Copy link
Contributor

Would this code work on Android and iOS?

@linkmauve
Copy link
Contributor Author

linkmauve commented Dec 13, 2020

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.

Salz pushed a commit to Salz/desmume that referenced this pull request Jan 13, 2021
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
rofl0r pushed a commit to rofl0r/desmume-gtk2 that referenced this pull request Oct 21, 2021
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
@phcoder
Copy link
Contributor

phcoder commented Feb 22, 2022

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.

Linux and Android. Android defines linux as well

mike8699 pushed a commit to mike8699/desmume that referenced this pull request Apr 2, 2022
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
Comment on lines +340 to +360
#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
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

marius851000 pushed a commit to marius851000/desmume that referenced this pull request Jul 11, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants