- // Call WaitForTick for Counter + 1 ticks to try to guarantee Counter tick\r
- // periods, thus attempting to ensure Microseconds of stall time.\r
- //\r
- if (Remainder != 0) {\r
- Counter++;\r
+ if (Microseconds > 0x1999999999999999ULL) {\r
+ //\r
+ // Microseconds is too large to multiple by 10 first. Perform the divide \r
+ // operation first and loop 10 times to avoid 64-bit math overflow.\r
+ //\r
+ Counter = DivU64x32Remainder (\r
+ Microseconds,\r
+ gMetronome->TickPeriod,\r
+ &Remainder\r
+ );\r
+ for (Index = 0; Index < 10; Index++) {\r
+ CoreInternalWaitForTick (Counter);\r
+ } \r
+\r
+ if (Remainder != 0) {\r
+ //\r
+ // If Remainder was not zero, then normally, Counter would be rounded \r
+ // up by 1 tick. In this case, since a loop for 10 counts was used\r
+ // to emulate the multiply by 10 operation, Counter needs to be rounded\r
+ // up by 10 counts.\r
+ //\r
+ CoreInternalWaitForTick (10);\r
+ }\r
+ } else {\r
+ //\r
+ // Calculate the number of ticks by dividing the number of microseconds by\r
+ // the TickPeriod. Calculation is based on 100ns unit.\r
+ //\r
+ Counter = DivU64x32Remainder (\r
+ MultU64x32 (Microseconds, 10),\r
+ gMetronome->TickPeriod,\r
+ &Remainder\r
+ );\r
+ if (Remainder != 0) {\r
+ //\r
+ // If Remainder is not zero, then round Counter up by one tick.\r
+ //\r
+ Counter++;\r
+ }\r
+ CoreInternalWaitForTick (Counter);\r