[Benchmarks] Fast Inverse Square Root #362
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please note that this PR includes benchmarks that depend on an extension which provides
bits2float
andfloat2bits
, which has not yet been merged.This PR adds two benchmarks, called
fastinvsqrt
anditerativefastinvsqrt
respectively. Both will compute1/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 requiresbits2float
andfloat2bits
, 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 at1/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 foriterativefastinvsqrt
only.It may be wise to hold off on merging this benchmark until the bit casting extension is merged.