-
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
fast_rsqrt for f32 and f64 types #13718
Conversation
…ts. It uses the Newton's method approach originally seen in Quake Arena
…m testing the function
Is there precedent for fast inverse square root in standard libraries? I'm only familiar with it's use in Quake. |
It is used in normalizing vectors quite frequently, it just so happens that a lot of quick vector normalization occurs in lighting for game engines. There also isn't a ton of precedent for inverse square roots in standard libraries in general (from what I have gathered at least), the fast that rust already has rsqrt probably means a fast version isn't much of a stretch considering they each have their separate use cases |
Is this the right implementation? The Quake fast inverse square root algorithm is both an order of magnitude slower and an order of magnitude less accurate than the |
It should be faster than the current rust rsqrt, but I would not be surprised if there is an x86 assembly instruction that does it faster. However, if we assume that rust will be used on non x86 platforms (ie ARM) then using x86 specific code isn't really the optimal solution. I could be totally wrong though, and if |
I'm against merging this in as it currently stands. Given the massive performance increase of using This shouldn't be part of the The implementation of There are no benchmarks. Irrelevant of platform capabilities, anything that touts performance needs benchmarks. |
The |
Actually, thinking on this further, I am completely against using the Quake III algorithm at all, at least on x86. The Steam Hardware & Software Survey does not even have a line for whether or not SSE exists on the persons machine and 99.95% of computers have SSE2. In other words, less than 1 in 2000 machines that steam collects data from will crash on the |
That's fair - I'll drop the Quake algorithm and modify the current |
@jacob-hegna I'd hold off on doing anything right now until the question of "is this something we want at all" is answered. |
Thank you for the contribution but I'm going to close this PR without merging for the following reasons: there seems to be a lack of precedent for providing this function in a general purpose stdlib; I believe the demand for this function is minimal. Every function that goes into std is a burden that must be carried by all Rust software forever, so if there's a reasonable case for not including it, then we often should not. Again, thanks. |
No problem, just trying to help out however I can |
Useful for applications that need to be as fast as possible, this function allows for faster inverse square root computation than the current rsqrt function. Both are necessary, and serve different purposes.