[Core] Simplify audio_duration_to_ms() and audio_ms_to_duration(), reduce firmware size by a few bytes. #21427
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.
This commit simplifies
audio_duration_to_ms()andaudio_ms_to_duration()and reduces firmware size by a few bytes.Description
This commit simplifies the audio duration unit conversion functions
audio_duration_to_ms()andaudio_ms_to_duration()to reduce firmware size. While the existing code has separate implementations for AVR vs. ARM, this revision is a single shared integer implementation for both.This revision has the same accuracy and supported numerical range as before. This is verified by new unit tests added with this commit. I've also added comments with a brief math analysis to clarify when these conversions are sure to work without overflow.
This revision costs a few bytes less in firmware size.
Checked firmware size with
qmk compilebefore vs. after:Checked number of instructions with godbolt (AVR results compiled with AVR gcc 13.1.0 -Os, ARM results with ARM 32-bit gcc 13.1 -Os):
Types of Changes
Checklist