Skip to content

Fixed float to integer punning in nanoprintf.c #590

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

Closed
wants to merge 1 commit into from

Conversation

ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Apr 16, 2025

union-cast is UB, let compiler optimize byte-copy loop.

The compiler wasn't able to see through the byte-copy loop so it generated inefficient code.
I have fixed this by using a memcpy to perform the float to integer punning. This reduced the required stack frame from 140 to 108 bytes, which allows the code to be within the +-127 byte range of IX

@ZERICO2005
Copy link
Contributor Author

This is actually a compiler bug that only occurs at -Oz I think. -Og -O1 -O2 -O3 -Ofast -Os are able to optimize the byte copy loop correctly.

Otherwise I am looking at updating nanoprintf, the newest version adds support for %a %e %g and might be smaller?

@ZERICO2005 ZERICO2005 marked this pull request as draft May 6, 2025 19:41
@ZERICO2005
Copy link
Contributor Author

superseded by #599

@ZERICO2005 ZERICO2005 closed this May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant