-
Notifications
You must be signed in to change notification settings - Fork 1k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
HI @honnet |
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 the C011 or C031 (32KB max), the following code will not compile without my PR: |
Hi @honnet |
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
Great! |
It is not yet merged 😉 |
My bad, sorry! |
@honnet seems you rebase and removed all changes.... |
Signed-off-by: Cedric Honnet <[email protected]> Co-Authored-By: Frederic Pillon <[email protected]>
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? |
I will restore it tomorrow. Do nothing until I fix the issue. |
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) |
You can use |
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 3
The 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.elf
Note
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?).