aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/modules.js4
-rw-r--r--src/runtime.js7
-rw-r--r--src/settings.js3
3 files changed, 9 insertions, 5 deletions
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