diff options
author | Vladimir Menshakov | 2011-06-16 00:20:30 +0400 |
---|---|---|
committer | Vladimir Menshakov | 2011-06-16 00:20:30 +0400 |
commit | e0efde7cf65e0f22d5afa830339fb1dc6ca91479 (patch) | |
tree | 05dcc4ec22131e7175d2bef18a5e0294c18dd7fe /devtools | |
parent | c1b9adb69122d86665079c619a535095d7fe1507 (diff) | |
download | scummvm-rg350-e0efde7cf65e0f22d5afa830339fb1dc6ca91479.tar.gz scummvm-rg350-e0efde7cf65e0f22d5afa830339fb1dc6ca91479.tar.bz2 scummvm-rg350-e0efde7cf65e0f22d5afa830339fb1dc6ca91479.zip |
DREAMWEB: optimized consequtive movsb/w and stosb/w
Diffstat (limited to 'devtools')
-rw-r--r-- | devtools/tasmrecover/tasm/cpp.py | 26 | ||||
-rw-r--r-- | devtools/tasmrecover/tasm/op.py | 16 | ||||
-rw-r--r-- | devtools/tasmrecover/tasm/proc.py | 29 |
3 files changed, 50 insertions, 21 deletions
diff --git a/devtools/tasmrecover/tasm/cpp.py b/devtools/tasmrecover/tasm/cpp.py index 4e37dc8e5b..2420829869 100644 --- a/devtools/tasmrecover/tasm/cpp.py +++ b/devtools/tasmrecover/tasm/cpp.py @@ -403,31 +403,31 @@ namespace %s { self.body += p def _rep(self): - self.body += "\twhile(context.cx--) "; + self.body += "\twhile(context.cx--) " def _lodsb(self): - self.body += "\tcontext._lodsb();\n"; + self.body += "\tcontext._lodsb();\n" def _lodsw(self): - self.body += "\tcontext._lodsw();\n"; + self.body += "\tcontext._lodsw();\n" - def _stosb(self): - self.body += "\tcontext._stosb();\n"; + def _stosb(self, n): + self.body += "\tcontext._stosb(%s);\n" %("" if n == 1 else n) - def _stosw(self): - self.body += "\tcontext._stosw();\n"; + def _stosw(self, n): + self.body += "\tcontext._stosw(%s);\n" %("" if n == 1 else n) - def _movsb(self): - self.body += "\tcontext._movsb();\n "; + def _movsb(self, n): + self.body += "\tcontext._movsb(%s);\n " %("" if n == 1 else n) - def _movsw(self): - self.body += "\tcontext._movsw();\n "; + def _movsw(self, n): + self.body += "\tcontext._movsw(%s);\n " %("" if n == 1 else n) def _stc(self): - self.body += "\tcontext.flags._c = true;\n "; + self.body += "\tcontext.flags._c = true;\n " def _clc(self): - self.body += "\tcontext.flags._c = false;\n "; + self.body += "\tcontext.flags._c = false;\n " def __proc(self, name, def_skip = 0): try: diff --git a/devtools/tasmrecover/tasm/op.py b/devtools/tasmrecover/tasm/op.py index 33f79c3e5c..9baebccfc3 100644 --- a/devtools/tasmrecover/tasm/op.py +++ b/devtools/tasmrecover/tasm/op.py @@ -316,27 +316,27 @@ class _lodsw(baseop): class _stosw(baseop): def __init__(self, arg): - pass + self.repeat = 1 def visit(self, visitor): - visitor._stosw() + visitor._stosw(self.repeat) class _stosb(baseop): def __init__(self, arg): - pass + self.repeat = 1 def visit(self, visitor): - visitor._stosb() + visitor._stosb(self.repeat) class _movsw(baseop): def __init__(self, arg): - pass + self.repeat = 1 def visit(self, visitor): - visitor._movsw() + visitor._movsw(self.repeat) class _movsb(baseop): def __init__(self, arg): - pass + self.repeat = 1 def visit(self, visitor): - visitor._movsb() + visitor._movsb(self.repeat) class _in(baseop): def __init__(self, arg): diff --git a/devtools/tasmrecover/tasm/proc.py b/devtools/tasmrecover/tasm/proc.py index 57f17518fb..3c4ac21372 100644 --- a/devtools/tasmrecover/tasm/proc.py +++ b/devtools/tasmrecover/tasm/proc.py @@ -27,6 +27,30 @@ class proc: self.stmts.remove(l) return + def optimize_sequence(self, cls): + i = 0 + stmts = self.stmts + while i < len(stmts): + if not isinstance(stmts[i], cls): + i += 1 + continue + j = i + 1 + + while j < len(stmts): + if not isinstance(stmts[j], cls): + break + j = j + 1 + + n = j - i + if n > 1: + print "Eliminate consequtive storage instructions at %u-%u" %(i, j) + del stmts[i + 1:j] + stmts[i].repeat = n + else: + i = j + + return + def optimize(self): print "optimizing..." #trivial simplifications, removing last ret @@ -72,6 +96,11 @@ class proc: if not used: print self.labels self.remove_label(s.name) + + self.optimize_sequence(op._stosb); + self.optimize_sequence(op._stosw); + self.optimize_sequence(op._movsb); + self.optimize_sequence(op._movsw); def add(self, stmt): #print stmt |