Repository navigation
perf(avr): -mcall-prologues, -1022 B atmega8 flash - #185
Merged
Merged
Conversation
AVR is the tightest row in the footprint tables and the one place where a further -Os knob still pays. -mcall-prologues routes every function's register-save prologue and epilogue through libgcc's shared __prologue_saves__ / __epilogue_restores__ pair instead of emitting both inline. Measured with tools/footprint.sh, and in a linked image to net out the helper pair: Full 8572 B -> 7550 B (-1022 B, -11.9%) Full, strict UTF-8 9028 B -> 7954 B (-1074 B) Minimal 2840 B -> 2438 B ( -402 B, -14.2%) Minimal, no object.c 1952 B -> 1678 B ( -274 B, -14.0%) linked image 8980 B -> 8068 B ( -912 B) The 110 B gap between archive and image is that helper pair, which an image pays once and a firmware built with the same flag amortises. The cost is cycles, which is the trade this library makes on these parts: flash is the scarce resource, speed is subordinate. It lives next to the other size flags in the top-level CMakeLists rather than in utils/avr/toolchain-avr.cmake, so a consumer who brings their own AVR toolchain file still gets it, and is guarded on CMAKE_SYSTEM_PROCESSOR because the flag is AVR-only. `naked` functions (utils/avr/startup.c) emit no prologue and are unaffected. The equivalents on the other targets were measured and deliberately not set: RISC-V -msave-restore wins 308 B in the archive but only 56 B in a linked image, because the __riscv_save_*/__riscv_restore_* set costs 1284 B there; on ARMv6-m -fno-jump-tables (+20 B), -fno-inline-functions-called-once (+16 B), -ftree-tail-merge, -fconserve-stack, -fno-tree-switch-conversion, -fipa-pta and --param=inline-unit-growth=0 (all +-0 B) buy nothing. README: all four atmega8 rows regenerated, the hold-back reference re-measured (512 B -> 398 B on atmega8), and the flag documented, since the tables no longer reproduce from a plain -Os build. Every non-AVR figure is bit-identical, and the hosted suite stays green (5/5). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AVR is the tightest row in the footprint tables and the one place where a further
-Osknob still pays.-mcall-prologuesroutes every function's register-save prologue and epilogue through libgcc's shared__prologue_saves__/__epilogue_restores__pair instead of emitting both inline.Measured
tools/footprint.sh, plus a linked image to net out the helper pair:.textobject.cThe 110 B gap between archive and image is that helper pair, which an image pays once and a firmware built with the same flag amortises. The cost is cycles — the trade this library makes on these parts: flash is the scarce resource, speed is subordinate.
Placement
Next to the other size flags in the top-level
CMakeLists.txtrather than inutils/avr/toolchain-avr.cmake, so a consumer who brings their own AVR toolchain file still gets it. Guarded onCMAKE_SYSTEM_PROCESSORbecause the flag is AVR-only.nakedfunctions (utils/avr/startup.c) emit no prologue and are unaffected.The equivalents elsewhere were measured and deliberately not set
-msave-restore— 308 B in the archive, but only 56 B in a linked image: the__riscv_save_*/__riscv_restore_*set costs 1284 B there. Only worth it if the whole firmware carries the flag.-fno-jump-tables(+20 B),-fno-inline-functions-called-once(+16 B), and-ftree-tail-merge,-fconserve-stack,-fno-tree-switch-conversion,-fipa-pta,--param=inline-unit-growth=0(all ±0 B).README
All four atmega8 rows regenerated, the hold-back reference re-measured (512 B → 398 B on atmega8), and the flag documented — the tables no longer reproduce from a plain
-Osbuild, and that is exactly the kind of driftutils/ci/build-config.shexists to prevent.Verification
-Werror, 5/5 ctest green.atmega328p, no-DAVR_MCU) builds.alltarget fails identically with and without the flag (Catch2 needs<chrono>, which avr-libc does not have) — pre-existing and flag-independent.Not touched
Two README footprint figures are unaffected by this flag but were not re-verified here, and may have drifted from the tagged-union work: the "about 375 B of ARMv6-m
.text" skip-code claim, and the per-TU C++ wrapper table (338 / 834 / 884 / 1034 B). Neither has a harness that regenerates it.🤖 Generated with Claude Code