stepcompress: Optimize push_delta_const() for common XY or Z only moves

Most moves are on the XY plane - avoid a few multiplications in the
inner loop in this case.  When there is a Z move, it is almost always
entirely a Z move - avoid the sqrt() call in the inner loop in this
case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-12-05 13:45:39 -05:00
parent 9c932ad514
commit 4565a73e91
1 changed files with 25 additions and 6 deletions

View File

@ -465,6 +465,24 @@ stepcompress_push_delta_const(
clock_offset += 0.5;
start_pos += movexy_r*closestxy_d;
height += .5 * step_dist;
if (!movez_r) {
// Optmized case for common XY only moves (no Z movement)
while (qn < end) {
double v = safe_sqrt(closest_height2 - height*height);
double pos = start_pos + (step_dist > 0. ? -v : v);
*qn++ = clock_offset + pos * inv_velocity;
height += step_dist;
}
} else if (!movexy_r) {
// Optmized case for Z only moves
double v = (step_dist > 0. ? -end_height : end_height);
while (qn < end) {
double pos = start_pos + movez_r*height + v;
*qn++ = clock_offset + pos * inv_velocity;
height += step_dist;
}
} else {
// General case (handles XY+Z moves)
while (qn < end) {
double relheight = movexy_r*height - movez_r*closestxy_d;
double v = safe_sqrt(closest_height2 - relheight*relheight);
@ -472,6 +490,7 @@ stepcompress_push_delta_const(
*qn++ = clock_offset + pos * inv_velocity;
height += step_dist;
}
}
sc->queue_next = qn;
return step_dist > 0. ? count : -count;
}