Skip to content

Conversation

@mt-xing
Copy link
Contributor

@mt-xing mt-xing commented Jan 30, 2025

Please note that this PR includes benchmarks that depend on an extension which provides bits2float and float2bits, which has not yet been merged.

This PR adds two benchmarks, called fastinvsqrt and iterativefastinvsqrt respectively. Both will compute 1/sqrt(x) using fast methods. The primary inspiration was the legendary Quake 3 Fast Inverse Square Root Algorithm, which computes the value extremely fast, using some bit magic to get a logarithmic approximation and then uses a single iteration of Newton's method to refine the estimate. Unfortunately, this requires bits2float and float2bits, which a peer has submitted a PR to add to bril that has not yet been merged.

As an alternative, iterativefastinvsqrt uses the much less interesting Newton's method, starting at 1/x and iterating until the step size becomes smaller than a user-defined precision. This benchmark runs fine even on bril as it exists today. The TOML test case is thus provided for iterativefastinvsqrt only.

It may be wise to hold off on merging this benchmark until the bit casting extension is merged.

@sampsyo
Copy link
Owner

sampsyo commented Jan 31, 2025

Sorry to be a stickler on a language thing here, but could you please rename "lame*" to something like "slow*" or "iterative*"?

@mt-xing
Copy link
Contributor Author

mt-xing commented Jan 31, 2025

Sorry to be a stickler on a language thing here, but could you please rename "lame*" to something like "slow*" or "iterative*"?

Sure! It's now called iterativefastinvsqrt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants