CMP Game Media Group Presents: Home
  JoinHelpContact UsShop

Newswire
Features
Connection
Job Search
Directories
By Rob Wyatt
Gamasutra
July 9, 1999
Vol. 3: Issue 27

Features
Wyatt's World

Processor Detection and a Pentium III Update

Contents

Introduction

Part 2

How do I get a textual name for the processor?

The code…

More code…

The code…

The code is implemented as a C++ class called ProcessorDetect. Within the constructor of this class, threads are created to interrogate all the processors in the machine, and the results are stored within the class. Storing the data locally enables information about any of the processors in the machine to be returned without regard to the affinity of the calling thread. All the class member functions return a bool indicating their success, and although errors could be handed by C++ exceptions, I wanted this code to be used by as many people as possible. Details of all the public class members are given below. More specific information is available within the source code comments.

The code is available as a Visual C++ project for download (CPUDetect.zip, which will be available 7/12/99). The project should build with version 6.0 of Visual C++ and with version 4.0 of the Intel compiler. I intend to keep this code as up to date as possible with new processor releases and bug fixes so keep checking back on the Gamasutra web site for the latest version.

Public Class Member 1:

bool get_processor_count
(

uint32_t& processor_count,
uint32_t& processor_avail

)

Description

Return the number of processors in the machine, as well as the number of processors available for the current process. The ID of the processor passed to all other members should be between 0 and processor_avail-1.

Parameters

processor_count is a reference to a 32-bit unsigned int that will be filled with the number of processors in the machine. On Windows 95/98 this will always be 1.

processor_avail is a reference to a 32-bit unsigned int that will be filled with the number of processors available to the current process. On Windows 95/98 this will always be 1.

Returns

False if an error occurred. Under these conditions the contents of any return values are undefined.

 

Public Class Member 2:

bool get_features
(

uint32_t processor,
uint32_t& feature_flags

)

Description

Returns the abstract features of the specified processor. The returned feature flag word is a bit set of the following:

CPU_CPUID processor supports CPUID instruction
CPU_FPUPRESENT processor as an FPU
CPU_CACHEINFO processor can give cache info
CPU_MMX MMX is present

CPU_CMOV CMOV/FCMOV/FCOMI instructions are present
CPU_APIC APIC is present (dual/multi processor)
CPU_RDTSC RDTSC and CR4 enable are supported
CPU_CMPXCHG8B CMPXCHG8B instruction is supported
CPU_DEBUG debug extensions are present
CPU_VME virtual mode extensions are present
CPU_PSE page size extensions are present
CPU_MSR Model Specific Registers are present
CPU_PAE Physical Address Extensions are present
CPU_SEP Fast System Calls are present
CPU_GPE global paging extensions are present
CPU_MCA machine check architecture is present
CPU_PAT page attribute table feature is present
CPU_MCE machine check exceptions are present
CPU_MTRR memory type range registers are present
CPU_SIMD streaming SIMD instructions are present
CPU_SIMD_ENABLE SIMD instructions are enabled with OS support
CPU_SIMD_EXCEPT SIMD exceptions are enabled with OS support
CPU_SNR processor has a serial number
CPU_PENTIUM processor will run Pentium code
CPU_PENTIUMPRO processor will run Pentium Pro code
CPU_3DNOW processor will run 3DNow code.
CPU_SIMD processor will run Streaming SIMD code

Parameters

processor is the ID number of the processor for which the information is required, must always be 0 on Windows 95/98.

feature_flags is a reference to a 32-bit unsigned int that contains the features specific to the requested processor. The features reported are listed above.

Returns

False if an error occurred or an invalid processor was passed in. Under these conditions the contents of any return values are undefined.

 

Public Class Member 3:

bool get_manufacturer

(

uint32_t processor,
ProcessorManufacturer& manufacturer

)

Description

Get the manufacturer of the specified processor if it is available.

Parameters

processor is the ID number of the processor for which the information is required. It must always be 0 on Windows 95/98.

manufacturer is a reference to a ProcessorManufacturer enum (32 bits in size) which will be filled with one of the following:

Intel 0
AMD 1
Cyrix 2
IDT 3
Unknown 0xffffffff

Processors without the CPUID instruction will return a processor type of Unknown, as will processors that are not made by one of the above manufacturers.

Returns

False if an error occurred or an invalid processor was passed in. Under these conditions the contents of any return values are undefined.

 

Public Class Member 4:

bool get_family

(

uint32_t processor,
ProcessorFamily& family

)

Description

Returns the family of the processor that is determined from the make, architecture family and stepping. If the processor has an unknown manufacturer then just the generic architecture will be returned. The manufacturer’s unknown values will be returned for future models by that manufacturer. If the processor has no CPUID and it is not a 386 or 486, then the result will be Unknown.

Parameters

processor is the ID number of the processor for which the information is required. It must always be 0 on Windows 95/98.

Family is a reference to a ProcessorFamily enum, which will be filled with one of the following:

Generic_Architecture4 4
Generic_Architecture5 5
Generic_Architecture6 6
Intel_80386 100
Intel_80486 101
Intel_Pentium 102
Intel_PentiumPro 103
Intel_PentiumII 104
Intel_PentiumIIZeon 105
Intel_PentiumIII 106
Intel_PentiumIIIZeon 107

Intel_Celeron 108
Intel_CeleronA 109
Intel_Unknown 199
AMD_AM486 200
AMD_K5 201
AMD_K6 202
AMD_K62 203
AMD_K63 204
AMD_K7 205
AMD_Unknown 299
Cyrix_686 300
Cyrix_M2 301
Cyrix_Unknown 399
IDT_WINCHIPC6 400
IDT_WINCHIP2 401
IDT_Unknown 499
Unknown 0xffffffff

 

Returns

False if an error occurred or an invalid processor was passed in. Under these conditions the contents of any return values are undefined.

 

Public Class Member 5:

bool get_clock_frequency
(

uint32_t processor,
float& mhz

)

Description

Returns the clock speed in MHz of the specified processor. This clock speed is the raw speed as measured, so it may not be the exact rated clock speed. For example, a 400MHz machine may return 400.1MHz or 399.9MHz.

Parameters

processor is the ID number of the processor for which the information is required. It must always be 0 on Windows 95/98.

mhz is a reference to a float that will be filled with the clock speed.

Returns

False if an error occurred or an invalid processor was passed in. Under these conditions the contents of any return values are undefined.


More code…
 


Home | Join | Help | Contact Us | Shop | Newswire | Site Map | Calendar
Write for Us | Features | Connection | Job Search | Directories


Copyright © 2000 CMP Media Inc. All rights reserved.
Privacy Policy