fixed cpu detection on 64bit windows (and removing nasty assembly for win32).

Note that this still works for 32bit windows.
This commit is contained in:
Jeff Hutchinson 2020-07-07 01:05:08 -04:00
parent 1173c4f153
commit 7880c71d9a
2 changed files with 15 additions and 72 deletions

View file

@ -30,6 +30,7 @@ Signal<void(void)> Platform::SystemInfoReady;
enum CPUFlags
{
// EDX Register flags
BIT_FPU = BIT(0),
BIT_RDTSC = BIT(4),
BIT_MMX = BIT(23),
@ -37,7 +38,7 @@ enum CPUFlags
BIT_SSE2 = BIT(26),
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_SSE3xt = BIT(9),
BIT_SSE4_1 = BIT(19),

View file

@ -25,22 +25,13 @@
#include "console/console.h"
#include "core/stringTable.h"
#include <math.h>
#include <intrin.h>
Platform::SystemInfo_struct Platform::SystemInfo;
extern void PlatformBlitInit();
extern void SetProcessorInfo(Platform::SystemInfo_struct::Processor& pInfo,
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()
{
// Reference:
@ -56,72 +47,23 @@ void Processor::init()
Platform::SystemInfo.processor.mhz = 0;
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 processor = 0;
U32 properties2 = 0;
#if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
__asm
{
//--------------------------------------
// is CPUID supported
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 vendorInfo[4];
__cpuid(vendorInfo, 0);
*reinterpret_cast<int*>(vendor) = vendorInfo[1]; // ebx
*reinterpret_cast<int*>(vendor + 4) = vendorInfo[3]; // edx
*reinterpret_cast<int*>(vendor + 8) = vendorInfo[2]; // ecx
//--------------------------------------
// Get Vendor Informaion using CPUID eax==0
xor eax, eax
cpuid
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
S32 cpuInfo[4];
__cpuid(cpuInfo, 1);
processor = cpuInfo[0]; // eax
properties = cpuInfo[3]; // edx
properties2 = cpuInfo[2]; // ecx
SetProcessorInfo(Platform::SystemInfo.processor, vendor, processor, properties, properties2);