From 80b29b727b82b36953ca28553068c12e0cf8f3ff Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Mon, 25 Nov 2013 18:06:43 -0500 Subject: [PATCH] DDA: Move axis calculations into loops, part 7. Clean up code to reduce duplication by consolidating code into loops for per-axis actions. Part 7 is, turn update_current_position() in dda.c partially into a loop. Surprise, surprise, this changes neither binary size nor performance. Looking into the generated assembly, the loop is indeed completely unrolled. Apparently that's smaller than a real loop. SIZES ATmega... '168 '328(P) '644(P) '1280 FLASH : 20270 bytes 142% 66% 32% 16% RAM : 2302 bytes 225% 113% 57% 29% EEPROM: 32 bytes 4% 2% 2% 1% short-moves.gcode Statistics (assuming a 20 MHz clock): LED on occurences: 888. Sum of all LED on time: 279945 clock cycles. LED on time minimum: 306 clock cycles. LED on time maximum: 722 clock cycles. LED on time average: 315.253 clock cycles. smooth-curves.gcode Statistics (assuming a 20 MHz clock): LED on occurences: 9124. Sum of all LED on time: 3297806 clock cycles. LED on time minimum: 311 clock cycles. LED on time maximum: 712 clock cycles. LED on time average: 361.443 clock cycles. triangle-odd.gcode Statistics (assuming a 20 MHz clock): LED on occurences: 1636. Sum of all LED on time: 546946 clock cycles. LED on time minimum: 306 clock cycles. LED on time maximum: 712 clock cycles. LED on time average: 334.319 clock cycles. --- dda.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dda.c b/dda.c index a3b8aab..029003b 100644 --- a/dda.c +++ b/dda.c @@ -847,12 +847,12 @@ void dda_clock() { /// update global current_position struct void update_current_position() { DDA *dda = &movebuffer[mb_tail]; + enum axis_e i; if (queue_empty()) { - current_position.axis[X] = startpoint.axis[X]; - current_position.axis[Y] = startpoint.axis[Y]; - current_position.axis[Z] = startpoint.axis[Z]; - current_position.axis[E] = startpoint.axis[E]; + for (i = X; i < AXIS_COUNT; i++) { + current_position.axis[i] = startpoint.axis[i]; + } } else if (dda->live) { if (dda->x_direction)