Skip to content

Commit

Permalink
Fixed detection of Altivec on Mac OS X, and added attempt at general …
Browse files Browse the repository at this point in the history
…detection

 with SIGILL/setjmp hackery for PowerPC Linux, etc.
  • Loading branch information
icculus committed Dec 1, 2005
1 parent 4bea1e4 commit 5bc17cc
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions code/unix/unix_main.c
Expand Up @@ -362,23 +362,49 @@ void Sys_Quit (void) {
Sys_Exit(0);
}


#if idppc_altivec && !MACOS_X
/* This is the brute force way of detecting instruction sets...
the code is borrowed from SDL, which got the idea from the libmpeg2
library - thanks!
*/
#include <signal.h>
#include <setjmp.h>
static jmp_buf jmpbuf;
static void illegal_instruction(int sig)
{
longjmp(jmpbuf, 1);
}
#endif

static void Sys_DetectAltivec(void)
{
// Only detect if user hasn't forcibly disabled it.
qboolean altivec = qfalse;
if (com_altivec->integer) {
#if idppc_altivec
#ifdef MACOS_X
#ifdef MACOS_X
long feat = 0;
OSErr err = Gestalt(gestaltPowerPCProcessorFeatures, &feat);
if ((err==noErr) && ((1 << gestaltPowerPCHasVectorInstructions) & feat)) {
Cvar_Set( "com_altivec", "1" );
altivec = qtrue;
}
#else
void (*handler)(int sig);
handler = signal(SIGILL, illegal_instruction);
if ( setjmp(jmpbuf) == 0 ) {
asm volatile ("mtspr 256, %0\n\t"
"vand %%v0, %%v0, %%v0"
:
: "r" (-1));
altivec = qtrue;
}
signal(SIGILL, handler);
#endif

if (!altivec) {
Cvar_Set( "com_altivec", "0" ); // we don't have it! Disable support!
}
#else // !!! FIXME: PowerPC Linux, etc: how to detect?
Cvar_Set( "com_altivec", "1" );
#endif
#else
// not an Altivec system, so never use it.
Cvar_Set( "com_altivec", "0" );
#endif
}
}
Expand Down

0 comments on commit 5bc17cc

Please sign in to comment.