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

FCSR operations generally cannot be used from Rust #148

Closed
RalfJung opened this issue Nov 4, 2023 · 2 comments
Closed

FCSR operations generally cannot be used from Rust #148

RalfJung opened this issue Nov 4, 2023 · 2 comments

Comments

@RalfJung
Copy link

RalfJung commented Nov 4, 2023

This crate seems to provide operations that can change the floating-point rounding mode and read the accrued exceptions flags. These operations generally cannot be used soundly from Rust; see rust-lang/stdarch#1478 for more explanation.

It would be good to clarify in the documentation when and how exactly these functions are meant to be used. As things stand, calling set_rounding_mode() will be immediate UB in almost all contexts, and read().fflags() will return an unreliable value.

@romancardenas
Copy link
Contributor

Thanks for this issue! I see that you are removing all the floating point configuration-related functions from the standard library. Thus here I see two options: either we leave all the functions unsafe and properly documenting them, or we just remove them following the standard implementation.

@RalfJung
Copy link
Author

RalfJung commented Nov 6, 2023

I originally planned to deprecate them, which was what we did on x86. But it was pointed out that they are still unstable so we might as well remove them.

Exposing some unsafely is an option, but the question here is what the expected use-case looks like. The one example I can imagine is implementing context switching, where you have to save/restore the FCSR of the userland process. But that's likely better done in inline assembly, there's going to be a bunch of inline assembly in that code anyway.

For regular userland code, there isn't really a way to use these functions correctly. However, if they are removed, documentation should probably be added that tells users why they aren't there, and how to use inline assembly instead.

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

3 participants