Fix asm::delay() variability due to alignment #587
Merged
+4
−0
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.
While testing a new clocking API in atsamd-rs, we encountered a very strange behaviour which took some time to track down - seemingly innocuous changes (eg, enabling features that weren't used by the firmware, or adding a debug call) would result in wildly different execution speed of a test program. In the context of testing at a new clocking API, at least two of us assumed the issue was down to the clock speed changing, but in fact it was the number of cycles of delay we were getting for calls to
asm::delay()
. This turns out to be a result of the Cortex-M4 taking a variable number of cycles to execute a conditional branch, based on the alignment of the target.Although the method is strictly conforming to the documentation by delaying /at least/ N cycles, the sensitivity to alignment is quite surprising. This PR aligns the loop target, to remove this surprising behaviour.
Resolves part of #151