From 608506719b4b3c485b8afaf52bdf1aa3c01001ac Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Thu, 30 Jul 2015 21:22:45 +0200 Subject: [PATCH] gcode_parse.h: order variables reasonably in groups of 4 bytes. This uses 4 bytes less RAM, without any loss, due to fewer holes in variable arrangements. The general strategy is simple: - Ideally, all variables are aligned in groups of 4 bytes (32 bits). This allows fastest access on 32-bit CPUs and doesn't change anything on 8 or 16 bit ones. - 1x 32-bits variable = 4 bytes = 4-byte group. - 2x 16-bits variable together = 4-byte group. - 4x 8-bits variable together = 4-byte group. - Have as few incomplete groups as possible. Another strategy is to simply order variables by size. There's a compiler flag to pack such variable arrangements, but this costs Flash size and processing time. --- gcode_parse.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gcode_parse.h b/gcode_parse.h index 3db8a84..84c4820 100644 --- a/gcode_parse.h +++ b/gcode_parse.h @@ -45,18 +45,18 @@ typedef struct { uint8_t option_inches :1; ///< inches or millimeters? }; + uint32_t N; ///< line number + uint32_t N_expected; ///< expected line number + + int32_t S; ///< S word (various uses) + uint16_t P; ///< P word (various uses) + uint8_t G; ///< G command number uint8_t M; ///< M command number TARGET target; ///< target position: X, Y, Z, E and F - int32_t S; ///< S word (various uses) - uint16_t P; ///< P word (various uses) - uint8_t T; ///< T word (tool index) - uint32_t N; ///< line number - uint32_t N_expected; ///< expected line number - uint8_t checksum_read; ///< checksum in gcode command uint8_t checksum_calculated; ///< checksum we calculated } GCODE_COMMAND;