Is the following code valid to check if a CPU supports the SSE3 instruction set?
Using the IsProcessorFeaturePresent() function apparently does not work on Windows XP.
bool CheckSSE3()
{
int CPUInfo[4] = {-1};
//-- Get number of valid info ids
__cpuid(CPUInfo, 0);
int nIds = CPUInfo[0];
//-- Get info for id "1"
if (nIds >= 1)
{
__cpuid(CPUInfo, 1);
bool bSSE3NewInstructions = (CPUInfo[2] & 0x1) || false;
return bSSE3NewInstructions;
}
return false;
}
I’ve created a GitHub repro that will detect CPU and OS support for all the major x86 ISA extensions: https://github.com/Mysticial/FeatureDetector
Here’s a shorter version:
First you need to access the CPUID instruction:
Then you can run the following code:
Note that this only detects whether the CPU supports the instructions. To actually run them, you also need to have operating system support.
Specifically, operating system support is required for:
ymmregisters. See Andy Lutomirski’s answer for how to detect this.zmmand mask registers. Detecting OS support for AVX512 is the same as with AVX, but using the flag0xe6instead of0x6.