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

RESOLVED FIXED in mozilla1.9.3a1

Status

()

Core
Graphics
RESOLVED FIXED
9 years ago
8 years ago

People

(Reporter: Michael Moy, Assigned: Michael Moy)

Tracking

Trunk
mozilla1.9.3a1
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

1.76 KB, patch
Joe Drew (not getting mail)
: review+
jrmuizel
: review+
Details | Diff | Splinter Review
(Assignee)

Description

9 years ago
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;
        }
(Assignee)

Comment 1

9 years ago
Created attachment 308253 [details] [diff] [review]
Change divisions to multiply
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)
Keywords: checkin-needed
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
Last Resolved: 8 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.