diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-01 15:28:11 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-01 21:11:32 -0700 |
commit | 545f0a7bd6623a744ef4dd5b35da01636dda565e (patch) | |
tree | 7f8761db6a2b04a2faf486e9f5b20feb64d13121 | |
parent | a08253a00a0c37563ffabb3163de8088bca23933 (diff) |
optimize asm function table emitting
-rwxr-xr-x | emscripten.py | 13 | ||||
-rw-r--r-- | src/modules.js | 8 | ||||
-rw-r--r-- | tools/asm_module.py | 2 |
3 files changed, 12 insertions, 11 deletions
diff --git a/emscripten.py b/emscripten.py index b70f2abb..786370e8 100755 --- a/emscripten.py +++ b/emscripten.py @@ -410,6 +410,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, simple = os.environ.get('EMCC_SIMPLE_ASM') class Counter: i = 0 + j = 0 pre_tables = last_forwarded_json['Functions']['tables']['pre'] del last_forwarded_json['Functions']['tables']['pre'] @@ -425,12 +426,17 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, body = raw[start+1:end].split(',') for j in range(settings['RESERVED_FUNCTION_POINTERS']): body[2 + 2*j] = 'jsCall_%s_%s' % (sig, j) + Counter.j = 0 def fix_item(item): - newline = '\n' in item - return (bad if item.replace('\n', '') == '0' else item) + ('\n' if newline else '') + Counter.j += 1 + newline = Counter.j % 30 == 1 + if item == '0': return bad if not newline else (bad + '\n') + return item if not newline else (item + '\n') body = ','.join(map(fix_item, body)) - return ('function %s(%s) { %s %s(%d); %s }' % (bad, params, coercions, 'abort' if not settings['ASSERTIONS'] else 'nullFunc', i, ret), raw[:start+1] + body + raw[end:]) + return ('function %s(%s) { %s %s(%d); %s }' % (bad, params, coercions, 'abort' if not settings['ASSERTIONS'] else 'nullFunc', i, ret), ''.join([raw[:start+1], body, raw[end:]])) + infos = [make_table(sig, raw) for sig, raw in last_forwarded_json['Functions']['tables'].iteritems()] + function_tables_defs = '\n'.join([info[0] for info in infos]) + '\n// EMSCRIPTEN_END_FUNCS\n' + '\n'.join([info[1] for info in infos]) asm_setup = '' @@ -470,6 +476,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, function_tables = ['dynCall_' + table for table in last_forwarded_json['Functions']['tables']] function_tables_impls = [] + for sig in last_forwarded_json['Functions']['tables'].iterkeys(): args = ','.join(['a' + str(i) for i in range(1, len(sig))]) arg_coercions = ' '.join(['a' + str(i) + '=' + asm_coerce('a' + str(i), sig[i]) + ';' for i in range(1, len(sig))]) diff --git a/src/modules.js b/src/modules.js index 2757c2cb..9662200c 100644 --- a/src/modules.js +++ b/src/modules.js @@ -373,14 +373,6 @@ var Functions = { } } } - if (table.length > 20) { - // add some newlines in the table, for readability - var j = 10; - while (j+10 < table.length) { - table[j] += '\n'; - j += 10; - } - } maxTable = Math.max(maxTable, table.length); } if (ASM_JS) maxTable = ceilPowerOfTwo(maxTable); diff --git a/tools/asm_module.py b/tools/asm_module.py index 226b66b8..f383eba6 100644 --- a/tools/asm_module.py +++ b/tools/asm_module.py @@ -248,12 +248,14 @@ class AsmModule(): def merge_tables(self, table, main, side, replacements, f_bases, f_sizes): sig = table.split('_')[-1] side = side[1:-1].split(',') + side = map(lambda s: s.strip(), side) side = map(lambda f: replacements[f] if f in replacements else f, side) if not main: f_bases[sig] = 0 f_sizes[table] = len(side) return '[' + ','.join(side) + ']' main = main[1:-1].split(',') + main = map(lambda m: m.strip(), main) # TODO: handle non-aliasing case too assert len(main) % 2 == 0 f_bases[sig] = len(main) |