{"ScriptPreparationCode":"var x = 0x12345678;\r\nvar y;\r\n\r\nMath.imula = function(opA, opB) {\r\n opB |= 0; // ensure that opB is an integer. opA will automatically be coerced.\r\n // floating points give us 53 bits of precision to work with plus 1 sign bit\r\n // automatically handled for our convienence:\r\n // 1. 0x003fffff /*opA \u0026 0x000fffff*/ * 0x7fffffff /*opB*/ = 0x1fffff7fc00001\r\n // 0x1fffff7fc00001 \u003C Number.MAX_SAFE_INTEGER /*0x1fffffffffffff*/\r\n var result = (opA \u0026 0x003fffff) * opB;\r\n // 2. We can remove an integer coersion from the statement above because:\r\n // 0x1fffff7fc00001 \u002B 0xffc00000 = 0x1fffffff800001\r\n // 0x1fffffff800001 \u003C Number.MAX_SAFE_INTEGER /*0x1fffffffffffff*/\r\n if (opA \u0026 0xffc00000 /*!== 0*/) result \u002B= (opA \u0026 0xffc00000) * opB |0;\r\n return result |0;\r\n};\r\n\r\n\r\n\r\n\r\nMath.imulb = function(a, b) {\r\n var aHi = (a \u003E\u003E\u003E 16) \u0026 0xffff;\r\n var aLo = a \u0026 0xffff;\r\n var bHi = (b \u003E\u003E\u003E 16) \u0026 0xffff;\r\n var bLo = b \u0026 0xffff;\r\n // the shift by 0 fixes the sign on the high part\r\n // the final |0 converts the unsigned value into a signed value\r\n return ((aLo * bLo) \u002B (((aHi * bLo \u002B aLo * bHi) \u003C\u003C 16) \u003E\u003E\u003E 0) | 0);\r\n};\r\n\r\n\r\n\r\nMath.imulc = function(x, y) {\r\n var UINT16 = 0xffff;\r\n var xn = \u002Bx;\r\n var yn = \u002By;\r\n var xl = UINT16 \u0026 xn;\r\n var yl = UINT16 \u0026 yn;\r\n return 0 | xl * yl \u002B ((UINT16 \u0026 xn \u003E\u003E\u003E 16) * yl \u002B xl * (UINT16 \u0026 yn \u003E\u003E\u003E 16) \u003C\u003C 16 \u003E\u003E\u003E 0);\r\n }","TestCases":[{"Name":"Math.imul","Code":"for (var i = 0;\u00A0i \u003C 10000; \u002B\u002Bi) {\r\n y = Math.imul(x, i);\r\n}","IsDeferred":false},{"Name":"Polyfill a","Code":"for (var i = 0;\u00A0i \u003C 10000; \u002B\u002Bi) {\r\n y = Math.imula(x, i);\r\n}","IsDeferred":false},{"Name":"Polyfill b","Code":"for (var i = 0;\u00A0i \u003C 10000; \u002B\u002Bi) {\r\n y = Math.imulb(x, i);\r\n}","IsDeferred":false},{"Name":"Polyfill c","Code":"for (var i = 0;\u00A0i \u003C 10000; \u002B\u002Bi) {\r\n y = Math.imulc(x, i);\r\n}","IsDeferred":false}]}