[gegl] buffer: use inlinable alternative to fabsf in cubic resampler
- From: Øyvind "pippin" Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: use inlinable alternative to fabsf in cubic resampler
- Date: Wed, 13 May 2020 01:01:36 +0000 (UTC)
commit 275d237dd6abd04328ec6a29c08c0ef652b6b324
Author: Øyvind Kolås <pippin gimp org>
Date: Wed May 13 02:52:01 2020 +0200
buffer: use inlinable alternative to fabsf in cubic resampler
We do not need to worry about NaNs which would bloat an inlinable
version from math.h. By using an inlinable version that only ensures the
sign bit is positive. The savings might be 8 function calls per pixels.
The difference is large enough that when rotating a 4770x3177 image 1.0
degrees 4 times in a row, user time spent drops from 6.3s to 5.6s, and
wall-clock time from 1.9s to 1.8s (including GEGL startup, jpeg decoding
and ppm saving).
gegl/buffer/gegl-sampler-cubic.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index 9beacd227..2f0c1b31d 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -281,22 +281,29 @@ set_property (GObject *object,
}
}
+static inline gfloat int_fabsf (const gfloat x)
+{
+ union {gfloat f; guint32 i;} u = {x};
+ u.i &= 0x7fffffff;
+ return u.f;
+}
+
static inline gfloat
cubicKernel (const gfloat x,
const gfloat b,
const gfloat c)
{
const gfloat x2 = x*x;
- const gfloat ax = fabsf (x);
+ const gfloat ax = int_fabsf (x);
- if (x2 <= (gfloat) 1.) return ( (gfloat) ((12-9*b-6*c)/6) * ax +
+ if (x2 <= (gfloat) 1.f) return ( (gfloat) ((12-9*b-6*c)/6) * ax +
(gfloat) ((-18+12*b+6*c)/6) ) * x2 +
(gfloat) ((6-2*b)/6);
- if (x2 < (gfloat) 4.) return ( (gfloat) ((-b-6*c)/6) * ax +
+ if (x2 < (gfloat) 4.f) return ( (gfloat) ((-b-6*c)/6) * ax +
(gfloat) ((6*b+30*c)/6) ) * x2 +
(gfloat) ((-12*b-48*c)/6) * ax +
(gfloat) ((8*b+24*c)/6);
- return (gfloat) 0.;
+ return (gfloat) 0.f;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]