Stub out win32 CPU functions for MinGW

Most of these use MSVC style asm.
Binaries compiled with MinGW will not use any SIMD code for now.
This commit is contained in:
dhewg 2011-12-14 00:41:01 +01:00
parent ed349d71cc
commit 661e8f453b
2 changed files with 56 additions and 6 deletions

View file

@ -46,12 +46,12 @@ Sys_GetClockTicks
================ ================
*/ */
double Sys_GetClockTicks( void ) { double Sys_GetClockTicks( void ) {
#if 0 #ifndef _MSC_VER
LARGE_INTEGER li; LARGE_INTEGER li;
QueryPerformanceCounter( &li ); QueryPerformanceCounter( &li );
return = (double ) li.LowPart + (double) 0xFFFFFFFF * li.HighPart; return (double ) li.LowPart + (double) 0xFFFFFFFF * li.HighPart;
#else #else
@ -78,7 +78,7 @@ Sys_ClockTicksPerSecond
*/ */
double Sys_ClockTicksPerSecond( void ) { double Sys_ClockTicksPerSecond( void ) {
static double ticks = 0; static double ticks = 0;
#if 0 #ifndef _MSC_VER
if ( !ticks ) { if ( !ticks ) {
LARGE_INTEGER li; LARGE_INTEGER li;
@ -130,6 +130,7 @@ HasCPUID
================ ================
*/ */
static bool HasCPUID( void ) { static bool HasCPUID( void ) {
#ifdef _MSC_VER
__asm __asm
{ {
pushfd // save eflags pushfd // save eflags
@ -159,6 +160,9 @@ err:
return false; return false;
good: good:
return true; return true;
#else
return false;
#endif
} }
#define _REG_EAX 0 #define _REG_EAX 0
@ -172,6 +176,7 @@ CPUID
================ ================
*/ */
static void CPUID( int func, unsigned regs[4] ) { static void CPUID( int func, unsigned regs[4] ) {
#ifdef _MSC_VER
unsigned regEAX, regEBX, regECX, regEDX; unsigned regEAX, regEBX, regECX, regEDX;
__asm pusha __asm pusha
@ -188,9 +193,14 @@ static void CPUID( int func, unsigned regs[4] ) {
regs[_REG_EBX] = regEBX; regs[_REG_EBX] = regEBX;
regs[_REG_ECX] = regECX; regs[_REG_ECX] = regECX;
regs[_REG_EDX] = regEDX; regs[_REG_EDX] = regEDX;
#else
regs[0] = 0;
regs[1] = 0;
regs[2] = 0;
regs[3] = 0;
#endif
} }
/* /*
================ ================
IsAMD IsAMD
@ -344,6 +354,7 @@ LogicalProcPerPhysicalProc
// processors per physical processor when execute cpuid with // processors per physical processor when execute cpuid with
// eax set to 1 // eax set to 1
static unsigned char LogicalProcPerPhysicalProc( void ) { static unsigned char LogicalProcPerPhysicalProc( void ) {
#ifdef _MSC_VER
unsigned int regebx = 0; unsigned int regebx = 0;
__asm { __asm {
mov eax, 1 mov eax, 1
@ -351,6 +362,9 @@ static unsigned char LogicalProcPerPhysicalProc( void ) {
mov regebx, ebx mov regebx, ebx
} }
return (unsigned char) ((regebx & NUM_LOGICAL_BITS) >> 16); return (unsigned char) ((regebx & NUM_LOGICAL_BITS) >> 16);
#else
return 0;
#endif
} }
/* /*
@ -362,6 +376,7 @@ GetAPIC_ID
// initial APIC ID for the processor this code is running on. // initial APIC ID for the processor this code is running on.
// Default value = 0xff if HT is not supported // Default value = 0xff if HT is not supported
static unsigned char GetAPIC_ID( void ) { static unsigned char GetAPIC_ID( void ) {
#ifdef _MSC_VER
unsigned int regebx = 0; unsigned int regebx = 0;
__asm { __asm {
mov eax, 1 mov eax, 1
@ -369,6 +384,9 @@ static unsigned char GetAPIC_ID( void ) {
mov regebx, ebx mov regebx, ebx
} }
return (unsigned char) ((regebx & INITIAL_APIC_ID_BITS) >> 24); return (unsigned char) ((regebx & INITIAL_APIC_ID_BITS) >> 24);
#else
return '\0';
#endif
} }
/* /*
@ -502,6 +520,7 @@ HasHTT
================ ================
*/ */
static bool HasDAZ( void ) { static bool HasDAZ( void ) {
#ifdef _MSC_VER
__declspec(align(16)) unsigned char FXSaveArea[512]; __declspec(align(16)) unsigned char FXSaveArea[512];
unsigned char *FXArea = FXSaveArea; unsigned char *FXArea = FXSaveArea;
DWORD dwMask = 0; DWORD dwMask = 0;
@ -524,6 +543,9 @@ static bool HasDAZ( void ) {
dwMask = *(DWORD *)&FXArea[28]; // Read the MXCSR Mask dwMask = *(DWORD *)&FXArea[28]; // Read the MXCSR Mask
return ( ( dwMask & ( 1 << 6 ) ) == ( 1 << 6 ) ); // Return if the DAZ bit is set return ( ( dwMask & ( 1 << 6 ) ) == ( 1 << 6 ) ); // Return if the DAZ bit is set
#else
return false;
#endif
} }
/* /*
@ -532,6 +554,7 @@ Sys_GetCPUId
================ ================
*/ */
int Sys_GetCPUId( void ) { int Sys_GetCPUId( void ) {
#ifdef _MSC_VER
int flags; int flags;
// verify we're at least a Pentium or 486 with CPUID support // verify we're at least a Pentium or 486 with CPUID support
@ -587,6 +610,9 @@ int Sys_GetCPUId( void ) {
} }
return flags; return flags;
#else
return CPUID_GENERIC;
#endif
} }
@ -646,6 +672,7 @@ Sys_FPU_PrintStateFlags
=============== ===============
*/ */
int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof, int inse, int opof, int opse ) { int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof, int inse, int opof, int opse ) {
#ifdef _MSC_VER
int i, length = 0; int i, length = 0;
length += sprintf( ptr+length, "CTRL = %08x\n" length += sprintf( ptr+length, "CTRL = %08x\n"
@ -673,6 +700,9 @@ int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof,
length += sprintf( ptr+length, " %-30s = %d\n", "Top of stack pointer", (stat>>11)&7 ); length += sprintf( ptr+length, " %-30s = %d\n", "Top of stack pointer", (stat>>11)&7 );
return length; return length;
#else
return 0;
#endif
} }
/* /*
@ -681,6 +711,7 @@ Sys_FPU_StackIsEmpty
=============== ===============
*/ */
bool Sys_FPU_StackIsEmpty( void ) { bool Sys_FPU_StackIsEmpty( void ) {
#ifdef _MSC_VER
__asm { __asm {
mov eax, statePtr mov eax, statePtr
fnstenv [eax] fnstenv [eax]
@ -692,6 +723,9 @@ bool Sys_FPU_StackIsEmpty( void ) {
return false; return false;
empty: empty:
return true; return true;
#else
return true;
#endif
} }
/* /*
@ -700,6 +734,7 @@ Sys_FPU_ClearStack
=============== ===============
*/ */
void Sys_FPU_ClearStack( void ) { void Sys_FPU_ClearStack( void ) {
#ifdef _MSC_VER
__asm { __asm {
mov eax, statePtr mov eax, statePtr
fnstenv [eax] fnstenv [eax]
@ -715,6 +750,7 @@ void Sys_FPU_ClearStack( void ) {
jmp emptyStack jmp emptyStack
done: done:
} }
#endif
} }
/* /*
@ -725,6 +761,7 @@ Sys_FPU_GetState
=============== ===============
*/ */
const char *Sys_FPU_GetState( void ) { const char *Sys_FPU_GetState( void ) {
#ifdef _MSC_VER
double fpuStack[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; double fpuStack[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
double *fpuStackPtr = fpuStack; double *fpuStackPtr = fpuStack;
int i, numValues; int i, numValues;
@ -821,6 +858,9 @@ const char *Sys_FPU_GetState( void ) {
Sys_FPU_PrintStateFlags( ptr, ctrl, stat, tags, inof, inse, opof, opse ); Sys_FPU_PrintStateFlags( ptr, ctrl, stat, tags, inof, inse, opof, opse );
return fpuString; return fpuString;
#else
return "";
#endif
} }
/* /*
@ -829,6 +869,7 @@ Sys_FPU_EnableExceptions
=============== ===============
*/ */
void Sys_FPU_EnableExceptions( int exceptions ) { void Sys_FPU_EnableExceptions( int exceptions ) {
#ifdef _MSC_VER
__asm { __asm {
mov eax, statePtr mov eax, statePtr
mov ecx, exceptions mov ecx, exceptions
@ -841,6 +882,7 @@ void Sys_FPU_EnableExceptions( int exceptions ) {
mov word ptr [eax], bx mov word ptr [eax], bx
fldcw word ptr [eax] fldcw word ptr [eax]
} }
#endif
} }
/* /*
@ -849,6 +891,7 @@ Sys_FPU_SetPrecision
=============== ===============
*/ */
void Sys_FPU_SetPrecision( int precision ) { void Sys_FPU_SetPrecision( int precision ) {
#ifdef _MSC_VER
short precisionBitTable[4] = { 0, 1, 3, 0 }; short precisionBitTable[4] = { 0, 1, 3, 0 };
short precisionBits = precisionBitTable[precision & 3] << 8; short precisionBits = precisionBitTable[precision & 3] << 8;
short precisionMask = ~( ( 1 << 9 ) | ( 1 << 8 ) ); short precisionMask = ~( ( 1 << 9 ) | ( 1 << 8 ) );
@ -863,6 +906,7 @@ void Sys_FPU_SetPrecision( int precision ) {
mov word ptr [eax], bx mov word ptr [eax], bx
fldcw word ptr [eax] fldcw word ptr [eax]
} }
#endif
} }
/* /*
@ -871,6 +915,7 @@ Sys_FPU_SetRounding
================ ================
*/ */
void Sys_FPU_SetRounding( int rounding ) { void Sys_FPU_SetRounding( int rounding ) {
#ifdef _MSC_VER
short roundingBitTable[4] = { 0, 1, 2, 3 }; short roundingBitTable[4] = { 0, 1, 2, 3 };
short roundingBits = roundingBitTable[rounding & 3] << 10; short roundingBits = roundingBitTable[rounding & 3] << 10;
short roundingMask = ~( ( 1 << 11 ) | ( 1 << 10 ) ); short roundingMask = ~( ( 1 << 11 ) | ( 1 << 10 ) );
@ -885,6 +930,7 @@ void Sys_FPU_SetRounding( int rounding ) {
mov word ptr [eax], bx mov word ptr [eax], bx
fldcw word ptr [eax] fldcw word ptr [eax]
} }
#endif
} }
/* /*
@ -893,6 +939,7 @@ Sys_FPU_SetDAZ
================ ================
*/ */
void Sys_FPU_SetDAZ( bool enable ) { void Sys_FPU_SetDAZ( bool enable ) {
#ifdef _MSC_VER
DWORD dwData; DWORD dwData;
_asm { _asm {
@ -906,6 +953,7 @@ void Sys_FPU_SetDAZ( bool enable ) {
mov dwData, eax mov dwData, eax
LDMXCSR dword ptr dwData LDMXCSR dword ptr dwData
} }
#endif
} }
/* /*
@ -914,6 +962,7 @@ Sys_FPU_SetFTZ
================ ================
*/ */
void Sys_FPU_SetFTZ( bool enable ) { void Sys_FPU_SetFTZ( bool enable ) {
#ifdef _MSC_VER
DWORD dwData; DWORD dwData;
_asm { _asm {
@ -927,4 +976,5 @@ void Sys_FPU_SetFTZ( bool enable ) {
mov dwData, eax mov dwData, eax
LDMXCSR dword ptr dwData LDMXCSR dword ptr dwData
} }
#endif
} }

View file

@ -39,7 +39,7 @@ If you have questions concerning this license or the applicable additional terms
#include <io.h> #include <io.h>
#include <conio.h> #include <conio.h>
#ifndef ID_DEDICATED #if !defined(ID_DEDICATED) && !defined(__MINGW32__)
#include <comdef.h> #include <comdef.h>
#include <comutil.h> #include <comutil.h>
#include <wbemidl.h> #include <wbemidl.h>
@ -110,7 +110,7 @@ returns in megabytes
================ ================
*/ */
int Sys_GetVideoRam( void ) { int Sys_GetVideoRam( void ) {
#ifdef ID_DEDICATED #if defined(ID_DEDICATED) || defined(__MINGW32__)
return 0; return 0;
#else #else
unsigned int retSize = 64; unsigned int retSize = 64;