Skip to content

Commit 17e6208

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. (cherry picked from commit 7490471)
1 parent 157f894 commit 17e6208

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
@@ -127,7 +127,7 @@
127127
#define CPU_CFG2_LSX (1 << 6)
128128
#define CPU_CFG2_LASX (1 << 7)
129129

130-
#if defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP) && !defined(__MACOSX__) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
130+
#if defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP) && !defined(__MACOSX__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && (defined(__LINUX__) && !defined(HAVE_GETAUXVAL))
131131
/* This is the brute force way of detecting instruction sets...
132132
the idea is borrowed from the libmpeg2 library - thanks!
133133
*/
@@ -356,6 +356,8 @@ static int CPU_haveAltiVec(void)
356356
elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
357357
altivec = cpufeatures & PPC_FEATURE_HAS_ALTIVEC;
358358
return altivec;
359+
#elif defined(__LINUX__) && defined(__powerpc__) && defined(HAVE_GETAUXVAL)
360+
altivec = getauxval(AT_HWCAP) & PPC_FEATURE_HAS_ALTIVEC;
359361
#elif defined(SDL_ALTIVEC_BLITTERS) && defined(HAVE_SETJMP)
360362
void (*handler)(int sig);
361363
handler = signal(SIGILL, illegal_instruction);

0 commit comments

Comments
 (0)