aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-21 19:04:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-21 19:04:38 -0700
commit6698b6bc347c911ed13d6c06a8426256b6fc1584 (patch)
tree882e55fe74f0821469aab14f0e303ff14ad5f65d
parentad160bfbe73e0835d7d1b46f6157910907b8464e (diff)
consider range and not just absolute value for using switches
-rw-r--r--src/jsifier.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 115a77d4..452b2d9e 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1132,13 +1132,16 @@ function JSify(data, functionsOnly, givenFunctions) {
});
makeFuncLineActor('switch', function(item) {
// use a switch if the range is not too big or sparse
- var maxx = 0;
+ var minn = Infinity, maxx = -Infinity;
item.switchLabels.forEach(function(switchLabel) {
- maxx = Math.max(maxx, Math.abs(parseInt(switchLabel.value)));
+ var curr = Math.abs(parseInt(switchLabel.value));
+ minn = Math.min(minn, curr);
+ maxx = Math.max(maxx, curr);
});
- var useIfs = (item.switchLabels.length+1) < 6 || maxx > 2*1024*1024 || (maxx/item.switchLabels.length) > 10*1024; // heuristics
+ var range = maxx - minn;
+ var useIfs = (item.switchLabels.length+1) < 6 || range > 2*1024*1024 || (range/item.switchLabels.length) > 10*1024; // heuristics
if (VERBOSE && useIfs && item.switchLabels.length > 2) {
- warn('not optimizing llvm switch into js switch because ' + [maxx, maxx/item.switchLabels.length]);
+ warn('not optimizing llvm switch into js switch because ' + [range, range/item.switchLabels.length]);
}
var phiSets = calcPhiSets(item);