-
Notifications
You must be signed in to change notification settings - Fork 3k
Add width modifier and prepending zeros for hexadecimal output and decimal precision for floating point #13548
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
Conversation
@EmbedEngineer, thank you for your changes. |
Please review astyle failures. |
@EmbedEngineer Thanks for the contribution, the width modifier is something I've personally wanted for while. Though any feature added increases the size of minimal printf - shall we make this feature configurable? @evedon @hugueskamba |
@EmbedEngineer That could be a great addition, do you have numbers in term of code size ? How much do we pay to print hexadecimal values with the width modifier ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes.
How does the change affect code size?
Perhaps it should be a configurable option as we do not want to increase code size for existing users.
Thanks for the PR. Like the others, I'd like to know the impact on code size. In addition could you add test for this? See https://github.com/ARMmbed/mbed-os/blob/master/platform/tests/TESTS/mbed_platform/minimal-printf/compliance/main.cpp |
@pan- @hugueskamba @evedon considering the size, I got 90 bytes more with 0s and arm gcc 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @EmbedEngineer, the code looks good in general
@EmbedEngineer This is the test for minimal-printf. Could you please extend Then the test can be run with
if you have a board connected. Thanks for the effort in so far! |
@LDong-Arm thanks. |
@LDong-Arm @evedon I finished the tests so far. Could you please review them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
platform/source/minimal-printf/README.md
also needs updating.
Done. Unfortunately I can't adapt the code sizes since I neither have an ARMC6 nor an IAR workbench compiler. |
@EmbedEngineer I tried it locally, and it uses an extra 1KB of flash with GCC and ARM compilers. I compared the latest master branch as of now vs this branch rebased onto latest master. All builds were clean builds. If I got things right, then it shows we need an extra configuration to conditionally enable/disable width and precision supports. The test looks good to me 👍 |
@LDong-Arm That's very interesting because I get 88 bytes more when i do the same thing with Thank you for looking over the test! |
8f00a96
to
ebe15a7
Compare
@LDong-Arm Could you please recheck your size calculations, because no matter what I do, I cannot find the 1kB of Flash usage. It always stays 88 bytes w/o floating points and 140 bytes with floating points, which makes kind of sense for me, since I only added about 20 lines of code. |
Sorry my bad, I checked again and the size increase is only 190 bytes with the Arm Compiler and floating point not enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good to me. But anyone thinks we need a config to enable/disable this?
*/ | ||
static void mbed_minimal_formatted_string_hexadecimal(char *buffer, size_t length, int *result, MBED_UNSIGNED_STORAGE value, FILE *stream, bool upper) | ||
static void mbed_minimal_formatted_string_hexadecimal( | ||
char *buffer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this changed to have arg on a new separate line? As the rest of the functions have it the way it was, should this be reverted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was a change request from @hugueskamba since the line got too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the contradictory comments but this change should be reverted for consistency with the rest of the file.
@EmbedEngineer That's would be great. Thanks. |
@evedon so far I think I'm finished |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, by default the tests do not run with floating points enabled. You need the following command:
mbed test -t gcc_arm -m k64f -n *minimal-printf* -vv --app-config platform/tests/TESTS/mbed_platform/minimal-printf/compliance/test_config.json
You will find that the current tests don't pass for floating point values. Look at my suggestion for a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! the implementation is correct now. Thanks for the work on this PR.
I'd suggest that you squash your commits and that @0xc0170 kicks off CI
I just noticed that the PR description needs updating, specifically the "Impact" section. Also this PR fixes #13783 so this should be added in the description |
ac250ae
to
c4f3450
Compare
@evedon I updated the pull request description and squashed the commits. |
…floating point output as well as decimal precision for floating point
c4f3450
to
03cf621
Compare
@evedon I think I'm finally done. Please let me know if there is anything else to do on this PR. Thank you for your input. I appreciated it very much. |
Code change approved but the PR description still needs updating as width modifier does not need to be an even number. Also update the "Impact" section to say what has been fixed; it is useful when we make the release notes. |
@evedon Done! |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
I did not find the test case of It seems that the |
This
Btw, thanks for raising the issue in minimal-printf! |
Summary of changes
Added width modifier and prepend zeros if the width modifier is given feature to printing integer, hexadecimal and floating point values. So e.g.
printf("%04X", i);
works now the same as the std version.Added precision specifier for printing floating point values, as it already existed for strings. If no precision specifier is given
MBED_CONF_PLATFORM_MINIMAL_PRINTF_SET_FLOATING_POINT_MAX_DECIMALS
will be used.This PR also fixes #13783.
Impact of changes
Prepending zeros and width modifier work with integer, hexadecimal and floating point values when using minimal_printf.
Also the precision modifier works for floating point variables. If no precision specifier is given
MBED_CONF_PLATFORM_MINIMAL_PRINTF_SET_FLOATING_POINT_MAX_DECIMALS
is used.Migration actions required
Documentation
None
Pull request type
Test results
Reviewers