-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
precise_time_ns
can overflow on Windows
#17845
Comments
As a datapoint, this is literally what microsoft itself recommends doing.
Where But we're multiplying by an extra 1000. |
In fairness to Microsoft, they're operating on a time difference computed mod 2^64, so as long as the interval length is reasonable (less than a few thousand hours for a typical tick rate) it can't overflow. But |
Since we're dealing with absolute time (and therefore something large), it's probably not unreasonable to divide first, or maybe even partially multiply by
maybe? What are "typical" and "extreme" tick rates and absolute ticks like? An incredibly robust implementation could presumably branch on the size of ticks to determine the optimal split of the |
The x86_64 architecture has the 64 bit MUL instruction whose result is effectively a 128 bit integer which never overflows. Likewise, the DIV instruction takes an effectively 128 bit integer as the dividened.
i386 offers (u32, u32) -> u64 MUL and (u64, u32) -> (u32, u32) DIV/MOD, so we should be able to implement 64 bit MUL and DIV without overflow. Windows RT runs on ARMv7 (=~ Cortex-A). It has (u32, u32) -> u64 UMULL but lacks DIV and we have to call a division routine. Perhaps we can forget about it for now... |
We could use techniques similar to division by a constant via multiplication and shifts. |
…elix which starts happening after ~2 hours of machine uptime. Closes rust-lang#17845
…elix which starts happening after ~2 hours of machine uptime. Closes rust-lang#17845
feat: Implement TAIT and fix ATPIT a bit Closes rust-lang#16296 (Commented on the issue) In rust-lang#16852, I implemented ATPIT, but as I didn't discern ATPIT and other non-assoc TAIT, I guess that it has been working for some TAITs. As the definining usage of TAIT requires it should be appear in the Def body's type(const blocks' type annotations or functions' signatures), this can be done in simlilar way with ATPIT And this PR also corrects some defining-usage resolution for ATPIT
The last line of
precise_time_ns
uses a 64 bit multiplication that will overflow frequently.Using floats would be the easy way out, but it would reduce precision to 53 bits.
The text was updated successfully, but these errors were encountered: