c++assemblyvisual-c++ssecpuid

Get SSE version without __asm on x64


I'm trying to build slightly modified versions of some functions of the VS2010 CRT library, all is well except for the parts where it tries to access a global variable which presumably holds the instruction set architecture version (ISA):

if (__isa_available > __ISA_AVAILABLE_SSE2)
{
    // ...
}
else if (__isa_available == __ISA_AVAILABLE_SSE2)
{
    // ...
}

The values it should hold I found in an assembly file

__ISA_AVAILABLE_X86   equ 0
__ISA_AVAILABLE_SSE2  equ 1
__ISA_AVAILABLE_SSE42 equ 2
__ISA_AVAILABLE_AVX   equ 3

How and where __isa_available is assigned a value is nowhere to be found (I've tried a find-in-files in all my directories...)

MSDN refers to the CPUID example to determine the instruction set. The problem with that is it uses __asm blocks and those are not allowed in my x64 build.

Does anyone knows how to quickly assign the correct value to __isa_available?


Solution

  • Microsoft decided to stop the support of inline assembly. But they introduced a new format. You can find more information about CPUID in the new format here (with example).

    The advantage of intrinsics over inline assembly is that they are compatible with both x86 and x64 without additional code and are easier to use.