Determine processor support for SSE2?

后端 未结 4 1116
囚心锁ツ
囚心锁ツ 2020-12-15 23:10

I need to do determine processor support for SSE2 prior installing a software. From what I understand, I came up with this:

bool TestSSE2(char * szErrorMsg)
         


        
4条回答
  •  醉话见心
    2020-12-15 23:49

    Call CPUID with eax = 1 to load the feature flags in to edx. Bit 26 is set if SSE2 is available. Some code for demonstration purposes, using MSVC++ inline assembly (only for x86 and not portable!):

    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;
    

提交回复
热议问题