SDL2: Replace some system info implementation

--HG--
branch : sdl2
hg/feature/sdl2
kaetemi 11 years ago
parent cd35d14374
commit 2f302e93a9

@ -43,30 +43,23 @@ public:
*/
static uint64 getProcessorFrequency (bool quick = false);
/** Tests whether the CPUID instruction is supported
* (always false on non Intel architectures)
*/
static bool hasCPUID ();
/** Helps to know whether the processor features MMX instruction set
* This is initialized at started, so its fast
* (always false on non 0x86 architecture ...)
*/
static bool hasMMX () {return _HaveMMX;}
static bool hasMMX ();
/** Helps to know whether the processor has streaming SIMD instructions (the OS must supports it)
* This is initialized at started, so its fast
* (always false on non 0x86 architecture ...)
*/
static bool hasSSE () {return _HaveSSE;}
/** Gets the CPUID (if available). Useful for debug info
*/
static uint32 getCPUID();
static bool hasSSE ();
/** true if the Processor has HyperThreading
/** Helps to know whether the processor has SSE2 (the OS must supports it)
* This is initialized at started, so its fast
* (always false on non 0x86 architecture ...)
*/
static bool hasHyperThreading();
static bool hasSSE2 ();
/** true if running under NT
*/
@ -95,10 +88,6 @@ public:
/** Returns the main video card name and the video driver version
*/
static bool getVideoInfo (std::string &deviceName, uint64 &driverVersion);
private:
static bool _HaveMMX;
static bool _HaveSSE;
};
} // NLMISC

@ -42,6 +42,8 @@
#include "nel/misc/command.h"
#include "nel/misc/variable.h"
#include <SDL_cpuinfo.h>
using namespace std;
#ifdef DEBUG_NEW
@ -901,188 +903,19 @@ uint64 CSystemInfo::getProcessorFrequency(bool quick)
return freq;
}
static bool DetectMMX()
{
#ifdef NL_CPU_INTEL
if (!CSystemInfo::hasCPUID()) return false; // cpuid not supported ...
sint32 CPUInfo[4];
nlcpuid(CPUInfo, 1);
// check for bit 23 = MMX instruction set
if (CPUInfo[3] & 0x800000) return true;
#endif // NL_CPU_INTEL
return false;
}
static bool DetectSSE()
{
#ifdef NL_CPU_INTEL
if (!CSystemInfo::hasCPUID()) return false; // cpuid not supported ...
sint32 CPUInfo[4];
nlcpuid(CPUInfo, 1);
if (CPUInfo[3] & 0x2000000)
{
// check OS support for SSE
try
{
#ifdef NL_OS_WINDOWS
#ifdef NL_NO_ASM
unsigned int tmp = _mm_getcsr();
nlunreferenced(tmp);
#else
__asm
{
xorps xmm0, xmm0 // Streaming SIMD Extension
}
#endif // NL_NO_ASM
#elif NL_OS_UNIX
__asm__ __volatile__ ("xorps %xmm0, %xmm0;");
#endif // NL_OS_UNIX
}
catch(...)
{
return false;
}
// printf("sse detected\n");
return true;
}
#endif // NL_CPU_INTEL
return false;
}
bool CSystemInfo::_HaveMMX = DetectMMX ();
bool CSystemInfo::_HaveSSE = DetectSSE ();
bool CSystemInfo::hasCPUID ()
bool CSystemInfo::hasMMX()
{
#ifdef NL_CPU_INTEL
uint32 result = 0;
#ifdef NL_OS_WINDOWS
#ifdef NL_NO_ASM
sint32 CPUInfo[4] = {-1};
nlcpuid(CPUInfo, 0);
if (CPUInfo[3] != -1) result = 1;
#else
__asm
{
pushad
pushfd
// If ID bit of EFLAGS can change, then cpuid is available
pushfd
pop eax // Get EFLAG
mov ecx,eax
xor eax,0x200000 // Flip ID bit
push eax
popfd // Write EFLAGS
pushfd
pop eax // read back EFLAG
xor eax,ecx
je noCpuid // no flip -> no CPUID instr.
popfd // restore state
popad
mov result, 1
jmp CPUIDPresent
noCpuid:
popfd // restore state
popad
mov result, 0
CPUIDPresent:
}
#endif // NL_NO_ASM
#elif NL_OS_UNIX // NL_OS_WINDOWS
__asm__ __volatile__ (
/* Save Register */
"pushl %%ebp;"
"pushl %%ebx;"
"pushl %%edx;"
/* Check if this CPU supports cpuid */
"pushf;"
"pushf;"
"popl %%eax;"
"movl %%eax, %%ebx;"
"xorl $(1 << 21), %%eax;" // CPUID bit
"pushl %%eax;"
"popf;"
"pushf;"
"popl %%eax;"
"popf;" // Restore flags
"xorl %%ebx, %%eax;"
"jz NoCPUID;"
"movl $1, %0;"
"jmp CPUID;"
"NoCPUID:;"
"movl $0, %0;"
"CPUID:;"
"popl %%edx;"
"popl %%ebx;"
"popl %%ebp;"
:"=a"(result)
);
#endif // NL_OS_UNIX
return result == 1;
#else
return false;
#endif
return SDL_HasMMX();
}
uint32 CSystemInfo::getCPUID()
bool CSystemInfo::hasSSE()
{
#ifdef NL_CPU_INTEL
if(hasCPUID())
{
uint32 result = 0;
sint32 CPUInfo[4];
nlcpuid(CPUInfo, 1);
return CPUInfo[3];
}
#endif // NL_CPU_INTEL
return 0;
return SDL_HasSSE();
}
/*
* Note: Not used in NeL probably in Ryzom closed source. Not translated in AT&T asm, I don't understand the aim of this method
* Returns true if the CPU has HT, even if it is disabled. Maybe shoud count how many (virtual) core there is.
*/
bool CSystemInfo::hasHyperThreading()
bool CSystemInfo::hasSSE2()
{
#ifdef NL_OS_WINDOWS
if(hasCPUID())
{
sint32 CPUInfo[4];
// get vendor string from cpuid
char vendor_id[32];
memset(vendor_id, 0, sizeof(vendor_id));
nlcpuid(CPUInfo, 0);
memcpy(vendor_id, &CPUInfo[1], sizeof(sint32));
memcpy(vendor_id+4, &CPUInfo[3], sizeof(sint32));
memcpy(vendor_id+8, &CPUInfo[2], sizeof(sint32));
// get cpuid flags
nlcpuid(CPUInfo, 1);
// pentium 4 or later processor?
if ((((CPUInfo[0] & 0xf00) == 0xf00) || (CPUInfo[0] & 0xf00000)) &&
strcmp(vendor_id, "GenuineIntel") == 0)
return (CPUInfo[3] & 0x10000000)!=0; // Intel Processor Hyper-Threading
}
#endif
return false;
return SDL_HasSSE2();
}
bool CSystemInfo::isNT()

@ -403,11 +403,6 @@ void setCPUMask ()
Debug_NewCPUMask= cpuMask;
}
void displayCPUInfo()
{
nlinfo("CPUInfo: CPUMask before change: %x, after change: %x, CPUID: %x, hasHyperThreading: %s", (uint32)Debug_OldCPUMask, (uint32)Debug_NewCPUMask, CSystemInfo::getCPUID(), (CSystemInfo::hasHyperThreading()?"YES":"NO"));
}
string getVersionString (uint64 version)
{
return toString ("%u.%u.%u.%u", (unsigned int) (version >> 48), (unsigned int) ((version >> 32) & 0xffff), (unsigned int) ((version >> 16) & 0xffff), (unsigned int) (version & 0xffff));
@ -421,10 +416,6 @@ string getSystemInformation()
s += "Process Virtual Memory: " + bytesToHumanReadable(CSystemInfo::virtualMemory()) + "\n";
s += "OS: " + CSystemInfo::getOS() + "\n";
s += "Processor: " + CSystemInfo::getProc() + "\n";
s += toString("CPUID: %x\n", CSystemInfo::getCPUID());
s += toString("HT: %s\n", CSystemInfo::hasHyperThreading()?"YES":"NO");
s += toString("CpuMask: %x\n", IProcess::getCurrentProcess ()->getCPUMask());
if(Driver)
s += "NeL3D: " + string(Driver->getVideocardInformation()) + "\n";
@ -794,9 +785,6 @@ void prelogInit()
setCrashCallback(crashCallback);
// Display Some Info On CPU
displayCPUInfo();
// Display the client version.
#if FINAL_VERSION
nlinfo("RYZOM VERSION : FV %s ("__DATE__" "__TIME__")", RYZOM_VERSION);

Loading…
Cancel
Save