diff options
author | alon@honor <none@none> | 2010-10-10 11:49:50 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-10-10 11:49:50 -0700 |
commit | 5a4c4614b70c0dfe7d5f19b72379b52210e4afa5 (patch) | |
tree | 61374bd571f444f7afef7c80c20b1ee0e29391fe | |
parent | ab097f0b3a1440911bfb48a0b26057176c02edfd (diff) |
clean up flattener code and remove unneeded flattener definitions; 3% speedup
-rw-r--r-- | src/analyzer.js | 22 | ||||
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | tests/runner.py | 7 | ||||
-rw-r--r-- | tests/settings.py | 10 |
4 files changed, 22 insertions, 19 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index c6c7b028..ce4a99af 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -172,9 +172,9 @@ function analyzer(data) { return; } type.flatSize = 0; - var sizes = []; + var diffs = []; + var prev = -1; type.flatIndexes = type.fields.map(function(field) { - var soFar = type.flatSize; var size; if (isNumberType(field) || isPointerType(field)) { size = getNativeFieldSize(field, true); // pack char; char; in structs, also char[X]s. @@ -183,14 +183,20 @@ function analyzer(data) { } else { assert(0); } - type.flatSize += size; - sizes.push(size); - return Runtime.alignMemory(soFar, Math.min(QUANTUM_SIZE, size)); // if necessary, place this on aligned memory + var curr = Runtime.alignMemory(type.flatSize, Math.min(QUANTUM_SIZE, size)); // if necessary, place this on aligned memory + type.flatSize = curr + size; + if (prev >= 0) { + diffs.push(curr-prev); + } + prev = curr; + return curr; }); - type.flatSize = Runtime.alignMemory(type.flatSize); // padding at end - if (dedup(sizes).length == 1) { - type.flatFactor = sizes[0]; + if (diffs.length == 0) { + type.flatFactor = type.flatSize; + } else if (dedup(diffs).length == 1) { + type.flatFactor = diffs[0]; } + type.flatSize = Runtime.alignMemory(type.flatSize); // final padding at end type.needsFlattening = (this.flatFactor != 1); dprint('types', 'type: ' + type.name_ + ' : ' + JSON.stringify(type.fields)); dprint('types', ' has final size of ' + type.flatSize + ', flatting: ' + type.needsFlattening + ' ? ' + (type.flatFactor ? type.flatFactor : JSON.stringify(type.flatIndexes))); diff --git a/src/jsifier.js b/src/jsifier.js index f69a22ee..bcc436a4 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -9,7 +9,7 @@ function JSify(data) { substrate.addZyme('Type', { processItem: function(item) { var type = TYPES[item.name_]; - if (type.needsFlattening) { + if (type.needsFlattening && !type.flatFactor) { item.JS = 'var ' + toNiceIdent(item.name_) + '___FLATTENER = ' + JSON.stringify(TYPES[item.name_].flatIndexes) + ';'; } else { item.JS = '// type: ' + item.name_; diff --git a/tests/runner.py b/tests/runner.py index 659dd5dc..3cd99993 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -881,10 +881,13 @@ else: COMPILER = LLVM_GCC PARSER_ENGINE = V8_ENGINE JS_ENGINE = SPIDERMONKEY_ENGINE + if JS_ENGINE == SPIDERMONKEY_ENGINE: + JS_ENGINE_OPTS += ['-j', '-m'] # TODO: use this everywhere else + RELOOP = OPTIMIZE = 1 GUARD_MEMORY = 0 QUANTUM_SIZE = 1 - TEST_REPS = 10 + TEST_REPS = 20 TOTAL_TESTS = 2 tests_done = 0 @@ -896,7 +899,7 @@ else: squared_times = map(lambda x: x*x, times) mean_of_squared = sum(squared_times)/len(times) std = math.sqrt(mean_of_squared - mean*mean) - print ' mean: %.2f (+-%.2f) seconds (max: %.2f, min: %.2f, noise/signal: %.2f) (%d runs)' % (mean, std, max(times), min(times), std/mean, TEST_REPS) + print ' mean: %.3f (+-%.3f) seconds (max: %.3f, min: %.3f, noise/signal: %.3f) (%d runs)' % (mean, std, max(times), min(times), std/mean, TEST_REPS) def do_benchmark(self, src, args=[], main_file=None): print 'Running benchmark:', inspect.stack()[1][3].replace('test_', '') diff --git a/tests/settings.py b/tests/settings.py index 04a3c0f7..4702dc09 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -33,16 +33,10 @@ V8_ENGINE=os.path.expanduser('~/Dev/v8/d8') #PARSER_ENGINE=SPIDERMONKEY_ENGINE PARSER_ENGINE=V8_ENGINE -#TODO -#if PARSER_ENGINE == SPIDERMONKEY_ENGINE: -# PARSER_ENGINE_OPS += ['-j', '-m'] - -JS_ENGINE=SPIDERMONKEY_ENGINE -#JS_ENGINE=V8_ENGINE +#JS_ENGINE=SPIDERMONKEY_ENGINE +JS_ENGINE=V8_ENGINE JS_ENGINE_OPTS=[] -if JS_ENGINE == SPIDERMONKEY_ENGINE: - JS_ENGINE_OPTS += ['-j', '-m'] OUTPUT_TO_SCREEN = 0 # useful for debugging specific tests, or for subjectively seeing what parts are slow |