Closed Bug 583939 Opened 15 years ago Closed 12 years ago

Optimize safe_add() as 32-bit addition [JSOP_SUNSPIDER]

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: froystig, Assigned: froystig)

Details

Attachments

(1 file)

There is a JS function called safe_add() in crypto-sha1 and crypto-md5 that custom-implements 32-bit addition in terms of 16-bit JS operations "to work around bugs in some JS interpreters." I conjecture that ours is not one such buggy interpreter. Hence, Andreas suggests that it would be nice to monitor for such script workarounds and lower them back into regular old 32-bit addition. We can catch these when trace-recording function calls, say, by noticing functions that happen to be bytecode-identical to safe_add().
Assignee: general → rfrostig
Is there a risk that we can be accused of benchmark-gaming if we have code that looks for and specially optimizes a specific function in SunSpider? Recognizing a common function in web code seems fair, but if we do a function that is only known to occur in SunSpider I am a little concerned.
Summary: Optimize safe_add() as 32-bit addition → Optimize safe_add() as 32-bit addition [JSOP_SUNSPIDER]
Word on the street is some competitors (must I mean closed source competitors? I could be missing open-source tuning for SunSpider) are doing similar and worse hacks. Anyone who remembers the SPEC wars of the '90s knows the game theory. /be
safe_add results in over 52,000 hits on google. The code is used all over the web.
(In reply to comment #3) > safe_add results in over 52,000 hits on google. The code is used all over the > web. Sounds good then.
This would probably render bug 575529 moot. This isn't necessarily a bad thing.
FWIW neither JSC nor V8 special cases safe_add. If I mutate the code so it does some other rubbish thing (with the same number of ALU ops), the time for JSC/V8 is unchanged. I am also concerned about the issues raised in comment 1; regardless of how often safe_add is used on the web, it still seems like benchmark-gaming. If you can tweak a few bits in a benchmark and introduce a major performance regression on some engines but not others, it makes those engines look bad (see bug 580018).
FWIW, here's a patch that specializes safe_add() in the ExprFilter. This is arguably less bogus than specializing on the bytecode, but not much. It also helps us a lot less than specializing on the bytecode because with this patch heaps of code gets generated that ends up dead, whereas with a bytecode approach that code wouldn't be generated at all. And compile-time dominates crypto-md5 for us. But it probably shouldn't be applied.
Time to WONTFIX this wee beastie.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: