mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-03-20 17:51:02 +00:00
Unify all Sys_GetProcessorId()
Use SDL functions whenever possible.
This commit is contained in:
parent
d4281b56bf
commit
6e0c766d14
6 changed files with 45 additions and 345 deletions
|
@ -95,6 +95,7 @@ static inline void CPUid(int index, int *a, int *b, int *c, int *d) {
|
|||
#error unsupported compiler
|
||||
#endif
|
||||
|
||||
#define c_SSE3 (1 << 0)
|
||||
#define d_FXSAVE (1 << 24)
|
||||
|
||||
static inline bool HasDAZ() {
|
||||
|
@ -109,6 +110,18 @@ static inline bool HasDAZ() {
|
|||
return (d & d_FXSAVE) == d_FXSAVE;
|
||||
}
|
||||
|
||||
static inline bool HasSSE3() {
|
||||
int a, b, c, d;
|
||||
|
||||
CPUid(0, &a, &b, &c, &d);
|
||||
if (a < 1)
|
||||
return false;
|
||||
|
||||
CPUid(1, &a, &b, &c, &d);
|
||||
|
||||
return (c & c_SSE3) == c_SSE3;
|
||||
}
|
||||
|
||||
#define MXCSR_DAZ (1 << 6)
|
||||
#define MXCSR_FTZ (1 << 15)
|
||||
|
||||
|
@ -173,3 +186,35 @@ void Sys_FPU_SetFTZ(bool enable) {
|
|||
EnableMXCSRFlag(MXCSR_FTZ, enable, "Flush-To-Zero");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GetProcessorId
|
||||
================
|
||||
*/
|
||||
int Sys_GetProcessorId( void ) {
|
||||
int flags = CPUID_GENERIC;
|
||||
|
||||
if (SDL_HasMMX())
|
||||
flags |= CPUID_MMX;
|
||||
|
||||
if (SDL_Has3DNow())
|
||||
flags |= CPUID_3DNOW;
|
||||
|
||||
if (SDL_HasSSE())
|
||||
flags |= CPUID_SSE;
|
||||
|
||||
if (SDL_HasSSE2())
|
||||
flags |= CPUID_SSE2;
|
||||
|
||||
#ifndef NO_SSE
|
||||
// there is no SDL_HasSSE3() in SDL 1.2
|
||||
if (HasSSE3())
|
||||
flags |= CPUID_SSE3;
|
||||
#endif
|
||||
|
||||
if (SDL_HasAltiVec())
|
||||
flags |= CPUID_ALTIVEC;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
|
|
@ -148,96 +148,6 @@ void Sys_Shutdown( void ) {
|
|||
Posix_Shutdown();
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
Sys_GetProcessorId
|
||||
===============
|
||||
*/
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
#if __x86_64__
|
||||
# define REG_b "rbx"
|
||||
# define REG_S "rsi"
|
||||
#elif __i386__
|
||||
# define REG_b "ebx"
|
||||
# define REG_S "esi"
|
||||
#endif
|
||||
|
||||
#define cpuid(index,eax,ebx,ecx,edx) \
|
||||
__asm__ volatile \
|
||||
( "mov %%" REG_b ", %%" REG_S "\n\t" \
|
||||
"cpuid\n\t" \
|
||||
"xchg %%" REG_b ", %%" REG_S \
|
||||
: "=a" (eax), "=S" (ebx), \
|
||||
"=c" (ecx), "=d" (edx) \
|
||||
: "0" (index));
|
||||
|
||||
int Sys_GetProcessorId( void ) {
|
||||
int eax, ebx, ecx, edx;
|
||||
int max_std_level, max_ext_level, std_caps=0, ext_caps=0;
|
||||
|
||||
int i = CPUID_GENERIC;
|
||||
|
||||
cpuid(0, max_std_level, ebx, ecx, edx);
|
||||
|
||||
if (max_std_level >= 1) {
|
||||
cpuid(1, eax, ebx, ecx, std_caps);
|
||||
|
||||
#ifdef __MMX__
|
||||
if (std_caps & (1<<23)) {
|
||||
Sys_Printf(" MMX");
|
||||
i |= CPUID_MMX;
|
||||
}
|
||||
#endif
|
||||
#ifdef __SSE__
|
||||
if (std_caps & (1<<25)) {
|
||||
Sys_Printf(" SSE");
|
||||
i |= CPUID_SSE;
|
||||
}
|
||||
#endif
|
||||
#ifdef __SSE2__
|
||||
if (std_caps & (1<<26)) {
|
||||
Sys_Printf(" SSE2");
|
||||
i |= CPUID_SSE2;
|
||||
}
|
||||
#endif
|
||||
#ifdef __SSE3__
|
||||
if (ecx & 1) {
|
||||
Sys_Printf(" SSE3");
|
||||
i |= CPUID_SSE3;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
cpuid(0x80000000, max_ext_level, ebx, ecx, edx);
|
||||
|
||||
if (max_ext_level >= 0x80000001) {
|
||||
cpuid(0x80000001, eax, ebx, ecx, ext_caps);
|
||||
|
||||
#ifdef __3dNOW__
|
||||
if (ext_caps & (1U<<31)) {
|
||||
Sys_Printf(" 3DNOW");
|
||||
i |= CPUID_3DNOW;
|
||||
}
|
||||
#endif
|
||||
#ifdef __MMX__
|
||||
if (ext_caps & (1<<23)) {
|
||||
if (!(i & CPUID_MMX))
|
||||
Sys_Printf(" MMX");
|
||||
i |= CPUID_MMX;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Sys_Printf("\n");
|
||||
|
||||
return i;
|
||||
}
|
||||
#else
|
||||
int Sys_GetProcessorId( void ) {
|
||||
return CPUID_GENERIC;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
===============
|
||||
Sys_FPU_EnableExceptions
|
||||
|
|
|
@ -464,22 +464,6 @@ void Sys_Shutdown( void ) {
|
|||
Posix_Shutdown();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
Sys_GetProcessorId
|
||||
===============
|
||||
*/
|
||||
int Sys_GetProcessorId( void ) {
|
||||
int cpuid = CPUID_GENERIC;
|
||||
#if defined(__ppc__)
|
||||
cpuid |= CPUID_ALTIVEC;
|
||||
#elif defined(__i386__)
|
||||
cpuid |= CPUID_MMX | CPUID_SSE | CPUID_SSE2 | CPUID_SSE3;
|
||||
#endif
|
||||
return cpuid;
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
Sys_FPU_EnableExceptions
|
||||
|
|
|
@ -30,232 +30,6 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
#include "sys/win32/win_local.h"
|
||||
|
||||
/*
|
||||
==============================================================
|
||||
|
||||
CPU
|
||||
|
||||
==============================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
================
|
||||
HasCPUID
|
||||
================
|
||||
*/
|
||||
static bool HasCPUID( void ) {
|
||||
#ifdef _MSC_VER
|
||||
__asm
|
||||
{
|
||||
pushfd // save eflags
|
||||
pop eax
|
||||
test eax, 0x00200000 // check ID bit
|
||||
jz set21 // bit 21 is not set, so jump to set_21
|
||||
and eax, 0xffdfffff // clear bit 21
|
||||
push eax // save new value in register
|
||||
popfd // store new value in flags
|
||||
pushfd
|
||||
pop eax
|
||||
test eax, 0x00200000 // check ID bit
|
||||
jz good
|
||||
jmp err // cpuid not supported
|
||||
set21:
|
||||
or eax, 0x00200000 // set ID bit
|
||||
push eax // store new value
|
||||
popfd // store new value in EFLAGS
|
||||
pushfd
|
||||
pop eax
|
||||
test eax, 0x00200000 // if bit 21 is on
|
||||
jnz good
|
||||
jmp err
|
||||
}
|
||||
|
||||
err:
|
||||
return false;
|
||||
good:
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define _REG_EAX 0
|
||||
#define _REG_EBX 1
|
||||
#define _REG_ECX 2
|
||||
#define _REG_EDX 3
|
||||
|
||||
/*
|
||||
================
|
||||
CPUID
|
||||
================
|
||||
*/
|
||||
static void CPUID( int func, unsigned regs[4] ) {
|
||||
#ifdef _MSC_VER
|
||||
unsigned regEAX, regEBX, regECX, regEDX;
|
||||
|
||||
__asm pusha
|
||||
__asm mov eax, func
|
||||
__asm __emit 00fh
|
||||
__asm __emit 0a2h
|
||||
__asm mov regEAX, eax
|
||||
__asm mov regEBX, ebx
|
||||
__asm mov regECX, ecx
|
||||
__asm mov regEDX, edx
|
||||
__asm popa
|
||||
|
||||
regs[_REG_EAX] = regEAX;
|
||||
regs[_REG_EBX] = regEBX;
|
||||
regs[_REG_ECX] = regECX;
|
||||
regs[_REG_EDX] = regEDX;
|
||||
#else
|
||||
regs[0] = 0;
|
||||
regs[1] = 0;
|
||||
regs[2] = 0;
|
||||
regs[3] = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Has3DNow
|
||||
================
|
||||
*/
|
||||
static bool Has3DNow( void ) {
|
||||
unsigned regs[4];
|
||||
|
||||
// check AMD-specific functions
|
||||
CPUID( 0x80000000, regs );
|
||||
if ( regs[_REG_EAX] < 0x80000000 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// bit 31 of EDX denotes 3DNow! support
|
||||
CPUID( 0x80000001, regs );
|
||||
if ( regs[_REG_EDX] & ( 1 << 31 ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
HasMMX
|
||||
================
|
||||
*/
|
||||
static bool HasMMX( void ) {
|
||||
unsigned regs[4];
|
||||
|
||||
// get CPU feature bits
|
||||
CPUID( 1, regs );
|
||||
|
||||
// bit 23 of EDX denotes MMX existence
|
||||
if ( regs[_REG_EDX] & ( 1 << 23 ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
HasSSE
|
||||
================
|
||||
*/
|
||||
static bool HasSSE( void ) {
|
||||
unsigned regs[4];
|
||||
|
||||
// get CPU feature bits
|
||||
CPUID( 1, regs );
|
||||
|
||||
// bit 25 of EDX denotes SSE existence
|
||||
if ( regs[_REG_EDX] & ( 1 << 25 ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
HasSSE2
|
||||
================
|
||||
*/
|
||||
static bool HasSSE2( void ) {
|
||||
unsigned regs[4];
|
||||
|
||||
// get CPU feature bits
|
||||
CPUID( 1, regs );
|
||||
|
||||
// bit 26 of EDX denotes SSE2 existence
|
||||
if ( regs[_REG_EDX] & ( 1 << 26 ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
HasSSE3
|
||||
================
|
||||
*/
|
||||
static bool HasSSE3( void ) {
|
||||
unsigned regs[4];
|
||||
|
||||
// get CPU feature bits
|
||||
CPUID( 1, regs );
|
||||
|
||||
// bit 0 of ECX denotes SSE3 existence
|
||||
if ( regs[_REG_ECX] & ( 1 << 0 ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GetCPUId
|
||||
================
|
||||
*/
|
||||
int Sys_GetCPUId( void ) {
|
||||
#ifdef _MSC_VER
|
||||
int flags;
|
||||
|
||||
// verify we're at least a Pentium or 486 with CPUID support
|
||||
if ( !HasCPUID() ) {
|
||||
return CPUID_UNSUPPORTED;
|
||||
}
|
||||
|
||||
// check for Multi Media Extensions
|
||||
if ( HasMMX() ) {
|
||||
flags |= CPUID_MMX;
|
||||
}
|
||||
|
||||
// check for 3DNow!
|
||||
if ( Has3DNow() ) {
|
||||
flags |= CPUID_3DNOW;
|
||||
}
|
||||
|
||||
// check for Streaming SIMD Extensions
|
||||
if ( HasSSE() ) {
|
||||
flags |= CPUID_SSE;
|
||||
}
|
||||
|
||||
// check for Streaming SIMD Extensions 2
|
||||
if ( HasSSE2() ) {
|
||||
flags |= CPUID_SSE2;
|
||||
}
|
||||
|
||||
// check for Streaming SIMD Extensions 3 aka Prescott's New Instructions
|
||||
if ( HasSSE3() ) {
|
||||
flags |= CPUID_SSE3;
|
||||
}
|
||||
|
||||
return flags;
|
||||
#else
|
||||
return CPUID_GENERIC;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============================================================================
|
||||
|
||||
|
|
|
@ -86,8 +86,6 @@ char *Sys_GetCurrentUser( void );
|
|||
|
||||
void Win_SetErrorText( const char *text );
|
||||
|
||||
int Sys_GetCPUId( void );
|
||||
|
||||
int MapKey (int key);
|
||||
|
||||
|
||||
|
@ -124,8 +122,6 @@ struct Win32Vars_t {
|
|||
|
||||
OSVERSIONINFOEX osversion;
|
||||
|
||||
int cpuid;
|
||||
|
||||
// when we get a windows message, we store the time off so keyboard processing
|
||||
// can know the exact time of an event (not really needed now that we use async direct input)
|
||||
int sysMsgTime;
|
||||
|
|
|
@ -858,15 +858,6 @@ void Sys_Shutdown( void ) {
|
|||
CoUninitialize();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GetProcessorId
|
||||
================
|
||||
*/
|
||||
int Sys_GetProcessorId( void ) {
|
||||
return win32.cpuid;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
||||
//#define SET_THREAD_AFFINITY
|
||||
|
|
Loading…
Reference in a new issue