Skip to content

Consider const_float_t obsolete - #25716

Merged
thinkyhead merged 1 commit into
MarlinFirmware:bugfix-2.1.xfrom
thinkyhead:bf2_avr_const_float_PR
Sep 26, 2025
Merged

Consider const_float_t obsolete#25716
thinkyhead merged 1 commit into
MarlinFirmware:bugfix-2.1.xfrom
thinkyhead:bf2_avr_const_float_PR

Conversation

@thinkyhead

@thinkyhead thinkyhead commented Apr 20, 2023

Copy link
Copy Markdown
Member

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

ellensp commented Apr 20, 2023

Copy link
Copy Markdown
Contributor

"makes a bug difference" foreshadowing?

@thinkyhead

thinkyhead commented Apr 20, 2023

Copy link
Copy Markdown
Member Author

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 from 7e515e2 to e370838 Compare May 2, 2023 05:20
@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 from 205da4d to c8e41c4 Compare August 20, 2023 17:43
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch from c8e41c4 to 5829dea Compare October 3, 2023 21:00
@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 bf2_avr_const_float_PR branch from 56d7511 to 6f22a80 Compare January 23, 2024 00:46
@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
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch from 6f22a80 to 38903f7 Compare September 28, 2024 03:18
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch from 38903f7 to a44a62b Compare March 16, 2025 06:16
@thinkyhead
thinkyhead force-pushed the bugfix-2.1.x branch 3 times, most recently from 4354891 to efa1758 Compare March 28, 2025 01:57
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch from a44a62b to 30410e3 Compare May 19, 2025 08:22
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch 2 times, most recently from a81f4c2 to 36a146d Compare June 1, 2025 23:03
@thinkyhead thinkyhead changed the title Apply const_float_t for AVR Consider const_float_t obsolete Jun 1, 2025
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch from 36a146d to 17a87c6 Compare June 1, 2025 23:07
@thinkyhead
thinkyhead force-pushed the bugfix-2.1.x branch 3 times, most recently from 3791e7d to 6ea4a16 Compare June 2, 2025 21:51
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch from 17a87c6 to e802a20 Compare September 6, 2025 22:20
@thinkyhead
thinkyhead force-pushed the bf2_avr_const_float_PR branch from e802a20 to ee0b8be Compare September 7, 2025 03:07
@thinkyhead
thinkyhead merged commit 6f3de26 into MarlinFirmware:bugfix-2.1.x Sep 26, 2025
67 checks passed
@thinkyhead
thinkyhead deleted the bf2_avr_const_float_PR branch September 26, 2025 04:32
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