aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analyzer.js2
-rw-r--r--src/jsifier.js5
-rw-r--r--src/library.js8
-rw-r--r--src/modules.js2
-rw-r--r--src/runtime.js17
5 files changed, 18 insertions, 16 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 31422201..03d44cb7 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -1509,7 +1509,7 @@ function analyzer(data, sidePass) {
calcAllocatedSize(item.allocatedType)*item.allocatedNum: 0;
if (USE_TYPED_ARRAYS === 2) {
// We need to keep the stack aligned
- item.allocatedSize = Runtime.forceAlign(item.allocatedSize, QUANTUM_SIZE);
+ item.allocatedSize = Runtime.forceAlign(item.allocatedSize, Runtime.STACK_ALIGN);
}
}
var index = 0;
diff --git a/src/jsifier.js b/src/jsifier.js
index acb0332b..2715ae3e 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1403,11 +1403,10 @@ function JSify(data, functionsOnly, givenFunctions) {
ret = makeSetValue(getFastValue('tempInt', '+', offset), 0, arg, type, null, null, QUANTUM_SIZE, null, ',');
offset += Runtime.getNativeFieldSize(type);
} else {
- assert(offset % 4 == 0); // varargs must be aligned
+ assert(offset % Runtime.STACK_ALIGN == 0); // varargs must be aligned
var size = calcAllocatedSize(removeAllPointing(type));
- assert(size % 4 == 0); // varargs must stay aligned
ret = makeCopyValues(getFastValue('tempInt', '+', offset), arg, size, null, null, varargsByVals[i], ',');
- offset += size;
+ offset += Runtime.forceAlign(size, Runtime.STACK_ALIGN);
}
return ret;
}).filter(function(arg) {
diff --git a/src/library.js b/src/library.js
index 067458fe..f9ff18ec 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2499,7 +2499,7 @@ LibraryManager.library = {
for (var formatIndex = 0; formatIndex < format.length;) {
if (format[formatIndex] === '%' && format[formatIndex+1] == 'n') {
var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}};
- argIndex += Runtime.getNativeFieldSize('void*');
+ argIndex += Runtime.getAlignSize('void*');
{{{ makeSetValue('argPtr', 0, 'soFar', 'i32') }}};
formatIndex += 2;
continue;
@@ -2508,7 +2508,7 @@ LibraryManager.library = {
// TODO: Support strings like "%5c" etc.
if (format[formatIndex] === '%' && format[formatIndex+1] == 'c') {
var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}};
- argIndex += Runtime.getNativeFieldSize('void*');
+ argIndex += Runtime.getAlignSize('void*');
fields++;
next = get();
{{{ makeSetValue('argPtr', 0, 'next', 'i8') }}}
@@ -2600,7 +2600,7 @@ LibraryManager.library = {
var text = buffer.join('');
var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}};
- argIndex += Runtime.getNativeFieldSize('void*');
+ argIndex += Runtime.getAlignSize('void*');
switch (type) {
case 'd': case 'u': case 'i':
if (half) {
@@ -2679,7 +2679,7 @@ LibraryManager.library = {
type = 'i32'; // varargs are always i32, i64, or double
ret = {{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}};
}
- argIndex += Runtime.getNativeFieldSize(type);
+ argIndex += Runtime.getAlignSize(type);
return ret;
}
diff --git a/src/modules.js b/src/modules.js
index ce162ac1..9cbe88aa 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -2,6 +2,8 @@
// Various namespace-like modules
+var STACK_ALIGN = TARGET_X86 ? 4 : 8;
+
var LLVM = {
LINKAGES: set('private', 'linker_private', 'linker_private_weak', 'linker_private_weak_def_auto', 'internal',
'available_externally', 'linkonce', 'common', 'weak', 'appending', 'extern_weak', 'linkonce_odr',
diff --git a/src/runtime.js b/src/runtime.js
index b15f4152..0a991117 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -14,8 +14,8 @@ var RuntimeGenerator = {
ret += sep + '_memset(' + type + 'TOP, 0, ' + size + ')';
}
ret += sep + type + 'TOP = (' + type + 'TOP + ' + size + ')|0';
- if ({{{ QUANTUM_SIZE }}} > 1 && !ignoreAlign) {
- ret += sep + RuntimeGenerator.alignMemory(type + 'TOP', {{{ QUANTUM_SIZE }}});
+ if ({{{ STACK_ALIGN }}} > 1 && !ignoreAlign) {
+ ret += sep + RuntimeGenerator.alignMemory(type + 'TOP', {{{ STACK_ALIGN }}});
}
return ret;
},
@@ -23,9 +23,8 @@ var RuntimeGenerator = {
// An allocation that lives as long as the current function call
stackAlloc: function(size, sep) {
sep = sep || ';';
- if (USE_TYPED_ARRAYS === 2) 'STACKTOP = (STACKTOP + STACKTOP|0 % ' + ({{{ QUANTUM_SIZE }}} - (isNumber(size) ? Math.min(size, {{{ QUANTUM_SIZE }}}) : {{{ QUANTUM_SIZE }}})) + ')' + sep;
- // The stack is always QUANTUM SIZE aligned, so we may not need to force alignment here
- var ret = RuntimeGenerator.alloc(size, 'STACK', false, sep, USE_TYPED_ARRAYS != 2 || (isNumber(size) && parseInt(size) % {{{ QUANTUM_SIZE }}} == 0));
+ if (USE_TYPED_ARRAYS === 2) 'STACKTOP = (STACKTOP + STACKTOP|0 % ' + ({{{ STACK_ALIGN }}} - (isNumber(size) ? Math.min(size, {{{ STACK_ALIGN }}}) : {{{ STACK_ALIGN }}})) + ')' + sep;
+ var ret = RuntimeGenerator.alloc(size, 'STACK', false, sep, USE_TYPED_ARRAYS != 2 || (isNumber(size) && parseInt(size) % {{{ STACK_ALIGN }}} == 0));
if (ASSERTIONS) {
ret += sep + 'assert(' + asmCoercion('(STACKTOP|0) < (STACK_MAX|0)', 'i32') + ')';
}
@@ -37,8 +36,8 @@ var RuntimeGenerator = {
var ret = 'var __stackBase__ = ' + (ASM_JS ? '0; __stackBase__ = ' : '') + 'STACKTOP';
if (initial > 0) ret += '; STACKTOP = (STACKTOP + ' + initial + ')|0';
if (USE_TYPED_ARRAYS == 2) {
- assert(initial % QUANTUM_SIZE == 0);
- if (ASSERTIONS && QUANTUM_SIZE == 4) {
+ assert(initial % Runtime.STACK_ALIGN == 0);
+ if (ASSERTIONS && Runtime.STACK_ALIGN == 4) {
ret += '; assert(' + asmCoercion('!(STACKTOP&3)', 'i32') + ')';
}
}
@@ -70,7 +69,7 @@ var RuntimeGenerator = {
alignMemory: function(target, quantum) {
if (typeof quantum !== 'number') {
- quantum = '(quantum ? quantum : {{{ QUANTUM_SIZE }}})';
+ quantum = '(quantum ? quantum : {{{ STACK_ALIGN }}})';
}
return target + ' = ' + Runtime.forceAlign(target, quantum);
},
@@ -175,6 +174,8 @@ var Runtime = {
set: set,
+ STACK_ALIGN: {{{ STACK_ALIGN }}},
+
// type can be a native type or a struct (or null, for structs we only look at size here)
getAlignSize: function(type, size) {
// we align i64s and doubles on 64-bit boundaries, unlike x86