Comment 2 for bug 697519

Revision history for this message
Jeff Hill (johill-lanl) wrote :

Agree that it should be

            offset = ( MAXLONGLONG - this->lastPerfCounter )
                                + ( curPerfCounter.QuadPart - MINLONGLONG ) + 1;

As it is currently written we have

offset = ( MAXLONGLONG - this->lastPerfCounter )
                                + ( curPerfCounter.QuadPart + MAXLONGLONG

#define MAXLONGLONG LL_CONSTANT(0x7fffffffffffffff)
#define MINLONGLONG LL_CONSTANT(~0x7fffffffffffffff)

and so we have currently I think an off by two ticks

for example, if this is a two's complement integer with max = 127 and min -128, but also with cur = 127 and next = -128 then we
would have

offset = (127 - cur) + (next+127) = (127 - 127) + (-128+127) = -1

The result should of course be 1 so we are off by two, negative side

The correct code is as follows

            offset = ( MAXLONGLONG - this->lastPerfCounter )
                                + ( curPerfCounter.QuadPart - MINLONGLONG ) + 1;

for example, if this is a two's complement integer with max = 127 and min -128, but also with cur = 127 and next = -128 then we
would have

offset = (127 - cur) + (next - (-128) ) = (127 - 127) + (-128 - (-128) ) + 1 = 1

This maybe hasn't been noticed, other than by Alex's sharp eyes, because it was only off by 2 ticks and the performance counter counts fast. Also, the performance counter's 64 bit integer takes typically 10 to 100 years to roll over.