Skip to content

Instantly share code, notes, and snippets.

@dreamlayers
Created January 16, 2014 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamlayers/8463670 to your computer and use it in GitHub Desktop.
Save dreamlayers/8463670 to your computer and use it in GitHub Desktop.
This is an improper fix for Emscripten relooper issue #1909, which is good enough for DOSBox. It avoids creating long chains of comparisons for switch statements, and greatly improves DOSBox performance in Firefox. This can generate assertion failures and JavaScript errors when running the relooper fuzzer. I have not observed any improperly runn…
diff --git a/src/relooper/Relooper.cpp b/src/relooper/Relooper.cpp
index de69e0e..ee3aedc 100644
--- a/src/relooper/Relooper.cpp
+++ b/src/relooper/Relooper.cpp
@@ -556,7 +556,7 @@ void Relooper::Calculate(Block *Entry) {
for (BlockSet::iterator iter = Curr->BranchesIn.begin(); iter != Curr->BranchesIn.end(); iter++) {
Queue.insert(*iter);
}
-#if 0
+#if 1
// Add elements it leads to, if they are dead ends. There is no reason not to hoist dead ends
// into loops, as it can avoid multiple entries after the loop
for (BlockBranchMap::iterator iter = Curr->BranchesOut.begin(); iter != Curr->BranchesOut.end(); iter++) {
@@ -580,7 +580,7 @@ void Relooper::Calculate(Block *Entry) {
}
}
-#if 0
+#if 1
// We can avoid multiple next entries by hoisting them into the loop.
if (NextEntries.size() > 1) {
BlockBlockSetMap IndependentGroups;
@@ -605,8 +605,11 @@ void Relooper::Calculate(Block *Entry) {
for (BlockBranchMap::iterator iter = Curr->BranchesOut.begin(); iter != Curr->BranchesOut.end(); iter++) {
Block *Target = iter->first;
if (Hoisted.find(Target) == Hoisted.end() && NextEntries.find(Target) == NextEntries.end()) {
+ // This is wrong but it almost always works and seems to cause
+ // errors, not incorrect behaviour.
+ NextEntries.insert(Target);
// abort this hoisting
- abort = true;
+ //abort = true;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment