Closed Bug 421761 Opened 16 years ago Closed 14 years ago

Use multiplication instead of division for gfxRGBA (gfxColor.h)

Categories

(Core :: Graphics, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.3a1

People

(Reporter: mmoy, Assigned: mmoy)

Details

Attachments

(1 file)

The first set of divides below gets called moderately (5K times logging into
gmail and reading a few emails) and changing the [/ 255.0] to [* (1.0 / 255.0)] results in a multiply instruction instead of a divide instruction on Win32 at -O1 optimization. Floating point divides typically take several times as long as floating point multiplies.

    gfxRGBA(PRUint32 c, PackedColorType colorType = PACKED_ABGR) {
        if (colorType == PACKED_ABGR ||
            colorType == PACKED_XBGR ||
            colorType == PACKED_ABGR_PREMULTIPLIED)
        {
            r = ((c >> 0) & 0xff) / 255.0;
            g = ((c >> 8) & 0xff) / 255.0;
            b = ((c >> 16) & 0xff) / 255.0;
            a = ((c >> 24) & 0xff) / 255.0;
        } else if (colorType == PACKED_ARGB ||
                   colorType == PACKED_XRGB ||
                   colorType == PACKED_ARGB_PREMULTIPLIED)
        {
            b = ((c >> 0) & 0xff) / 255.0;
            g = ((c >> 8) & 0xff) / 255.0;
            r = ((c >> 16) & 0xff) / 255.0;
            a = ((c >> 24) & 0xff) / 255.0;
        }
Product: Core → Core Graveyard
Component: GFX → Graphics
Product: Core Graveyard → Core
QA Contact: general → thebes
Attachment #308253 - Flags: superreview?(vladimir)
Attachment #308253 - Flags: review?(jmuizelaar)
Attachment #308253 - Flags: superreview?(vladimir) → superreview?(joe)
Comment on attachment 308253 [details] [diff] [review]
Change divisions to multiply

This patch doesn't really need sr.

I can't think of any fp precision issues that can result from this, so looks good on my end!
Attachment #308253 - Flags: superreview?(joe) → review+
Keywords: checkin-needed
Attachment #308253 - Flags: review?(jmuizelaar)
Comment on attachment 308253 [details] [diff] [review]
Change divisions to multiply

Should've mentioned that I still want Jeff to look at it, because he is very smart.
Attachment #308253 - Flags: review?(jmuizelaar)
Comment on attachment 308253 [details] [diff] [review]
Change divisions to multiply

I don't know that the performance of this code really matters and the new code is less clear. Still it doesn't really hurt either and does save a couple of cycles so why not.
Attachment #308253 - Flags: review?(jmuizelaar) → review+
Keywords: checkin-needed
http://hg.mozilla.org/mozilla-central/rev/69bcd1261933
Status: NEW → RESOLVED
Closed: 14 years ago
Keywords: checkin-needed
OS: Windows XP → All
Hardware: x86 → All
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a1
You need to log in before you can comment on or make changes to this bug.