Browse Source

Minor optimizations to planner code

- Prefetch values used more than once
Scott Lahteine 10 years ago
parent
commit
af14c684b5
1 changed files with 11 additions and 12 deletions
  1. 11
    12
      Marlin/planner.cpp

+ 11
- 12
Marlin/planner.cpp View File

315
       // Recalculate if current block entry or exit junction speed has changed.
315
       // Recalculate if current block entry or exit junction speed has changed.
316
       if (current->recalculate_flag || next->recalculate_flag) {
316
       if (current->recalculate_flag || next->recalculate_flag) {
317
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
317
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
318
-        calculate_trapezoid_for_block(current,
319
-          current->entry_speed / current->nominal_speed,
320
-          next->entry_speed / current->nominal_speed);
318
+        float nom = current->nominal_speed;
319
+        calculate_trapezoid_for_block(current, current->entry_speed / nom, next->entry_speed / nom);
321
         current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
320
         current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
322
       }
321
       }
323
     }
322
     }
325
   }
324
   }
326
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
325
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
327
   if (next) {
326
   if (next) {
328
-    calculate_trapezoid_for_block(next, next->entry_speed/next->nominal_speed,
329
-    MINIMUM_PLANNER_SPEED/next->nominal_speed);
327
+    float nom = next->nominal_speed;
328
+    calculate_trapezoid_for_block(next, next->entry_speed / nom, MINIMUM_PLANNER_SPEED / nom);
330
     next->recalculate_flag = false;
329
     next->recalculate_flag = false;
331
   }
330
   }
332
 }
331
 }
373
     uint8_t block_index = block_buffer_tail;
372
     uint8_t block_index = block_buffer_tail;
374
 
373
 
375
     while (block_index != block_buffer_head) {
374
     while (block_index != block_buffer_head) {
376
-      if ((block_buffer[block_index].steps[X_AXIS] != 0) ||
377
-          (block_buffer[block_index].steps[Y_AXIS] != 0) ||
378
-          (block_buffer[block_index].steps[Z_AXIS] != 0)) {
379
-        float se=(float(block_buffer[block_index].steps[E_AXIS])/float(block_buffer[block_index].step_event_count))*block_buffer[block_index].nominal_speed;
380
-        //se; mm/sec;
375
+      block_t *block = &block_buffer[block_index];
376
+      if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) {
377
+        float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
381
         if (se > high) high = se;
378
         if (se > high) high = se;
382
       }
379
       }
383
       block_index = next_block_index(block_index);
380
       block_index = next_block_index(block_index);
399
     unsigned char tail_valve_pressure = ValvePressure,
396
     unsigned char tail_valve_pressure = ValvePressure,
400
                   tail_e_to_p_pressure = EtoPPressure;
397
                   tail_e_to_p_pressure = EtoPPressure;
401
   #endif
398
   #endif
399
+
402
   block_t *block;
400
   block_t *block;
403
 
401
 
404
   if (blocks_queued()) {
402
   if (blocks_queued()) {
405
     uint8_t block_index = block_buffer_tail;
403
     uint8_t block_index = block_buffer_tail;
406
     tail_fan_speed = block_buffer[block_index].fan_speed;
404
     tail_fan_speed = block_buffer[block_index].fan_speed;
407
     #ifdef BARICUDA
405
     #ifdef BARICUDA
408
-      tail_valve_pressure = block_buffer[block_index].valve_pressure;
409
-      tail_e_to_p_pressure = block_buffer[block_index].e_to_p_pressure;
406
+      block = &block_buffer[block_index];
407
+      tail_valve_pressure = block->valve_pressure;
408
+      tail_e_to_p_pressure = block->e_to_p_pressure;
410
     #endif
409
     #endif
411
     while (block_index != block_buffer_head) {
410
     while (block_index != block_buffer_head) {
412
       block = &block_buffer[block_index];
411
       block = &block_buffer[block_index];

Loading…
Cancel
Save