Skip to content
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

Proving IEEE-754 2008 compliance for all sqrt/sqrtf implementations on all platforms. #255

Open
james7132 opened this issue Jul 15, 2021 · 1 comment

Comments

@james7132
Copy link

Rust's f32/f64 types specify that they're IEEE-754 2008 compliant, from which the behavior of sqrt is explicitly defined by the standard. The SSE/SSE2 path in both is currently the only target-feature based platform specific alterations in the libm codebase. While these intrinsic based paths are significantly faster, there should be extensive testing to show that these alternative implementations produce identical results across platforms that is consistent with the standard.

For deterministic game networking and simulation stability, we're relying on libm to provide bit-for-bit identical output across multiple targets for common mathematical functions that are not consistent across hardware implementations (i.e. much of the x87 transcendental instructions), and sqrt(f) is a particularly common function to see used.

@Lokathor
Copy link
Contributor

For Background: The f32::sqrt and f64::sqrt methods in std use the compiler intrinsic for sqrt. This means that all sqrt method calls should naturally utilize hardware as much as possible. This means not only on targets with sse/sse2, but also arm, wasm, etc. The conditional compilation in libm::sqrtf and libm::sqrt does use a CPU intrinsic when statically available. However, that code path only exists as an optimization to be used by no_std libraries that need to do a sqrt and so are calling libm directly. Uses of the sqrt methods in std should never end up lowering into a libm call if the hardware supports a sqrt operation.

That said, we welcome improvements to the crate's test suite.

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

No branches or pull requests

2 participants