mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-09-23 03:55:44 -04:00
Improve SIMD detection (#72)
This commit is contained in:
parent
a1c4897e5e
commit
7aac7353ff
@ -171,7 +171,7 @@ int LegoDeviceEnumerate::FUN_1009d0d0()
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
int k = -1;
|
int k = -1;
|
||||||
int cpu_mmx = SupportsMMX();
|
bool cpu_mmx = SupportsSIMD();
|
||||||
|
|
||||||
for (list<MxDriver>::iterator it = m_list.begin(); it != m_list.end(); it++, i++) {
|
for (list<MxDriver>::iterator it = m_list.begin(); it != m_list.end(); it++, i++) {
|
||||||
|
|
||||||
@ -199,64 +199,49 @@ int LegoDeviceEnumerate::FUN_1009d0d0()
|
|||||||
// FUNCTION: CONFIG 0x00402930
|
// FUNCTION: CONFIG 0x00402930
|
||||||
// FUNCTION: LEGO1 0x1009d1a0
|
// FUNCTION: LEGO1 0x1009d1a0
|
||||||
// FUNCTION: BETA10 0x1011cf54
|
// FUNCTION: BETA10 0x1011cf54
|
||||||
int LegoDeviceEnumerate::SupportsMMX()
|
bool LegoDeviceEnumerate::SupportsSIMD()
|
||||||
{
|
{
|
||||||
int supports_mmx = SupportsCPUID();
|
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64)
|
||||||
|
// All x86_64 and 64-bit ARM CPUs support at least SSE2 or NEON
|
||||||
if (supports_mmx) {
|
return true;
|
||||||
#ifdef _MSC_VER
|
#elif defined(__i386__) || defined(_M_IX86)
|
||||||
#if defined(_M_IX86)
|
// 32-bit x86 - need to use CPUID to check for MMX or SSE
|
||||||
__asm {
|
if (!SupportsCPUID()) {
|
||||||
push ebx
|
return false;
|
||||||
mov eax, 0x0 ; EAX=0: Highest Function Parameter and Manufacturer ID
|
|
||||||
#if _MSC_VER > 1100
|
|
||||||
cpuid ; Run CPUID
|
|
||||||
#else
|
|
||||||
__emit 0x0f
|
|
||||||
__emit 0xa2
|
|
||||||
#endif
|
|
||||||
mov eax, 0x1 ; EAX=1: Processor Info and Feature Bits (unused)
|
|
||||||
#if _MSC_VER > 1100
|
|
||||||
cpuid ; Run CPUID
|
|
||||||
#else
|
|
||||||
__emit 0x0f
|
|
||||||
__emit 0xa2
|
|
||||||
#endif
|
|
||||||
xor eax, eax ; Zero EAX register
|
|
||||||
bt edx, 0x17 ; Test bit 0x17 (23): MMX instructions (64-bit SIMD) (Store in CF)
|
|
||||||
adc eax, eax ; Add with carry: EAX = EAX + EAX + CF = CF
|
|
||||||
pop ebx
|
|
||||||
mov supports_mmx, eax ; Save eax into C variable
|
|
||||||
}
|
|
||||||
#elif defined(_M_IX64)
|
|
||||||
supports_mmx = 1;
|
|
||||||
#else
|
|
||||||
supports_mmx = 0;
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
__asm__("movl $0x0, %%eax\n\t" // EAX=0: Highest Function Parameter and Manufacturer ID
|
|
||||||
"cpuid\n\t" // Run CPUID\n"
|
|
||||||
"mov $0x1, %%eax\n\t" // EAX=1: Processor Info and Feature Bits (unused)
|
|
||||||
"cpuid\n\t" // Run CPUID
|
|
||||||
"xorl %%eax, %%eax\n\t" // Zero EAX register
|
|
||||||
"btl $0x15, %%edx\n\t" // Test bit 0x17 (23): MMX instructions (64-bit SIMD) (Store in CF)
|
|
||||||
"adc %%eax, %%eax" // Add with carry: EAX = EAX + EAX + CF = CF
|
|
||||||
: "=a"(supports_mmx) // supports_mmx == EAX
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return supports_mmx;
|
int edx;
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER >= 1310
|
||||||
|
int cpuInfo[4];
|
||||||
|
__cpuid(cpuInfo, 1);
|
||||||
|
edx = cpuInfo[3];
|
||||||
|
#else
|
||||||
|
__asm__ __volatile__("movl $1, %%eax\n\t"
|
||||||
|
"cpuid\n\t"
|
||||||
|
: "=d"(edx)
|
||||||
|
:
|
||||||
|
: "%eax", "%ebx", "%ecx");
|
||||||
|
#endif
|
||||||
|
return (edx & (1 << 23)) != 0; // Bit 23: MMX
|
||||||
|
#elif defined(__arm__) && defined(__ANDROID__)
|
||||||
|
// Runtime check for NEON on 32-bit ARM (using Android NDK)
|
||||||
|
return android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON;
|
||||||
|
#else
|
||||||
|
// Prevent unsupported builds
|
||||||
|
#error "Unsupported platform: SIMD feature detection not implemented"
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: CONFIG 0x00402970
|
// FUNCTION: CONFIG 0x00402970
|
||||||
// FUNCTION: LEGO1 0x1009d1e0
|
// FUNCTION: LEGO1 0x1009d1e0
|
||||||
// FUNCTION: BETA10 0x1011cf97
|
// FUNCTION: BETA10 0x1011cf97
|
||||||
int LegoDeviceEnumerate::SupportsCPUID()
|
bool LegoDeviceEnumerate::SupportsCPUID()
|
||||||
{
|
{
|
||||||
|
#if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
|
||||||
|
return true;
|
||||||
|
#elif defined(_M_IX86) || defined(__i386__)
|
||||||
int has_cpuid;
|
int has_cpuid;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#if defined(_M_IX86)
|
|
||||||
__asm {
|
__asm {
|
||||||
xor eax, eax ; Zero EAX register
|
xor eax, eax ; Zero EAX register
|
||||||
pushfd ; Push EFLAGS register value on the stack
|
pushfd ; Push EFLAGS register value on the stack
|
||||||
@ -268,13 +253,7 @@ int LegoDeviceEnumerate::SupportsCPUID()
|
|||||||
popfd ; Push EFLAGS register value on the stack (again, and makes sure the stack remains the same)
|
popfd ; Push EFLAGS register value on the stack (again, and makes sure the stack remains the same)
|
||||||
mov has_cpuid, eax ; Save eax into C variable
|
mov has_cpuid, eax ; Save eax into C variable
|
||||||
}
|
}
|
||||||
#elif defined(_M_X64)
|
|
||||||
has_cpuid = 1;
|
|
||||||
#else
|
#else
|
||||||
has_cpuid = 0;
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(__i386__)
|
|
||||||
__asm__("xorl %%eax, %%eax\n\t" // Zero EAX register
|
__asm__("xorl %%eax, %%eax\n\t" // Zero EAX register
|
||||||
"pushfl\n\t" // Push EFLAGS register value on the stack
|
"pushfl\n\t" // Push EFLAGS register value on the stack
|
||||||
"orl $0x200000, (%%esp)\n\t" // Set bit 0x200000: Able to use CPUID instruction (Pentium+)
|
"orl $0x200000, (%%esp)\n\t" // Set bit 0x200000: Able to use CPUID instruction (Pentium+)
|
||||||
@ -285,13 +264,11 @@ int LegoDeviceEnumerate::SupportsCPUID()
|
|||||||
"popfl" // Push EFLAGS register value on the stack (again, and makes sure the stack remains the same)
|
"popfl" // Push EFLAGS register value on the stack (again, and makes sure the stack remains the same)
|
||||||
: "=a"(has_cpuid) // has_cpuid == EAX
|
: "=a"(has_cpuid) // has_cpuid == EAX
|
||||||
);
|
);
|
||||||
#elif defined(__x86_64__) || defined(__amd64__)
|
|
||||||
has_cpuid = 1;
|
|
||||||
#else
|
|
||||||
has_cpuid = 0;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
return has_cpuid;
|
return has_cpuid;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: CONFIG 0x004029a0
|
// FUNCTION: CONFIG 0x004029a0
|
||||||
|
@ -15,8 +15,8 @@ public:
|
|||||||
int FormatDeviceName(char* p_buffer, const MxDriver* p_ddInfo, const Direct3DDeviceInfo* p_d3dInfo) const;
|
int FormatDeviceName(char* p_buffer, const MxDriver* p_ddInfo, const Direct3DDeviceInfo* p_d3dInfo) const;
|
||||||
int BETA_1011cc65(int p_idx, char* p_buffer);
|
int BETA_1011cc65(int p_idx, char* p_buffer);
|
||||||
int FUN_1009d0d0();
|
int FUN_1009d0d0();
|
||||||
static int SupportsMMX();
|
static bool SupportsSIMD();
|
||||||
static int SupportsCPUID();
|
static bool SupportsCPUID();
|
||||||
int FUN_1009d210();
|
int FUN_1009d210();
|
||||||
unsigned char DriverSupportsRequiredDisplayMode(MxDriver& p_driver);
|
unsigned char DriverSupportsRequiredDisplayMode(MxDriver& p_driver);
|
||||||
unsigned char FUN_1009d3d0(Direct3DDeviceInfo& p_device);
|
unsigned char FUN_1009d3d0(Direct3DDeviceInfo& p_device);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user