-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
optimisation: stepper: make dda_isteps_t
an array
#4427
Conversation
All values in bytes. Δ Delta to base
|
28af1d6
to
3653dda
Compare
This way we can loop through it with a for-loop and save some code size
3653dda
to
f6737d2
Compare
counter_z.lo = counter_x.lo; | ||
counter_e.lo = counter_x.lo; | ||
const int16_t value = -(current_block->step_event_count.lo >> 1); | ||
for (uint8_t axis = 0; axis < NUM_AXIS; axis++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can even iterate from the back which saves 2-4 bytes more
for (uint8_t axis = NUM_AXIS-1; axis >=0 ; --axis){
counter[axis].lo = value;
}
Caches and memory ordering is not an issue on the AVR IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about this, using postdecrementation :
for (uint8_t axis = NUM_AXIS; axis-- ; ){
counter[axis].lo = value;
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petrubecheru Thanks but compiling with PF-build.sh
the usage of Flash and RAM are the same before and after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 most of the savings in this PR come from setting counter_*
variables in loops. The rest is just a mechanical rewrite to match the proposed "array" principle.
I'm surprised that the compiler understood the intent and actually saved something while not breaking the rest of the code.
This way we can loop through it with a for-loop
and save some code size