Repository navigation
Description
This is a tracking issue for the RFC 3453 (rust-lang/rfcs#3453).
The feature gate for the issue is #![feature(f16)] and #![feature(f128)].
From the RFC:
This RFC proposes adding new IEEE-compliant floating point types
f16andf128into 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 below section for details)
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved questions
- Do any new target features need to be marked as "forbidden" since they affect ABI? The logic here looks like that may be the case.
- LLVM seems entirely unable to properly deal with the ABI for these operations, see e.g. this or this. It looks like fixing this will need some non-trivial LLVM changes to pick builtins with the right ABI, or else non-trivial Rust logic to reject e.g.
*onf16if LLVM would get the ABI wrong. - Clang rejects programs that try to use f16 on x86 without SSE. This means we have no template for what
extern "C"should do, so maybe we should just reject code that tries to pass such values acrossextern "C"?
Implementation history and Future Steps
- Add basic support stubs to IR and backend interfaces: Add stubs in IR and ABI for
f16andf128#121728 - Add AST support and intrinsics:
f16andf128step 2: intrinsics #121841 (comment) - Connect the frontend, add the feature gate:
f16andf128step 3: compiler support & feature gate #121926 - Add the most basic traits that
rustcmore or less expects for primitives Add basic trait impls forf16andf128#123085 - Finish support in rustdoc Add
f16andf128to rustdoc'sPrimitiveType#123581 - Add library support.
Some parts are blocked on const eval, compiler builtins updates, and LLVM lowering bugs.hooray, this part is done!-
f16andf128step 4: basic library support #122470 - Add a
Debugimpl and some basic functions tof16andf128#123783 - Add constants for f16 and f128 #123850
- Add more constants, functions, and tests for
f16andf128#126608 - Add classify and related methods for f16 and f128 #127020
- Add
f16andf128math functions #127027
-
- Add needed functions to compiler-builtins. Unfortunately this one will block almost everything else on the list.
- Add builtins for
f16/f128float conversions compiler-builtins#593 - Add addition, subtraction, multiplication, and compare operations for
f128compiler-builtins#606 - Add
f128float to integer conversion functions compiler-builtins#613 - Add f128 int to float conversions compiler-builtins#624
- Add
__divtf3compiler-builtins#622 - Add
__powitf2symbol forf128integer exponentiation compiler-builtins#614 - Others
- Add builtins for
- Figure out parsing and printing
- Migrate the tester to accept more types Rewrite
test-float-parsein Rust #127510 - Add
f16, which should be straightforward Addf16formatting and parsing #127013 - Figure out
f128which will not be straightforward. Our current implementations are prettyu64-dependent so they can't fit af128mantissa. We could make them generic but probably want to instead use an implementation that is slower but better for size.
- Migrate the tester to accept more types Rewrite
- Update const eval
- Basic arithmetic Add
f16andf128const eval for binary and unary operationations #126429 - Casting Enable const casting for
f16andf128#127032 - Miri
f16shims addf16support miri#4895 - Miri
f128shims (partially implemented by implement sqrt and add fixme forf128miri#4902)
- Basic arithmetic Add
- Figure out mangling
Add encoding forAdd v0 symbol mangling forf16andf128#122106f16andf128#123816 -
Ensure known demanglers get updated or at least have issues for adding the new typesunneeded with the forward-compatible demangling - Add SIMD operations that can make use of these types Add SIMD operations that use f16 and f128 #125440
- Implement AVX512_FP16 stdarch#1605
- NVPTX: Add f16 SIMD intrinsics stdarch#1626
- others (help welcome)
- Enable assembly registers where it makes sense Enable
f16andf128in assembly on platforms that support it #125398- Add
f16andf128inline ASM support foraarch64#129536 - Add
f16andf128inline ASM support forx86andx86-64#126417 - Add
f16inline ASM support for RISC-V #126530 - Add
f16inline ASM support for 32-bit ARM #126555 - Add
f16inline asm support for LoongArch #142481 - Add
f16inline ASM support for s390x #150826 - Add MSA and
f16inline ASM support for MIPS #160851 - Add floating point inline ASM support for SPARC #160949
- Add
f16andf128inline ASM support for PowerPC #161135 - Add
f16inline ASM support fornvptx64-nvidia-cuda#161667 - Add
f16inline ASM support tospirv.rs#163281
- Add
- Add c-variadic support for
f128and validate that it works correctly- powerpc64 uses an alignment of 16 for
f128(but only of 8 fori128)
- powerpc64 uses an alignment of 16 for
- Make sure the GCC and Clif backends handle these types gracefully
- Support
f16andf128rustc_codegen_gcc#461 - Support
f16andf128rustc_codegen_cranelift#1461 - Migrate float intrinsics to have a fallback (changes from Wishlist: allow adding intrinsics in a way that doesn't break every backend #93145)
- Support
- Make sure all relevant
unimplementeds andFIXMEs are removed from tools that need library support - Make use of new diagnostic attributes:
-
f16_nanAddf16andf128toinvalid_nan_comparison#132439 -
f16_epsilonfor Clippy (needs to be added)
-
- Figure out ABI & platform-specific problems (thanks @beetrees for just about all of these)
- f16 ABI bugs in compiler-rt
f16generates code that uses the incorrect ABI for compiler-rt #123885 - 32-bit ABI bugs from LLVM [clang] missing support for _Float128 (C23) llvm/llvm-project#80195 (comment) (checked because I believe these are all tracked elsewhere at this time)
- f16 miscompilations from LLVM (affects T2 and T3 targets) LLVM miscompiles consecutive
halfoperations by using too much precision on several backends llvm/llvm-project#97975 LLVM miscompiles passing/returninghalfon several backends by using lossy conversions llvm/llvm-project#97981 - f16 abs and neg quieten signalling NaNs on emulated targets [X86] LLVM >= 18 folding bitcast -> and -> bitcast to
@llvm.fabs.f16generates call to__extendhfsf2llvm/llvm-project#104915 (comment) - x86-32 f16 ABI isn't supported in our baseline x86-32 "f16" ABI needs SSE, incompatible with i586 targets #131819, ABI for float builtins depends on target features llvm/llvm-project#112885
- Tier 1 MinGW f16/f128 incompatibilities from GCC https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054
- Tier2 PowerPC BE precision issues
f128symbols on powerpc64 give inaccurate results #125109 - Tier2 Power9 possible ABI issues
f128from_bits/to_bitssometimes gets reversed on ppc #125102 - Tier2 PowerPC LE
f128 as f16casting bug LLVM f128 -> f16 conversion selection failure on powerpc64le llvm/llvm-project#92866 - Tier 2 PowerPC f16<->f128 sometimes uses the wrong symbol names PowerPC
fp128->halfuses__trunctfhf2but should be__trunckfhf2llvm/llvm-project#98126 - Tier 2 Loongarch failure to select loongarch64 half (f16) failure to select with
+fand+dllvm/llvm-project#93894 (fixed upstream) - Tier 2 arm64ec does not support
f128Can't pass or returnhalforfp128onarm64ecllvm/llvm-project#94434 (f16supported since [Arm64EC] Add support forhalfllvm/llvm-project#152843) - Tier 2 aarch64-*-softfloat has crashes with f16 [AArch64]
-fp-armv8crash usingselectwithhalfllvm/llvm-project#129394 - Tier 2 s390x-unknown-linux-gnu doesn't support f16: SystemZ Backend: Add support for operations such as FP16_TO_FP and FP_TO_FP16 llvm/llvm-project#50374
- Tier 2 wasm32 correctness bug On
wasm32,halfoperation results aren't correctly rounded between each operation llvm/llvm-project#96437 - Tier 2 nvptx64-nvidia-cuda doesn't support f128:
fp128causes compilation failures when compiling fornvptx64-nvidia-cudallvm/llvm-project#95471 - Tier 3 mips LLVM crashes with
f128Compiler crash when targetingmips64when returningfp128after calling a function returning{ i8, i128 }llvm/llvm-project#96432 - Tier 3 sparc-unknown-linux-gnu doesn't support passing f128 directly (error message SPARCv8 does not handle f128 in calls; pass indirectly): Passing long double args on 32-bit SPARC violates ABI llvm/llvm-project#41838
- Tier 3
powerpc64-ibm-aixdoesn't currently supportf128arguments:fp128arguments cause a compiler error onpowerpc64-ibm-aixllvm/llvm-project#101545 - Generally go through The ABI of float types can be changed by
-Ctarget-feature#116344 (and in particular Figure out which target features are required/incompatible for which ABI #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 (see f16 and f128 have non-trivial ABI requirements on some targets #138616) - Intrinsics for
minimumandmaximumdon't work on x86 and aarch64 [aarch64]Cannot select: constant:i128<0>forllvm.maximum.f128llvm/llvm-project#139380 [x86]: Cannot select:constant:i128<0>forllvm.maximum.f128llvm/llvm-project#139381 (nonblocking as we are using the fallback for now) -
minimum/maximumforf128don't work on tier 2 wasm targetsf128on wasm does not support maximum intrinsic #158673
- f16 ABI bugs in compiler-rt
- Other misc miscompilations or bugs
- LLVM does
fma.f16incorrectlyllvm.fma.f16intrinsic is expanded incorrectly on targets without nativehalfFMA support llvm/llvm-project#98389 -
powi.f16constant folding returns incorrect values Misoptimization:EarlyCSEPassuses replacespowi.f16withfloatresult llvm/llvm-project#98665
- LLVM does
- Implement an internal
cfgthat lets us gate tests based on backend support Implement the internal featurecfg_target_has_reliable_f16_f128#140323 - Eventually, stabilization
Note that // FIXME(f128)/// FIXME(f16)/// FIXME(f16,f128) and unimplemented!("f16_f128") are being used where relevant, to make the todo list easily greppable.
Nice to have changes:
- Better debuginfo for MSVC Improve MSVC debug info for f16 and f128 #121837
- A bit of ecosystem support
- Rust-analyzer Add
f16andf128support (add toFloatTy) rust-analyzer#17451 - Bytemuck Support
f16andf128under a nightly flag Lokathor/bytemuck#250 - Zerocopy Add support for the unstable f16 and f128 types google/zerocopy#2042
- Serde add f16 and f128 support serde-rs/serde#2941
- num Add f16, f128 rust-num/num-traits#333
- rug https://gitlab.com/tspiteri/rug/-/issues/68
- syntax highlighters
- Rust-analyzer Add
Activity
traviscross commentedon Oct 18, 2023
traviscross commentedon Oct 19, 2023
tgross35 commentedon Oct 19, 2023
gorentbarak commentedon Oct 27, 2023
gorentbarak commentedon Oct 27, 2023
gorentbarak commentedon Oct 27, 2023
gorentbarak commentedon Oct 27, 2023
rustbot commentedon Oct 27, 2023
gorentbarak commentedon Oct 27, 2023
132 remaining items
Rollup merge of rust-lang#151468 - folkertdev:f16-fixmes, r=tgross35
Unrolled build for #151468
Rollup merge of #151468 - folkertdev:f16-fixmes, r=tgross35
pinskia commentedon Jan 23, 2026
pinskia commentedon Jan 23, 2026
This is bad form. The underyling target should decide if f16 and f128 are support rather than the language. This is how Fortran, C and many other languages are done.
bjoernager commentedon Jan 23, 2026
They are already, and with the exact naming that you propose. ;)
It seems that the consensus is to yield such optimisations to the programmer. But this statement also assumes that performance is more important than portability, which is not always the case for all software. Also, even just having the types for storage is useful.
Almost. It is not uncommon for compilers to provide soft floats on some embedded targets. But GCC and Clang, at least, do not seem do so on every target.
programmerjake commentedon Jan 23, 2026
I strongly disagree, any pure-computation API that Rust has should work anywhere, that allows code that needs those types to work anywhere even if a bit slowly instead of only wherever the target deigns to provide those types (not that many targets and IIRC some of them need very recent CPUs).
That said, tracking issues aren't the place to have a long discussion, if you want to discuss it more, feel free to create a topic on https://internals.rust-lang.org/ and link it here.
pinskia commentedon Jan 23, 2026
bjoernager commentedon Jan 23, 2026
tgross35 commentedon Jan 23, 2026
I assume you are coming here from the discussion on a GCC fallback?
We eventually want these types available on all platforms because that shouldn't be the average programmer's concern. Of course the best case scenario is that the platform's ABI tells us exactly what to do, but it's not a good user experience if an otherwise functional library doesn't build on some platform just because they stopped updating their ABI a decade ago. Maybe the library could do something better on platforms that don't support f16/f128, but we'd like that to be a performance concern rather than a "does it work" concern. And then if they do eventually update the ABI, rust can adjust things as needed to match.
I realize this is differs from the usual GCC path which e.g. doesn't support __int128 on i386 since it (despite my efforts) isn't specified there. But I think this is the perfect example where it would be nice if the compiler smoothed things over, because it is inconvenient and measurably bad for performance to roll your own __int128 to implement soft _Float128 ops (which is specified in i386. I'm aware
_BitIntexists now.). And GCC also has some extensions.AFAIK LLVM's
halftype now works on all targets since LLVM22, using i16 ABI and libcalls as a fallback. f128 still has some work to be done. For reference, we keep track of this atrust/compiler/rustc_codegen_llvm/src/llvm_util.rs
Lines 374 to 445 in d222ddc
Regarding where to discuss: the policy is absolutely not for the purpose of ignoring feedback. Things just get cluttered given the lack of threads on GH issues. Discussing on separate issues or at https://rust-lang.zulipchat.com is preferred for that reason, but I'd rather address this here than not at all.
pinskia commentedon Jan 23, 2026
tgross35 commentedon Jan 23, 2026
Opened #151557 to continue this thread.
There is not, Zulip more or less took over the threaded discussion / public archive role.
workingjubilee commentedon Jan 25, 2026
While it seems that this discussion has been successfully channeled, I am locking this to discourage further reuse of this issue out-of-bounds of strictly "tracking" concerns, per rust-lang/compiler-team#739
If you are not a team member and so cannot speak "over" the lock then you can create a new issue and ping back this one by linking to it. If it constitutes what should be an "unresolved question", "future step", or what-have-you, then a team member can edit that new issue into the tracking issue's initial post. Let all new comments from this point be of a similar procedural or "meta-level" nature.
ChrisDenton commentedon Jul 1, 2026
The maximum intrinsic is missing for wasm targets: #158673