[cairo] Reduce number of floating point operations
Behdad Esfahbod
behdad at behdad.org
Wed Sep 20 10:36:06 PDT 2006
[CCing cairo list back]
On Wed, 2006-09-20 at 20:03 +0000, Aivars Kalvans wrote:
> Behdad Esfahbod wrote:
> > Hi Aivars,
> >
> > I like most of your patch. Comments below:
> >
> > On Thu, 2006-09-14 at 18:30 -0400, Aivars Kalvans wrote:
> >
> >> _cairo_matrix_is_identity (const cairo_matrix_t *matrix)
> >> {
> >> +#if defined (__arm__)
> >>
> >
> > We should do something about this. Either a configure test or option to
> > detect FPU, or hardcode one way or the other. Anybody sees any reason
> > why hardcoding memcmp is a bad idea?
> >
> No real reason, it should be memcmp.
> (I was thinking about 4 fp instructions vs. function call, but compiler
> should be able to inline this)
The inlined memcmp is faster on all systems.
> >> + /* memcmp() should be faster than 4 soft float operations */
> >> + static const cairo_matrix_t identity = {
> >> + 1.0, 0.0,
> >> + 0.0, 1.0,
> >> + 0.0, 0.0
> >> + };
> >> + return (memcmp (matrix, &identity, 4 * sizeof(double)) == 0);
> >> +#else
> >> return (matrix->xx == 1.0 && matrix->yx == 0.0 &&
> >> - matrix->xy == 0.0 && matrix->yy == 1.0 &&
> >> - matrix->x0 == 0.0 && matrix->y0 == 0.0);
> >> + matrix->xy == 0.0 && matrix->yy == 1.0);
> >> +#endif
> >>
> >
> > Why is it called is_identity if it doesn't check for translation?
> >
> According to wikipedia (http://en.wikipedia.org/wiki/Identity_matrix)
> identity matrix is n x n, so third row in cairo_matrix_t actually is a
> translation vector.
Right, so the wikipedia article just confirms that a 6-item matrix
cannot be identity. However, it can be an identity transformation:
http://en.wikipedia.org/wiki/Identity_transform
and that's most of the time what the intention is.
As for your case, I suggest cairo_matrix_is_translation().
--
behdad
http://behdad.org/
"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
-- Dan Bern, "New American Language"
More information about the cairo
mailing list