質問

私は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用プロセッサのサポートを決定するのですか?

役に立ちましたか?

解決

EDXにして機能フラグをロードするためにEAX = 1でCPUIDを呼び出します。 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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top