Skip to content

Commit 0c6be5a

Browse files
linkmauvemike8699
authored andcommitted
Improve ARM runtime feature detection on Linux
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
1 parent 7c7e35e commit 0c6be5a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

desmume/src/libretro-common/features/features_cpu.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,27 @@ static void arm_enable_runfast_mode(void)
311311
#endif
312312

313313
#if defined(__linux__) && !defined(CPU_X86)
314+
#if __ARM_ARCH
315+
#include <sys/auxv.h>
316+
#endif
317+
314318
static unsigned char check_arm_cpu_feature(const char* feature)
315319
{
320+
#if __ARM_ARCH < 8
321+
uint64_t hwcap = getauxval(AT_HWCAP);
322+
if (!strcmp(feature, "neon"))
323+
return (hwcap & HWCAP_ARM_NEON) != 0;
324+
if (!strcmp(feature, "vfpv3"))
325+
return (hwcap & HWCAP_ARM_VFPv3) != 0;
326+
if (!strcmp(feature, "vfpv4"))
327+
return (hwcap & HWCAP_ARM_VFPv4) != 0;
328+
return 0;
329+
#elif __ARM_ARCH == 8
330+
uint64_t hwcap = getauxval(AT_HWCAP);
331+
if (!strcmp(feature, "asimd"))
332+
return (hwcap & HWCAP_ASIMD) != 0;
333+
return 0;
334+
#else
316335
char line[1024];
317336
unsigned char status = 0;
318337
RFILE *fp = filestream_open("/proc/cpuinfo", RFILE_MODE_READ_TEXT, -1);
@@ -334,6 +353,7 @@ static unsigned char check_arm_cpu_feature(const char* feature)
334353
filestream_close(fp);
335354

336355
return status;
356+
#endif
337357
}
338358

339359
#if !defined(_SC_NPROCESSORS_ONLN)

0 commit comments

Comments
 (0)