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

@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
Copy link
Contributor Author

tgross35 commented Mar 4, 2025

Edit: Could you try add test-float-parse to x.py suggest?

I don't think I've ever used this and I have no idea how it works 😆 any improvements to running test-float-parse via bootstrap are welcome though, I wired it up just enough to run tests in CI.

@speedy-lex
Copy link
Contributor

I'm not very familiar with the CI system; can you link me to where you wired it up?
I've added it to suggest with speedy-lex@e0ca633 but I'm not sure how to get suggest to run ./test-float-parse --skip-huge

@jieyouxu
Copy link
Member

jieyouxu commented Mar 4, 2025

./x suggest is mostly stale as I don't think anyone actually uses it.

@speedy-lex
Copy link
Contributor

Doesn't CI use it?

@jieyouxu
Copy link
Member

jieyouxu commented Mar 4, 2025

It does not AFAIK. It was mostly added to help local developers. #109933

I don't think it's been worked on for a while.

@speedy-lex
Copy link
Contributor

speedy-lex commented Mar 4, 2025

What's the system for registering CI commands?
Where is it? I've searched through the many.sh files and I can't find anything.

@jieyouxu
Copy link
Member

jieyouxu commented Mar 4, 2025

The CI goes through some shell wrappers x.ps1 or x.sh to invoke the x.py python wrapper1 which in turn invokes the bootstrap python wrapper bootstrap.py to build the bootstrap crate (incl. the bootstrap binary) itself, which is the build system.

What do you want to do with "registering CI commands"? CI also goes through bootstrap.

Footnotes

  1. they are to facade away platform shell/python differences.

@tgross35
Copy link
Contributor Author

tgross35 commented Mar 7, 2025

Thanks @speedy-lex for the tests, almost everything is passing (including test-float-parse!). I have a few todos to address before the final cleanup.

What's the system for registering CI commands? Where is it? I've searched through the many.sh files and I can't find anything.

Bootstrap can be set up to build a path as a crate, ./x t --stage src/etc/test-float-parse and (I think) ./x t --stage test-float-parse should work. If you search for test-float-parse within src/bootstrap it should point you to the right place, something like impl Step for TestFloatParse. These specific CI invocation is here

$(Q)$(BOOTSTRAP) test --stage 2 \
src/tools/cargo \
src/tools/cargotest \
src/etc/test-float-parse \
$(BOOTSTRAP_ARGS)

@speedy-lex
Copy link
Contributor

@tgross35, I've figured out CI on my own already but thanks for commenting.

Also, what else needs to be done before this is finished?

@tgross35
Copy link
Contributor Author

tgross35 commented Mar 7, 2025

There are a few small places where I added tests for consistency but didn’t yet update them, labeled todo:. I’ll get to them tonight, but feel free to beat me to it :)

After that this should be review-ready

check_exact!(f(f16::MIN_POSITIVE) => b"6103515625 ", -4);
check_exact!(f(minf16) => b"59604644775390625", -7);

// todo: add tables from f32 and f64
Copy link
Contributor Author

@tgross35 tgross35 Mar 8, 2025

Choose a reason for hiding this comment

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

This is the last thing remaining to do, I think it might take a bit of work to apply the algorithms from the Paxson paper to binary16. @speedy-lex have you touched this at all?

(I'm working on it, thinking the described algorithm would be good in test-float-parse)

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't really looked at it since everything was so hard to find. Have you made any progress on it so far?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made some progress but wasn't getting very good results with basically a direct implementation of the described algorithm. It's pretty complex and probably needs some thought put into it to figure out what is wrong, but I think we should be okay just leaving this as a FIXME for now.

My scratch work for reference https://github.com/tgross35/float-paxson-format-test

Copy link
Contributor

@speedy-lex speedy-lex left a comment

Choose a reason for hiding this comment

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

@tgross35, you missed some func calls when you added the target_arch stuff.

@bors
Copy link
Collaborator

bors commented Apr 2, 2025

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

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) and adds a
`FromStr` implementation.
@tgross35 tgross35 force-pushed the f16-format-parse branch 2 times, most recently from 0c4ca7c to ddeae7b Compare April 2, 2025 20:56
@tgross35 tgross35 marked this pull request as ready for review April 2, 2025 21:14
@tgross35
Copy link
Contributor Author

tgross35 commented Apr 2, 2025

I didn't manage to get the last group of tests implemented yet #127013 (comment), but everything else is passing so I think this should be mergable.

r? libs

tgross35 and others added 2 commits April 3, 2025 05:34
Extend the existing tests for `f32` and `f64` with versions that include
`f16`'s new printing and parsing implementations.

Co-authored-by: Speedy_Lex <alex.ciocildau@gmail.com>
This requires a fix to the subnormal test to cap the maximum allowed
value within the maximum mantissa.
@tgross35
Copy link
Contributor Author

tgross35 commented Apr 3, 2025

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 3, 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
Copy link
Collaborator

bors commented Apr 3, 2025

⌛ Trying commit 6f07075 with merge cbb26c3...

@bors
Copy link
Collaborator

bors commented Apr 3, 2025

☀️ Try build successful - checks-actions
Build commit: cbb26c3 (cbb26c3f0959f14f1046f01715cb0dd6a506a8cd)

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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

9 participants