Hello there,

I have tried two computers I have access to (both AMD64 single cores (one 3000/3200) and with both I get negative values from QueryPerformanceCounter.

Maybe I'm doing something wrong or maybe it's a MS bug. Attached is a dialog doing the following when hitting the button:


.data
ALIGN 8
QPF QWORD 0
QPC QWORD 0
.code
invoke QueryPerformanceFrequency,offset QPF
invoke QueryPerformanceCounter,offset QPC
mov eax, dword ptr
PrintDec eax, "QueryPerformanceFrequency"
mov eax, dword ptr
PrintDec eax, "QueryPerformanceCounter"


If you hit the button more than once - one can actually see that the QPC is counting upwards from whatever negative amount there is.

I surfed the net for quite awhile and I did see some issues relating to negative numbers but these issues are mostly (from what I understand) related to dual core CPUs.

Could someone run this app and try it for themselves? Or maybe I'm just using the values wrong?

Here are some of my results:
eax = 3579545, QueryPerformanceFrequency (QPF.asm, 72)
eax = -53794507, QueryPerformanceCounter (QPF.asm, 74)
eax = -44768916, QueryPerformanceCounter (QPF.asm, 74)
eax = -30254733, QueryPerformanceCounter (QPF.asm, 74)
eax = -25128629, QueryPerformanceCounter (QPF.asm, 74)
eax = -20861691, QueryPerformanceCounter (QPF.asm, 74)
eax = -17024308, QueryPerformanceCounter (QPF.asm, 74)
eax = -10036786, QueryPerformanceCounter (QPF.asm, 74)
eax = -6485756, QueryPerformanceCounter (QPF.asm, 74)
eax = -3249768, QueryPerformanceCounter (QPF.asm, 74)
eax = -70993, QueryPerformanceCounter (QPF.asm, 74)
eax = 2907010, QueryPerformanceCounter (QPF.asm, 74)
eax = 5890470, QueryPerformanceCounter (QPF.asm, 74)
eax = 8806447, QueryPerformanceCounter (QPF.asm, 74)
eax = 11670265, QueryPerformanceCounter (QPF.asm, 74)
eax = 14619918, QueryPerformanceCounter (QPF.asm, 74)
Attachments:
Posted on 2006-08-18 12:14:31 by JimmyClif
something obvious here is that you print lower DWord of a QWord with PrintDec
which prints decimal (Signed DWord), but lower dword can be in range 0-0FFFFFFFFh (meaning it can be signed if you look at it separately)
i suggest you use printf from libc/msvcrt ("%I64u" format), or print it in hex as two dwords "%.8X%.8X" with wsprintf
Posted on 2006-08-18 12:46:47 by drizz
Hi
The returned values are qwords (not dwords). To correctly evaluate the result you have to apply qword arithmentic or use the FPU with a code similar to this:

    mov dMultiplicator, 1000
    fild .qTicks
    fild .qFrequency
    fdivp st(1), st(0)
    fimul dMultiplicator
    fistp qword ptr qTime

Regards,

Biterider
Posted on 2006-08-18 12:59:29 by Biterider
Oh, thank you. After converting it to "%.8X%.8X" with wsprintf it does make a little more sense. It in fact counts upwards at all times. Seems like I'm a tard :-/

Thank you both for the help.

Biterider, what excatly is (Ticks/Freq)*1000 = qTime in your snippet ? In case it's just a made up sample forget it, but it appears like it's actually doing something real :)
Posted on 2006-08-18 13:13:19 by JimmyClif
It is an snipet of the StopWatch.GetTime method. It is used to convert the tick count to a ms value.
If you want to take a look at the full source code, I attached the object.

Biterider
Attachments:
Posted on 2006-08-18 23:34:22 by Biterider