diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-02 10:57:35 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-02 10:57:35 -0700 |
commit | 4faa7bd2204efbaad697250180fb4f324fed34ab (patch) | |
tree | d4485b7cc449ef300625d3e2412f95ca7ff7e1ca | |
parent | 3f4c28afcd9b03ddcb5cc1834d0c50c3cfa33b9c (diff) |
make function pointer aliasing configurable
-rwxr-xr-x | emscripten.py | 13 | ||||
-rw-r--r-- | src/modules.js | 4 | ||||
-rw-r--r-- | src/runtime.js | 7 | ||||
-rw-r--r-- | src/settings.js | 3 |
4 files changed, 16 insertions, 11 deletions
diff --git a/emscripten.py b/emscripten.py index a6ff7390..2b62c93a 100755 --- a/emscripten.py +++ b/emscripten.py @@ -329,8 +329,9 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, # calculations on merged forwarded data forwarded_json['Functions']['indexedFunctions'] = {} - i = 2 # universal counter - if settings['ASM_JS']: i += 2*settings['RESERVED_FUNCTION_POINTERS'] + i = settings['FUNCTION_POINTER_ALIGNMENT'] # universal counter + if settings['ASM_JS']: i += settings['RESERVED_FUNCTION_POINTERS']*settings['FUNCTION_POINTER_ALIGNMENT'] + base_fp = i table_counters = {} # table-specific counters alias = settings['ASM_JS'] and settings['ALIASING_FUNCTION_POINTERS'] sig = None @@ -339,12 +340,12 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, sig = forwarded_json['Functions']['implementedFunctions'].get(indexed) or forwarded_json['Functions']['unimplementedFunctions'].get(indexed) assert sig, indexed if sig not in table_counters: - table_counters[sig] = 2 + 2*settings['RESERVED_FUNCTION_POINTERS'] + table_counters[sig] = base_fp curr = table_counters[sig] - table_counters[sig] += 2 + table_counters[sig] += settings['FUNCTION_POINTER_ALIGNMENT'] else: curr = i - i += 2 + i += settings['FUNCTION_POINTER_ALIGNMENT'] #logging.debug('function indexing', indexed, curr, sig) forwarded_json['Functions']['indexedFunctions'][indexed] = curr # make sure not to modify this python object later - we use it in indexize @@ -426,7 +427,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, end = raw.rindex(']') body = raw[start+1:end].split(',') for j in range(settings['RESERVED_FUNCTION_POINTERS']): - body[2 + 2*j] = 'jsCall_%s_%s' % (sig, j) + body[settings['FUNCTION_POINTER_ALIGNMENT'] * (1 + j)] = 'jsCall_%s_%s' % (sig, j) Counter.j = 0 def fix_item(item): Counter.j += 1 diff --git a/src/modules.js b/src/modules.js index 9662200c..d9888c24 100644 --- a/src/modules.js +++ b/src/modules.js @@ -234,7 +234,7 @@ var Types = { preciseI64MathUsed: (PRECISE_I64_MATH == 2) }; -var firstTableIndex = (ASM_JS ? 2*RESERVED_FUNCTION_POINTERS : 0) + 2; +var firstTableIndex = FUNCTION_POINTER_ALIGNMENT * ((ASM_JS ? RESERVED_FUNCTION_POINTERS : 0) + 1); var Functions = { // All functions that will be implemented in this file. Maps id to signature @@ -287,7 +287,7 @@ var Functions = { ret = this.indexedFunctions[ident]; if (!ret) { ret = this.nextIndex; - this.nextIndex += 2; // Need to have indexes be even numbers, see |polymorph| test + this.nextIndex += FUNCTION_POINTER_ALIGNMENT; this.indexedFunctions[ident] = ret; } ret = ret.toString(); diff --git a/src/runtime.js b/src/runtime.js index 00031fed..a281045b 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -347,22 +347,23 @@ var Runtime = { for (var i = 0; i < Runtime.functionPointers.length; i++) { if (!Runtime.functionPointers[i]) { Runtime.functionPointers[i] = func; - return 2 + 2*i; + return {{{ FUNCTION_POINTER_ALIGNMENT }}}*(1 + i); } } throw 'Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.'; #else var table = FUNCTION_TABLE; var ret = table.length; + assert(ret % {{{ FUNCTION_POINTER_ALIGNMENT }}} === 0); table.push(func); - table.push(0); + for (var i = 0; i < {{{ FUNCTION_POINTER_ALIGNMENT }}}-1; i++) table.push(0); return ret; #endif }, removeFunction: function(index) { #if ASM_JS - Runtime.functionPointers[(index-2)/2] = null; + Runtime.functionPointers[(index-{{{ FUNCTION_POINTER_ALIGNMENT }}})/{{{ FUNCTION_POINTER_ALIGNMENT }}}] = null; #else var table = FUNCTION_TABLE; table[index] = null; diff --git a/src/settings.js b/src/settings.js index 5cf054a9..3eb43f1c 100644 --- a/src/settings.js +++ b/src/settings.js @@ -170,6 +170,9 @@ var ALIASING_FUNCTION_POINTERS = 0; // Whether to allow function pointers to ali // a different type. This can greatly decrease table sizes // in asm.js, but can break code that compares function // pointers across different types. +var FUNCTION_POINTER_ALIGNMENT = 2; // Byte alignment of function pointers - we will fill the + // tables with zeros on aligned values. 1 means all values + // are aligned and all will be used (which is optimal). var ASM_HEAP_LOG = 0; // Simple heap logging, like SAFE_HEAP_LOG but cheaper, and in asm.js |