Skip to content

Add f16 formatting and parsing #127013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Jun 27, 2024

Use the same algorithms as for f32 and f64 to implement f16 parsing and printing.

try-job: aarch64-gnu
try-job: dist-s390x-linux
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 27, 2024
@rust-log-analyzer

This comment has been minimized.

@tgross35
Copy link
Contributor Author

@rustbot label +rla-silenced

@rustbot rustbot added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Jun 27, 2024
@tgross35
Copy link
Contributor Author

@rustbot label +F-f16_and_f128

@rustbot rustbot added the F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` label Jun 27, 2024
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 9, 2024

This will need #127510

@bors
Copy link
Collaborator

bors commented Jul 15, 2024

☔ The latest upstream changes (presumably #127020) made this pull request unmergeable. Please resolve the merge conflicts.

@tgross35 tgross35 force-pushed the f16-format-parse branch 2 times, most recently from 7c3f9c1 to f3ebeb3 Compare July 23, 2024 09:52
@tgross35
Copy link
Contributor Author

Update: I'm really just waiting on #128083 to bump stage0, managing #[cfg(not(bootstrap))] and always building stage1 got too painful.

@bors
Copy link
Collaborator

bors commented Jul 30, 2024

☔ The latest upstream changes (presumably #128360) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC Dylan-DPC added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2024
@tgross35 tgross35 force-pushed the f16-format-parse branch 6 times, most recently from 21ffabc to 2098f01 Compare August 25, 2024 07:53
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 25, 2024
@tgross35 tgross35 force-pushed the f16-format-parse branch 5 times, most recently from 404089f to 3636530 Compare August 30, 2024 09:04
@tgross35 tgross35 force-pushed the f16-format-parse branch 2 times, most recently from 6840636 to bea36a2 Compare May 14, 2025 14:57
@tgross35
Copy link
Contributor Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request May 14, 2025
Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: aarch64-gnu
@bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as outdated.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 14, 2025
@tgross35 tgross35 force-pushed the f16-format-parse branch 2 times, most recently from 7d0475a to 4638679 Compare May 15, 2025 09:30
@tgross35
Copy link
Contributor Author

@bors try

@bors
Copy link
Collaborator

bors commented May 15, 2025

⌛ Trying commit 4638679 with merge f604e77...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 15, 2025
Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: aarch64-gnu
try-job: dist-s390x-linux
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@bors bors mentioned this pull request May 15, 2025
@bors
Copy link
Collaborator

bors commented May 15, 2025

☀️ Try build successful - checks-actions
Build commit: f604e77 (f604e77dcb12df97d709ff8c82b52e42ecd8fdf0)

@tgross35
Copy link
Contributor Author

@Mark-Simulacrum the only thing that changed from the original approval should be the addition of the fallback. I double checked with Bjorn and there shouldn’t be any problems with that.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels May 15, 2025
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with nit fixed

// FIXME(f16_f128): A fallback is used when the backend+target does not support f16 well, in order
// to avoid ICEs.

// After the bootstrap bump this should be: `#[cfg(not(target_has_reliable_f16))`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If true, please write this as a pair of cfg_attrs not a comment - we have some partial automation that can find and replace cfg attrs automatically but comments are near invisible to that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is indeed not correct, the comment is from before the post-bump rebase. Removed.

tgross35 and others added 3 commits May 15, 2025 20:57
Use the existing Lemire (decimal -> float) and Dragon / Grisu algorithms
(float -> decimal) to add support for `f16`. This allows updating the
implementation for `Display` to the expected behavior for `Display`
(currently it prints the a hex bitwise representation), matching other
floats, and adds a `FromStr` implementation.

In order to avoid crashes when compiling with Cranelift or on targets
where f16 is not well supported, a fallback is used if
`cfg(target_has_reliable_f16)` is not true.
Extend the existing tests for `f32` and `f64` with versions that include
`f16`'s new printing and parsing implementations.

Co-authored-by: Speedy_Lex <[email protected]>
This requires a fix to the subnormal test to cap the maximum allowed
value within the maximum mantissa.
@tgross35 tgross35 force-pushed the f16-format-parse branch from 4638679 to 221d7f3 Compare May 15, 2025 20:58
@tgross35
Copy link
Contributor Author

@bors r=Mark-Simulacrum

@bors
Copy link
Collaborator

bors commented May 15, 2025

📌 Commit 221d7f3 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 15, 2025
hkBst added a commit to hkBst/rust that referenced this pull request May 16, 2025
…Simulacrum

Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: aarch64-gnu
try-job: dist-s390x-linux
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` rla-silenced Silences rust-log-analyzer postings to the PR it's added on. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants