Skip to content
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

std.fmt.formatFloat: implement 32-bit and 64-bit ryu backends #19264

Closed
tiehuis opened this issue Mar 12, 2024 · 0 comments · Fixed by #19484
Closed

std.fmt.formatFloat: implement 32-bit and 64-bit ryu backends #19264

tiehuis opened this issue Mar 12, 2024 · 0 comments · Fixed by #19484
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@tiehuis
Copy link
Member

tiehuis commented Mar 12, 2024

The ryu floating point formatting algorithm was recently added to std. This implemented only the 128-bit backend, which we use to print all floating point values: #19229

We should also consider implementing the 32-bit and 64-bit backends. At minimum, the 64-bit backend is valuable as it is much faster and reduces the large need for fast 128-bit integer support to make use of the existing backend. The 32-bit backend may be more valuable for smaller code-size specifically for embedded targets.

Upstream reference can be found at: https://github.com/ulfjack/ryu
An old (but outdated) implementation can be found at: https://github.com/tiehuis/zig-ryu

@tiehuis tiehuis added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library. labels Mar 12, 2024
@Vexu Vexu added this to the 0.13.0 milestone Mar 12, 2024
tiehuis added a commit to tiehuis/zig that referenced this issue Mar 29, 2024
The 64-bit backend supports printing all floats up to 64-bits. The
128-bit continues to be used for larger values.

This backend is approximately ~3x faster. Code size is a little smaller
in the full table case and much smaller if using the samll tables.

The implementation uses the same code-paths, parameterized by a set of
tables and their pow5 implementations. We continue to use the same
rounding/formatting mechanisms. Initially I explored a separate
implementation, as upstream does this and has specific optimizations for
these paths but for simplicity we don't. The performance loss is small
enough at this point and keeping them combined keeps them in sync.

Closes ziglang#19264.
tiehuis added a commit to tiehuis/zig that referenced this issue Mar 29, 2024
The 64-bit backend supports printing all floats up to 64-bits. The
128-bit continues to be used for larger values.

This backend is approximately ~3x faster. Code size is a little smaller
in the full table case and much smaller if using the samll tables.

The implementation uses the same code-paths, parameterized by a set of
tables and their pow5 implementations. We continue to use the same
rounding/formatting mechanisms. Initially I explored a separate
implementation, as upstream does this and has specific optimizations for
these paths but for simplicity we don't. The performance loss is small
enough at this point and keeping them combined keeps them in sync.

Closes ziglang#19264.
andrewrk pushed a commit that referenced this issue Mar 30, 2024
The 64-bit backend supports printing all floats up to 64-bits. The
128-bit continues to be used for larger values.

This backend is approximately ~3x faster. Code size is a little smaller
in the full table case and much smaller if using the samll tables.

The implementation uses the same code-paths, parameterized by a set of
tables and their pow5 implementations. We continue to use the same
rounding/formatting mechanisms. Initially I explored a separate
implementation, as upstream does this and has specific optimizations for
these paths but for simplicity we don't. The performance loss is small
enough at this point and keeping them combined keeps them in sync.

Closes #19264.
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Mar 30, 2024
Rexicon226 pushed a commit to Rexicon226/zig that referenced this issue Apr 3, 2024
The 64-bit backend supports printing all floats up to 64-bits. The
128-bit continues to be used for larger values.

This backend is approximately ~3x faster. Code size is a little smaller
in the full table case and much smaller if using the samll tables.

The implementation uses the same code-paths, parameterized by a set of
tables and their pow5 implementations. We continue to use the same
rounding/formatting mechanisms. Initially I explored a separate
implementation, as upstream does this and has specific optimizations for
these paths but for simplicity we don't. The performance loss is small
enough at this point and keeping them combined keeps them in sync.

Closes ziglang#19264.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants