CPU Identification

Source-code only - please, don't post questions here.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

CPU Identification

Postby MichaelW » Jun 14, 2006 23:04

This is translated from a MASM source that I coded recently. The MASM version reportedly has a problem with the Intel Brand String on some processors, but the code looks correct, and it works correctly on the processors that I have available.

Code: Select all

option explicit

'*********************************************************************

'' Returns a bit range value, with the value
'' shifted to place lowbit at bit position 0.
''
function brval( byval dwordval as uinteger,_
                byval highbit as uinteger,_
                byval lowbit as uinteger )_
                as uinteger
    dwordval = dwordval shl (31 - highbit)
    dwordval = dwordval shr (31 - highbit + lowbit)
    return dwordval
end function

function cpuid_eax( byval func as uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [function], eax
end function

function cpuid_ebx( byval func as uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [function], ebx
end function

function cpuid_ecx( byval func as uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [function], ecx
end function

function cpuid_edx( byval func as uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [function], edx
end function

enum cpufeatures
    CPUID = 1
    TSC:CX8:CMOV:CLFSH:FXSR:HHT
    FPU:MMX:SSE:SSE2:SSE3:TDNOW:TDNOW2
end enum

'' Returns 1 if the specified feature is supported, otherwise 0.
''
function cpufeat( feature as uinteger ) as uinteger
    select case feature
        case CPUID
            '' CPUID supported if can set/clear
            '' ID flag (EFLAGS bit 21).
            asm
                pushfd
                pop edx
                pushfd
                pop eax
                xor eax, &h200000 '' Flip ID flag
                push eax
                popfd
                pushfd
                pop eax
                xor eax, edx
                shr eax, 21
                mov [function], eax
            end asm
        case TSC
            return brval( cpuid_edx( 1 ), 4, 4 )
        case CX8
            return brval( cpuid_edx( 1 ), 8, 8 )
        case CMOV
            return brval( cpuid_edx( 1 ), 15, 15 )
        case CLFSH
            return brval( cpuid_edx( 1 ), 19, 19 )
        case FXSR
            return brval( cpuid_edx( 1 ), 24, 24 )
        case HHT
            return brval( cpuid_edx( 1 ), 28, 28 )
        case FPU
            return brval( cpuid_edx( 1 ), 0, 0 )
        case MMX
            return brval( cpuid_edx( 1 ), 23, 23 )
        case SSE
            return brval( cpuid_edx( 1 ), 25, 25 )
        case SSE2
            return brval( cpuid_edx( 1 ), 26, 26 )
        case SSE3
            return brval( cpuid_ecx( 1 ), 0, 0 )
        case TDNOW
            if cpuid_eax( &h80000000 ) > &h80000000 then
                return brval( cpuid_edx( &h80000001 ), 31, 31 )
            endif   
        case TDNOW2
            if cpuid_eax( &h80000000 ) > &h80000000 then
                return brval( cpuid_edx( &h80000001 ), 30, 30 )
            endif
    end select
end function

'*********************************************************************

#define VENDOR_OTHER 0
#define VENDOR_INTEL 1
#define VENDOR_AMD   2

dim maxCpuidInput   as uinteger  '' maximum basic function
dim signature       as uinteger  '' EAX (function 1)
dim steppingID      as uinteger  '' EAX bits 3-0 (function 1)
dim model           as uinteger  '' EAX bits 7-4 (function 1)
dim displayModel    as uinteger  '' calculated
dim family          as uinteger  '' EAX bits 11-8 (function 1)
dim displayFamily   as uinteger  '' calculated
dim extendedModel   as uinteger  '' EAX bits 19-16 (function 1)
dim extendedFamily  as uinteger  '' EAX bits 27-20 (function 1)
dim brandID         as uinteger  '' EBX bits 7-0 (function 1)
dim maxCpuidInputEx as uinteger  '' maximum extended function
dim signatureEx     as uinteger  '' EAX (function 80000001h)
dim vendor          as uinteger  '' vendor identifier

dim vendorID as zstring * 13     '' (function 0)
dim nameString as zstring * 49   '' (function 80000002h-4h, AMD)

if cpufeat( CPUID ) = 0 then
    print "CPUID not supported, press any key to exit..."
    sleep
    end
endif

maxCpuidInput = cpuid_eax( 0 )
asm
    xor eax, eax
    cpuid
    mov [vendorID], ebx
    mov [vendorID+4], edx
    mov [vendorID+8], ecx
end asm

select case vendorID
    case "GenuineIntel"
        vendor = VENDOR_INTEL
    case "AuthenticAMD"
        vendor = VENDOR_AMD
end select

if maxCpuidInput then
    signature = cpuid_eax( 1 )
    steppingID = brval( signature, 3, 0 )
    model = brval( signature, 7, 4 )
    family = brval( signature, 11, 8 )
    extendedModel  = brval( signature, 19, 16 )
    extendedFamily = brval( signature, 27, 20 )
    brandID  = brval( cpuid_ebx( 1 ), 7, 0 )
    ''
    '' For AMD only use the family and extendedFamily
    '' returned by function 80000001h, if available.
    ''
    if vendor = VENDOR_AMD then
        maxCpuidInputEx = cpuid_eax( &h80000000 )
        if maxCpuidInputEx > &h80000000 then
            family = brval( cpuid_eax( &h80000001 ), 11, 8 )
            extendedFamily = brval( cpuid_eax( &h80000001 ), 27, 20 )
        endif
    endif
endif
''
'' The AMD Processor Name String, supported starting with the
'' K5 Model 1, contains the actual processor name. The Intel
'' Processor Brand String is retrieved in the same manner as
'' the AMD Processor Name String, but instead of a processor
'' name it contains frequency and multiplier information that
'' is of no use here.
''
if vendor = VENDOR_AMD then   
    if maxCpuidInputEx > &h80000000 then
        signatureEx = cpuid_eax( &h80000001 )
        if maxCpuidInputEx > &h80000003 then
            asm
                mov eax, &h80000002
                cpuid
                mov [nameString], eax
                mov [nameString+4], ebx
                mov [nameString+8], ecx
                mov [nameString+12], edx
                mov eax, &h80000003
                cpuid
                mov [nameString+16], eax
                mov [nameString+20], ebx
                mov [nameString+24], ecx
                mov [nameString+28], edx
                mov eax, &h80000004
                cpuid
                mov [nameString+32], eax
                mov [nameString+36], ebx
                mov [nameString+40], ecx
                mov [nameString+44], edx
            end asm
        endif
    endif
endif
''
'' Use the Intel rules to calc the displayed family and model.
''
displayFamily = family
displayModel =  model
if family = &hF then displayFamily += extendedFamily
if family = 6 or family = &hF then displayModel += extendedModel
''
'' Display the family, model, and stepping in decimal instead
'' of the hex that Intel now recommends.
''
print vendorID;
print "  Family ";displayFamily;
print "  Model ";displayModel;
print "  Stepping ";steppingID
''
'' Display the detected features.
''
print "Features: ";
if cpufeat( CPUID ) then print "CPUID ";
if cpufeat( TSC ) then print "TSC ";
if cpufeat( CX8 ) then print "CX8 ";
if cpufeat( CMOV ) then print "CMOV ";
if cpufeat( CLFSH ) then print "CLFSH ";
if cpufeat( FXSR ) then print "FXSR ";
if cpufeat( HHT ) then print "HHT ";
if cpufeat( FPU ) then print "FPU ";
if cpufeat( MMX ) then print "MMX ";
if cpufeat( SSE ) then print "SSE ";
if cpufeat( SSE2 ) then print "SSE2 ";
if cpufeat( SSE3 ) then print "SSE3 ";
if cpufeat( TDNOW ) then print "3DNow ";
if cpufeat( TDNOW2 ) then print "3DNow2";
print

''
'' For Intel processors, display the Intel Brand String from
'' a table. If the brand ID is zero, display a processor
'' identification based on the family, model, and features.
''
'' The table is adapted from the IA-32 Intel Architecture
'' Software Developer’s Manual Volume 2A, 253666-015,
'' April 2005, Table 3-19.
''
if vendor = VENDOR_INTEL then
    print "Intel Brand String: ";
    select case brandID
        case 0
            print "NA";
            select case family
                case 4
                    print ", processor is 486"
                case 5
                    if cpufeat( MMX ) then
                        print ", processor is Pentium MMX"
                    else
                        print ", processor is Pentium I"
                    endif
                case 6
                    if cpufeat( SSE ) then
                        print ", processor is Pentium III"
                    elseif cpufeat( MMX ) then
                        print ", processor is Pentium II"
                    else
                        print ", processor is Pentium Pro"
                    endif
            end select
        case 1
            print "Intel(R) Celeron(R) processor"
        case 2
            print "Intel(R) Pentium(R) III processor"
        case 3
            if signature = &h6B1 then
                print "Intel(R) Celeron(R) processor"
            else
                print "Intel(R) Pentium(R) III Xeon(TM) processor"
            endif
        case 4
            print "Intel(R) Pentium(R) III processor"
        case 6
            print "Mobile Intel(R) Pentium(R) III processor-M"
        case 7
            print "Mobile Intel(R) Celeron(R) processor"
        case 8, 9
            print "Intel(R) Pentium(R) 4 processor"
        case &ha
            print "Intel(R) Celeron(R) processor"
        case &hb
            if signature = &hF13 then
                print "Intel(R) Xeon(TM) processor MP"
            else
                print "Intel(R) Xeon(TM) processor"
            endif
        case &hc
            print "Intel(R) Xeon(TM) processor MP"
        case &he
            if signature = &hF13 then
                print "Intel(R) Xeon(TM) processor"
            else
                print "Mobile Intel(R) Pentium(R) 4 processor-M"
            endif
        case &hf
            print "Mobile Intel(R) Celeron(R) processor"
        case &h13
            print "Mobile Intel(R) Celeron(R) processor"
        case &h16
            print "Intel(R) Pentium(R) M processor"
        case &h17
            print "Mobile Intel(R) Celeron(R) processor"
        case else   
            print "NA, unknown Brand ID"
    end select
endif
''
'' For AMD processors, display the name string, if available,
'' or a processor identification based on the family.
''
if vendor = VENDOR_AMD then
    print "AMD Name String: ";
    if maxCpuidInputEx > &h80000003 then
        print nameString
    else   
        if family = 4 then
            print "NA, processor is 486/5x86"
        else
            print "NA, processor is K5 Model 0"
        endif
    endif
endif

sleep
voodooattack
Posts: 605
Joined: Feb 18, 2006 13:30
Location: Alexandria / Egypt
Contact:

Postby voodooattack » Jun 16, 2006 11:55

COOL!! :D

works ok here :)

i wonder if this would work with a multi-processor system?
not without OS-Specific APIs i guess, like launching a thread on every processor perhaps?

also, is there a way to determine the speed (GHz)? ^_^
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Postby 1000101 » Jun 16, 2006 12:24

voodooattack wrote:also, is there a way to determine the speed (GHz)? ^_^


Yes, this was all done by several people months ago.

May 21, 2006: http://www.freebasic.net/forum/viewtopic.php?t=4221
May 12, 2006: http://www.freebasic.net/forum/viewtopic.php?t=3277
Sep 09, 2005: http://www.freebasic.net/forum/viewtopic.php?t=1135
Aug 27, 2005: http://www.freebasic.net/forum/viewtopic.php?t=686
voodooattack
Posts: 605
Joined: Feb 18, 2006 13:30
Location: Alexandria / Egypt
Contact:

Postby voodooattack » Jun 16, 2006 12:58

rugxulo
Posts: 181
Joined: Jun 30, 2006 5:31
Location: Usono (aka, USA)
Contact:

Postby rugxulo » Jun 30, 2006 6:17

I don't know all the gritty details of my Intel P4 by heart, but your program more or less seems to work. However, I've noticed that there are LOTS of cpu detection programs out there, and they never seem to work 100%. I suggest you test it some more (and go to http://board.flatassembler.net if you need specific assembly help).
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Jun 30, 2006 8:23

The main reasons that the identification apps are not 100% is that Intel and AMD are headed in different directions on some of the details, some of the details are not well documented, and (IMO) Intel has in the past made a mess out of some parts of it. The only way to really get it right would be to test on a very large number of different processors, and few individuals are in a position to do this.
netaces2k
Posts: 57
Joined: Jan 26, 2006 21:57
Location: USA
Contact:

More New CPUID Features

Postby netaces2k » Oct 07, 2006 19:02

I've added a whole host of new features to the program written by MichaelW. So it's swell now.

Code: Select all

'-------------
' CPUID32.BAS
'-------------

'$Dynamic
 Option Explicit
 Common Shared CPUFt$, TimeS, StartTime,

EndTime, Famly!, Famly$, Comma$
 Common Shared Stepp!, Stepp$, CModel$,

CModel!, Brand$, CPUI$, Comma!
 Common Shared CPUA$, CPUL$, CPUN$,

CPUR$, Revis!, Revis$, CNumb!, CNumb$
 Common Shared HTT
 DECLARE SUB Delay(Time)

'****************************************************

************************
' netaces2k - 07 Oct 2006: mods to ADD

additional CPUID features, and
'             further display details.  Otherwise, nice

coding job... :o)
'             See also:

http://www.paradicesoftware.com/specs/cpuid/cp

uid.htm
'             The detection system is now modified to

detect most / all of
'             the Intel(R) Pentium(R) class features

that are available.
'             See also:

http://www.sandpile.org/ia32/cpuid.htm
'             26 Oct 2006: I have added 55 new

instructions to the feature
'             detection system.  Intel's P2,P3,P4/M/D

are all onboard now (not Core2Duo yet).
'             AMD's

Duron,Athlon,AthlonXP,Sempron,Turion,Athlon6

4/X2/FX,Opteron/Opteron64.

'Features detected are: (63 In All!)
' v86, DE, PSE, TSC, MSR, PAE, MCE, CX8,

SEP, DCPL, GPE, MTRR, PGE, MCA, SYSE,

MP
' CMOV, PAT, PSE36, APIC, MON, PSN,

CLFSH, FXSR, HT, FPU, DTES, ACPI, MMX+,

ACC
' PBE, SSE4, MMX, SS, SSE, SSE2, SSE3,

3DNow, 3DNow+, AMD64, IA-64, CPUID, NX,

XD
' RDTSCP, CX16, VMX, SMX, EST, TM2, CID,

XTPR, DCA, RAZ, SVM, CMPL, AMC8, ABM
' SSE4A, maSSE, EXTas, LAHF

'Notes:
' The features, some of them, are brand specific

(Intel/AMD).  So don't be
' shocked not to see one.  Your processor may

not have it.  The program will
' NOT detect a feature that is not normally part of

your brand of CPU.
'****************************************************

************************

' This function queries the processor...
' Returns a bit range value, with the value
' shifted to place lowbit at bit position 0.
'
 Function brval( Byval dwordval As Uinteger,_
                 Byval highbit As Uinteger,_
                 Byval lowbit As Uinteger )_
                 As Uinteger
      dwordval = dwordval Shl (31 - highbit)
      dwordval = dwordval Shr (31 - highbit +

lowbit)
      Return dwordval
  Exit Function
 End Function

 Function cpuid_eax( Byval func As Uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [Function], eax
  Exit Function
 End Function

 Function cpuid_ebx( Byval func As Uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [Function], ebx
  Exit Function
 End Function

 Function cpuid_ecx( Byval func As Uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [Function], ecx
  Exit Function
 End Function

 Function cpuid_edx( Byval func As Uinteger)
    asm mov eax, [func]
    asm cpuid
    asm mov [Function], edx
  Exit Function
 End Function

' This is the list to check on, in the detection

process...
 Enum cpufeatures
  CPUID = 1
 

VME:DE:PSE:TSC:MSR:PAE:MCE:CX8:SEP:D

CPL:ACC:TM1:MP
 

GPE:SYSE:MTRR:PGE:MCA:CMOV:PAT:PSE3

6:APIC:MON:NX
 

PSN:CLFSH:FXSR:HHT:FPU:DTES:ACPI:MXx:

PBE:SSE4:XD
 

MMX:SSE:SSE2:SSNP:SSE3:TDNow:TDNow2:

X64:IA64:CX16
 

VMX:SMX:EST:TM2:CID:XTPR:DCA:RDTSCP:

RAZ:SVM:CMP
  AMC8:ABM:SSE4A:maSSE:EXTas:LAHF
 End Enum

' Returns:
' Supported = 1, NOT Supported = 0.

 Function cpufeat( feature As Uinteger ) As

Uinteger
    Select Case feature
        Case CPUID
            ' CPUID supported if can set/clear
            ' ID flag (EFLAGS bit 21).
            asm
                pushfd
                pop edx
                pushfd
                pop eax
                Xor eax, &h200000   ' Flip ID flag
                push eax
                popfd
                pushfd
                pop eax
                Xor eax, edx
                Shr eax, 21
                mov [Function], eax
            End asm
        Case FPU                                 

'Math-Coprocessor
            Return brval( cpuid_edx( 1 ), 0, 0 )
        Case VME                                 

'VirtualMachineExt-x86
            Return brval( cpuid_edx( 1 ), 1, 1 )
        Case DE                                   

'DebugModeExtension
            Return brval( cpuid_edx( 1 ), 2, 2 )
        Case PSE                                 

'PageSizeExtension
            Return brval( cpuid_edx( 1 ), 3, 3 )
        Case TSC                                 

'TimeStampCounters
            Return brval( cpuid_edx( 1 ), 4, 4 )
        Case MSR                                 

'ModelSpecificRegisters
            Return brval( cpuid_edx( 1 ), 5, 5 )
        Case PAE                                 

'PhysicalAddressExtension
            Return brval( cpuid_edx( 1 ), 6, 6 )
        Case MCE                                 

'MachineCheckException
            Return brval( cpuid_edx( 1 ), 7, 7 )
        Case CX8                                 

'CMPXCHG8B
            Return brval( cpuid_edx( 1 ), 8, 8 )
        Case GPE, APIC                            'Intel =

APIC, AMD = GPE/APIC
            Return brval( cpuid_edx( 1 ), 9, 9 )
        Case SYSE                                 

'SystemCall (Enter/Exit/Return)
            Return brval( cpuid_edx( 1 ), 11, 11 )
        Case MTRR                                 

'MemoryTypeRegisters
            Return brval( cpuid_edx( 1 ), 12, 12 )
        Case PGE                                 

'PageGlobalExtensions
            Return brval( cpuid_edx( 1 ), 13, 13 )
        Case MCA                                 

'MachineCheckArchitecture
            Return brval( cpuid_edx( 1 ), 14, 14 )
        Case CMOV                                 

'ConditionalMove
            Return brval( cpuid_edx( 1 ), 15, 15 )
        Case PAT                                 

'PageAddressTable
            Return brval( cpuid_edx( 1 ), 16, 16 )
        Case PSE36                               

'PageSizeExtensions36bit
            Return brval( cpuid_edx( 1 ), 17, 17 )
        Case PSN                                  'Intel P3

Serial Number
            Return brval( cpuid_edx( 1 ), 18, 18 )
       '    Return brval( cpuid_eax( 0 ), 3, 3 ) 

'Serial Location???
        Case CLFSH                                'CLFluSH
            Return brval( cpuid_edx( 1 ), 19, 19 )
        Case MP                                   

'Multi-Processor Capable(Intel?)
            Return brval( cpuid_eax( 1 ), 19, 19 )
        Case NX, XD                               'No

eXecute/eXecute Diasble
            If cpuid_eax( &h80000000 ) >

&h80000000 Then
               Return brval( cpuid_edx( &h80000001

), 20, 20 )
            End If
        Case DTES                                 

'DebugStore Trace MSR's
            Return brval( cpuid_edx( 1 ), 21, 21 )
        Case ACPI                                 'ACPI
            Return brval( cpuid_edx( 1 ), 22, 22 )
        Case MMX                                 

'MultiMedia-eXtensions
            Return brval( cpuid_edx( 1 ), 23, 23 )
        Case FXSR                                 

'FPFastSaveLoad
            Return brval( cpuid_edx( 1 ), 24, 24 )
        Case SSE                                  'SSE
            Return brval( cpuid_edx( 1 ), 25, 25 )
        Case SSE2                                 'SSE v2
            Return brval( cpuid_edx( 1 ), 26, 26 )
        Case SSNP                                 'Self-Snoop
            Return brval( cpuid_edx( 1 ), 27, 27 )
        Case HHT                                 

'HyperTransport/Threading
            Return brval( cpuid_edx( 1 ), 28, 28 )
        Case TM1                                 

'ThermalMonitor1
            Return brval( cpuid_edx( 1 ), 29, 29 )
        Case PBE                                 

'PendingBreakEvent
            Return brval( cpuid_edx( 1 ), 31, 31 )
        Case SSE3                                 'SSE v3
            Return brval( cpuid_ecx( 1 ), 0, 0 )
        Case LAHF                                 'AMD's

LAHF (AMD x64)
            Return brval( cpuid_ecx( 1 ), 0, 0 )
        Case CMP                                 

'CoreMuitlProcessorLegacy
            Return brval( cpuid_ecx( 1 ), 1, 1 )
        Case SVM                                 

'SecureVirtualMachine
            Return brval( cpuid_ecx( 1 ), 2, 2 )
        Case MON                                 

'Monitor/WaitSrvc
            Return brval( cpuid_ecx( 1 ), 3, 3 )
        Case EXTas                               

'ExtendedAPICSpace
            Return brval( cpuid_ecx( 1 ), 3, 3 )
        Case DCPL                                 

'QualifiedDebugStore (Intel)
            Return brval( cpuid_ecx( 1 ), 4, 4 )
        Case AMC8                                 'AltMovCr8

(AMD)
            Return brval( cpuid_ecx( 1 ), 4, 4 )
        Case VMX                                 

'VirtualMachineExtensions
            Return brval( cpuid_ecx( 1 ), 5, 5 )
        Case ABM                                 

'AdvancedBitManipulation
            Return brval( cpuid_ecx( 1 ), 5, 5 )
        Case SMX                                 

'SecurityMgmtExtensions
            Return brval( cpuid_ecx( 1 ), 6, 6 )
        Case SSE4a                                'SSE4A
            Return brval( cpuid_ecx( 1 ), 6, 6 )
        Case maSSE                               

'MisAlignedSSE
            Return brval( cpuid_ecx( 1 ), 7, 7 )
        Case EST                                 

'EnhancedSpeedStep
            Return brval( cpuid_ecx( 1 ), 7, 7 )
        Case TM2                                 

'ThermalMonitor2
            Return brval( cpuid_ecx( 1 ), 8, 8 )
        Case SSE4                                 'SSE v4
            Return brval( cpuid_ecx( 1 ), 9, 9 )
        Case CID                                  'ContextID
            Return brval( cpuid_ecx( 1 ), 10, 10 )
        Case CX16                                 

'CMPXCHG16B
            Return brval( cpuid_ecx( 1 ), 13, 13 )
        Case XTPR                                 

'SendTaskPriorityMsgs
            Return brval( cpuid_ecx( 1 ), 14, 14 )
        Case DCA                                 

'DirectCacheAccess
            Return brval( cpuid_ecx( 1 ), 18, 18 )
        Case RDTSCP                               

'RDTSCP (TSC)
            Return brval( cpuid_ecx( 1 ), 27, 27 )
        Case RAZ                                 

'ReadAsZero
            Return brval( cpuid_ecx( 1 ), 31, 31 )
        Case MXx                                  'AMD's

MMX+ w/SSE
            If cpuid_eax( &h80000000 ) >

&h80000000 Then
               Return brval( cpuid_edx( &h80000001

), 22, 22 )
            End If
        Case TDNow                                'AMD's

3DNow!
            If cpuid_eax( &h80000000 ) >

&h80000000 Then
               Return brval( cpuid_edx( &h80000001

), 31, 31 )
            End If   
        Case TDNow2                               'AMD's

3DNow! 2/Pro
            If cpuid_eax( &h80000000 ) >

&h80000000 Then
               Return brval( cpuid_edx( &h80000001

), 30, 30 )
            End If
        Case X64                                  'AMD's

x86-64
            If cpuid_eax( &h80000000 ) >

&h80000000 Then
               Return brval( cpuid_edx( &h80000001

), 29, 29 )
            End If
        Case ACC                                 

'AccessCodeControl
            If cpuid_eax( &h80000000 ) >

&h80000000 Then
               Return brval( cpuid_edx( &h80000001

), 29, 29 )
            End If
        Case IA64                                 'Intel's IA-64

(Itanium)
            If cpuid_eax( &h80000000 ) >

&h80000000 Then
               Return brval( cpuid_edx( &h80000001

), 30, 30 )
            End If
     Case Else:
    End Select
  Exit Function
 End Function

'****************************************************

************************

 #define VENDOR_OTHER 0           ' and

Unknowns
 #define VENDOR_INTEL 1
 #define VENDOR_AMD   2           ' NexGen
 #define VENDOR_CYRIX 3           ' Also

VIA/Centaur

 Dim maxCpuidInput   As Uinteger  '     

Maximum Basic Function
 Dim signature       As Uinteger  ' EAX (Function

1)
 Dim steppingID      As Uinteger  ' EAX bits 3-0

(function 1)
 Dim model           As Uinteger  ' EAX bits 7-4

(function 1)
 Dim displayModel    As Uinteger  '     Calculated
 Dim family          As Uinteger  ' EAX bits 11-8

(function 1)
 Dim cputype         As Uinteger  ' EAX bits 13-12

(function 1)
 Dim tlbcache        As Uinteger  ' EAX bit 2

(function 0)
 Dim displayFamily   As Uinteger  '     Calculated
 Dim extendedModel   As Uinteger  ' EAX bits

19-16 (function 1)
 Dim extendedFamily  As Uinteger  ' EAX bits

27-20 (function 1)
 Dim brandID         As Uinteger  ' EBX bits 7-0

(function 1)
 Dim maxCpuidInputEx As Uinteger  '     

Maximum Extended Function
 Dim signatureEx     As Uinteger  ' EAX

Extended CPU ID Info (function 80000001h)
 Dim vendor          As Uinteger  '     Vendor

Identifier
 Dim vendorID As Zstring * 13     ' BrandMarker

(function 0)
 Dim nameString As Zstring * 49   ' CPU Name

(Function 80000002h-4h, AMD)

 Print: Color 15, 0
 Print "FreeBASIC CPUID/32 þ v1.02R1 þ This

Version By netaces2k: 05 Jul 2007"
 Print "Original Version By MichaelW: 14 Jun

2006 - http://www.freebasic.net/forum/"
 Color 9, 0: Print String(75, 196): Color 7, 0

 If cpufeat( CPUID ) = 0 Then
    Beep: Color 7, 0
    GOTO Vend
    Print "The CPUID Features Are Not

Supported.  Press SPACE To Exit."
    Sleep: End
 End If

 maxCpuidInput = cpuid_eax( 0 )
 asm
    Xor eax, eax
    cpuid
    mov [vendorID], ebx
    mov [vendorID + 4], edx
    mov [vendorID + 8], ecx
 End asm

Vend: 'Jump point...
 'VendorID String, Len=12/Text
 Select Case vendorID
    Case "GenuineIntel"        '1 = International

Electronics (Intel Corp.)
        vendor = VENDOR_INTEL
    Case "AuthenticAMD"        '2 = Advanced

Micro Devices (AMD)
        vendor = VENDOR_AMD
     Case "CyrixInstead"       '3 = Cyrix (now VIA

Technologies)
        vendor = VENDOR_CYRIX
     Case Else:
        vendor = VENDOR_OTHER
 End Select
 'VendorID Strings:
 ' "GenuineIntel" - Intel Corp.
 ' "AuthenticAMD" - Advanced Micro Devices
 ' "CyrixInstead" - Cyrix(VIA)
 ' "CentaurHauls" - Centaur(VIA)
 ' "SiS SiS SiS " - Silicon Information Systems
 ' "NEC NEC NEC " - National Electronics Corp.
 ' "NexGenDriven" - NexGen(AMD)
 ' "GenuineTMx86", "TransMetaCPU" -

TransMeta
 ' "RiseRiseRise" - Rise
 ' "UMC UMC UMC " - United MicroElectronics

Corp.
 ' "Geode by NSC" - National Semiconductor

Corp.
'SELECT CASE Vendor
' CASE INTEL: Ven = "Intel":     Copy$ =

"GenuineIntel": COwn$ = "International

Electronics Corp.":    CUrl$ =

"http://www.intel.com/"
' CASE AMD:   Ven = "AMD":       Copy$ =

"AuthenticAMD": COwn$ = "Advanced Micro

Devices, Inc.":       CUrl$ =

"http://www.amd.com/"
' CASE CYRIX: Ven = "Cyrix":     Copy$ =

"CyrixInstead": COwn$ = "VIA Technologies,

Inc.":             CUrl$ = "http://www.viatech.com/"
' CASE UMC:   Ven = "UMC":       Copy$ =

"UMC UMC UMC ": COwn$ = "United

Microelectronics Corp.":      CUrl$ =

"http://www.umc.com/"
' CASE NEC:   Ven = "NEC":       Copy$ = "NEC

NEC NEC ": COwn$ = "National Electronics

Corp.":         CUrl$ = "http://www.nec.com/"
' CASE NSC:   Ven = "NSC":       Copy$ =

"Goods by NSC": COwn$ = "National

Semiconductor Corp.":       CUrl$ =

"http://www.nsc.com/"
' CASE SIS:   Ven = "SIS":       Copy$ = "SIS SIS

SIS ": COwn$ = "Silicon Information Systems":   

    CUrl$ = "http://www.sis.com/"
' CASE NXGEN: Ven = "NexGen":    Copy$ =

"NexGenDriven": COwn$ = "NexGen Software

Technologies, Inc.": CUrl$ =

"http://www.nexgen.com/"
' CASE IDT:   Ven = "VIA":       Copy$ =

"CentaurHauls": COwn$ = "VIA Technologies,

Inc.":             CUrl$ = "http://www.viatech.com/"
' CASE RISE:  Ven = "Rise":      Copy$ =

"RiseRiseRise": COwn$ = "Rise Corporation":     

              CUrl$ = "http://www.rise.com/"
' CASE TRNS:  Ven = "TransMeta": Copy$ =

"GenuineTMx86": COwn$ = "TransMeta

Corporation":              CUrl$ =

"http://www.transmeta.com/"
' CASE ELSE:  Ven = "VendorCode = " +

LTRIM$(STR$(Vendor))
'END SELECT

 If maxCpuidInput Then
    signature      =  cpuid_eax( 1 )
    steppingID     = brval( signature, 3, 0 )
    model          = brval( signature, 7, 4 )
    family         = brval( signature, 11, 8 )
    cputype        = brval( cpuid_eax( 1 ), 13, 12 )
    extendedModel  = brval( signature, 19, 16 )
    extendedFamily = brval( signature, 27, 20 )
    brandID        = brval( cpuid_ebx( 1 ), 7, 0 )
    tlbcache       = brval( cpuid_eax( 2 ), 0, 0 )

 ' For AMD only use the family and

extendedFamily
 ' returned by function 80000001h, if available.

    If vendor = VENDOR_AMD Then
        maxCpuidInputEx = cpuid_eax(

&h80000000 )
        If maxCpuidInputEx > &h80000000 Then
            family = brval( cpuid_eax( &h80000001

), 11, 8 )
            extendedFamily = brval( cpuid_eax(

&h80000001 ), 27, 20 )
        End If
    End If
 End If

' AMD processor name string, supported starting

with the AMD
' K5 Model 1, contains the actual processor

name.
' Intel processor brand string is retrieved in the

same manner
' as the AMD Processor Name String, but

instead of a processor
' name it contains frequency and multiplier

information that
' is of no use here.

 If vendor = VENDOR_AMD Then   
    If maxCpuidInputEx > &h80000000 Then
        signatureEx = cpuid_eax( &h80000001 )
        If maxCpuidInputEx > &h80000003 Then
            asm
                mov eax, &h80000002
                cpuid
                mov [nameString], eax
                mov [nameString+4], ebx
                mov [nameString+8], ecx
                mov [nameString+12], edx
                mov eax, &h80000003
                cpuid
                mov [nameString+16], eax
                mov [nameString+20], ebx
                mov [nameString+24], ecx
                mov [nameString+28], edx
                mov eax, &h80000004
                cpuid
                mov [nameString+32], eax
                mov [nameString+36], ebx
                mov [nameString+40], ecx
                mov [nameString+44], edx
            End asm
        End If
    End If
 End If

' Use the Intel rules to calc the displayed family

and model.

 displayFamily = family
 displayModel =  model
 If family = &hF Then displayFamily +=

extendedFamily
 If family = 6 Or family = &hF Then displayModel

+= extendedModel

' Display the family, model, and stepping in

decimal instead
' of the hex that Intel now recommends.

 Color 7, 0:  Print "CPU Vendor: ";
 Color 15, 0: Print vendorID  ';

String$(2,32);"(";ltrim$(Str$(vendor)); ")"
 Gosub Intel: Gosub AMD
 Print
 Color 7, 0:  Print String$(4,32);"Family: ";
 Color 15, 0: Print displayFamily  ';

String$(2,32);"(";ltrim$(Str$(family)); ")"
 Color 7, 0:  Print String(5,32);"Model: ";
 Color 15, 0: Print displayModel  ';

String$(2,32);"(";ltrim$(Str$(model)); ")"
 Color 7, 0:  Print String$(2,32);"Stepping: ";
 Color 15, 0: Print steppingID
 Color 7, 0:  Print String$(3,32);"CPU Key: ";
 Color 15, 0: Print "000"; Hex$(signature)
'Color 7, 0:  Print String$(2,32);"CPU Type: ";
'Color 15, 0: Print Hex$(cputype)
'Color 7, 0:  Print String$(2,32);"CPUCache: ";
'Color 15, 0: Print Hex$(tlbcache)
 Print
 If cpufeat( CPUID ) = 0 Then GOTO Finish

'Display the detected features.

'Shoe Ext. CPUID Data...  (From Win2k/XP

ENVIRON set...)
 GOSUB Envir
 Print

 Color 7, 0:  Print String$(2,32);"Features: ";
'General List of Features (Usually supported)...
 If cpufeat( CPUID ) Then CPUFt$ = CPUFt$ +

"CPUID "
 If cpufeat( FPU ) Then CPUFt$ = CPUFt$ +

"FPU "
 If cpufeat( VME ) Then CPUFt$ = CPUFt$ +

"v86 "
 If cpufeat( DE )  Then CPUFt$ = CPUFt$ + "DE

"
 If cpufeat( PSE ) Then CPUFt$ = CPUFt$ +

"PSE "
 If cpufeat( TSC ) Then CPUFt$ = CPUFt$ +

"TSC "
 If cpufeat( MSR ) Then CPUFt$ = CPUFt$ +

"MSR "
 If cpufeat( PAE ) Then CPUFt$ = CPUFt$ +

"PAE "
 If cpufeat( MCE ) Then CPUFt$ = CPUFt$ +

"MCE "
 If cpufeat( CX8 ) Then CPUFt$ = CPUFt$ +

"CX8 "
 If cpufeat( GPE ) Then CPUFt$ = CPUFt$ +

"GPE "
 If cpufeat( APIC ) Then CPUFt$ = CPUFt$ +

"APIC "
 If cpufeat( SYSE ) Then CPUFt$ = CPUFt$ +

"SYSE "
 If cpufeat( MTRR ) Then CPUFt$ = CPUFt$ +

"MTRR "
 If cpufeat( PGE ) Then CPUFt$ = CPUFt$ +

"PGE "
 If cpufeat( MCA ) Then CPUFt$ = CPUFt$ +

"MCA "
 If cpufeat( CMOV ) Then CPUFt$ = CPUFt$ +

"CMOV "
 If cpufeat( PAT ) Then CPUFt$ = CPUFt$ +

"PAT "
 If cpufeat( PSE36 ) Then CPUFt$ = CPUFt$ +

"PSE36 "
 If cpufeat( CLFSH ) Then CPUFt$ = CPUFt$ +

"CLFSH "
 If cpufeat( FXSR ) Then CPUFt$ = CPUFt$ +

"FXSR "
 If cpufeat( HHT ) Then CPUFt$ = CPUFt$ +

"HTT "
 If cpufeat( MP )  Then CPUFt$ = CPUFt$ + "MP

"
 If cpufeat( ACPI ) Then CPUFt$ = CPUFt$ +

"ACPI "
 If cpufeat( MMX ) Then CPUFt$ = CPUFt$ +

"MMX "
 If cpufeat( SSE ) Then CPUFt$ = CPUFt$ +

"SSE "
 If cpufeat( SSE2 ) Then CPUFt$ = CPUFt$ +

"SSE2 "
 If cpufeat( SSE3 ) Then CPUFt$ = CPUFt$ +

"SSE3 "
 If cpufeat( TDNow ) Then CPUFt$ = CPUFt$ +

"3DNow "
 If cpufeat( TDNow2 ) Then CPUFt$ = CPUFt$ +

"3DNow+ "

'AMD(tm) Specific...
 If cpufeat( RDTSCP ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "RTSC "
 If cpufeat( SVM ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "SVM "
 If cpufeat( CMP ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "CMPL "
 If cpufeat( RAZ ) AND vendor = 2 Then CPUFt$

= CPUFt$ + "RAZ "
 If cpufeat( NX ) AND vendor = 2 Then CPUFt$

= CPUFt$ + "NX "
 If cpufeat( CX16 ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "CX16 "
 If cpufeat( MXx ) AND vendor = 2 Then CPUFt$

= CPUFt$ + "MMX+ "
 If cpufeat( X64 ) AND vendor = 2 Then CPUFt$

= CPUFt$ + "AA-64 "
 IF cpufeat( AMC8 ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "AMC8 "
 IF cpufeat( ABM ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "ABM "
 IF cpufeat( maSSE ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "MASSE "
 IF cpufeat( EXTas ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "EXTAS "
 IF cpufeat( LAHF ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "LAHF "
 IF cpufeat( SSE4a ) AND vendor = 2 Then

CPUFt$ = CPUFt$ + "SSE4A "

'Intel(R) Specific...
 If cpufeat( PSN ) AND vendor = 1 Then CPUFt$

= CPUFt$ + "PSN "
 If cpufeat( DTES ) AND vendor = 1 Then

CPUFt$ = CPUFt$ + "DTES "
 If cpufeat( SSNP ) AND vendor = 1 Then

CPUFt$ = CPUFt$ + "SS "
 If cpufeat( SSE4 ) AND vendor = 1 Then

CPUFt$ = CPUFt$ + "SSE4 "
 If cpufeat( CX16 ) AND vendor = 1 Then

CPUFt$ = CPUFt$ + "CX16 "
 If cpufeat( ACC ) And vendor = 1 Then CPUFt$

= CPUFt$ + "ACC "
 If cpufeat( TM1 ) And vendor = 1 Then CPUFt$

= CPUFt$ + "TM1 "
 If cpufeat( TM2 ) And vendor = 1 Then CPUFt$

= CPUFt$ + "TM2 "
 If cpufeat( EST ) And vendor = 1 Then CPUFt$

= CPUFt$ + "EST "
 If cpufeat( DCA ) And vendor = 1 Then CPUFt$

= CPUFt$ + "DCA "
 If cpufeat( VMX ) And vendor = 1 Then CPUFt$

= CPUFt$ + "VMX "
 If cpufeat( SMX ) And vendor = 1 Then CPUFt$

= CPUFt$ + "SMX "
 If cpufeat( XTPR ) And vendor = 1 Then

CPUFt$ = CPUFt$ + "XTPR "
 If cpufeat( CID ) And vendor = 1 Then CPUFt$

= CPUFt$ + "CID "
 If cpufeat( IA64 ) And vendor = 1 Then CPUFt$

= CPUFt$ + "IA-64 "
 If cpufeat( DCPL ) And vendor = 1 Then

CPUFt$ = CPUFt$ + "DSCPL "
 If cpufeat( PBE ) And vendor = 1 Then CPUFt$

= CPUFt$ + "PBE "
 If cpufeat( MON ) And vendor = 1 Then CPUFt$

= CPUFt$ + "MON "
 If cpufeat( XD ) AND vendor = 1 Then CPUFt$

= CPUFt$ + "XD "

 Color 15, 0: Print Mid$(CPUFt$, 1, 68);
 Color 15, 0: Print tab(13);

LTRIM$(Mid$(CPUFt$, 69, 68));
 Color 15, 0: Print tab(13);

LTRIM$(Mid$(CPUFt$, 137, 68));
 Color 15, 0: Print tab(13);

LTRIM$(Mid$(CPUFt$, 205, 68));
 Print

Quit: 'Exit the program...
 Sleep: Color 7, 0: End

Finish: 'Final lookups & displays...
' For Intel processors, display the Intel Brand

String from
' a table. If the brand ID is zero, display a

processor
' identification based on the family, model, and

features.

' The table is adapted from the IA-32 Intel

Architecture
' Software Developer’s Manual Volume 2A,

253666-015,
' April 2005, Table 3-19.

Intel: 'International Electronics...
 If vendor = VENDOR_INTEL Then
    Color 7, 0:  Print String$(2, 32); "CPU Name:

";
    Color 15, 0:
    Select Case brandID
        Case 0
            Print "NA";
            Select Case family
                Case 4
                    Print "Intel(R) i486"
                Case 5
                    If cpufeat( MMX ) Then
                        Print "Intel(R) Pentium(R) MMX"
                    Else
                        Print "Intel(R) Pentium(R)

(Classic)"
                    End If
                Case 6
                    If cpufeat( SSE ) Then
                        Print "Intel(R) Pentium(R) III"
                    Elseif cpufeat( MMX ) Then
                        Print "Intel(R) Pentium(R) II"
                    Else
                        Print "Intel(R) Pentium(R) Pro"
                    End If
             Case Else:
            End Select
        Case 1
            Print "Intel(R) Celeron(R) Processor"
        Case 2
            Print "Intel(R) Pentium(R) III Processor"
        Case 3
            If signature = &h6B1 Then
                Print "Intel(R) Celeron(R) Processor"
            Else
                Print "Intel(R) Pentium(R) III Xeon(TM)

Processor"
            End If
        Case 4
            Print "Intel(R) Pentium(R) III Processor"
        Case 6
            Print "Mobile Intel(R) Pentium(R) III

Processor-M"
        Case 7
            Print "Mobile Intel(R) Celeron(R)

Processor"
        Case 8, 9
            Print "Intel(R) Pentium(R) 4 Processor"
        Case &ha
            Print "Intel(R) Celeron(R) Processor"
        Case &hb
            If signature = &hF13 Then
                Print "Intel(R) Xeon(TM) Processor

MP"
            Else
                Print "Intel(R) Xeon(TM) Processor"
            End If
        Case &hc
            Print "Intel(R) Xeon(TM) Processor MP"
        Case &he
            If signature = &hF13 Then
                Print "Intel(R) Xeon(TM) Processor"
            Else
                Print "Mobile Intel(R) Pentium(R) 4-M

Processor"
            End If
        Case &hf
            Print "Mobile Intel(R) Celeron(R)

Processor"
        Case &h13
            Print "Mobile Intel(R) Celeron(R)

Processor"
        Case &h14  '6.14.8 (6F2, 6F6)
            Print "Mobile Intel(R) Core2Duo(R)

Processor"
        Case &h16
            Print "Intel(R) Pentium(R) M Processor"
        Case &h17
            Print "Mobile Intel(R) Celeron(R)

Processor"
        Case Else   
            Print "Unknown/New CPUID: "; Family;

"."; Model; "."; steppingID; ":"; signature
    End Select
 Else
 End If
RETURN

AMD: 'Advanced Micro Devices...
' For AMD processors, display the name string, if

available,
' or a processor identification based on the

family.

 If vendor = VENDOR_AMD Then
    Color 7, 0:  Print String$(2, 32); "CPU Name:

";
    Color 15, 0:
    If maxCpuidInputEx > &h80000003 Then
        Print nameString
    Else
        If family = 4 Then
            Print "Am486/Am 5x86 (X5)"
        Elseif family = 5 Then
            Print "K5 Family"
        Elseif family = 6 Then
            Print "K6 Family"
        Else
            Print "Unknown/New CPUID: ";

displayFamily; "."; displayModel; "."; steppingID;

":"; signature
        End If
    End If
 Else
 End If
RETURN

Envir: 'Get the ENVIRON$ variables...
 IF ENVIRON$("OS") = "Windows_NT" THEN
  CPUN$ =

ENVIRON$("NUMBER_OF_PROCESSORS")
  CPUA$ =

ENVIRON$("PROCESSOR_ARCHITECTURE")
  CPUL$ =

ENVIRON$("PROCESSOR_LEVEL")
  CPUR$ =

ENVIRON$("PROCESSOR_REVISION")
  CPUI$ =

ENVIRON$("PROCESSOR_IDENTIFIER")
 ELSE
 END IF
 GOSUB Finder
RETURN

Finder: 'Find the information...
 Famly! = INSTR(1, CPUI$, "Family") + 7
 CModel! = INSTR(1, CPUI$, "Model") + 6
 Stepp! = INSTR(1, CPUI$, "Stepping") + 9
 Comma! = INSTR(1, CPUI$, CHR$(44)) + 2
 Revis! = INSTR(1, CPUR$, CHR$(61)) + 1
 CNumb! = INSTR(1, CPUN$, CHR$(61)) + 1
 Famly$ = MID$(CPUI$, Famly!, 2)
 CModel$ = MID$(CPUI$, CModel!, 2)
 Stepp$ = MID$(CPUI$, Stepp!, 1)
 Brand$ = MID$(CPUI$, Comma!, 12)
 Revis$ = UCASE$(RTRIM$(MID$(CPUR$,

Revis!, 6)))
 CNumb$ = UCASE$(RTRIM$(MID$(CPUN$,

CNumb!, 2)))

 GOSUB ExtCPUID
RETURN

ExtCPUID: 'Show Extended CPUID

Information...
 COLOR 7, 0:  PRINT string$(4, 32); "Family: ";
 COLOR 15, 0: PRINT Famly$
 COLOR 7, 0:  PRINT string$(5, 32); "Model: ";
 COLOR 15, 0: PRINT CModel$
 COLOR 7, 0:  PRINT string$(2, 32); "Stepping:

";
 COLOR 15, 0: PRINT Stepp$
 COLOR 7, 0:  PRINT string$(4, 32); "# CPUs: ";
 COLOR 15, 0: PRINT CNumb$
 COLOR 7, 0:  PRINT string$(4, 32); "RevKey: ";
 COLOR 15, 0: PRINT Revis$
'COLOR 7, 0:  PRINT string$(4, 32); "Vendor: ";
'COLOR 15, 0: PRINT Brand$
RETURN

SUB Delay(TimeS)
  StartTime = TIMER
  EndTime = (TIMER + TimeS)
  IF EndTime > 86400 THEN EndTime =

(EndTime - 86400)
  DO: LOOP UNTIL TIMER > EndTime
 EXIT SUB
END SUB


Sample Screen Shot:
FreeBASIC CPUID/32 ■ v1.02R1 ■ This Version By netaces2k: 05 Jul 2007
Original Version By MichaelW: 14 Jun 2006 - http://www.freebasic.net/forum/
───────────────────────────────────────────────────────────────────────────
CPU Vendor: AuthenticAMD
CPU Name: AMD Athlon(tm) 64 X2 Dual Core Processor 3800+

Family: 15
Model: 13
Stepping: 1
CPU Key: 00020FB1

Family: 15
Model: 43
Stepping: 1
# CPUs: 2
RevKey: 2B01

Features: CPUID FPU v86 DE PSE TSC MSR PAE MCE CX8 GPE APIC SYSE MTRR PGE MCA
CMOV PAT PSE36 CLFSH FXSR HTT MMX SSE SSE2 SSE3 3DNow 3DNow+ NX MMX+
AA-64 LAHF


The program is able to detect many CPU features. Including IA-64, AMD x64 and others as well.

EDIT: The program has been patched to reveal the CPUID data, whether or not if finds the CPUID feature data.
setiajie
Posts: 23
Joined: Jan 27, 2010 13:30

it's works ...

Postby setiajie » Feb 01, 2010 13:25

[setiajie@localhost FreeBasic_Projects]$ fbc cpuident.bas -lang fblite
/opt/freebasic/fbc: Symbol `ospeed' has different size in shared object, consider re-linking
[setiajie@localhost FreeBasic_Projects]$ ./cpuident
GenuineIntel Family 15 Model 4 Stepping 9
Features: CPUID TSC CX8 CMOV CLFSH FXSR HHT FPU MMX SSE SSE2 SSE3
Intel Brand String: NA
[setiajie@localhost FreeBasic_Projects]$
dodicat
Posts: 4473
Joined: Jan 10, 2006 20:30
Location: Scotland

Postby dodicat » Feb 01, 2010 14:01

voodooattack wrote:COOL!! :D

works ok here :)

i wonder if this would work with a multi-processor system?
not without OS-Specific APIs i guess, like launching a thread on every processor perhaps?

also, is there a way to determine the speed (GHz)? ^_^

Hi
I've got two, no, it just gives one.
Speed?, sorry I'm still in Mhz.
Here's a quick speed getter (in Mhz.)

Code: Select all

#include "windows.bi"
Function cpu() As Integer
    Dim As LARGE_INTEGER    Q1, Q2, Hz
    QueryPerformanceCounter( @Q1 )
    Dim As Double   T = Timer + 1.0
    While Timer < T : Wend
    QueryPerformanceCounter( @Q2 )
    Hz.QuadPart = Q2.QuadPart - Q1.QuadPart
    Return Cint(Hz.QuadPart/1000000)
End Function
print cpu;" Mhz."
sleep
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Feb 01, 2010 14:24

Try using SetProcessAffinityMask to control which processor the app runs on. You can get a workable handle for the process with GetCurrentProcess.

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 0 guests