From 4ed1fc5bfff0a905989b9242e916ccb69422a416 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 4 May 2025 15:01:25 -0500 Subject: [PATCH] cpuinfo: Use auxv for AltiVec on Linux if possible The SIGILL handler is not very reliable and can cause crashes. Linux provides the CPU's AltiVec support status in getauxval. (cherry picked from commit 7490471796f287cb284b21ec2643af98e9982b53) (cherry picked from commit 17e6208c1bd106a29efa16414d1b3dfea7f6e206) --- src/cpuinfo/SDL_cpuinfo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index 1291d493aa..3075f6ab3f 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -127,7 +127,7 @@ #define CPU_CFG2_LSX (1 << 6) #define CPU_CFG2_LASX (1 << 7) -#if defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP) && !defined(__MACOSX__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) +#if defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP) && !defined(__MACOSX__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && (defined(__LINUX__) && !defined(HAVE_GETAUXVAL)) /* This is the brute force way of detecting instruction sets... the idea is borrowed from the libmpeg2 library - thanks! */ @@ -356,6 +356,8 @@ static int CPU_haveAltiVec(void) elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures)); altivec = cpufeatures & PPC_FEATURE_HAS_ALTIVEC; return altivec; +#elif defined(__LINUX__) && defined(__powerpc__) && defined(HAVE_GETAUXVAL) + altivec = getauxval(AT_HWCAP) & PPC_FEATURE_HAS_ALTIVEC; #elif defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP) void (*handler)(int sig); handler = signal(SIGILL, illegal_instruction);