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

Merged
merged 3 commits into from
May 18, 2025
Merged

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: x86_64-gnu-aux

@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
@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 18, 2025
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.
@tgross35

This comment was marked as outdated.

@bors

This comment was marked as outdated.

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

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

try-job: x86_64-gnu-aux
tgross35 and others added 2 commits May 18, 2025 16:51
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 1c38c28 to 250869e Compare May 18, 2025 16:51
@tgross35
Copy link
Contributor Author

@bors try

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

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

try-job: x86_64-gnu-aux
@bors
Copy link
Collaborator

bors commented May 18, 2025

⌛ Trying commit 250869e with merge fc768c1...

@rust-log-analyzer

This comment was marked as outdated.

@bors
Copy link
Collaborator

bors commented May 18, 2025

☀️ Try build successful - checks-actions
Build commit: fc768c1 (fc768c1d28c6ea7cd5c231c94c80f94ac5b7ee52)

@tgross35
Copy link
Contributor Author

Needed a config for Miri.

@bors r=Mark-Simulacrum rollup=iffy

@bors
Copy link
Collaborator

bors commented May 18, 2025

📌 Commit 250869e has been approved by Mark-Simulacrum

It is now in the queue for this repository.

fmease added a commit to fmease/rust that referenced this pull request May 18, 2025
…Simulacrum

Add `f16` formatting and parsing

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

try-job: x86_64-gnu-aux
bors added a commit to rust-lang-ci/rust that referenced this pull request May 18, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang#127013 (Add `f16` formatting and parsing)
 - rust-lang#130887 (Safer implementation of RepeatN)
 - rust-lang#140154 (Cygwin support in rustc)
 - rust-lang#140874 (make `rustc_attr_parsing` less dominant in the rustc crate graph)
 - rust-lang#141094 (add regression test for rust-lang#101650)
 - rust-lang#141110 ([std] fix the presentation of `split_off_mut` and `split_off` documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Collaborator

bors commented May 18, 2025

⌛ Testing commit 250869e with merge 4d051fb...

@bors
Copy link
Collaborator

bors commented May 18, 2025

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 4d051fb to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 18, 2025
@bors bors merged commit 4d051fb into rust-lang:master May 18, 2025
7 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 18, 2025
Copy link

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 4455c89 (parent) -> 4d051fb (this PR)

Test differences

Show 17 test diffs

Stage 0

  • num::dec2flt::decimal::check_fast_path_f16: [missing] -> pass (J1)
  • num::dec2flt::float::test_f16_consts: [missing] -> pass (J1)
  • num::dec2flt::float::test_f16_integer_decode: [missing] -> pass (J1)
  • num::dec2flt::lemire::compute_float_f16_rounding: [missing] -> pass (J1)
  • num::flt2dec::random::exact_f16_random_equivalence_test: [missing] -> pass (J1)
  • num::flt2dec::random::shortest_f16_exhaustive_equivalence_test: [missing] -> pass (J1)

Stage 1

  • num::dec2flt::decimal::check_fast_path_f16: [missing] -> pass (J0)
  • num::dec2flt::float::test_f16_consts: [missing] -> pass (J0)
  • num::dec2flt::float::test_f16_integer_decode: [missing] -> pass (J0)
  • num::dec2flt::lemire::compute_float_f16_rounding: [missing] -> pass (J0)
  • num::flt2dec::random::exact_f16_random_equivalence_test: [missing] -> pass (J0)
  • num::flt2dec::random::shortest_f16_exhaustive_equivalence_test: [missing] -> pass (J2)
  • num::flt2dec::random::shortest_f16_exhaustive_equivalence_test: [missing] -> ignore (J3)

Additionally, 4 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 4d051fb306e661654d088892e02e69b8c0c39d43 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-aarch64-linux: 5276.3s -> 7698.3s (45.9%)
  2. dist-x86_64-apple: 10179.7s -> 7488.0s (-26.4%)
  3. x86_64-apple-2: 4891.2s -> 4440.8s (-9.2%)
  4. aarch64-apple: 3815.6s -> 4158.7s (9.0%)
  5. x86_64-apple-1: 7586.7s -> 6936.2s (-8.6%)
  6. dist-apple-various: 5946.6s -> 6435.1s (8.2%)
  7. x86_64-msvc-ext1: 7033.4s -> 7521.5s (6.9%)
  8. i686-gnu-2: 6282.8s -> 6683.9s (6.4%)
  9. x86_64-gnu-aux: 5838.3s -> 6206.0s (6.3%)
  10. x86_64-gnu-llvm-20-2: 6240.9s -> 5852.2s (-6.2%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@tgross35
Copy link
Contributor Author

🎉🎉🎉 just a month short of this PR’s one year anniversary, I’m very glad to have this in! Thanks @speedy-lex for all the help.

@tgross35 tgross35 deleted the f16-format-parse branch May 18, 2025 23:56
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4d051fb): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.8% [0.4%, 1.0%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 0.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.6%, 0.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.6%] 2
All ❌✅ (primary) - - 0

Cycles

Results (secondary 1.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.9% [0.4%, 5.4%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.9% [-2.0%, -1.9%] 3
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.2%, secondary 0.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.0%, 0.5%] 16
Regressions ❌
(secondary)
0.3% [0.0%, 0.5%] 71
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.0%, 0.5%] 16

Bootstrap: 775.321s -> 775.275s (-0.01%)
Artifact size: 365.53 MiB -> 365.57 MiB (0.01%)

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)]` merged-by-bors This PR was explicitly merged by bors. 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.