Browse Source

Change parser codebits from array to int32_t

Scott Lahteine 7 years ago
parent
commit
80d3ded895
2 changed files with 18 additions and 19 deletions
  1. 2
    2
      Marlin/src/gcode/parser.cpp
  2. 16
    17
      Marlin/src/gcode/parser.h

+ 2
- 2
Marlin/src/gcode/parser.cpp View File

60
 
60
 
61
 #if ENABLED(FASTER_GCODE_PARSER)
61
 #if ENABLED(FASTER_GCODE_PARSER)
62
   // Optimized Parameters
62
   // Optimized Parameters
63
-  byte GCodeParser::codebits[4];   // found bits
63
+  uint32_t GCodeParser::codebits;  // found bits
64
   uint8_t GCodeParser::param[26];  // parameter offsets from command_ptr
64
   uint8_t GCodeParser::param[26];  // parameter offsets from command_ptr
65
 #else
65
 #else
66
   char *GCodeParser::command_args; // start of parameters
66
   char *GCodeParser::command_args; // start of parameters
83
     subcode = 0;                        // No command sub-code
83
     subcode = 0;                        // No command sub-code
84
   #endif
84
   #endif
85
   #if ENABLED(FASTER_GCODE_PARSER)
85
   #if ENABLED(FASTER_GCODE_PARSER)
86
-    ZERO(codebits);                     // No codes yet
86
+    codebits = 0;                       // No codes yet
87
     //ZERO(param);                      // No parameters (should be safe to comment out this line)
87
     //ZERO(param);                      // No parameters (should be safe to comment out this line)
88
   #endif
88
   #endif
89
 }
89
 }

+ 16
- 17
Marlin/src/gcode/parser.h View File

51
   static char *value_ptr;           // Set by seen, used to fetch the value
51
   static char *value_ptr;           // Set by seen, used to fetch the value
52
 
52
 
53
   #if ENABLED(FASTER_GCODE_PARSER)
53
   #if ENABLED(FASTER_GCODE_PARSER)
54
-    static byte codebits[4];        // Parameters pre-scanned
54
+    static uint32_t codebits;       // Parameters pre-scanned
55
     static uint8_t param[26];       // For A-Z, offsets into command args
55
     static uint8_t param[26];       // For A-Z, offsets into command args
56
   #else
56
   #else
57
     static char *command_args;      // Args start here, for slow scan
57
     static char *command_args;      // Args start here, for slow scan
88
   // Reset is done before parsing
88
   // Reset is done before parsing
89
   static void reset();
89
   static void reset();
90
 
90
 
91
-  // Index so that 'X' falls on index 24
92
-  #define PARAM_IND(N)  ((N) >> 3)
93
-  #define PARAM_BIT(N)  ((N) & 0x7)
94
-  #define LETTER_OFF(N) ((N) - 'A')
95
-  #define LETTER_IND(N) PARAM_IND(LETTER_OFF(N))
96
-  #define LETTER_BIT(N) PARAM_BIT(LETTER_OFF(N))
91
+  #define LETTER_BIT(N) ((N) - 'A')
97
 
92
 
98
   #if ENABLED(FASTER_GCODE_PARSER)
93
   #if ENABLED(FASTER_GCODE_PARSER)
99
 
94
 
100
     // Set the flag and pointer for a parameter
95
     // Set the flag and pointer for a parameter
101
     static void set(const char c, char * const ptr) {
96
     static void set(const char c, char * const ptr) {
102
-      const uint8_t ind = LETTER_OFF(c);
97
+      const uint8_t ind = LETTER_BIT(c);
103
       if (ind >= COUNT(param)) return;           // Only A-Z
98
       if (ind >= COUNT(param)) return;           // Only A-Z
104
-      SBI(codebits[PARAM_IND(ind)], PARAM_BIT(ind));        // parameter exists
99
+      SBI(codebits, ind);                        // parameter exists
105
       param[ind] = ptr ? ptr - command_ptr : 0;  // parameter offset or 0
100
       param[ind] = ptr ? ptr - command_ptr : 0;  // parameter offset or 0
106
       #if ENABLED(DEBUG_GCODE_PARSER)
101
       #if ENABLED(DEBUG_GCODE_PARSER)
107
         if (codenum == 800) {
102
         if (codenum == 800) {
108
-          SERIAL_ECHOPAIR("Set bit ", (int)PARAM_BIT(ind));
109
-          SERIAL_ECHOPAIR(" of index ", (int)PARAM_IND(ind));
110
-          SERIAL_ECHOLNPAIR(" | param = ", (int)param[ind]);
103
+          SERIAL_ECHOPAIR("Set bit ", (int)ind);
104
+          SERIAL_ECHOPAIR(" of codebits (", hex_address((void*)(codebits >> 16)));
105
+          print_hex_word((uint16_t)(codebits & 0xFFFF));
106
+          SERIAL_ECHOLNPAIR(") | param = ", (int)param[ind]);
111
         }
107
         }
112
       #endif
108
       #endif
113
     }
109
     }
115
     // Code seen bit was set. If not found, value_ptr is unchanged.
111
     // Code seen bit was set. If not found, value_ptr is unchanged.
116
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
112
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
117
     static bool seen(const char c) {
113
     static bool seen(const char c) {
118
-      const uint8_t ind = LETTER_OFF(c);
114
+      const uint8_t ind = LETTER_BIT(c);
119
       if (ind >= COUNT(param)) return false; // Only A-Z
115
       if (ind >= COUNT(param)) return false; // Only A-Z
120
-      const bool b = TEST(codebits[PARAM_IND(ind)], PARAM_BIT(ind));
121
-      if (b) value_ptr = param[ind] ? command_ptr + param[ind] : (char*)NULL;
116
+      const bool b = TEST(codebits, ind);
117
+      if (b) {
118
+        char * const ptr = command_ptr + param[ind];
119
+        value_ptr = param[ind] && valid_float(ptr) ? ptr : (char*)NULL;
120
+      }
122
       return b;
121
       return b;
123
     }
122
     }
124
 
123
 
125
-    static bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
124
+    static bool seen_any() { return !!codebits; }
126
 
125
 
127
-    #define SEEN_TEST(L) TEST(codebits[LETTER_IND(L)], LETTER_BIT(L))
126
+    #define SEEN_TEST(L) TEST(codebits, LETTER_BIT(L))
128
 
127
 
129
   #else // !FASTER_GCODE_PARSER
128
   #else // !FASTER_GCODE_PARSER
130
 
129
 

Loading…
Cancel
Save