Last Comment Bug 643037 - JM: OOL path to truncate small doubles
: JM: OOL path to truncate small doubles
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: x86 Mac OS X
-- normal (vote)
: ---
Assigned To: general
: Jason Orendorff [:jorendorff]
Depends on:
Blocks: 619423 642412
  Show dependency treegraph
Reported: 2011-03-18 16:38 PDT by Brian Hackett (:bhackett)
Modified: 2011-04-13 10:29 PDT (History)
5 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Description User image Brian Hackett (:bhackett) 2011-03-18 16:38:59 PDT
About 85% of the slow paths we take when converting doubles to ints in the kraken pbkdf2 benchmark (or at least the version posted in bug 642412) are due to truncating the result of adding several int32s together, such that the value is within 2^32 of an int32.  These can be truncated by adding/subtracting 2^32 to get the value in range, then converting to an int32 (exact conversion is required, as truncation behaves incorrectly if the value changes sign).
Comment 1 User image Brian Hackett (:bhackett) 2011-03-18 16:47:12 PDT
Patch landed on the TI branch. This could also be added to the TM branch.

On the pbkdf2 test in bug 642412, this improves JM+TI time from 438ms to 361ms.  On this microbenchmark:

function foo(x) {
  var a = x;
  for (var i = 0; i < 3000000; i++) {
    a += x | 0;
  return a + x;

JM+TI (old): 108
JM+TI (new): 20
JM+TM: 56
V8: 95

This is a little gamey but I think that doing bitwise ops on nearly-int32 values (especially uint32s) is pretty common in crypto code.

Note You need to log in before you can comment on or make changes to this bug.