From 061924f44893245a6bdb3f1b2caa12fb26bea4b3 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Tue, 22 Nov 2016 02:20:23 +0100 Subject: [PATCH] dda_queue.c: inline a simplified version of next_move(). As we're in an interrupt already, we can simplify the test for an empty queue. Slowest step down to 446 clock cycles, another 26 ticks less. Binary size only 36 bytes up: ATmega sizes '168 '328(P) '644(P) '1280 Program: 19472 bytes 136% 64% 31% 16% Data: 2177 bytes 213% 107% 54% 27% EEPROM: 32 bytes 4% 2% 2% 1% short-moves.gcode statistics: LED on occurences: 888. LED on time minimum: 226 clock cycles. LED on time maximum: 403 clock cycles. LED on time average: 262.922 clock cycles. smooth-curves.gcode statistics: LED on occurences: 23648. LED on time minimum: 251 clock cycles. LED on time maximum: 446 clock cycles. LED on time average: 286.203 clock cycles. triangle-odd.gcode statistics: LED on occurences: 1636. LED on time minimum: 251 clock cycles. LED on time maximum: 403 clock cycles. LED on time average: 276.561 clock cycles. --- dda_queue.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dda_queue.c b/dda_queue.c index d58fb3e..d6fd180 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -83,7 +83,17 @@ void queue_step() { // Start the next move if this one is done. if ( ! movebuffer[mb_tail].live) { - next_move(); + /** + This is a simplified version of next_move() (which we'd use it it wasn't + so performance critical here). + + queue_empty() used in next_move() needs no atomic protection, because + we're in an interrupt already. + */ + if (mb_tail != mb_head) { + mb_tail = MB_NEXT(mb_tail); + dda_start(&movebuffer[mb_tail]); + } } }