diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-30 14:20:48 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-30 14:20:58 -0800 |
commit | 2aa334869496781389ad531f1811830ca7d61799 (patch) | |
tree | ee0c293c71be6aa04f4c19e896f832b5b3add9c4 | |
parent | 602d114eaab01aef167159aedba7d5bbfc634eef (diff) |
asmify rand
-rwxr-xr-x | emscripten.py | 7 | ||||
-rw-r--r-- | src/library.js | 7 |
2 files changed, 11 insertions, 3 deletions
diff --git a/emscripten.py b/emscripten.py index ce929858..77082aee 100755 --- a/emscripten.py +++ b/emscripten.py @@ -474,6 +474,9 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, basic_vars.append('F_BASE_%s' % sig) asm_setup += ' var F_BASE_%s = %s;\n' % (sig, 'FUNCTION_TABLE_OFFSET' if settings.get('SIDE_MODULE') else '0') + '\n' + if '_rand' in exported_implemented_functions or '_srand' in exported_implemented_functions: + basic_vars += ['___rand_seed'] + asm_runtime_funcs = ['stackAlloc', 'stackSave', 'stackRestore', 'setThrew'] + ['setTempRet%d' % i for i in range(10)] # function tables function_tables = ['dynCall_' + table for table in last_forwarded_json['Functions']['tables']] @@ -518,6 +521,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, exports = '{ ' + ', '.join(exports) + ' }' else: exports = '_main' + # calculate globals try: del forwarded_json['Variables']['globals']['_llvm_global_ctors'] # not a true variable @@ -975,6 +979,9 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, basic_vars.append('F_BASE_%s' % sig) asm_setup += ' var F_BASE_%s = %s;\n' % (sig, 'FUNCTION_TABLE_OFFSET' if settings.get('SIDE_MODULE') else '0') + '\n' + if '_rand' in exported_implemented_functions or '_srand' in exported_implemented_functions: + basic_vars += ['___rand_seed'] + asm_runtime_funcs = ['stackAlloc', 'stackSave', 'stackRestore', 'setThrew'] + ['setTempRet%d' % i for i in range(10)] # function tables function_tables = ['dynCall_' + table for table in last_forwarded_json['Functions']['tables']] diff --git a/src/library.js b/src/library.js index 20cb64f4..30453137 100644 --- a/src/library.js +++ b/src/library.js @@ -3454,7 +3454,6 @@ LibraryManager.library = { }, rand_r__sig: 'ii', rand_r__asm: true, - rand_r__deps: ['__rand_seed'], rand_r: function(seedp) { seedp = seedp|0; var val = 0; @@ -3462,9 +3461,11 @@ LibraryManager.library = { {{{ makeSetValueAsm('seedp', 0, 'val', 'i32') }}}; return val|0; }, - rand__deps: ['rand_r'], + rand__sig: 'i', + rand__asm: true, + rand__deps: ['rand_r', '__rand_seed'], rand: function() { - return _rand_r(___rand_seed); + return _rand_r(___rand_seed)|0; }, drand48: function() { |