mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
Merge pull request #240 from JeffProgrammer/wincpu_detect
fixed cpu detection on 64bit windows
This commit is contained in:
commit
9d42895b2e
2 changed files with 15 additions and 72 deletions
|
|
@ -30,6 +30,7 @@ Signal<void(void)> Platform::SystemInfoReady;
|
||||||
|
|
||||||
enum CPUFlags
|
enum CPUFlags
|
||||||
{
|
{
|
||||||
|
// EDX Register flags
|
||||||
BIT_FPU = BIT(0),
|
BIT_FPU = BIT(0),
|
||||||
BIT_RDTSC = BIT(4),
|
BIT_RDTSC = BIT(4),
|
||||||
BIT_MMX = BIT(23),
|
BIT_MMX = BIT(23),
|
||||||
|
|
@ -37,7 +38,7 @@ enum CPUFlags
|
||||||
BIT_SSE2 = BIT(26),
|
BIT_SSE2 = BIT(26),
|
||||||
BIT_3DNOW = BIT(31),
|
BIT_3DNOW = BIT(31),
|
||||||
|
|
||||||
// These use a different value for comparison than the above flags
|
// These use a different value for comparison than the above flags (ECX Register)
|
||||||
BIT_SSE3 = BIT(0),
|
BIT_SSE3 = BIT(0),
|
||||||
BIT_SSE3xt = BIT(9),
|
BIT_SSE3xt = BIT(9),
|
||||||
BIT_SSE4_1 = BIT(19),
|
BIT_SSE4_1 = BIT(19),
|
||||||
|
|
|
||||||
|
|
@ -25,22 +25,13 @@
|
||||||
#include "console/console.h"
|
#include "console/console.h"
|
||||||
#include "core/stringTable.h"
|
#include "core/stringTable.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <intrin.h>
|
||||||
|
|
||||||
Platform::SystemInfo_struct Platform::SystemInfo;
|
Platform::SystemInfo_struct Platform::SystemInfo;
|
||||||
extern void PlatformBlitInit();
|
extern void PlatformBlitInit();
|
||||||
extern void SetProcessorInfo(Platform::SystemInfo_struct::Processor& pInfo,
|
extern void SetProcessorInfo(Platform::SystemInfo_struct::Processor& pInfo,
|
||||||
char* vendor, U32 processor, U32 properties, U32 properties2); // platform/platformCPU.cc
|
char* vendor, U32 processor, U32 properties, U32 properties2); // platform/platformCPU.cc
|
||||||
|
|
||||||
|
|
||||||
#if defined(TORQUE_SUPPORTS_NASM)
|
|
||||||
// asm cpu detection routine from platform code
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
void detectX86CPUInfo(char *vendor, U32 *processor, U32 *properties);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void Processor::init()
|
void Processor::init()
|
||||||
{
|
{
|
||||||
// Reference:
|
// Reference:
|
||||||
|
|
@ -56,72 +47,23 @@ void Processor::init()
|
||||||
Platform::SystemInfo.processor.mhz = 0;
|
Platform::SystemInfo.processor.mhz = 0;
|
||||||
Platform::SystemInfo.processor.properties = CPU_PROP_C | CPU_PROP_LE;
|
Platform::SystemInfo.processor.properties = CPU_PROP_C | CPU_PROP_LE;
|
||||||
|
|
||||||
char vendor[13] = {0,};
|
char vendor[0x20];
|
||||||
|
dMemset(vendor, 0, sizeof(vendor));
|
||||||
U32 properties = 0;
|
U32 properties = 0;
|
||||||
U32 processor = 0;
|
U32 processor = 0;
|
||||||
U32 properties2 = 0;
|
U32 properties2 = 0;
|
||||||
|
|
||||||
#if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
|
S32 vendorInfo[4];
|
||||||
__asm
|
__cpuid(vendorInfo, 0);
|
||||||
{
|
*reinterpret_cast<int*>(vendor) = vendorInfo[1]; // ebx
|
||||||
//--------------------------------------
|
*reinterpret_cast<int*>(vendor + 4) = vendorInfo[3]; // edx
|
||||||
// is CPUID supported
|
*reinterpret_cast<int*>(vendor + 8) = vendorInfo[2]; // ecx
|
||||||
push ebx
|
|
||||||
push edx
|
|
||||||
push ecx
|
|
||||||
pushfd
|
|
||||||
pushfd // save EFLAGS to stack
|
|
||||||
pop eax // move EFLAGS into EAX
|
|
||||||
mov ebx, eax
|
|
||||||
xor eax, 0x200000 // flip bit 21
|
|
||||||
push eax
|
|
||||||
popfd // restore EFLAGS
|
|
||||||
pushfd
|
|
||||||
pop eax
|
|
||||||
cmp eax, ebx
|
|
||||||
jz EXIT // doesn't support CPUID instruction
|
|
||||||
|
|
||||||
//--------------------------------------
|
S32 cpuInfo[4];
|
||||||
// Get Vendor Informaion using CPUID eax==0
|
__cpuid(cpuInfo, 1);
|
||||||
xor eax, eax
|
processor = cpuInfo[0]; // eax
|
||||||
cpuid
|
properties = cpuInfo[3]; // edx
|
||||||
|
properties2 = cpuInfo[2]; // ecx
|
||||||
mov DWORD PTR vendor, ebx
|
|
||||||
mov DWORD PTR vendor+4, edx
|
|
||||||
mov DWORD PTR vendor+8, ecx
|
|
||||||
|
|
||||||
// get Generic Extended CPUID info
|
|
||||||
mov eax, 1
|
|
||||||
cpuid // eax=1, so cpuid queries feature information
|
|
||||||
|
|
||||||
and eax, 0x0fff3fff
|
|
||||||
mov processor, eax // just store the model bits
|
|
||||||
mov properties, edx
|
|
||||||
mov properties2, ecx
|
|
||||||
|
|
||||||
// Want to check for 3DNow(tm). Need to see if extended cpuid functions present.
|
|
||||||
mov eax, 0x80000000
|
|
||||||
cpuid
|
|
||||||
cmp eax, 0x80000000
|
|
||||||
jbe MAYBE_3DLATER
|
|
||||||
mov eax, 0x80000001
|
|
||||||
cpuid
|
|
||||||
and edx, 0x80000000 // 3DNow if bit 31 set -> put bit in our properties
|
|
||||||
or properties, edx
|
|
||||||
MAYBE_3DLATER:
|
|
||||||
|
|
||||||
|
|
||||||
EXIT:
|
|
||||||
popfd
|
|
||||||
pop ecx
|
|
||||||
pop edx
|
|
||||||
pop ebx
|
|
||||||
}
|
|
||||||
#elif defined(TORQUE_SUPPORTS_NASM)
|
|
||||||
|
|
||||||
detectX86CPUInfo(vendor, &processor, &properties);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SetProcessorInfo(Platform::SystemInfo.processor, vendor, processor, properties, properties2);
|
SetProcessorInfo(Platform::SystemInfo.processor, vendor, processor, properties, properties2);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue