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

Apply const_float_t for AVR #25716

Open
wants to merge 1 commit into
base: bugfix-2.1.x
Choose a base branch
from

Conversation

thinkyhead
Copy link
Member

@thinkyhead thinkyhead commented Apr 20, 2023

Since AVR has 16-bit pointers some calls and code size may be optimized using a const float& instead of a const float. Whether this makes a big difference in practice is yet to be widely tested, but this PR applies const_float_t for consistency anyway.

@ellensp
Copy link
Contributor

ellensp commented Apr 20, 2023

"makes a bug difference" foreshadowing?

@thinkyhead
Copy link
Member Author

thinkyhead commented Apr 20, 2023

foreshadowing

The cogent exploration here is whether const float & is still helpful with the most recent AVR compilers.

The old advice was that function calls are faster/smaller because it only requires 2 bytes on AVR to pass a float or long by reference, whereas passing by value requires 4 bytes. However, in order to pass a float literal by reference, the compiler must first create temporary storage, presumably outside of PROGMEM, or it may sometimes need to generate two distinct functions - one taking a value and the other taking a reference, whereas a literal passed by value can simply be embedded in the program code.

In testing the difference tonight, the code size is 90 bytes smaller using the const_float_t on AVR for the default build, but for some other builds the code size can be hundreds of bytes larger than const float. Is that due to hidden polymorphism, or due to some other factor?

An isolated test shows no apparent code size difference when passing by value or by reference, but I have not yet looked at the assembler output to compare the difference in the resulting assembler code.

If the AVR compiler has become smarter and can find the best balance of faster/smaller then the const_xxxx_t types can go away, and we can just use const float on all targets without worry. So this would be an interesting thing for Marlin contributors to look into so that we have a definite answer.

@thinkyhead thinkyhead force-pushed the bf2_avr_const_float_PR branch 5 times, most recently from 8aac7b6 to 7e515e2 Compare April 23, 2023 05:44
@thinkyhead thinkyhead force-pushed the bf2_avr_const_float_PR branch 4 times, most recently from 0306534 to 205da4d Compare August 7, 2023 08:28
@thinkyhead thinkyhead force-pushed the bf2_avr_const_float_PR branch 2 times, most recently from 1bb6412 to 56d7511 Compare October 27, 2023 20:57
@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 2 times, most recently from 9c65146 to 4f65466 Compare January 26, 2024 00:13
@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 2 times, most recently from 0f1df8b to 37d77d6 Compare September 28, 2024 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants