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

use -mrelax optimization to save flash #141

Closed
SpenceKonde opened this issue Feb 24, 2022 · 1 comment
Closed

use -mrelax optimization to save flash #141

SpenceKonde opened this issue Feb 24, 2022 · 1 comment

Comments

@SpenceKonde
Copy link
Contributor

The -mrelax option can be passed to the toolchain and should be.

This instructs the linker to, where possible, replace full size jmp's with rjmps and full size call's with rcall.

Each replacement it can make (after the vector table) gets an extra word of flash back for the application and saves 1 clock cycle of execution time.. In the case of the vectors, when the ISR is placed such that it can be reached with an rjmp, this means 1 fewer clock cycles before the ISR starts executing, as well. This is a safe optimization option and has been in use on DxCore and megaTinyCore for some months now without issue (I was honestly rather taken aback when I realized it was ever not being used).

In practice, this seems to trigger additional reshuffling of routines within the flash at linktime, and frequently results in greater flash savings than can be accounted for with just the number of jumps replaced with rjmps.

MCUdude added a commit that referenced this issue Mar 16, 2022
@SpenceKonde
Copy link
Contributor Author

Are you seeing the same scale of improvement in binary size that I do?

Apparently te only reason that it was optional is that in the distant past, it wasn't always safe in all situations, has been for several versions of GCC, but it was never made default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant