29 #include "../../idlib/precompiled.h"
53 QueryPerformanceCounter( &li );
54 return = (double ) li.LowPart + (
double) 0xFFFFFFFF * li.HighPart;
69 return (
double ) lo + (double) 0xFFFFFFFF * hi;
80 static double ticks = 0;
85 QueryPerformanceFrequency( &li );
96 if ( !RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey ) ) {
98 buflen =
sizeof( ProcSpeed );
99 ret = RegQueryValueEx( hKey,
"~MHz",
NULL,
NULL, (LPBYTE) &ProcSpeed, &buflen );
101 if ( ret != ERROR_SUCCESS ) {
102 ret = RegQueryValueEx( hKey,
"~Mhz",
NULL,
NULL, (LPBYTE) &ProcSpeed, &buflen );
104 if ( ret != ERROR_SUCCESS ) {
105 ret = RegQueryValueEx( hKey,
"~mhz",
NULL,
NULL, (LPBYTE) &ProcSpeed, &buflen );
108 if ( ret == ERROR_SUCCESS ) {
109 ticks = (double) ((
unsigned long)ProcSpeed) * 1000000;
132 static bool HasCPUID(
void ) {
174 static void CPUID(
int func,
unsigned regs[4] ) {
175 unsigned regEAX, regEBX, regECX, regEDX;
181 __asm mov regEAX, eax
182 __asm mov regEBX, ebx
183 __asm mov regECX, ecx
184 __asm mov regEDX, edx
199 static bool IsAMD(
void ) {
201 char processorString[13];
204 CPUID( 0, (
unsigned int * ) pstring );
205 processorString[0] = pstring[4];
206 processorString[1] = pstring[5];
207 processorString[2] = pstring[6];
208 processorString[3] = pstring[7];
209 processorString[4] = pstring[12];
210 processorString[5] = pstring[13];
211 processorString[6] = pstring[14];
212 processorString[7] = pstring[15];
213 processorString[8] = pstring[8];
214 processorString[9] = pstring[9];
215 processorString[10] = pstring[10];
216 processorString[11] = pstring[11];
217 processorString[12] = 0;
219 if (
strcmp( processorString,
"AuthenticAMD" ) == 0 ) {
230 static bool HasCMOV(
void ) {
237 if ( regs[
_REG_EDX] & ( 1 << 15 ) ) {
248 static bool Has3DNow(
void ) {
252 CPUID( 0x80000000, regs );
253 if ( regs[
_REG_EAX] < 0x80000000 ) {
258 CPUID( 0x80000001, regs );
259 if ( regs[
_REG_EDX] & ( 1 << 31 ) ) {
271 static bool HasMMX(
void ) {
278 if ( regs[
_REG_EDX] & ( 1 << 23 ) ) {
289 static bool HasSSE(
void ) {
296 if ( regs[
_REG_EDX] & ( 1 << 25 ) ) {
307 static bool HasSSE2(
void ) {
314 if ( regs[
_REG_EDX] & ( 1 << 26 ) ) {
325 static bool HasSSE3(
void ) {
332 if ( regs[
_REG_ECX] & ( 1 << 0 ) ) {
343 #define NUM_LOGICAL_BITS 0x00FF0000 // EBX[23:16] Bit 16-23 in ebx contains the number of logical
346 static unsigned char LogicalProcPerPhysicalProc(
void ) {
347 unsigned int regebx = 0;
361 #define INITIAL_APIC_ID_BITS 0xFF000000 // EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
364 static unsigned char GetAPIC_ID(
void ) {
365 unsigned int regebx = 0;
383 #define HT_NOT_CAPABLE 0
385 #define HT_DISABLED 2
386 #define HT_SUPPORTED_NOT_ENABLED 3
387 #define HT_CANNOT_DETECT 4
389 int CPUCount(
int &logicalNum,
int &physicalNum ) {
397 info.dwNumberOfProcessors = 0;
398 GetSystemInfo (&info);
402 physicalNum = info.dwNumberOfProcessors;
404 unsigned char HT_Enabled = 0;
406 logicalNum = LogicalProcPerPhysicalProc();
408 if ( logicalNum >= 1 ) {
409 HANDLE hCurrentProcessHandle;
410 DWORD dwProcessAffinity;
411 DWORD dwSystemAffinity;
412 DWORD dwAffinityMask;
417 unsigned char i = 1, PHY_ID_MASK = 0xFF, PHY_ID_SHIFT = 0;
419 while( i < logicalNum ) {
425 hCurrentProcessHandle = GetCurrentProcess();
426 GetProcessAffinityMask( hCurrentProcessHandle, &dwProcessAffinity, &dwSystemAffinity );
430 if ( dwProcessAffinity != dwSystemAffinity ) {
437 while ( dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity ) {
439 if ( dwAffinityMask & dwProcessAffinity ) {
440 if ( SetProcessAffinityMask( hCurrentProcessHandle, dwAffinityMask ) ) {
441 unsigned char APIC_ID, LOG_ID, PHY_ID;
445 APIC_ID = GetAPIC_ID();
446 LOG_ID = APIC_ID & ~PHY_ID_MASK;
447 PHY_ID = APIC_ID >> PHY_ID_SHIFT;
454 dwAffinityMask = dwAffinityMask << 1;
458 SetProcessAffinityMask( hCurrentProcessHandle, dwProcessAffinity );
460 if ( logicalNum == 1 ) {
465 physicalNum /= logicalNum;
480 static bool HasHTT(
void ) {
482 int logicalNum, physicalNum, HTStatusFlag;
488 if ( !( regs[
_REG_EDX] & ( 1 << 28 ) ) ) {
492 HTStatusFlag =
CPUCount( logicalNum, physicalNum );
504 static bool HasDAZ(
void ) {
505 __declspec(align(16)) unsigned
char FXSaveArea[512];
506 unsigned char *FXArea = FXSaveArea;
518 memset( FXArea, 0,
sizeof( FXSaveArea ) );
525 dwMask = *(
DWORD *)&FXArea[28];
526 return ( ( dwMask & ( 1 << 6 ) ) == ( 1 << 6 ) );
606 static byte fpuState[128], *statePtr = fpuState;
607 static char fpuString[2048];
609 {
"Invalid operation", 0 },
610 {
"Denormalized operand", 1 },
611 {
"Divide-by-zero", 2 },
612 {
"Numeric overflow", 3 },
613 {
"Numeric underflow", 4 },
614 {
"Inexact result (precision)", 5 },
615 {
"Infinity control", 12 },
618 static char *precisionControlField[] = {
619 "Single Precision (24-bits)",
621 "Double Precision (53-bits)",
622 "Double Extended Precision (64-bits)"
624 static char *roundingControlField[] = {
631 {
"Invalid operation", 0 },
632 {
"Denormalized operand", 1 },
633 {
"Divide-by-zero", 2 },
634 {
"Numeric overflow", 3 },
635 {
"Numeric underflow", 4 },
636 {
"Inexact result (precision)", 5 },
637 {
"Stack fault", 6 },
638 {
"Error summary status", 7 },
651 length +=
sprintf( ptr+length,
"CTRL = %08x\n"
659 ctrl, stat, tags, inof, inse, opof, opse );
661 length +=
sprintf( ptr+length,
"Control Word:\n" );
662 for ( i = 0; controlWordFlags[
i].
name[0]; i++ ) {
663 length +=
sprintf( ptr+length,
" %-30s = %s\n", controlWordFlags[i].
name, ( ctrl & ( 1 << controlWordFlags[i].bit ) ) ?
"true" :
"false" );
665 length +=
sprintf( ptr+length,
" %-30s = %s\n",
"Precision control", precisionControlField[(ctrl>>8)&3] );
666 length +=
sprintf( ptr+length,
" %-30s = %s\n",
"Rounding control", roundingControlField[(ctrl>>10)&3] );
668 length +=
sprintf( ptr+length,
"Status Word:\n" );
669 for ( i = 0; statusWordFlags[
i].
name[0]; i++ ) {
670 ptr +=
sprintf( ptr+length,
" %-30s = %s\n", statusWordFlags[i].
name, ( stat & ( 1 << statusWordFlags[i].bit ) ) ?
"true" :
"false" );
672 length +=
sprintf( ptr+length,
" %-30s = %d%d%d%d\n",
"Condition code", (stat>>8)&1, (stat>>9)&1, (stat>>10)&1, (stat>>14)&1 );
673 length +=
sprintf( ptr+length,
" %-30s = %d\n",
"Top of stack pointer", (stat>>11)&7 );
728 double fpuStack[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
729 double *fpuStackPtr = fpuStack;
744 fst qword ptr [edi+0]
751 fst qword ptr [edi+8]
759 fst qword ptr [edi+16]
767 fst qword ptr [edi+24]
775 fst qword ptr [edi+32]
783 fst qword ptr [edi+40]
791 fst qword ptr [edi+48]
799 fst qword ptr [edi+56]
806 int ctrl = *(
int *)&fpuState[0];
807 int stat = *(
int *)&fpuState[4];
808 int tags = *(
int *)&fpuState[8];
809 int inof = *(
int *)&fpuState[12];
810 int inse = *(
int *)&fpuState[16];
811 int opof = *(
int *)&fpuState[20];
812 int opse = *(
int *)&fpuState[24];
815 ptr +=
sprintf( ptr,
"FPU State:\n"
816 "num values on stack = %d\n", numValues );
817 for ( i = 0; i < 8; i++ ) {
818 ptr +=
sprintf( ptr,
"ST%d = %1.10e\n", i, fpuStack[i] );
837 fnstcw
word ptr [eax]
838 mov bx,
word ptr [eax]
841 mov
word ptr [eax], bx
852 short precisionBitTable[4] = { 0, 1, 3, 0 };
853 short precisionBits = precisionBitTable[precision & 3] << 8;
854 short precisionMask = ~( ( 1 << 9 ) | ( 1 << 8 ) );
858 mov cx, precisionBits
859 fnstcw
word ptr [eax]
860 mov bx,
word ptr [eax]
861 and bx, precisionMask
863 mov
word ptr [eax], bx
874 short roundingBitTable[4] = { 0, 1, 2, 3 };
875 short roundingBits = roundingBitTable[rounding & 3] << 10;
876 short roundingMask = ~( ( 1 << 11 ) | ( 1 << 10 ) );
881 fnstcw
word ptr [eax]
882 mov bx,
word ptr [eax]
885 mov
word ptr [eax], bx
899 movzx ecx,
byte ptr enable
902 STMXCSR
dword ptr dwData
907 LDMXCSR
dword ptr dwData
920 movzx ecx,
byte ptr enable
923 STMXCSR
dword ptr dwData
928 LDMXCSR
dword ptr dwData
bool Sys_FPU_StackIsEmpty(void)
__declspec(dllimport) HRESULT WINAPI EAXDirectSoundCreate(GUID *
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
struct bitFlag_s bitFlag_t
int Sys_FPU_PrintStateFlags(char *ptr, int ctrl, int stat, int tags, int inof, int inse, int opof, int opse)
double Sys_GetClockTicks(void)
void Sleep(const int time)
double Sys_ClockTicksPerSecond(void)
cpuid_t Sys_GetCPUId(void)
int CPUCount(int &logicalNum, int &physicalNum)
const char * Sys_FPU_GetState(void)
void Sys_FPU_ClearStack(void)
void Sys_FPU_SetFTZ(bool enable)
static WindowRef ValidModeCallbackProc inCallback OSStatus err
#define INITIAL_APIC_ID_BITS
void Sys_FPU_SetDAZ(bool enable)
GLsizei const GLcharARB const GLint * length
#define HT_SUPPORTED_NOT_ENABLED
void Sys_FPU_EnableExceptions(int exceptions)
if(!ValidDisplayID(prefInfo.prefDisplayID)) prefInfo.prefDisplayID
int sprintf(idStr &string, const char *fmt,...)
void Sys_FPU_SetPrecision(int precision)
void Sys_FPU_SetRounding(int rounding)