Repository: rust
Issue: Tracking Issue for `f16` and `f128` float types
Labels: B-RFC-approved,T-lang,T-compiler,C-tracking-issue,F-f16_and_f128

This is a tracking issue for the RFC 3453 (rust-lang/rfcs#3453).

The feature gate for the issue is `#![feature(f16_and_f128)]`.

From the RFC:

> This RFC proposes adding new IEEE-compliant floating point types `f16` and `f128` into the core language and standard library. We will provide a soft float implementation for all targets, and use hardware support where possible.

### About tracking issues

Tracking issues are used to record the overall progress of implementation.  They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.  A tracking issue is however *not* meant for large scale discussion, questions, or bug reports about a feature.  Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

### Steps

- [ ] Implement the RFC ([see the list of tasks here](https://github.com/rust-lang/rust/issues/116909#issuecomment-1969554030)]
- [ ] Adjust documentation ([see instructions on rustc-dev-guide][doc-guide])
- [ ] Stabilization PR ([see instructions on rustc-dev-guide][stabilization-guide])

[stabilization-guide]: https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr
[doc-guide]: https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#documentation-prs

### Unresolved questions

- Do any new target features need to be marked as "forbidden" since they affect ABI? The logic [here](https://github.com/llvm/llvm-project/blob/5d734fa4c8f358299a4dfd2a7f9315a226b94a4a/llvm/lib/Target/ARM/ARMISelLowering.cpp#L792) looks like that may be the case.

### Implementation history

- [x] Add basic support stubs to IR and backend interfaces: https://github.com/rust-lang/rust/pull/121728
- [x] Add AST support and intrinsics: https://github.com/rust-lang/rust/pull/121841#issuecomment-1973756875
- [x] Connect the frontend, add the feature gate: https://github.com/rust-lang/rust/pull/121926
- [x] Add the most basic traits that `rustc` more or less expects for primitives https://github.com/rust-lang/rust/pull/123085
- [x] Finish support in rustdoc https://github.com/rust-lang/rust/pull/123581
- [x] Add library support. ~~Some parts are blocked on const eval,  compiler builtins updates, and LLVM lowering bugs.~~ hooray, this part is done!
  - [x] https://github.com/rust-lang/rust/pull/122470
  - [x] https://github.com/rust-lang/rust/pull/123783
  - [x] https://github.com/rust-lang/rust/pull/123850
  - [x] https://github.com/rust-lang/rust/pull/126608
  - [x] https://github.com/rust-lang/rust/pull/127020
  - [x] https://github.com/rust-lang/rust/pull/127027
- [x] Add needed functions to compiler-builtins. Unfortunately this one will block almost everything else on the list.
  - [x] https://github.com/rust-lang/compiler-builtins/pull/593
  - [x] https://github.com/rust-lang/compiler-builtins/pull/606
  - [x] https://github.com/rust-lang/compiler-builtins/pull/613
  - [x] https://github.com/rust-lang/compiler-builtins/pull/624
  - [x] https://github.com/rust-lang/compiler-builtins/pull/622
  - [x] https://github.com/rust-lang/compiler-builtins/pull/614
  - [x] Others
- [ ] Figure out parsing and printing
  - [x] Migrate the tester to accept more types https://github.com/rust-lang/rust/pull/127510
  - [ ] Add `f16`, which should be straightforward https://github.com/rust-lang/rust/pull/127013
  - [ ] Figure out `f128` which will not be straightforward. Our current implementations are pretty `u64`-dependent so they can't fit a `f128` mantissa. We could make them generic but probably want to instead use an implementation that is slower but better for size.
- [ ] Update const eval
  - [x] Basic arithmetic https://github.com/rust-lang/rust/pull/126429
  - [x] Casting https://github.com/rust-lang/rust/pull/127032
  - [ ] Miri shims
- [x] Figure out mangling ~~https://github.com/rust-lang/rust/pull/122106~~ https://github.com/rust-lang/rust/pull/123816
- [x] ~~Ensure known demanglers get updated or at least have issues for adding the new types~~ unneeded with the forward-compatible demangling 
- [ ] Add SIMD operations that can make use of these types https://github.com/rust-lang/rust/issues/125440
  - [x] https://github.com/rust-lang/stdarch/pull/1605
  - [x] https://github.com/rust-lang/stdarch/pull/1626
- [ ] Enable assembly registers where it makes sense https://github.com/rust-lang/rust/issues/125398
  - [x] https://github.com/rust-lang/rust/pull/129536
  - [x] https://github.com/rust-lang/rust/pull/126417
  - [x] https://github.com/rust-lang/rust/pull/126530
  - [x] https://github.com/rust-lang/rust/pull/126555
- [ ] Make sure the GCC and Clif backends handle these types gracefully
  - [x] https://github.com/rust-lang/rustc_codegen_gcc/issues/461 (merged upstream, waiting on sync)
  - [ ] https://github.com/rust-lang/rustc_codegen_cranelift/issues/1461
  - [ ] Migrate float intrinsics to have a fallback (changes from https://github.com/rust-lang/rust/issues/93145)
- [ ] Make sure all relevant `unimplemented`s and `FIXME`s are removed from tools that need library support
  - [x] https://github.com/rust-lang/rust/pull/126636
  - [x] https://github.com/rust-lang/rust/pull/123088
  - [x] https://github.com/rust-lang/rust/pull/127496
- [ ] Make use of new diagnostic attributes, e.g. `f16_nan`
- [ ] Figure out ABI & platform-specific problems (thanks @beetrees for just about all of these)
  - [x] f16 ABI bugs in compiler-rt https://github.com/rust-lang/rust/issues/123885
  - [ ] 32-bit ABI bugs from LLVM https://github.com/llvm/llvm-project/issues/80195#issuecomment-2105497560
  - [ ] f16 miscompilations from LLVM (affects T2 and T3 targets) https://github.com/llvm/llvm-project/issues/97975 https://github.com/llvm/llvm-project/issues/97981
  - [ ] f16 abs and neg quieten signalling NaNs on emulated targets https://github.com/llvm/llvm-project/issues/104915#issuecomment-2408760679
  - [ ] #131819
  - [ ] Tier 1 MinGW incompatibilities from GCC https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054
  - [ ] Tier2 PowerPC BE precision issues https://github.com/rust-lang/rust/issues/125109
  - [ ] Tier2 Power9 possible ABI issues https://github.com/rust-lang/rust/issues/125102
  - [ ] Tier2 PowerPC LE `f128 as f16` casting bug https://github.com/llvm/llvm-project/issues/92866
  - [ ] Tier 2 PowerPC sometimes uses the wrong symbol names https://github.com/llvm/llvm-project/issues/98126
  - [x] Tier 2 Loongarch failure to select https://github.com/llvm/llvm-project/issues/93894 (fixed upstream)
  - [ ] Tier 2 arm64ec does not support these types https://github.com/llvm/llvm-project/issues/94434
  - [ ] Tier 2 s390x-unknown-linux-gnu doesn't support f16: https://github.com/llvm/llvm-project/issues/50374
  - [ ] Tier 2 wasm32 correctness bug https://github.com/llvm/llvm-project/issues/96437
  - [ ] Tier 2 nvptx64-nvidia-cuda doesn't support f128: https://github.com/llvm/llvm-project/issues/95471
  - [ ] Tier 3 mips LLVM crashes with `f128` https://github.com/llvm/llvm-project/issues/96432
  - [ ] Tier 3 sparc-unknown-linux-gnu doesn't support passing f128 directly (error message SPARCv8 does not handle f128 in calls; pass indirectly): https://github.com/llvm/llvm-project/issues/41838
  - [ ] Tier 3 `powerpc64-ibm-aix` doesn't currently support `f128` arguments: https://github.com/llvm/llvm-project/issues/101545
  - [ ] Generally go through https://github.com/rust-lang/rust/issues/116344 (and in particular https://github.com/rust-lang/rust/issues/131799) for all targets; those issues are mostly focusing on f32 and f64 so there might be more target features we have to worry about for f16/f128
- [ ] Other misc miscompilations or bugs
  - [ ] LLVM does `fma.f16` incorrectly https://github.com/llvm/llvm-project/issues/98389
  - [x] `powi.f16` constant folding returns incorrect values https://github.com/llvm/llvm-project/issues/98665
- [ ] Eventually, stabilization

Note that `unimplemented!("f16_f128")` and `// FIXME(f16_f128)` is being used where relevant, to make the todo list easily greppable.

Nice to have changes:

- [ ] Better debuginfo for MSVC https://github.com/rust-lang/rust/issues/121837
  - [x] `f16`: https://github.com/rust-lang/rust/pull/127001
  - [ ] `f128`
- [ ] A bit of ecosystem support
  - [ ] Rust-analyzer https://github.com/rust-lang/rust-analyzer/issues/17451
  - [x] Bytemuck https://github.com/Lokathor/bytemuck/issues/250
  - [x] Zerocopy https://github.com/google/zerocopy/pull/2042
  - [ ] Serde
  - [ ] num
  - [x] rug https://gitlab.com/tspiteri/rug/-/issues/68
  - [ ] syntax highlighters

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"tgross35"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->