Ver código fonte

Minor optimizations to planner code

- Prefetch values used more than once
Scott Lahteine 9 anos atrás
pai
commit
af14c684b5
1 arquivos alterados com 11 adições e 12 exclusões
  1. 11
    12
      Marlin/planner.cpp

+ 11
- 12
Marlin/planner.cpp Ver arquivo

@@ -315,9 +315,8 @@ void planner_recalculate_trapezoids() {
315 315
       // Recalculate if current block entry or exit junction speed has changed.
316 316
       if (current->recalculate_flag || next->recalculate_flag) {
317 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 320
         current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
322 321
       }
323 322
     }
@@ -325,8 +324,8 @@ void planner_recalculate_trapezoids() {
325 324
   }
326 325
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
327 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 329
     next->recalculate_flag = false;
331 330
   }
332 331
 }
@@ -373,11 +372,9 @@ void plan_init() {
373 372
     uint8_t block_index = block_buffer_tail;
374 373
 
375 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 378
         if (se > high) high = se;
382 379
       }
383 380
       block_index = next_block_index(block_index);
@@ -399,14 +396,16 @@ void check_axes_activity() {
399 396
     unsigned char tail_valve_pressure = ValvePressure,
400 397
                   tail_e_to_p_pressure = EtoPPressure;
401 398
   #endif
399
+
402 400
   block_t *block;
403 401
 
404 402
   if (blocks_queued()) {
405 403
     uint8_t block_index = block_buffer_tail;
406 404
     tail_fan_speed = block_buffer[block_index].fan_speed;
407 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 409
     #endif
411 410
     while (block_index != block_buffer_head) {
412 411
       block = &block_buffer[block_index];

Carregando…
Cancelar
Salvar