aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-12 16:38:58 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-12 16:38:58 -0800
commit8f42941647a97122aa5b357aeff5970f72a30019 (patch)
tree791172c9f2f07a610ed73eaa801e6891ed2dbea3
parent2aa6d93eddceca6d908e4903ce55952180c7d40d (diff)
support for Math.imul
-rwxr-xr-xemscripten.py7
-rw-r--r--src/parseTools.js3
-rw-r--r--src/settings.js1
3 files changed, 9 insertions, 2 deletions
diff --git a/emscripten.py b/emscripten.py
index e635b2bb..4ea5c768 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -301,9 +301,12 @@ def emscript(infile, settings, outfile, libraries=[]):
return 'function %s(%s) { %s abort(%d); %s };\n' % (bad, params, coercions, i, ret) + raw.replace('[0,', '[' + bad + ',').replace(',0,', ',' + bad + ',').replace(',0,', ',' + bad + ',').replace(',0]', ',' + bad + ']').replace(',0]', ',' + bad + ']')
function_tables_defs = '\n'.join([make_table(sig, raw) for sig, raw in last_forwarded_json['Functions']['tables'].iteritems()])
- asm_setup = '\n'.join(['var %s = %s;' % (f.replace('.', '_'), f) for f in ['Runtime.bitshift64', 'Math.floor', 'Math.min']])
+ maths = ['Runtime.bitshift64', 'Math.floor', 'Math.min']
+ if settings['USE_MATH_IMUL']:
+ maths += ['Math.imul']
+ asm_setup = '\n'.join(['var %s = %s;' % (f.replace('.', '_'), f) for f in maths])
fundamentals = ['buffer', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
- basic_funcs = ['abort', 'assert', 'Runtime_bitshift64', 'Math_floor', 'Math_min']
+ basic_funcs = ['abort', 'assert'] + [m.replace('.', '_') for m in maths]
basic_vars = ['STACKTOP', 'STACK_MAX', 'tempDoublePtr', 'ABORT']
if not settings['NAMED_GLOBALS']: basic_vars += ['GLOBAL_BASE']
if forwarded_json['Types']['preciseI64MathUsed']:
diff --git a/src/parseTools.js b/src/parseTools.js
index c297b278..0bacebd9 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1975,6 +1975,9 @@ function processMathop(item) {
if (ASM_JS) {
// 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 (USE_MATH_IMUL) {
+ return 'Math.imul(' + idents[0] + ',' + idents[1] + ')';
+ }
return '(~~(+' + idents[0] + ' * +' + idents[1] + '))';
}
return handleOverflow(getFastValue(idents[0], '*', idents[1], item.type), bits);
diff --git a/src/settings.js b/src/settings.js
index b9dfa9e9..acf71c03 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -295,6 +295,7 @@ var HEADLESS = 0; // If 1, will include shim code that tries to 'fake' a browser
// keep your expectations low for this to work.
var ASM_JS = 0; // If 1, generate code in asm.js format
+var USE_MATH_IMUL = 0; // If 1, use Math.imul when useful
var NECESSARY_BLOCKADDRS = []; // List of (function, block) for all block addresses that are taken.