Skip to content

Commit 9886d89

Browse files
pkubajslouken
authored andcommitted
Fix AltiVec detection on FreeBSD
The previous code was not correct, because there's no PPC_FEATURE_HAS_ALTIVEC MIB. Instead, elf vector check should be done.
1 parent c45facf commit 9886d89

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/cpuinfo/SDL_cpuinfo.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@
5050
#endif
5151
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
5252
#include <sys/sysctl.h> /* For AltiVec check */
53-
#elif (defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__powerpc__)
53+
#elif defined(__OpenBSD__) && defined(__powerpc__)
5454
#include <sys/param.h>
5555
#include <sys/sysctl.h> /* For AltiVec check */
5656
#include <machine/cpu.h>
57+
#elif defined(__FreeBSD__) && defined(__powerpc__)
58+
#include <machine/cpu.h>
59+
#include <sys/auxv.h>
5760
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
5861
#include <signal.h>
5962
#include <setjmp.h>
@@ -110,7 +113,7 @@
110113
#define CPU_HAS_AVX512F (1 << 12)
111114
#define CPU_HAS_ARM_SIMD (1 << 13)
112115

113-
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
116+
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__ && !__FreeBSD__
114117
/* This is the brute force way of detecting instruction sets...
115118
the idea is borrowed from the libmpeg2 library - thanks!
116119
*/
@@ -314,11 +317,9 @@ CPU_haveAltiVec(void)
314317
{
315318
volatile int altivec = 0;
316319
#ifndef SDL_CPUINFO_DISABLED
317-
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__)) || (defined(__FreeBSD__) && defined(__powerpc__))
320+
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
318321
#ifdef __OpenBSD__
319322
int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
320-
#elif defined(__FreeBSD__)
321-
int selectors[2] = { CTL_HW, PPC_FEATURE_HAS_ALTIVEC };
322323
#else
323324
int selectors[2] = { CTL_HW, HW_VECTORUNIT };
324325
#endif
@@ -327,6 +328,11 @@ CPU_haveAltiVec(void)
327328
int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
328329
if (0 == error)
329330
altivec = (hasVectorUnit != 0);
331+
#elif defined(__FreeBSD__) && defined(__powerpc__)
332+
unsigned long cpufeatures = 0;
333+
elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
334+
altivec = cpufeatures & PPC_FEATURE_HAS_ALTIVEC;
335+
return altivec;
330336
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
331337
void (*handler) (int sig);
332338
handler = signal(SIGILL, illegal_instruction);

0 commit comments

Comments
 (0)