Bug 7497 - _cairo_color_compute_shorts fails with FPU set to single precision
Summary: _cairo_color_compute_shorts fails with FPU set to single precision
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 1.2.1
Hardware: x86 (IA32) Windows (All)
: high blocker
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 8550
  Show dependency treegraph
 
Reported: 2006-07-12 01:22 UTC by Sebastian Tusk
Modified: 2006-10-16 09:27 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
proposed patch (4.24 KB, patch)
2006-08-01 19:20 UTC, Behdad Esfahbod
Details | Splinter Review
correct patch (4.74 KB, patch)
2006-08-01 21:40 UTC, Behdad Esfahbod
Details | Splinter Review

Description Sebastian Tusk 2006-07-12 01:22:57 UTC
On a Intel Pentium 4 CPU the function _cairo_color_compute_shorts has a bug if
the FPU is set to single precision mode. I guess that this problem occurs on
other CPUs as well.

The reason for this is found in this line:
#define CAIRO_COLOR_ONE_MINUS_EPSILON (65536.0 - 1e-5)

(65536.0 - 1e-5) is so close to 65536 that in single precision mode it
essentially becomes 65536. If one of the color channels is set to 1 this leads
to a short value of 0x10000 which is shortened to 0.

My temporary fix is to use
#define CAIRO_COLOR_ONE_MINUS_EPSILON (65536.0 - 1e-2)
Comment 1 Behdad Esfahbod 2006-07-12 01:33:54 UTC
Good catch.  Can be committed IMO.
Comment 2 Carl Worth 2006-07-12 06:56:07 UTC
I'd prefer this change to be discussed on the cairo mailing list before any
change is made. We've had subtle bugs in this area before, so caution is called for.

-Carl
Comment 3 Behdad Esfahbod 2006-07-15 18:34:09 UTC
I confirmed that changing to 1e-2, the image surface still passes the test suite.
Comment 4 Behdad Esfahbod 2006-07-31 14:45:11 UTC
*** Bug 7712 has been marked as a duplicate of this bug. ***
Comment 5 Sam Sirlin 2006-07-31 15:14:53 UTC
The fix given does not help bug 7712, on sparc solaris. To fix that I did

/* Try to recover a cairo_format_t from a pixman_format
 * by looking at the bpp and masks values. */
static cairo_format_t
_cairo_format_from_pixman_format (pixman_format_t *pixman_format)
{
    int bpp, am, rm, gm, bm;

    pixman_format_get_masks (pixman_format, &bpp, &am, &rm, &gm, &bm);

    /*fprintf(stderr, "[sws cairo] bpp %d\n", bpp);*/

    switch (bpp) {
    case 32:
	if (am == 0xff000000 &&
	    rm == 0x00ff0000 &&
	    gm == 0x0000ff00 &&
	    bm == 0x000000ff)
	    return CAIRO_FORMAT_ARGB32;
	if (am == 0x0 &&
	    rm == 0x00ff0000 &&
	    gm == 0x0000ff00 &&
	    bm == 0x000000ff)
	    return CAIRO_FORMAT_RGB24;

        /* sws try this rather than crash */
        fprintf(stderr, "[sws cairo] bpp %d, falling through!\n", bpp);
        return CAIRO_FORMAT_RGB24;

I see the error printout here, but mozilla, firefox now work fine.
Comment 6 Behdad Esfahbod 2006-07-31 15:20:46 UTC
Sam, I'm really sorry.  I dupped to the wrong bug.  It's fixed now.  Please
resubmit your comment to bug #7294.
Comment 7 Behdad Esfahbod 2006-07-31 15:22:21 UTC
Carl,

I raised this on the list:

http://lists.freedesktop.org/archives/cairo/2006-July/007449.html

with no response.  Should we fix this now?
Comment 8 Carl Worth 2006-07-31 15:50:13 UTC
(In reply to comment #7)
> Carl,
> 
> I raised this on the list:
> 
> http://lists.freedesktop.org/archives/cairo/2006-July/007449.html
> 
> with no response.  Should we fix this now?

Not yet. I've got a reply to make, but I need to draw some pictures first.

-Carl
Comment 9 Behdad Esfahbod 2006-08-01 19:20:53 UTC
Created attachment 6425 [details] [review]
proposed patch

Ok, using float.h to use the best epsilon possible.  It uses DBL_EPSILON if
it's defined, and 1e-7 otherwise.  1e-7 should work on 32bit float too.

Can you check that this solves your problem?
Comment 10 Behdad Esfahbod 2006-08-01 19:22:02 UTC
Lets not fix this in the 1.2.x.
Comment 11 Behdad Esfahbod 2006-08-01 21:40:30 UTC
Created attachment 6428 [details] [review]
correct patch

Same patch, using floor() instead of relying of the FPU rounding down.
Comment 12 Behdad Esfahbod 2006-10-16 06:36:22 UTC
This was extensively discussed here:

http://lists.freedesktop.org/archives/cairo/2006-August/007709.html

With proposed solution about here:

http://lists.freedesktop.org/archives/cairo/2006-August/007718.html

and an alternative solution here:

http://lists.freedesktop.org/archives/cairo/2006-August/007732.html

And finally, a dup here:

http://lists.freedesktop.org/archives/cairo/2006-October/008181.html

I think we can go with the first solution.  I can push it in.  Carl?
Comment 13 Carl Worth 2006-10-16 09:27:04 UTC
(In reply to comment #12)
> With proposed solution about here:
> 
> http://lists.freedesktop.org/archives/cairo/2006-August/007718.html
...
> I think we can go with the first solution.  I can push it in.  Carl?

Behdad,

Thanks for digging up all the old history on this---and sorry you had to do
that. We had done all the work, but somehow I hadn't pushed out the branch, (I
had one created with the correct fix sitting on it). I've pushed the fix out now:

http://gitweb.freedesktop.org/?p=cairo;a=commit;h=b62710d4f8602203d848daf2d444865b611fff09

-Carl



Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.