- Notifications
You must be signed in to change notification settings - Fork1k
Add print(float) to save space (VS double).#2036
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
fpistm commentedJun 7, 2023
HI@honnet |
honnet commentedJun 7, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the feedback! Sadly, with the simple accelerometer example, enabling Newlib with prinrtf takes too much space (=> linker error). ...but it says how much memory is missing so I got the following values:
As a comparison, with my PR, the space used is 27K (which is already tight for the 32K available flash). Edit - other example: For theC011 orC031 (32KB max), the following code will not compile without my PR: |
fpistm commentedJun 26, 2023
Hi@honnet |
fpistm left a comment
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.
LGTM
honnet commentedJun 26, 2023
Great! |
fpistm commentedJun 26, 2023
It is not yet merged 😉 |
honnet commentedJun 26, 2023
My bad, sorry! |
fpistm commentedJun 26, 2023
@honnet seems you rebase and removed all changes.... |
Signed-off-by: Cedric Honnet <honnet@telecom-paristech.org>Co-Authored-By: Frederic Pillon <frederic.pillon@st.com>
honnet commentedJun 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Damn, I didn't pay attention and I thought I integrated your modifications! I found a hash in my terminal history, cherry-picked it and pushed it: Does it make the PR usable now, or should I do it again? |
fpistm commentedJun 26, 2023
I will restore it tomorrow. Do nothing until I fix the issue. |
honnet commentedJun 29, 2023
I just tested a c/cpp compiler option to forbid doubles: It's even more systematic and future proof against libraries that hide implicit doubles (in constants for example). ...but I'm not sure how to make it user friendly:
Is it worth exploring something clean? (any advice would be appreciated) |
fpistm commentedJun 29, 2023
You can use |
honnet commentedJun 29, 2023
Perfect! |
Summary
This PR implements the following methods in Print.h and Print.cpp:
Motivation
Some of the new MCUs have a limited memory (ex: 32KB for STM32C011D6) and don't have floating point calculation unit, so a simple accelerometer driver (example) can take more than 100% of the flash if we don't optimize it a bit (the compilation fails at first).
This PR saves up to 10K by avoiding the compiler to use ARM libs for double calculation subroutines such as
__aeabi_dsub,__aeabi_dadd,__aeabi_dmul, etc.Validation
The following command allows listing the heaviest functions after compilation:
arm-none-eabi-nm --print-size --size-sort --radix=d -l file.elf | tail -n 3The problem can also be observed in the assembly code [with C code + comments using debug enabled (-g) if there's enough space]:
arm-none-eabi-objdump -S file.elfNote
The printFloat(float) function repeats a lot of what printFloat(double) does and it should probably be factorized.
I expect that this PR could be rejected for this reason at least, let me know if you have any suggestion of how to implement it (using templates?).