calculations are only done with the lowpart of them. So the negative
values are simply the result of too big numbers.
I made a version of the code that calculates everything in 64bit.
Unfortunalety, on about every 2nd call, it returns a wrong value.
(always the same wrong value.)
Do you guys get the same? And does anybody have an idea why?
Here comes the code:
Code: Select all
Structure bit64
LowPart.l
HighPart.l
EndStructure
Procedure CPUSpeed()
DefType.bit64 ulValue, ulTicks, ulFreq, ulStart
QueryPerformanceFrequency_(ulFreq)
QueryPerformanceCounter_(ulTicks)
; ulValue = ulTicks
ulValue\LowPart = ulTicks\LowPart
ulValue\HighPart = ulTicks\HighPart
; ulValue + ulFreq
MOV eax, ulFreq\LowPart
MOV edx, ulFreq\HighPart
ADD ulValue\LowPart, eax
ADC ulValue\HighPart, edx
; ulStart = Processor Timestamp
!RDTSC
MOV ulStart\LowPart, eax
MOV ulStart\HighPart, edx
; While ulTicks <= ulValue
CPU_Loop_Start:
MOV eax, ulTicks\HighPart
CMP eax, ulValue\HighPart
JG l_CPU_Loop_End
JNE l_CPU_Loop_Run
MOV eax, ulTicks\LowPart
CMP eax, ulValue\LowPart
JG l_CPU_Loop_End
CPU_Loop_Run:
QueryPerformanceCounter_(ulTicks)
JMP l_CPU_Loop_Start
CPU_Loop_End:
; eax:edx = Processor Timestamp
; eax:edx - ulStart
!RDTSC
SUB eax, ulStart\LowPart
SBB edx, ulStart\HighPart
; lStart\LowPart = eax:edx / 1000000
MOV ebx, dword 1000000
DIV ebx
MOV ulStart\LowPart, eax
ProcedureReturn ulStart\LowPart
EndProcedure; Takes 1 second to calculate...
For i = 1 To 20
Debug CPUSpeed()
Next i