CPUID Sample: Determines CPU Capabilities
The CPUID sample provides a routine that uses the CPUID instruction to determine the capabilities of the CPU being run.
The sample provides the function int _cpuid(_p_info *pinfo), which returns data about the CPU. The int return value is a bitmask of flags for major processor features. The bits that might be set are:
#define _CPU_FEATURE_MMX 0x0001
#define _CPU_FEATURE_SSE 0x0002
#define _CPU_FEATURE_SSE2 0x0004
#define _CPU_FEATURE_3DNOW 0x0008
Security Note |
|---|
|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To get samples and instructions for installing them:
To access samples from Visual Studio
-
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
The sample includes a test.cpp file that trivially calls _cpuid and outputs the values in the resulting _p_info struct. For example, on a Pentium III computer that supports MMX and SSE, the program output would look something like this:
C:\work\cpuid>test
v_name: GenuineIntel
model: INTEL Pentium-III
family: 6
model: 8
stepping: 3
feature: 00000003
yes _CPU_FEATURE_MMX
yes _CPU_FEATURE_SSE
no _CPU_FEATURE_SSE2
no _CPU_FEATURE_3DNOW
os_support: 00000003
yes _CPU_FEATURE_MMX
yes _CPU_FEATURE_SSE
no _CPU_FEATURE_SSE2
no _CPU_FEATURE_3DNOW
checks: 0000000f
Security Note