Closed Bug 740096 Opened 13 years ago Closed 5 months ago

IonMonkey: Demote fdivs to idivs when inputs are int32s and result is floored or truncated

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect

Tracking

()

RESOLVED WONTFIX

People

(Reporter: djvj, Unassigned)

Details

(Whiteboard: [ion:t])

Attachments

(1 file)

In expressions such as 'Math.floor(i/j)', '(i/j)>>x', and '(i/j)&x' where 'i' and 'j' are integers, but the result of the division may be non-integer, Ion currently promotes i and j to doubles, and then does a floating point divide, followed by a truncate or round as appropriate. These operations can be simplified in the case of result-truncation by removing any incoming ToDoubles, and converting any incoming Constant doubles to Constant int32s, and then using integer division to generate an auto-truncated result. These operations can be simplified in the case of result-flooring by doing a quick adjustment of the truncated result after an integer divmod.
Attached file Not-quite-ready patch
This patch is not quite ready for prime time. It only generates code on x86 and x64 architectures, which means that it generates INCORRECT code on ARM. Also, it doesn't show any gains on benches. It does show a 40% gain on the following microbench: var V=3; function foo(i) { return ((i / 9)>>V) + ((i / 10)>>V); } var sum = 0; for(var i = 0; i < 1000 * 1000 * 300; i++) { sum += foo(i); } print("SCRIPTOUT: " + sum); This patch might be more relevant in the future when its gains on real code are more apparent, and it can be fixed up and thrown in, but right now it's here for holding for future-reference purposes.
Assignee: general → nobody
Severity: normal → S3
Status: NEW → RESOLVED
Closed: 5 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: