aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analyzer.js5
-rw-r--r--src/runtime.js10
-rw-r--r--tests/runner.py13
3 files changed, 21 insertions, 7 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 47c7281b..92aa0a8a 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -177,7 +177,7 @@ function analyzer(data) {
var soFar = type.flatSize;
var size;
if (isNumberType(field) || isPointerType(field)) {
- size = getNativeFieldSize(field);
+ size = getNativeFieldSize(field, true); // pack char; char; in structs, also char[X]s.
} else if (isStructType(field)) {
size = item.types[field].flatSize;
} else {
@@ -185,8 +185,9 @@ function analyzer(data) {
}
type.flatSize += size;
sizes.push(size);
- return soFar;
+ return Runtime.alignMemory(soFar, Math.min(QUANTUM_SIZE, size)); // if necessary, place this on aligned memory
});
+ type.flatSize = Runtime.alignMemory(type.flatSize); // padding at end
if (dedup(sizes).length == 1) {
type.flatFactor = sizes[0];
}
diff --git a/src/runtime.js b/src/runtime.js
index 250eb50a..346020b0 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -11,7 +11,7 @@ RuntimeGenerator = {
}
ret += '; ' + type + 'TOP += ' + size;
if (QUANTUM_SIZE > 1) {
- ret += ';' + RuntimeGenerator.alignMemory(type + 'TOP');
+ ret += ';' + RuntimeGenerator.alignMemory(type + 'TOP', QUANTUM_SIZE);
}
return ret;
},
@@ -38,8 +38,11 @@ RuntimeGenerator = {
return RuntimeGenerator.alloc(size, 'STATIC');
},
- alignMemory: function(target) {
- return target + ' = Math.ceil(' + target + '/QUANTUM_SIZE)*QUANTUM_SIZE;';
+ alignMemory: function(target, quantum) {
+ if (typeof quantum !== 'number') {
+ quantum = '(quantum ? quantum : QUANTUM_SIZE)';
+ }
+ return target + ' = Math.ceil(' + target + '/' + quantum + ')*' + quantum + ';';
},
};
@@ -56,6 +59,7 @@ function unInline(name_, params) {
Runtime = {
stackAlloc: unInline('stackAlloc', ['size']),
staticAlloc: unInline('staticAlloc', ['size']),
+ alignMemory: unInline('alignMemory', ['size', 'quantum']),
};
function getRuntime() {
diff --git a/tests/runner.py b/tests/runner.py
index 95b5ba64..28ffc7c7 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -795,17 +795,26 @@ class T(unittest.TestCase):
}
};
+ struct B { char buffer[62]; int last; char laster; char laster2; };
+
int main() {
hashtable t;
+
+ // Part 2 - the char[] should be compressed, BUT have a padding space at the end so the next
+ // one is aligned properly. Also handle char; char; etc. properly.
+ B *b = NULL;
+ printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\\n", int(b), int(&(b->buffer)), int(&(b->buffer[0])), int(&(b->buffer[1])), int(&(b->buffer[2])),
+ int(&(b->last)), int(&(b->laster)), int(&(b->laster2)), ES_SIZEOF(B));
+
return 0;
}
'''
if QUANTUM_SIZE == 1:
# Compressed memory
- self.do_test(src, '*4,0,1,2,2,3|5,0,1,1,2,3,3,4|6,0,5,0,1,1,2,3,3,4*')
+ self.do_test(src, '*4,0,1,2,2,3|5,0,1,1,2,3,3,4|6,0,5,0,1,1,2,3,3,4*\n*0,0,0,1,2,62,63,64,65*')
else:
# Bloated memory; same layout as C/C++
- self.do_test(src, '*16,0,4,8,8,12|20,0,4,4,8,12,12,16|24,0,20,0,4,4,8,12,12,16*')
+ self.do_test(src, '*16,0,4,8,8,12|20,0,4,4,8,12,12,16|24,0,20,0,4,4,8,12,12,16*\n*0,0,0,1,2,64,68,69,72*')
def test_fannkuch(self):
results = [ (1,0), (2,1), (3,2), (4,4), (5,7), (6,10), (7, 16), (8,22) ]