Skip to content

Commit 7490471

Browse files
awilfoxslouken
authored andcommitted
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.
1 parent 17bba02 commit 7490471

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/cpuinfo/SDL_cpuinfo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
#define CPU_CFG2_LSX (1 << 6)
116116
#define CPU_CFG2_LASX (1 << 7)
117117

118-
#if defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP) && !defined(SDL_PLATFORM_MACOS) && !defined(SDL_PLATFORM_OPENBSD) && !defined(SDL_PLATFORM_FREEBSD)
118+
#if defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP) && !defined(SDL_PLATFORM_MACOS) && !defined(SDL_PLATFORM_OPENBSD) && !defined(SDL_PLATFORM_FREEBSD) && (defined(SDL_PLATFORM_LINUX) && !defined(HAVE_GETAUXVAL))
119119
/* This is the brute force way of detecting instruction sets...
120120
the idea is borrowed from the libmpeg2 library - thanks!
121121
*/
@@ -344,6 +344,8 @@ static int CPU_haveAltiVec(void)
344344
elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
345345
altivec = cpufeatures & PPC_FEATURE_HAS_ALTIVEC;
346346
return altivec;
347+
#elif defined(SDL_PLATFORM_LINUX) && defined(__powerpc__) && defined(HAVE_GETAUXVAL)
348+
altivec = getauxval(AT_HWCAP) & PPC_FEATURE_HAS_ALTIVEC;
347349
#elif defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP)
348350
void (*handler)(int sig);
349351
handler = signal(SIGILL, illegal_instruction);

0 commit comments

Comments
 (0)