optimize varargs calls by avoiding calling allocate there

This commit is contained in:
Alon Zakai 2012-01-10 11:19:58 -08:00
Родитель 66a79e74a4
Коммит 5beb9b6b19
2 изменённых файлов: 23 добавлений и 10 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);
}
};