aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-11-14 15:12:53 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-11-14 15:12:53 -0500
commitfd7cb99f47e5f3dd39a9069b225d8c4ee27680e8 (patch)
tree3f188d599be05404be7a1a6d576b46044c616354
parent5a1ec817d4a1be304ad873ef839c329f8a8f6a58 (diff)
downloadkutter-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>
-rw-r--r--klippy/stepcompress.c11
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 *