Is the following code sufficient to verify if a CPU supports the SSE3 instruction set?
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; }
Unfortunately, the provided code snippet has a limitation on Windows XP. To overcome this and ensure accurate detection of SSE3 support across a wider range of systems, a more comprehensive solution is recommended.
Below is an approach that provides reliable SSE3 detection on both Windows XP and other operating systems:
// Access CPUID instruction #ifdef _WIN32 #define cpuid(info, x) __cpuidex(info, x, 0) #else #include <cpuid.h> void cpuid(int info[4], int InfoType){ __cpuid_count(InfoType, 0, info[0], info[1], info[2], info[3]); } #endif // Detect SSE3 support bool HW_SSE3; int info[4]; cpuid(info, 0); int nIds = info[0]; if (nIds >= 0x00000001){ cpuid(info,0x00000001); HW_SSE3 = (info[2] & ((int)1 << 0)) != 0; }
The above is the detailed content of Is the Provided Code Sufficient for Checking SSE3 Support on CPUs?. For more information, please follow other related articles on the PHP Chinese website!