From c0008242b0f162d8c7717009ba792ed61b2924d1 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 22 Jan 2010 21:35:23 +0000 Subject: [PATCH] misc: Only use custom lround() under DISABLE_SOME_FLOATING_POINT On my Core2, the library version of lround() is faster than our hand-rolled non-floating point implementation. So only enable our code if we are trying to minimise the number of floating point operations -- even then, it would worth investigating the library performance first. [Just a reminder that optimisation choices will change over time as our hardware and software evolves.] --- src/cairo-misc.c | 2 ++ src/cairo-ps-surface.c | 4 ++-- src/cairoint.h | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cairo-misc.c b/src/cairo-misc.c index 56409afc3..32c2428ce 100644 --- a/src/cairo-misc.c +++ b/src/cairo-misc.c @@ -463,6 +463,7 @@ _cairo_operator_bounded_by_either (cairo_operator_t op) } +#if DISABLE_SOME_FLOATING_POINT /* This function is identical to the C99 function lround(), except that it * performs arithmetic rounding (floor(d + .5) instead of away-from-zero rounding) and * has a valid input range of (INT_MIN, INT_MAX] instead of @@ -673,6 +674,7 @@ _cairo_lround (double d) #undef MSW #undef LSW } +#endif /* Convert a 32-bit IEEE single precision floating point number to a * 'half' representation (s10.5) diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 3e48ebbb0..b7f3aa2b7 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -880,8 +880,8 @@ _cairo_ps_surface_get_page_media (cairo_ps_surface_t *surface) page->name = strdup (page_name); } else { snprintf (buf, sizeof (buf), "%dx%dmm", - _cairo_lround (surface->width * 25.4/72), - _cairo_lround (surface->height * 25.4/72)); + (int) _cairo_lround (surface->width * 25.4/72), + (int) _cairo_lround (surface->height * 25.4/72)); page->name = strdup (buf); } diff --git a/src/cairoint.h b/src/cairoint.h index acc5769e4..9cd5cfab6 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -947,8 +947,13 @@ _cairo_round (double r) return floor (r + .5); } +#if DISABLE_SOME_FLOATING_POINT cairo_private int _cairo_lround (double d) cairo_const; +#else +#define _cairo_lround lround +#endif + cairo_private uint16_t _cairo_half_from_float (float f) cairo_const;