Improve ARM runtime feature detection on Linux#176
Open
linkmauve wants to merge 1 commit intolibretro:masterfrom
Open
Improve ARM runtime feature detection on Linux#176linkmauve wants to merge 1 commit intolibretro:masterfrom
linkmauve wants to merge 1 commit intolibretro:masterfrom
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.
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
Contributor
|
Would this code work on Android and iOS? |
Contributor
Author
|
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
Contributor
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
SpriteOvO
suggested changes
Aug 29, 2022
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 |
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.