aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-07 16:19:54 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-07 16:19:54 -0800
commit153638d05a56434ede6803c31566d97813f92c76 (patch)
tree10b872e0220192023e1a96b863e536784cb5527e /src
parent3954f1d108105bcdd5411fe19abb8f068b22bd24 (diff)
set asm function table sizes to power of two, and add proper masking
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js4
-rw-r--r--src/modules.js1
-rw-r--r--src/utility.js6
3 files changed, 10 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index a83b2d3d..50824562 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1278,10 +1278,12 @@ function JSify(data, functionsOnly, givenFunctions) {
if (byPointer) {
var returnType = type.split(' ')[0];
+ var sig = Functions.getSignature(returnType, argsTypes);
if (ASM_JS) {
assert(returnType.search(/\("'\[,/) == -1); // XXX need isFunctionType(type, out)
+ ident = '(' + ident + ')&{{{ FTM_' + sig + ' }}}'; // the function table mask is set in emscripten.py
}
- ident = Functions.getTable(Functions.getSignature(returnType, argsTypes)) + '[' + ident + ']';
+ ident = Functions.getTable(sig) + '[' + ident + ']';
}
return ident + '(' + args.join(', ') + ')';
diff --git a/src/modules.js b/src/modules.js
index 71fec0cd..5c1d6a1d 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -259,6 +259,7 @@ var Functions = {
// Generate code for function indexing
generateIndexing: function() {
var total = this.nextIndex;
+ if (ASM_JS) total = ceilPowerOfTwo(total); // must be power of 2 for mask
function emptyTable(sig) {
return zeros(total);
}
diff --git a/src/utility.js b/src/utility.js
index 84b50ce9..63582ae8 100644
--- a/src/utility.js
+++ b/src/utility.js
@@ -321,6 +321,12 @@ function isPowerOfTwo(x) {
return x > 0 && ((x & (x-1)) == 0);
}
+function ceilPowerOfTwo(x) {
+ var ret = 1;
+ while (ret < x) ret <<= 1;
+ return ret;
+}
+
function Benchmarker() {
var starts = {}, times = {}, counts = {};
this.start = function(id) {