Skip to content

Commit ad1ec3a

Browse files
committed
Prepare RFC 3514 to be merged
1 parent f953191 commit ad1ec3a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

text/3514-float-semantics.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- Feature Name: `float_semantics`
22
- Start Date: 2023-10-14
33
- RFC PR: [rust-lang/rfcs#3514](https://github.com/rust-lang/rfcs/pull/3514)
4-
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
4+
- Tracking Issue: [rust-lang/rust#128288](https://github.com/rust-lang/rust/issues/128288)
55

66
# Summary
77
[summary]: #summary
@@ -26,7 +26,6 @@ This is caused by a combination of surprising effects introduced by LLVM optimiz
2626

2727
It's time to stop leaving our users in the dark about what actually is and is not guaranteed.
2828

29-
3029
# Guide-level explanation
3130
[guide-level-explanation]: #guide-level-explanation
3231

@@ -45,7 +44,6 @@ In particular, the bit pattern produced at compile-time can differ from the bit
4544
Certain targets unfortunately are known to not implement these semantics precisely (see [below](#target-specific-problems)).
4645
The [platform support page](https://doc.rust-lang.org/rustc/platform-support.html) will list those caveats.
4746

48-
4947
# Reference-level explanation
5048
[reference-level-explanation]: #reference-level-explanation
5149

@@ -96,6 +94,7 @@ when a floating-point operation produces a NaN result, the resulting NaN bit pat
9694
However, the exact function is not specified, and it is allowed to change across targets and Rust versions, and even with compiler flags.
9795
In particular, there is no guarantee that the choice made in const evaluation is consistent with the choice made at runtime.
9896
That is, the following assertion is allowed to fail (and in fact, it [fails on current versions of Rust](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a594d2975c29b1c7fa457a4ec4ae4b87)):
97+
9998
```rust
10099
use std::hint::black_box;
101100

@@ -111,6 +110,7 @@ This means that evaluating the same `const fn` on the same arguments can produce
111110
However, note that these functions are already non-deterministic: even evaluating the same function with the same arguments twice at runtime can [and does](https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=50b5a549fa1fe259cea5ad138066ccf0) produce different results!
112111

113112
In other words, consider this code:
113+
114114
```rust
115115
const fn div(x: f32) -> i32 {
116116
unsafe { std::mem::transmute(x / x) }
@@ -123,6 +123,7 @@ assert_eq!(div(0.0), div(0.0));
123123
const C: i32 = div(0.0);
124124
assert_eq!(C, div(0.0));
125125
```
126+
126127
The first assertion is very unlikely to fail in practice (it would require the two invocations of `div` to be optimized differently).
127128
The second however [actually fails](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=0b4b952929c9ebcd2bd50aee54e6cdf4) on current nightlies in debug mode.
128129

@@ -178,8 +179,6 @@ We should consider documenting on the "platform support" page (and we probably w
178179
- On old MIPS, the interpretation of "signaling" and "quiet" is the opposite of what has been specified above. The effective spec on those targets is that any NaN-producing operation can non-deterministically produce an arbitrary (signaling or quiet) NaN. Currently, LLVM does not have a way of implementing their own NaN semantics for this target, so there's not a lot we can do on the Rust side. [LLVM issue](https://github.com/llvm/llvm-project/issues/60796)
179180
- On 32bit ARM, NEON SIMD operations [always flush-to-zero](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Pre-RFC.3A.20floating.20point.20guarantees/near/376893307). *If* LLVM auto-vectorizes code for that target, that would lead to divergence from IEEE semantics. It is currently unclear whether this is the case; people keep bringing this up as a cause of potential non-conformance but the author was unable to find concrete records of any actual misbehavior. However, this will become an issue if NEON operations are ever exposed to Rust users: we would expect SIMD operations to follow the same NaN rules as their non-SIMD counterparts, but ARM NEON would violate those semantics.
180181

181-
182-
183182
# Rationale and alternatives
184183
[rationale-and-alternatives]: #rationale-and-alternatives
185184

0 commit comments

Comments
 (0)