Bug 15761

Summary: Speed up JSImmediate::getTruncated* by using custom float -> int code
Product: WebKit Reporter: Eric Seidel (no email) <eric>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Normal CC: darin, mjs
Priority: P2    
Version: 523.x (Safari 3)   
Hardware: Mac   
OS: OS X 10.4   
Attachments:
Description Flags
broken fix
none
nearly correct functions (fail two tests) inside test harness
none
an actual patch for JSC (same code as in test above) none

Description Eric Seidel (no email) 2007-10-30 03:17:42 PDT
Speed up JSImmediate::getTruncated* by using custom float -> int code

I've written some code for this (attached).  It seems to break sun-spider, even though my printf-debugging seems to suggest my code is correct.  Not sure yet what's wrong.  Anyone should feel free to fix/land this as needed, I probably won't get to look at it for several days.
Comment 1 Eric Seidel (no email) 2007-10-30 03:19:00 PDT
Created attachment 16944 [details]
broken fix
Comment 2 Eric Seidel (no email) 2007-10-30 19:22:06 PDT
Created attachment 16956 [details]
nearly correct functions (fail two tests) inside test harness
Comment 3 Eric Seidel (no email) 2007-10-30 19:23:49 PDT
The test output:

Running JSImmediate::getTruncated* tests, this will take a while.
                       testing : -2147483648 : 1000 0000 0000 0000 0000 0000 0000 0000 
getTruncatedUInt32 -0.000000 expected: 0 (1) got: 0 (0)
                       testing : -822083584 : 1100 1111 0000 0000 0000 0000 0000 0000 
getTruncatedInt32  -2147483648.000000 expected: -2147483648 (1) got: -2147483648 (0)

The first failure is obvious.  Not sure if we need to support it (depending on how 0 is stored in JSImmediate floats), probably though.  The second failure seems to be related to exponent size.
Comment 4 Eric Seidel (no email) 2007-10-30 19:56:55 PDT
FYI, in addition to being slightly wrong... this code is also slightly (but only slightly!) slower than the current float -> int code.  I'm confident that both correctness and speed can be fixed, but I'm a bit tired to do so myself.  Perhaps someone will do so while I'm in Mexico.
Comment 5 Eric Seidel (no email) 2007-10-30 20:18:28 PDT
Created attachment 16957 [details]
an actual patch for JSC (same code as in test above)
Comment 6 Darin Adler 2007-11-08 22:59:14 PST
Oliver got good results by switching our immediate optimization from floating point to int instead.