Closed
Bug 934174
Opened 11 years ago
Closed 11 years ago
Optimize the interpreter's int32 add
Categories
(Core :: JavaScript Engine, enhancement)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla28
People
(Reporter: sunfish, Assigned: sunfish)
Details
(Whiteboard: [qa-])
Attachments
(1 file)
1002 bytes,
patch
|
luke
:
review+
|
Details | Diff | Splinter Review |
This patch optimizes the int32 + int32 path to do an int32 add, to avoid going through floating-point in the common case.
Attachment #826365 -
Flags: review?(luke)
Comment 1•11 years ago
|
||
Comment on attachment 826365 [details] [diff] [review] interp-add.patch Makes sense.
Attachment #826365 -
Flags: review?(luke) → review+
Comment 2•11 years ago
|
||
As long as you're optimizing interp add and we have SafeAdd to abstract the grossness, you might consider trying alternative overflow tests: http://hg.mozilla.org/mozilla-central/rev/9c869e64ee26#l89.2964 I suppose it depends on how smart the compiler is about 64-bit int addition (my experience looking at GCC output a few years ago left me unimpressed). (Yes, that code also has the signed-overflow UB you just reported on SafeAdd; uint32_t should work.) Alternatively, I keep expecting there to be some compiler builtin bool __add_with_overflow(int32 lhs,int32 rhs,int32 *result) that returns whether the addition overflowed so that we could take advantage of the overflow bit that the compiler already sets, but every time I go looking I can't find one. Do you know of one?
Comment 3•11 years ago
|
||
s/the compiler already sets/the processor already sets/
Comment 4•11 years ago
|
||
(In reply to Luke Wagner [:luke] from comment #2) > As long as you're optimizing interp add and we have SafeAdd to abstract the > grossness, you might consider trying alternative overflow tests: > http://hg.mozilla.org/mozilla-central/rev/9c869e64ee26#l89.2964 > I suppose it depends on how smart the compiler is about 64-bit int addition > (my experience looking at GCC output a few years ago left me unimpressed). Do you remember what sort of problems you saw? > Alternatively, I keep expecting there to be some compiler builtin > bool __add_with_overflow(int32 lhs,int32 rhs,int32 *result) > that returns whether the addition overflowed so that we could take advantage > of the overflow bit that the compiler already sets, but every time I go > looking I can't find one. Do you know of one? clang might have it; I know they have one for multiplication. GCC does not.
Comment 5•11 years ago
|
||
(In reply to Nathan Froyd (:froydnj) from comment #4) > Do you remember what sort of problems you saw? IIRC, it was on x86 (x64 was fine, as you might hope :) and I just noticed a ton of what seemed like unnecessary spilling as the int64 values got moved around.
Comment 6•11 years ago
|
||
Also, and this might have been an issue with structs, not int64, but after the move to 64-bit js::Value (which was/is a 64-bit struct), we found more than a few perf regressions where the fix was to transform a loop of the form: for (int i = 0; i < N; i++) dst[i] = src[i] into for (Value *dstp = dst, *srcp = src, *srcend = src + N; srcp != srcend; srcp++, dstp++) *dstp = *srcp; because either the struct or 64-bit-ness was throwing off all the normal optimizations that usually allow us to write the former w/o loss of performance.
Assignee | ||
Comment 7•11 years ago
|
||
Yeah, clang does have builtin functions for these. And yeah, that thing with the xors looks like a pretty good alternative. Next time I take another look at interpreter performance, I'll take a look, though I don't know when that'll be.
Assignee | ||
Comment 8•11 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/d0cad525a6b4
https://hg.mozilla.org/mozilla-central/rev/d0cad525a6b4
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28
Updated•10 years ago
|
Whiteboard: [qa-]
You need to log in
before you can comment on or make changes to this bug.
Description
•