diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-10 11:19:58 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-10 11:19:58 -0800 |
commit | 5beb9b6b1909da1c527ac5cd9601fdba82f39ad5 (patch) | |
tree | 4e8d90635ca073a3bf7670e1054d7ef8bb87cab7 | |
parent | 66a79e74a4d01f6cfc6fb8e289a00896e397d12f (diff) |
optimize varargs calls by avoiding calling allocate there
-rw-r--r-- | src/jsifier.js | 13 | ||||
-rw-r--r-- | src/runtime.js | 20 |
2 files changed, 23 insertions, 10 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 3f41c179..501ed3f9 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1063,7 +1063,18 @@ function JSify(data, functionsOnly, givenFunctions) { varargs = [0]; varargsTypes = ['i32']; } - varargs = makePointer('[' + varargs + ']', 0, 'ALLOC_STACK', varargsTypes); + var offset = 0; + varargs = '(tempInt=' + RuntimeGenerator.stackAlloc(varargs.length, ',') + ',' + + varargs.map(function(arg, i) { + var type = varargsTypes[i]; + if (type == 0) return null; + if (I64_MODE == 1 && type == 'i64') type = 'i32'; // We have [i64, 0, 0, 0, i32, 0, 0, 0] in the layout at this point + var ret = makeSetValue(getFastValue('tempInt', '+', offset), 0, arg, type, null, null, QUANTUM_SIZE); + offset += Runtime.getNativeFieldSize(type); + return ret; + }).filter(function(arg) { + return arg !== null; + }).join(',') + ',tempInt)'; } args = args.concat(varargs); diff --git a/src/runtime.js b/src/runtime.js index 605de749..2c3cb117 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -7,24 +7,26 @@ // itself is as optimized as possible - no unneeded runtime checks). var RuntimeGenerator = { - alloc: function(size, type, init) { + alloc: function(size, type, init, sep) { + sep = sep || ';'; var ret = type + 'TOP'; if (init) { - ret += '; _memset(' + type + 'TOP, 0, ' + size + ')'; + ret += sep + '_memset(' + type + 'TOP, 0, ' + size + ')'; } - ret += '; ' + type + 'TOP += ' + size; + ret += sep + type + 'TOP += ' + size; if ({{{ QUANTUM_SIZE }}} > 1) { - ret += ';' + RuntimeGenerator.alignMemory(type + 'TOP', {{{ QUANTUM_SIZE }}}); + ret += sep + RuntimeGenerator.alignMemory(type + 'TOP', {{{ QUANTUM_SIZE }}}); } return ret; }, // An allocation that lives as long as the current function call - stackAlloc: function(size) { - if (USE_TYPED_ARRAYS === 2) 'STACKTOP += STACKTOP % ' + ({{{ QUANTUM_SIZE }}} - (isNumber(size) ? Math.min(size, {{{ QUANTUM_SIZE }}}) : {{{ QUANTUM_SIZE }}})) + ';'; - var ret = RuntimeGenerator.alloc(size, 'STACK', INIT_STACK); + stackAlloc: function(size, sep) { + sep = sep || ';'; + if (USE_TYPED_ARRAYS === 2) 'STACKTOP += STACKTOP % ' + ({{{ QUANTUM_SIZE }}} - (isNumber(size) ? Math.min(size, {{{ QUANTUM_SIZE }}}) : {{{ QUANTUM_SIZE }}})) + sep; + var ret = RuntimeGenerator.alloc(size, 'STACK', INIT_STACK, sep); if (ASSERTIONS) { - ret += '; assert(STACKTOP < STACK_ROOT + STACK_MAX, "Ran out of stack")'; + ret += sep + 'assert(STACKTOP < STACK_ROOT + STACK_MAX, "Ran out of stack")'; } return ret; }, @@ -63,7 +65,7 @@ var RuntimeGenerator = { if (typeof quantum !== 'number') { quantum = '(quantum ? quantum : {{{ QUANTUM_SIZE }}})'; } - return target + ' = ' + Runtime.forceAlign(target, quantum) + ';'; + return target + ' = ' + Runtime.forceAlign(target, quantum); } }; |