aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2011-01-29 16:55:59 -0800
committerAlon Zakai <azakai@mozilla.com>2011-01-29 16:55:59 -0800
commiteb4d457adee5f14f62731e0389c0d8402688d780 (patch)
treebd4f7abcd522c56200a7c0857ffac7590f17e808 /src
parent5958a6a754324de9eeff39fe1f21ba2b7042f833 (diff)
fix for structure alignment handling +test
Diffstat (limited to 'src')
-rw-r--r--src/runtime.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/runtime.js b/src/runtime.js
index 165ecce6..6b0d4be6 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -116,21 +116,24 @@ Runtime = {
// which would remove much of the complexity here.
calculateStructAlignment: function calculateStructAlignment(type, otherTypes) {
type.flatSize = 0;
+ type.alignSize = 0;
var diffs = [];
- var prev = -1, maxSize = -1;
+ var prev = -1;
type.flatIndexes = type.fields.map(function(field) {
- var size;
+ var size, alignSize;
if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) {
size = Runtime.getNativeFieldSize(field, true); // pack char; char; in structs, also char[X]s.
- maxSize = Math.max(maxSize, size);
+ alignSize = size;
} else if (Runtime.isStructType(field)) {
size = otherTypes[field].flatSize;
- maxSize = Math.max(maxSize, QUANTUM_SIZE);
+ alignSize = otherTypes[field].alignSize;
} else {
dprint('Unclear type in struct: ' + field + ', in ' + type.name_);
assert(0);
}
- var curr = Runtime.alignMemory(type.flatSize, Math.min(QUANTUM_SIZE, size)); // if necessary, place this on aligned memory
+ alignSize = Math.min(alignSize, QUANTUM_SIZE);
+ type.alignSize = Math.max(type.alignSize, alignSize);
+ var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
type.flatSize = curr + size;
if (prev >= 0) {
diffs.push(curr-prev);
@@ -138,7 +141,7 @@ Runtime = {
prev = curr;
return curr;
});
- type.flatSize = Runtime.alignMemory(type.flatSize, maxSize);
+ type.flatSize = Runtime.alignMemory(type.flatSize, type.alignSize);
if (diffs.length == 0) {
type.flatFactor = type.flatSize;
} else if (Runtime.dedup(diffs).length == 1) {
@@ -147,7 +150,6 @@ Runtime = {
type.needsFlattening = (type.flatFactor != 1);
return type.flatIndexes;
}
-
};
function getRuntime() {