This documentation is archived and is not being maintained.

CPUID Sample: Determines CPU Capabilities

Visual Studio 2008

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 noteSecurity Note:

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

To build and run this sample

  1. Open the solution cpuid.sln.

  2. From the Build menu, click Build.

  3. From the Debug menu, select Start Without Debugging.

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:

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