' CPU_ID.Bas - by Volta 01.07.2008
' bug fix 06.07.2008 (is_intel corcount)
#Include Once "windows.bi"
#Define ext " Extensions"
#Define sim " Streaming SIMD" + ext
#Define cr Chr(10)
#Define inst " instructions"
#Define ins inst + cr
#Define Yes =1
#Define insu " instruction support" + cr
#Define amde " AMD extensions to"
#Define No =0
Type CPU_ID
As UInteger hat_CPUID No
Private:
As String*13 Vendor="no CPUID "+Chr(0)
As String*48 CPU_typ="no brand"
As UByte is_amd, is_intel
As UByte family, model, Stepping
As UByte hat_mmx, hat_sse, hat_sse2, hat_sse3, hat_HTT, hat_cor
As UByte Intel64, hat_ssse3, hat_SSE41, hat_SSE42, hat_vmx
As UByte hat_mmxe, hat_3dNow, hat_3dNowe, AMD64, hat_SSE4A
As UByte hat_SSE5, AMD_CmpLegacy
Public:
Declare Constructor
Declare Function WinInfo As String
Private:
Declare Function Stand_Feature () As Integer
Declare Function cpuvendor () As Integer
Declare Function brand () As String
Declare Function Intel (As Integer) As Integer
Declare Function AMD () As Integer
End Type
Constructor CPU_ID
Dim As UInteger erg = fb_CpuDetect
If (erg And &h0fffffff) >0 Then
hat_CPUID Yes
'Processor Standard Feature Bits
'können ab FB 0.20.0 auch hier bestimmt werden
'If erg And &h00800000 Then hat_mmx Yes'Bit 23
'If erg And &h02000000 Then hat_sse Yes'Bit 25
'If erg And &h04000000 Then hat_sse2 Yes'Bit 26
erg = cpuvendor
If InStr(Vendor, "AMD") Then is_amd Yes
If InStr(Vendor, "Intel") Then is_intel Yes
If erg > 0 Then Stand_Feature
If is_intel Then Intel(erg)
If is_amd Then AMD
Else
family = (erg Shr 28)
EndIf
End Constructor
Function CPU_ID.Stand_Feature () As Integer
Dim As UInteger tmp, tmp1, tmp2
Asm
mov eax, 1
cpuid
mov [tmp],eax
mov [tmp1],edx
mov [tmp2],ecx
End Asm
Stepping = (tmp And &h0F)
model = ((tmp Shr 4) And &h0F)
family = ((tmp Shr 8) And &h0F)
'Processor Standard Feature Bits
If tmp1 And &h00800000 Then hat_mmx Yes 'Bit 23
If tmp1 And &h02000000 Then hat_sse Yes 'Bit 25
If tmp1 And &h04000000 Then hat_sse2 Yes 'Bit 26
If tmp1 And &h10000000 Then hat_HTT Yes 'Bit 28
If tmp2 And &h00000001 Then hat_sse3 Yes 'Bit 0
If tmp2 And &H00080000 Then hat_SSE41 Yes 'Bit 19
Function=tmp1
End Function
Function CPU_ID.cpuvendor () As Integer
Dim ven As Any Ptr = @Vendor
Asm
mov eax, 0
cpuid
mov [Function], eax
mov eax,[ven]
mov [eax], ebx 'vendor String 12 Byte
mov [eax+4], edx
mov [eax+8], ecx
End Asm
End Function
Function CPU_ID.brand () As String
Dim As String*48 Proztyp = String(48," ")
Asm
mov eax, &H80000002 'Brand String 48Byte
cpuid
cmp eax, 0 'wenn eax=00 kein String
jz noo_brand
mov [Proztyp], eax
mov [Proztyp+4], ebx
mov [Proztyp+8], ecx
mov [Proztyp+12], edx
mov eax, &H80000003
cpuid
mov [Proztyp+16], eax
mov [Proztyp+20], ebx
mov [Proztyp+24], ecx
mov [Proztyp+28], edx
mov eax, &H80000004
cpuid
mov [Proztyp+32], eax
mov [Proztyp+36], ebx
mov [Proztyp+40], ecx
mov [Proztyp+44], edx
noo_brand:
End Asm
Function = Trim(Proztyp)
End Function
Function CPU_ID.Intel (erg As Integer) As Integer
Dim As UInteger tmp, tmp1, tmp2
Asm
mov eax, 1
cpuid
mov [tmp],ecx
Shr ebx, 16
And ebx, &h0ff
mov [tmp2],ebx' LogicalProcessorCount
End Asm
If tmp And &H00000020 Then hat_vmx Yes 'Bit 5
If tmp And &H00000200 Then hat_ssse3 Yes 'Bit 9
If tmp And &H00100000 Then hat_SSE42 Yes 'Bit 20
If tmp2 > 1 Then 'IF LogicalProcessorCount
If hat_HTT Then
If erg >= 4 Then 'CPUID(0).EAX >= 4
Asm
mov eax, 4
mov ecx, 0
cpuid
Shr eax, 26
And eax, &h3F
Inc eax
mov [tmp],eax ' corcount
End Asm
If tmp2\tmp <2 Then hat_HTT No
If tmp > 1 Then hat_cor = tmp
EndIf
EndIf
Else
hat_HTT No
EndIf
'Test auf extended functions
Asm
mov eax,&h80000000
cpuid
And eax, &h0fffffff
mov [tmp], eax
End Asm
If tmp > 0 Then
Asm
mov eax,&h80000001
cpuid
mov [tmp1],edx
End Asm
If tmp1 And &h20000000 Then Intel64 Yes 'Bit 29
End If
If tmp > 3 Then CPU_typ= brand
Function=tmp1
End Function
Function CPU_ID.AMD () As Integer
Dim As UInteger erg, tmp, tmp1
Dim As Byte mnc
Asm
mov eax, &h80000000
cpuid
And eax, &h0fffffff
mov [erg], eax
End Asm
'Test auf extended functions
If erg > 0 Then
Asm
mov eax,&h80000001
cpuid
mov [tmp],edx
mov [tmp1],ecx
End Asm
If tmp And &h00400000 Then hat_mmxe Yes 'Bit 22
If tmp And &h80000000 Then hat_3dNow Yes 'Bit 31
If tmp And &h40000000 Then hat_3dNowe Yes 'Bit 30
If tmp And &h20000000 Then AMD64 Yes 'Bit 29
If tmp1 And &h00000002 Then AMD_CmpLegacy Yes 'Bit 1
If tmp1 And &h00000040 Then hat_SSE4A Yes 'Bit 6
If tmp1 And &h00000800 Then hat_SSE5 Yes 'Bit 11
End If
If erg > 3 Then CPU_typ= brand
If hat_HTT And (erg >=8) Then
Asm
mov eax,&h80000008
cpuid
mov [mnc], cl
Shr ecx,12
And ecx,15
mov [tmp],ecx
End Asm
If tmp=0 Then
hat_cor=mnc+1
Else
hat_cor=(1 Shl tmp)
EndIf
End If
Function=erg
End Function
Function CPU_ID.WinInfo ()As String
Dim As String aus
If hat_CPUID Then aus = "CPU typ : " & CPU_typ & cr
aus += "Vendor : " + Vendor + cr
aus += "family : " & family & cr
If hat_CPUID Then
aus += "model : " & model & cr
aus += "stepping : " & Stepping & cr
If hat_cor Then aus += "cores : " & hat_cor & cr
If hat_mmx Then aus += " MMX" + ins
If hat_mmxe Then aus += amde + " MMX" + ins
If hat_3dNow Then aus += " 3DNow!" + ins
If hat_3dNowe Then aus += amde + " 3DNow!" + ins
If hat_sse Then aus += " SSE" + ins
If hat_sse2 Then aus += " SSE2" + ins
If hat_sse3 Then aus += " SSE3" + ins
If hat_vmx Then aus += " VMX Virtual Machine" + ext + cr
If hat_ssse3 Then aus += " SSSE3 Supplemental" + sim +" 3" + cr
If Intel64 Then aus += " Intel 64 Instruction Set Architecture" + cr
If AMD64 Then aus += " AMD64 Long Mode" + cr
If hat_SSE4A Then aus += " SSE4A" + insu
If hat_sse41 Then aus += " SSE4.1" + sim +" 4.1" + cr
If hat_sse42 Then aus += " SSE4.2" + sim +" 4.2" + cr
If hat_sse5 Then aus += " SSE5" + insu
If hat_HTT Then aus += " Hyper-Threading Technology" + cr
End If
Function=aus
End Function
Dim cpu As CPU_ID
MessageBox (0, cpu.WinInfo, "CPU_ID", MB_OK))
|
|