r398 - trunk/code/unix
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Dec 1 06:49:02 EST 2005
Author: icculus
Date: 2005-12-01 06:49:02 -0500 (Thu, 01 Dec 2005)
New Revision: 398
Modified:
trunk/code/unix/unix_main.c
Log:
Fixed detection of Altivec on Mac OS X, and added attempt at general detection
with SIGILL/setjmp hackery for PowerPC Linux, etc.
Modified: trunk/code/unix/unix_main.c
===================================================================
--- trunk/code/unix/unix_main.c 2005-12-01 11:16:36 UTC (rev 397)
+++ trunk/code/unix/unix_main.c 2005-12-01 11:49:02 UTC (rev 398)
@@ -362,24 +362,50 @@
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 // !!! FIXME: PowerPC Linux, etc: how to detect?
- Cvar_Set( "com_altivec", "1" );
+ #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!
+ }
#endif
-#else
- // not an Altivec system, so never use it.
- Cvar_Set( "com_altivec", "0" );
-#endif
}
}
More information about the quake3-commits
mailing list