SSE2에 대한 프로세서 지원을 결정 하시겠습니까?
-
18-09-2019 - |
문제
소프트웨어를 설치하기 전에 SSE2에 대한 프로세서 지원을 결정해야합니다. 내가 이해 한 바에 따르면, 나는 이것을 생각해 냈습니다.
bool TestSSE2(char * szErrorMsg)
{
__try
{
__asm
{
xorpd xmm0, xmm0 // executing SSE2 instruction
}
}
#pragma warning (suppress: 6320)
__except (EXCEPTION_EXECUTE_HANDLER)
{
if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
{
_tcscpy_s(szErrorMsg,MSGSIZE, _T("Streaming SIMD Extensions 2(SSE2) is not supported by the CPU.\r\n Unable to launch APP"));
return false;
}
_tcscpy_s(szErrorMsg,MSGSIZE, _T("Streaming SIMD Extensions 2(SSE2) is not supported by the CPU.\r\n Unable to launch APP"));
return false;
}
return true;
}
이것이 효과가 있습니까? CPU가 지원하기 때문에 테스트 방법을 잘 모르겠습니다. 따라서 함수 호출에서 거짓이 발생하지 않습니다.
SSE2에 대한 프로세서 지원을 어떻게 결정합니까?
해결책
EAX = 1으로 CPUID를 호출하여 기능 플래그를 EDX에로드하십시오. SSE2를 사용할 수있는 경우 비트 26이 설정됩니다. MSVC ++ 인라인 어셈블리를 사용하여 데모 목적을위한 일부 코드 (x86 만 휴대용이 없음) : :
inline unsigned int get_cpu_feature_flags()
{
unsigned int features;
__asm
{
// Save registers
push eax
push ebx
push ecx
push edx
// Get the feature flags (eax=1) from edx
mov eax, 1
cpuid
mov features, edx
// Restore registers
pop edx
pop ecx
pop ebx
pop eax
}
return features;
}
// Bit 26 for SSE2 support
static const bool cpu_supports_sse2 = (cpu_feature_flags & 0x04000000)!=0;
제휴하지 않습니다 StackOverflow