Closed
Bug 863349
Opened 13 years ago
Closed 13 years ago
IonMonkey: Optimize double truncation code
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla23
People
(Reporter: jandem, Assigned: jandem)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
|
27.98 KB,
patch
|
bhackett1024
:
review+
|
Details | Diff | Splinter Review |
Kraken's crypto tests need fast truncation of doubles outside the int32 range. we have some code to handle this but we can do better. On x64, we should use cvttsd2sq instead of cvttsd2si. On x86, we can use the SSE3 fisttp instruction.
The quick-and-dirty x64 change wins about 50 ms on Kraken stanford-crypto-pbkdf2 (190 to 140 ms). x86 will likely be less.
Comment 1•13 years ago
|
||
Are these doubles actually uint32s?
Comment 2•13 years ago
|
||
If I'm remembering the test case, they aren't uint32's, they are well outside of the range of reasonable for truncation (although still small enough that they can exactly represent every integer)
| Assignee | ||
Comment 3•13 years ago
|
||
What we used to do on x86 and x64 is:
(1) Use cvtsd2si (32-bit truncate)
(2) OOL path for doubles within 2^32 of int32 range.
(3) OOL callWithABI for everything else.
With this patch we do the following on x64:
(1) Use cvttsd2sq (64-bit truncate)
(2) OOL callWithABI if it fails.
With patch on x86 with SSE3:
(1) Use cvttsd2si (32-bit truncate)
(2) OOL path uses SSE3 fisttp (64-bit truncate).
(3) OOL callWithABI if it fails.
If SSE3 is not available we use the old code for (2). SSE3 was introduced in 2004 and even some of the newer Pentium 4's support it.
The SSE3 code is based on what V8 does, so the algorithm should be fine.
Perf numbers for the following micro-benchmark:
function f(x) {
var a = 0;
for (var i=0; i<10000000; i++) {
a = x|0;
x += 1;
}
print(a);
return a;
}
var t = new Date;
f(1e9);
print(new Date - t);
32-bit:
before after
1 billion: 12 ms 12 ms
3 billion: 27 ms 21 ms
8 billion: 263 ms 21 ms
10e15: 167 ms 21 ms
64-bit:
before after
1 billion: 12 ms 12 ms
3 billion: 31 ms 13 ms
8 billion: 300 ms 13 ms
10e15: 203 ms 13 ms
As expected, this shows that for smaller numbers there's no difference, but it's a win for numbers outside the int32 range, especially on x64. Also note that on x86 the SSE3 instruction is faster than what we used to do for numbers within 2^32 of a signed int32.
The patch does not yet address bug 818750, I think that's better left to a separate bug (this patch should reduce the size of the OOL code though, especially on x64).
Attachment #739544 -
Flags: review?(bhackett1024)
Updated•13 years ago
|
Attachment #739544 -
Flags: review?(bhackett1024) → review+
| Assignee | ||
Comment 4•13 years ago
|
||
| Assignee | ||
Comment 5•13 years ago
|
||
According to AWFY this was an 18% win on crypto-sha256-iterative, 27% on crypto-pbkdf2 on x64. As expected x86 is much less, but still a few percent on sha256-iterative (crypto-pbkdf2 is too unstable to say much at this point).
Comment 6•13 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
You need to log in
before you can comment on or make changes to this bug.
Description
•