Commit e098d91c authored by Jayke Meijer's avatar Jayke Meijer

Changed algebraic optimizations to proper mult structure.

parent 72807a00
......@@ -137,7 +137,7 @@ def fold_constants(block):
register[s[0]] = constants[s[1]]
elif s.name in ['addu', 'subu', 'mult', 'div']:
# Calculation with constants
rd, rs, rt = s
rd, rs, rt = s[0], s[1], s[2]
rs_known = rs in register
rt_known = rt in register
......@@ -255,17 +255,22 @@ def algebraic_transformations(block):
if (s.is_command('addu') or s.is_command('subu')) and s[2] == 0:
block.replace(1, [S('command', 'move', s[0], s[1])])
changed = True
elif s.is_command('mult') and s[2] == 1:
block.replace(1, [S('command', 'move', s[0], s[1])])
elif s.is_command('mult'):
next = block.peek()
if next.is_command('mflo'):
if s[1] == 1:
block.replace(2, [S('command', 'move', next[0], s[0])])
changed = True
elif s.is_command('mult') and s[2] == 0:
block.replace(1, [S('command', 'li', '$1', to_hex(0))])
break
elif s[1] == 0:
block.replace(2, [S('command', 'li', '$1', to_hex(0))])
changed = True
elif s.is_command('mult'):
shift_amount = log(s[2], 2)
break
shift_amount = log(s[1], 2)
if shift_amount.is_integer():
new_command = S('command', 'sll', s[0], s[1], shift_amount)
block.replace(1, [new_command])
new_command = S('command', 'sll', next[0], s[0], int(shift_amount))
block.replace(2, [new_command])
changed = True
return changed
......@@ -125,7 +125,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def test_algebraic_transforms_mult0(self):
block = B([self.foo,
S('command', 'mult', '$1', '$2', 0),
S('command', 'mult', '$2', 0),
S('command', 'mflo', '$1'),
self.bar])
self.assertTrue(algebraic_transformations(block))
......@@ -135,7 +136,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def test_algebraic_transforms_mult1(self):
block = B([self.foo,
S('command', 'mult', '$1', '$2', 1),
S('command', 'mult', '$2', 1),
S('command', 'mflo', '$1'),
self.bar])
self.assertTrue(algebraic_transformations(block))
......@@ -145,7 +147,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def test_algebraic_transforms_mult2(self):
block = B([self.foo,
S('command', 'mult', '$1', '$2', 2),
S('command', 'mult', '$2', 2),
S('command', 'mflo', '$1'),
self.bar])
self.assertTrue(algebraic_transformations(block))
......@@ -155,7 +158,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def test_algebraic_transforms_mult16(self):
block = B([self.foo,
S('command', 'mult', '$1', '$2', 16),
S('command', 'mult', '$2', 16),
S('command', 'mflo', '$1'),
self.bar])
self.assertTrue(algebraic_transformations(block))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment