Browse Source

Optimize seen_axis by moving 'X' to index 24

Scott Lahteine 7 years ago
parent
commit
bd776df8c1
1 changed files with 29 additions and 15 deletions
  1. 29
    15
      Marlin/gcode.h

+ 29
- 15
Marlin/gcode.h View File

97
   // Reset is done before parsing
97
   // Reset is done before parsing
98
   static void reset();
98
   static void reset();
99
 
99
 
100
+  // Index so that 'X' falls on index 24
101
+  #define PARAM_IND(N)  ((N) >> 3)
102
+  #define PARAM_BIT(N)  ((N) & 0x7)
103
+  #define LETTER_OFF(N) ((N) - 'A' + 1)
104
+  #define LETTER_IND(N) PARAM_IND(LETTER_OFF(N))
105
+  #define LETTER_BIT(N) PARAM_BIT(LETTER_OFF(N))
106
+
100
   #if ENABLED(FASTER_GCODE_PARSER)
107
   #if ENABLED(FASTER_GCODE_PARSER)
101
 
108
 
102
     // Set the flag and pointer for a parameter
109
     // Set the flag and pointer for a parameter
105
         , const bool debug=false
112
         , const bool debug=false
106
       #endif
113
       #endif
107
     ) {
114
     ) {
108
-      const uint8_t ind = c - 'A';
115
+      const uint8_t ind = LETTER_OFF(c);
109
       if (ind >= COUNT(param)) return;           // Only A-Z
116
       if (ind >= COUNT(param)) return;           // Only A-Z
110
-      SBI(codebits[ind >> 3], ind & 0x7);        // parameter exists
117
+      SBI(codebits[PARAM_IND(ind)], PARAM_BIT(ind));        // parameter exists
111
       param[ind] = ptr ? ptr - command_ptr : 0;  // parameter offset or 0
118
       param[ind] = ptr ? ptr - command_ptr : 0;  // parameter offset or 0
112
       #if ENABLED(DEBUG_GCODE_PARSER)
119
       #if ENABLED(DEBUG_GCODE_PARSER)
113
         if (debug) {
120
         if (debug) {
114
-          SERIAL_ECHOPAIR("Set bit ", (int)(ind & 0x7));
115
-          SERIAL_ECHOPAIR(" of index ", (int)(ind >> 3));
121
+          SERIAL_ECHOPAIR("Set bit ", (int)PARAM_BIT(ind));
122
+          SERIAL_ECHOPAIR(" of index ", (int)PARAM_IND(ind));
116
           SERIAL_ECHOLNPAIR(" | param = ", hex_address((void*)param[ind]));
123
           SERIAL_ECHOLNPAIR(" | param = ", hex_address((void*)param[ind]));
117
         }
124
         }
118
       #endif
125
       #endif
120
 
127
 
121
     // Code seen bit was set. If not found, value_ptr is unchanged.
128
     // Code seen bit was set. If not found, value_ptr is unchanged.
122
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
129
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
130
+    // This is volatile because its side-effects are important
123
     static volatile bool seen(const char c) {
131
     static volatile bool seen(const char c) {
124
-      const uint8_t ind = c - 'A';
132
+      const uint8_t ind = LETTER_OFF(c);
125
       if (ind >= COUNT(param)) return false; // Only A-Z
133
       if (ind >= COUNT(param)) return false; // Only A-Z
126
-      const bool b = TEST(codebits[ind >> 3], ind & 0x7);
134
+      const bool b = TEST(codebits[PARAM_IND(ind)], PARAM_BIT(ind));
127
       if (b) value_ptr = command_ptr + param[ind];
135
       if (b) value_ptr = command_ptr + param[ind];
128
       return b;
136
       return b;
129
     }
137
     }
130
 
138
 
131
-    static volatile bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
139
+    static bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
140
+
141
+    #define SEEN_TEST(L) TEST(codebits[LETTER_IND(L)], LETTER_BIT(L))
132
 
142
 
133
-    #define SEEN_TEST(L) TEST(codebits[(L - 'A') >> 3], (L - 'A') & 0x7)
143
+    // Seen any axis parameter
144
+    // Optimized by moving 'X' up to index 24
145
+    FORCE_INLINE bool seen_axis() { return codebits[3] || SEEN_TEST('E'); }
134
 
146
 
135
   #else // !FASTER_GCODE_PARSER
147
   #else // !FASTER_GCODE_PARSER
136
 
148
 
137
     // Code is found in the string. If not found, value_ptr is unchanged.
149
     // Code is found in the string. If not found, value_ptr is unchanged.
138
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
150
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
151
+    // This is volatile because its side-effects are important
139
     static volatile bool seen(const char c) {
152
     static volatile bool seen(const char c) {
140
       const char *p = strchr(command_args, c);
153
       const char *p = strchr(command_args, c);
141
       const bool b = !!p;
154
       const bool b = !!p;
143
       return b;
156
       return b;
144
     }
157
     }
145
 
158
 
146
-    static volatile bool seen_any() { return *command_args == '\0'; }
159
+    static bool seen_any() { return *command_args == '\0'; }
147
 
160
 
148
     #define SEEN_TEST(L) !!strchr(command_args, L)
161
     #define SEEN_TEST(L) !!strchr(command_args, L)
149
 
162
 
163
+    // Seen any axis parameter
164
+    static bool seen_axis() {
165
+      return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
166
+    }
167
+
150
   #endif // !FASTER_GCODE_PARSER
168
   #endif // !FASTER_GCODE_PARSER
151
 
169
 
152
   // Populate all fields by parsing a single line of GCode
170
   // Populate all fields by parsing a single line of GCode
153
   // This uses 54 bytes of SRAM to speed up seen/value
171
   // This uses 54 bytes of SRAM to speed up seen/value
154
   static void parse(char * p);
172
   static void parse(char * p);
155
 
173
 
156
-  // Code value pointer was set
174
+  // The code value pointer was set
157
   FORCE_INLINE static bool has_value() { return value_ptr != NULL; }
175
   FORCE_INLINE static bool has_value() { return value_ptr != NULL; }
158
 
176
 
159
-  // Seen and has value
177
+  // Seen a parameter with a value
160
   inline static bool seenval(const char c) { return seen(c) && has_value(); }
178
   inline static bool seenval(const char c) { return seen(c) && has_value(); }
161
 
179
 
162
-  static volatile bool seen_axis() {
163
-    return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
164
-  }
165
-
166
   // Float removes 'E' to prevent scientific notation interpretation
180
   // Float removes 'E' to prevent scientific notation interpretation
167
   inline static float value_float() {
181
   inline static float value_float() {
168
     if (value_ptr) {
182
     if (value_ptr) {

Loading…
Cancel
Save