diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-11-14 15:12:53 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-11-14 15:12:53 -0500 |
commit | fd7cb99f47e5f3dd39a9069b225d8c4ee27680e8 (patch) | |
tree | 3f188d599be05404be7a1a6d576b46044c616354 /klippy/stepcompress.c | |
parent | 5a1ec817d4a1be304ad873ef839c329f8a8f6a58 (diff) | |
download | kutter-fd7cb99f47e5f3dd39a9069b225d8c4ee27680e8.tar.gz kutter-fd7cb99f47e5f3dd39a9069b225d8c4ee27680e8.tar.xz kutter-fd7cb99f47e5f3dd39a9069b225d8c4ee27680e8.zip |
stepcompress: Optimize safe_sqrt() code
Optimize the code by putting the uncommon case out-of-line.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/stepcompress.c')
-rw-r--r-- | klippy/stepcompress.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/klippy/stepcompress.c b/klippy/stepcompress.c index 992155d2..afd9886b 100644 --- a/klippy/stepcompress.c +++ b/klippy/stepcompress.c @@ -256,16 +256,21 @@ check_line(struct stepcompress *sc, struct step_move move) * Step compress interface ****************************************************************/ +#define likely(x) __builtin_expect(!!(x), 1) + // Wrapper around sqrt() to handle small negative numbers -static inline double -safe_sqrt(double v) +static double +_safe_sqrt(double v) { - if (v < 0. && v > -0.001) + if (v > -0.001) // Due to floating point truncation, it's possible to get a // small negative number - treat it as zero. return 0.; return sqrt(v); } +static inline double safe_sqrt(double v) { + return likely(v >= 0.) ? sqrt(v) : _safe_sqrt(v); +} // Allocate a new 'stepcompress' object struct stepcompress * |