Check for SSE support on startup

floating-point
Nicolas Hake 2010-05-19 07:25:07 +02:00
parent e3542d739d
commit b620bc24cf
1 changed files with 22 additions and 0 deletions

View File

@ -81,6 +81,7 @@ C4Application::~C4Application()
bool C4Application::DoInit()
{
assert(AppState == C4AS_None);
// Config overwrite by parameter
StdStrBuf sConfigFilename;
char szParameter[_MAX_PATH+1];
@ -119,6 +120,27 @@ bool C4Application::DoInit()
// Open log
OpenLog();
// Check for SSE support
bool has_sse = false;
struct registers
{
int eax, ebx, ecx, edx;
} regs = {0};
const uint32_t CPUID_EDX_HAS_SSE_FLAG = 1 << 25;
#if defined _MSC_VER
__cpuid(reinterpret_cast<int*>(&regs), 1);
#elif defined __GNUC__
__asm__ __volatile__("cpuid":"=d"(regs.edx):"a"(1):"%ebx","%ecx");
#endif
has_sse = (regs.edx & CPUID_EDX_HAS_SSE_FLAG) != 0;
if (!has_sse)
{
const char *message = "Your CPU does not support the SSE instruction set that is required by this program.";
Log(message);
MessageDialog(message);
return false;
}
Revision.Ref(OC_HG_REVISION);
// init system group