-
Notifications
You must be signed in to change notification settings - Fork 271
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
Rust does not let you observe or mutate the floating-point register in well-defined ways #1454
Rust does not let you observe or mutate the floating-point register in well-defined ways #1454
Conversation
…n well-defined ways
r? @Amanieu (rustbot has picked a reviewer for you, use r? to override) |
@@ -1401,6 +1410,16 @@ pub unsafe fn _mm_getcsr() -> u32 { | |||
/// * The *denormals-are-zero mode flag* turns all numbers which would be | |||
/// denormalized (exponent bits are all zeros) into zeros. | |||
/// | |||
/// Note that modfying the masking flags, rounding mode, or denormals-are-zero mode flags leads to | |||
/// **immediate Undefined Behavior**: Rust assumes that these are always in their default state and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes this function basically impossible to use in a UB-free way. Should we deprecate it in favor of inline assembly blocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I don't see why we wouldn't. As far as I can tell this function always either has no effect or is UB to call
Co-authored-by: Jacob Lifshay <[email protected]>
Do other architectures have similar vendor intrinsics that would also need the same kind of comment? |
There is some precedent for deprecating unsound intrinsics, see rust-lang/rust#51810.
At least not on ARM or RISC-V. I'm less familiar with MIPS/PPC. |
Ah that deprecated even the functions reading eflags, since they don't behave as expected -- even if they don't cause UB. So I made this deprecate both getcsr and setcsr. |
explain why we can mutate the FPU control word This is usually not allowed (see rust-lang/stdarch#1454), but here we have a special case.
explain why we can mutate the FPU control word This is usually not allowed (see rust-lang/stdarch#1454), but here we have a special case.
@Amanieu how do we proceed with this PR? |
Thanks @eduardosm for pointing me to these operations.
Cc @rust-lang/lang @rust-lang/opsem