Skip to content

Commit

Permalink
misc: Only use custom lround() under DISABLE_SOME_FLOATING_POINT
Browse files Browse the repository at this point in the history
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.]
  • Loading branch information
Chris Wilson committed Jan 22, 2010
1 parent 1236c41 commit c000824
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/cairo-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/cairo-ps-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions src/cairoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c000824

Please sign in to comment.