Closed Bug 1006597 Opened 10 years ago Closed 10 years ago

IonMonkey: Add Range Analysis to Math.floor.

Categories

(Core :: JavaScript Engine: JIT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla32

People

(Reporter: nbp, Assigned: jlevesy)

References

Details

(Whiteboard: [good first bug][mentor=nbp][lang=c++])

Attachments

(1 file, 1 obsolete file)

Range Analysis[1] is a compilation phase which consist in finding the range of int/double math expressions.  Math functions such as "Math.floor(…)", are sometime known by the compiler as MFloor[2], and they can be optimize in a similar way as we do for other math operators such as MAbs[3].

To work on this bug, you need to build SpiderMonkey shell and be able to run the test suites[4].

[1] http://dxr.mozilla.org/mozilla-central/source/js/src/jit/RangeAnalysis.cpp
[2] http://dxr.mozilla.org/mozilla-central/source/js/src/jit/MIR.h?from=MFloor
[3] http://dxr.mozilla.org/mozilla-central/search?tree=mozilla-central&q=MAbs%3A%3AcomputeRange
[4] https://wiki.mozilla.org/JavaScript:New_to_SpiderMonkey
Hello,

I will give it a try as my first bug. If I understood well, I have to implement a computeRange method for the MFloor class?

Cheers,

c0nfy
(In reply to c0nfy from comment #1)
> I will give it a try as my first bug. If I understood well, I have to
> implement a computeRange method for the MFloor class?

This is right.  The computeRange function should give us the ability to propagate the Range of the input into the result.  Currently the MIRType  is used in the Range::Range(MDefinition *) constructor to shrink the range seen by other operations, but we could improve the range seen by other operations by making a copy of the range of the input.  Later, when we have this information, we could also add a MFloor::collectRangeInfoPreTrunc() function in order to optimize the generated code, if we know that the input is always [0, INT_MAX[ or ]INT_MIN, 0].

You can use Iongraph[1] (after running, IONFLAGS=logs ./debug/js/src/dist/js my-test.js) to show the Ranges of each instructions, to make sure that your patch is working well.

[1] https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Hacking_Tips#Using_IonMonkey_spew_%28JS_shell%29
Here's a patch, implementing only operand range forwarding in range analysis,  as we discussed by mail.

I'm actually interested in continuing to optmize Math.floor, but I will need some help in order to achieve that.
Could you please tell me where to start ? And if possible some pointers to documents about how Ion actually works.
Which can help me to get a better understanding of what's going on under the hood !
Thanks :)
Attachment #8426447 - Flags: review?(nicolas.b.pierron)
Comment on attachment 8426447 [details] [diff] [review]
Implemented Range Analaysis to Math.floor

Review of attachment 8426447 [details] [diff] [review]:
-----------------------------------------------------------------

Nice, almost done ;)

::: js/src/jit/RangeAnalysis.cpp
@@ +1179,5 @@
> +MFloor::computeRange(TempAllocator &alloc)
> +{
> +    Range other(getOperand(0));
> +    Range *copy = new(alloc) Range(other);
> +    setRange(copy);

This would make a plain copy, including the potential fractional part of the input. The result of floor should not have any fractional part.

Add a function to reset the fractional part and assert for the Range invariants.
Attachment #8426447 - Flags: review?(nicolas.b.pierron) → feedback+
Here's a new version.
Created and implemented Range::resetFractionalPart() which clears the flag and call optimize()
And calls it from MFloor::computeRange.
All tests passed on my setup.
Attachment #8426447 - Attachment is obsolete: true
Attachment #8426538 - Flags: review?(nicolas.b.pierron)
Comment on attachment 8426538 [details] [diff] [review]
Implemented Range Analaysis to Math.floor

Review of attachment 8426538 [details] [diff] [review]:
-----------------------------------------------------------------

This sounds good to me.
Attachment #8426538 - Flags: review?(nicolas.b.pierron) → review+
Assignee: nobody → jlevesy
https://hg.mozilla.org/mozilla-central/rev/80bbd2f2526b
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla32
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: