rust-lang/rust

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

traviscross opened this issue ยท 32 comments

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

  • 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.

Implementation history

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:

@rustbot labels +T-lang

@rustbot labels +B-rfc-approved

WIP implementation: #114607

@rustbot release-assignment

@rustbot prioritize

@rustbot ping types

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.

@rustbot label: +T-compiler

lqd commented

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

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

#114607 (comment)

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

(massive todo list moved to the top post)

@rustbot claim

@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 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 #122106

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

@wargio #122106 wound up being closed in favor of C3f16 and C4f128 (#123816), which should already demangle correctly. So I think you should be able to revert the addition. Sorry for the noise!

@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!

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

More LLVM bugs:

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

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).

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.

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 llvm/llvm-project#50374)

After #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!

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.

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 #127588, thanks!

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

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

Tier 3 powerpc64-ibm-aix doesn't currently support f128 arguments: llvm/llvm-project#101545

llvm/llvm-project#104915: f16 abs and neg quieten signalling NaNs on targets where f16 is not natively supported.

86maid commented

Hurry up. I can't wait

Warning: div_euclid and rem_euclid is buggy. I'm not sure whether they need be marked as unsafe, since calculate div/rem with floating types are strongly discouraged.

#![feature(f16, f128)]
fn main() {
    let a = 1.2f16;
    let b = 1.1f32;
    let c = 1.1f64;
    let d = 1.1f128;
    println!(
        "{} {} {} {}",
        (12f16).div_euclid(a) as f64,
        (11f32).div_euclid(b),
        (11f64).div_euclid(c),
        (11f128).div_euclid(d) as f64
    );
    println!(
        "{} {} {} {}",
        (12f16).rem_euclid(a) as f64,
        (11f32).rem_euclid(b),
        (11f64).rem_euclid(c),
        (11f128).rem_euclid(d) as f64
    );
}
// 10 10 10 10
// 1.1982421875 1.0999998 1.0999999999999992 1.1

@Neutron3529: If you could, the thing to do would be to file a separate issue for that if there isn't one already. Reference this tracking issue in that new issue.