aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-02-04 11:05:09 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-02-04 11:05:09 -0800
commit5535dcad8cdca9c6ad949e4e2df8a5ee9919b3a2 (patch)
tree5ecd9fffd74110c299fabc5d5a8f2a5e70dfb2d0
parent87c84e8898c0a4ff9af8596f1558b469ea672327 (diff)
emit simple multiply in asm if the values are small enough to avoid double rounding concerns
-rw-r--r--src/parseTools.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index f5e2f33f..40051e29 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1045,9 +1045,14 @@ function asmCoercion(value, type, signedness) {
}
}
+var TWO_TWENTY = Math.pow(2, 20);
+
function asmMultiplyI32(a, b) {
// special-case: there is no integer multiply in asm, because there is no true integer
// multiply in JS. While we wait for Math.imul, do double multiply
+ if ((isNumber(a) && Math.abs(a) < TWO_TWENTY) || (isNumber(b) && Math.abs(b) < TWO_TWENTY)) {
+ return '(((' + a + ')*(' + b + '))&-1)'; // small enough to emit directly as a multiply
+ }
if (USE_MATH_IMUL) {
return 'Math.imul(' + a + ',' + b + ')';
}