From d5eb8cd9169411877805f896450b986bf1730cc5 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 27 Nov 2016 20:54:28 +0100 Subject: [PATCH] DDA: avoid looking up the movebuffer array. As we have mb_tail_dda now, that's no longer necessary. Using something like movebuffer[mb_tail] is more expensive than dereferencing mb_tail_dda directly. This is the first time we see a stepping performance improvement since introducing mb_tail_dda. 13 clock cycles faster on the slowest step, which is 9 cycles faster than before that introduction. Binary size also a nice 94 bytes down. ATmega sizes '168 '328(P) '644(P) '1280 Program: 19270 bytes 135% 63% 31% 15% Data: 2179 bytes 213% 107% 54% 27% EEPROM: 32 bytes 4% 2% 2% 1% short-moves.gcode statistics: LED on occurences: 888. LED on time minimum: 218 clock cycles. LED on time maximum: 395 clock cycles. LED on time average: 249.051 clock cycles. smooth-curves.gcode statistics: LED on occurences: 23648. LED on time minimum: 237 clock cycles. LED on time maximum: 438 clock cycles. LED on time average: 272.216 clock cycles. triangle-odd.gcode statistics: LED on occurences: 1636. LED on time minimum: 237 clock cycles. LED on time maximum: 395 clock cycles. LED on time average: 262.572 clock cycles. --- clock.c | 10 +++++----- dda.c | 4 ++-- dda_queue.c | 6 +++--- gcode_process.c | 14 +++++++------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/clock.c b/clock.c index b01b58f..01a8ab1 100644 --- a/clock.c +++ b/clock.c @@ -116,11 +116,11 @@ static void clock_250ms(void) { // target position sersendf_P(PSTR("Dst: %lq,%lq,%lq,%lq,%lu\n"), - movebuffer[mb_tail].endpoint.axis[X], - movebuffer[mb_tail].endpoint.axis[Y], - movebuffer[mb_tail].endpoint.axis[Z], - movebuffer[mb_tail].endpoint.axis[E], - movebuffer[mb_tail].endpoint.F); + mb_tail_dda->endpoint.axis[X], + mb_tail_dda->endpoint.axis[Y], + mb_tail_dda->endpoint.axis[Z], + mb_tail_dda->endpoint.axis[E], + mb_tail_dda->endpoint.F); // Queue print_queue(); diff --git a/dda.c b/dda.c index 92cf576..9ca1fe6 100644 --- a/dda.c +++ b/dda.c @@ -940,7 +940,7 @@ void dda_clock() { /// update global current_position struct void update_current_position() { - DDA *dda = &movebuffer[mb_tail]; + DDA *dda = mb_tail_dda; enum axis_e i; static const axes_uint32_t PROGMEM steps_per_m_P = { @@ -950,7 +950,7 @@ void update_current_position() { STEPS_PER_M_E }; - if (dda->live) { + if (dda != NULL) { uint32_t axis_steps, axis_um; for (i = X; i < AXIS_COUNT; i++) { diff --git a/dda_queue.c b/dda_queue.c index 93ac376..7f987c5 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -58,8 +58,8 @@ uint8_t queue_full() { /// Take a step or go to the next move. void queue_step() { - if (movebuffer[mb_tail].live) { - dda_step(&movebuffer[mb_tail]); + if (mb_tail_dda != NULL) { + dda_step(mb_tail_dda); } /** @@ -67,7 +67,7 @@ void queue_step() { This needs no atomic protection, because we're in an interrupt already. */ - if ( ! movebuffer[mb_tail].live) { + if ( ! mb_tail_dda->live) { if (mb_tail != mb_head) { mb_tail = MB_NEXT(mb_tail); mb_tail_dda = &(movebuffer[mb_tail]); diff --git a/gcode_process.c b/gcode_process.c index 5c185ca..73922c1 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -611,15 +611,15 @@ void process_gcode_command() { if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) { sersendf_P(PSTR("Endpoint: X:%ld,Y:%ld,Z:%ld,E:%ld,F:%lu,c:%lu}\n"), - movebuffer[mb_tail].endpoint.axis[X], - movebuffer[mb_tail].endpoint.axis[Y], - movebuffer[mb_tail].endpoint.axis[Z], - movebuffer[mb_tail].endpoint.axis[E], - movebuffer[mb_tail].endpoint.F, + mb_tail_dda->endpoint.axis[X], + mb_tail_dda->endpoint.axis[Y], + mb_tail_dda->endpoint.axis[Z], + mb_tail_dda->endpoint.axis[E], + mb_tail_dda->endpoint.F, #ifdef ACCELERATION_REPRAP - movebuffer[mb_tail].end_c + mb_tail_dda->end_c #else - movebuffer[mb_tail].c + mb_tail_dda->c #endif ); print_queue();