aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parseTools.js9
-rw-r--r--src/settings.js10
2 files changed, 18 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 86e3c643..e37f3a99 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1794,7 +1794,14 @@ function processMathop(item) {
case 'add': return handleOverflow(getFastValue(idents[0], '+', idents[1], item.type), bits);
case 'sub': return handleOverflow(getFastValue(idents[0], '-', idents[1], item.type), bits);
case 'sdiv': case 'udiv': return makeRounding(getFastValue(idents[0], '/', idents[1], item.type), bits, op[0] === 's');
- case 'mul': return handleOverflow(getFastValue(idents[0], '*', idents[1], item.type), bits);
+ case 'mul': {
+ if (bits == 32 && PRECISE_I32_MUL) {
+ preciseI64MathUsed = true;
+ return '(i64Math.multiply(' + idents[0] + ',0,' + idents[1] + ',0),i64Math.result[0])';
+ } else {
+ return handleOverflow(getFastValue(idents[0], '*', idents[1], item.type), bits);
+ }
+ }
case 'urem': case 'srem': return getFastValue(idents[0], '%', idents[1], item.type);
case 'or': {
if (bits > 32) {
diff --git a/src/settings.js b/src/settings.js
index 75b30003..110cc246 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -76,6 +76,16 @@ var DOUBLE_MODE = 1; // How to load and store 64-bit doubles. Without typed arra
// NaN or an infinite number.
var PRECISE_I64_MATH = 1; // If enabled, i64 addition etc. is emulated - which is slow but precise. If disabled,
// we use the 'double trick' which is fast but incurs rounding at high values.
+ // Note that we do not catch 32-bit multiplication by default (which must be done in
+ // 64 bits for high values for full precision) - you must manually set PRECISE_I32_MUL
+ // for that.
+var PRECISE_I32_MUL = 1; // If enabled, i64 math is done in i32 multiplication. This is necessary if the values
+ // exceed the JS double-integer limit of ~52 bits. This option can normally be disabled
+ // because generally i32 multiplication works ok without it, and enabling it has a big
+ // impact on performance.
+ // Note that you can hand-optimize your code to avoid the need for this: If you do
+ // multiplications that actually need 64-bit precision inside 64-bit values, things
+ // will work properly. (Unless the LLVM optimizer turns them into 32-bit values?)
var CLOSURE_ANNOTATIONS = 0; // If set, the generated code will be annotated for the closure
// compiler. This potentially lets closure optimize the code better.