rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
95.1k stars 12.27k forks source link

Tracking Issue for `f16` and `f128` float types #116909

Open traviscross opened 9 months ago

traviscross commented 9 months ago

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

Unresolved questions

None so far.

Implementation history

traviscross commented 9 months ago

@rustbot labels +T-lang

traviscross commented 9 months ago

@rustbot labels +B-rfc-approved

tgross35 commented 9 months ago

WIP implementation: https://github.com/rust-lang/rust/pull/114607

gorentbarak commented 8 months ago

@rustbot claim

gorentbarak commented 8 months ago

@rustbot release-assignment

gorentbarak commented 8 months ago

@rustbot prioritize

gorentbarak commented 8 months ago

@rustbot ping types

rustbot commented 8 months ago

Error: Only Rust team members can ping teams.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

gorentbarak commented 8 months ago

@rustbot label: +T-compiler

lqd commented 8 months ago

This is a tracking issue and doesn't need prioritization.

tgross35 commented 7 months ago

A blocking issue should be added: ensure C compatibility with ABI-cafe or similar

https://github.com/rust-lang/rust/pull/114607#discussion_r1421042343

tgross35 commented 4 months ago

Implementation steps (could somebody link this in the top post?):

This is based on the suggested pattern at https://github.com/rust-lang/rust/pull/120645#issuecomment-1925900572. I have a more complete reference PR with most of these done at https://github.com/rust-lang/rust/pull/114607

I am trying to consistently use unimplemented!("f16_f128") and // FIXME(f16_f128) to make needed changes easily greppable.

Nice to have changes:

@rustbot claim

wargio commented 3 months ago

@tgross35 we (rizinorg) have merged the changes on our demangling library. i have added also some tests https://github.com/rizinorg/rz-libdemangle/blob/main/test/test_rust.c#L75-L78

tgross35 commented 3 months ago

@tgross35 we (rizinorg) have merged the changes on our demangling library. i have added also some tests https://github.com/rizinorg/rz-libdemangle/blob/main/test/test_rust.c#L75-L78

That was super fast :) the update is much appreciated.

Note that the mangling isn't actually finalized but does seem reasonably likely to merge as-is https://github.com/rust-lang/rust/pull/122106

wargio commented 3 months ago

i don't think that will be a big issue. i can always fix this once is merged if it ever changes.

tgross35 commented 3 months ago

@wargio https://github.com/rust-lang/rust/pull/122106 wound up being closed in favor of C3f16 and C4f128 (https://github.com/rust-lang/rust/pull/123816), which should already demangle correctly. So I think you should be able to revert the addition. Sorry for the noise!

wargio commented 3 months ago

@tgross35 i will. i read about the decision yesterday, so for me is just a couple of lines that needs to be removed. thank you for your wonderful work!

beetrees commented 1 month ago

arm64ec-pc-windows-msvc can't compile functions that pass or return f16 or f128 due to llvm/llvm-project#94434.

beetrees commented 1 month ago

More LLVM bugs:

beetrees commented 3 weeks ago

64-bit MIPS targets (all tier 3) have a bug involving f128 that prevents compilation of compiler-builtins in debug mode without the no-f16-f128 feature: llvm/llvm-project#96432

beetrees commented 3 weeks ago

wasm32 (tier 2) has f16 bugs with failing to round in-between operations (llvm/llvm-project#96437) and quietening signalling NaNs in some situations when passing to and returning from a function (llvm/llvm-project#96438).

beetrees commented 1 week ago

It seems the LLVM f16 excess precision and ABI-handling bugs aren't limited to WASM:

The list of affected LLVM backends is included in each issue: both affect tier 2 and tier 3 Rust targets.

uweigand commented 6 days ago

The test suite currently fails on s390x in the following doctests:

    library/core/src/num/f16.rs - f16::f16::is_sign_negative (line 377)
    library/core/src/num/f16.rs - f16::f16::is_sign_positive (line 354)
    library/core/src/num/f16.rs - f16::f16::to_be_bytes (line 695)
    library/core/src/num/f16.rs - f16::f16::to_le_bytes (line 716)
    library/core/src/num/f16.rs - f16::f16::to_ne_bytes (line 743)

due to

rustc-LLVM ERROR: Cannot select: 0x3ffcc0737a0: i32 = fp_to_fp16 0x3ffcc072fc0

(which is https://github.com/llvm/llvm-project/issues/50374)

After https://github.com/rust-lang/rust/pull/127235 most doctests are already restricted to x64_64 (or aarch64), but these few listed above remain active on all Linux platforms. Could those also be restricted for now (until the s390x LLVM back-end is fixed) so that the test suite passes again? Thanks!

tgross35 commented 6 days ago

Thanks for reporting @uweigand, yes those could be restricted too. Feel free to open a PR similar to #127235 if you're up for it, otherwise I'll try to put one up in the next couple days.

uweigand commented 6 days ago

Thanks for reporting @uweigand, yes those could be restricted too. Feel free to open a PR similar to #127235 if you're up for it, otherwise I'll try to put one up in the next couple days.

I've now opened https://github.com/rust-lang/rust/pull/127588, thanks!

beetrees commented 6 days ago

LLVM lowers f16 FMA incorrectly on targets without native f16 FMA support (so this will affect most targets including all tier 1 targets): llvm/llvm-project#98389

scottmcm commented 2 days ago

It appears that today f128 doesn't trigger the incomplete_features lint: https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=9d8a3698d5d506fc960bde270e9a1a54

It might be a good idea to do that for now, to avoid people making threads like https://users.rust-lang.org/t/display-for-f128/114405?u=scottmcm