aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-02-22 18:41:37 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-02-22 18:55:13 -0800
commitc00e097d60100c7a562ac25664eb3c25bb9403ae (patch)
treef724c92e09a6c24c85110a33fc40561a2b0dcbb4
parent90710c0c8ee4425c06402cc7831abdee8c519a43 (diff)
always use Math.imul, with fast polyfill. will be useful for faster 64-bit math
-rwxr-xr-xemscripten.py5
-rw-r--r--src/parseTools.js6
-rw-r--r--src/preamble.js2
-rw-r--r--src/settings.js1
4 files changed, 5 insertions, 9 deletions
diff --git a/emscripten.py b/emscripten.py
index af762a21..b3e153c1 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -322,10 +322,7 @@ def emscript(infile, settings, outfile, libraries=[]):
function_tables_defs = '\n'.join([info[0] for info in infos] + [info[1] for info in infos])
asm_setup = ''
- maths = ['Math.' + func for func in ['floor', 'abs', 'sqrt', 'pow', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'atan2', 'exp', 'log', 'ceil']]
- if settings['USE_MATH_IMUL']:
- maths += ['Math.imul']
- asm_setup += 'if (!Math.imul) Math.imul = function(x, y) { return (x*y)|0 }; // # not a real polyfill since semantics not identical, but close and fairly fast\n'
+ maths = ['Math.' + func for func in ['floor', 'abs', 'sqrt', 'pow', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'atan2', 'exp', 'log', 'ceil', 'imul']]
fundamentals = ['Math', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
math_envs = ['Runtime.bitshift64', 'Math.min'] # TODO: move min to maths
asm_setup += '\n'.join(['var %s = %s;' % (f.replace('.', '_'), f) for f in math_envs])
diff --git a/src/parseTools.js b/src/parseTools.js
index 15c2169b..514d74d0 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1046,10 +1046,8 @@ function asmMultiplyI32(a, b) {
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 + ')';
- }
- return '(~~(+((' + a + ')|0) * +((' + b + ')|0)))';
+ return 'Math.imul(' + a + ',' + b + ')';
+ // non-imul version: return '(~~(+((' + a + ')|0) * +((' + b + ')|0)))';
}
function asmFloatToInt(x) {
diff --git a/src/preamble.js b/src/preamble.js
index 503b09f1..b355f130 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -742,6 +742,8 @@ Module['writeArrayToMemory'] = writeArrayToMemory;
{{{ unSign }}}
{{{ reSign }}}
+if (!Math.imul) Math.imul = function(x, y) { return (x*y)|0 }; // # not a real polyfill since semantics not identical, but close and fast
+
// A counter of dependencies for calling run(). If we need to
// do asynchronous work before running, increment this and
// decrement it. Incrementing must happen in a place like
diff --git a/src/settings.js b/src/settings.js
index f4e23c5b..1023ee11 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -325,7 +325,6 @@ var BENCHMARK = 0; // If 1, will just time how long main() takes to execute, and
var ASM_JS = 0; // If 1, generate code in asm.js format. XXX This is highly experimental,
// and will not work on most codebases yet. It is NOT recommended that you
// try this yet.
-var USE_MATH_IMUL = 1; // If 1, use Math.imul when normal int math can't be done in ASM_JS
var EXPLICIT_ZEXT = 0; // If 1, generate an explicit conversion of zext i1 to i32, using ?: