Commit 2aac7d87 authored by Taddeus Kroes's avatar Taddeus Kroes

Fixed division in constant flding.

parent f971a60e
......@@ -173,13 +173,11 @@ def fold_constants(block):
# Move of `Hi' register to another register
register[s[0]] = register['$hi']
known.append((s[0], register[s[0]]))
elif s.name in ['mult', 'div'] \
and s[0]in register and s[1] in register:
elif s.name == 'mult' and s[0]in register and s[1] in register:
# Multiplication/division with constants
rs, rt = s
a, b = register[rs], register[rt]
if s.name == 'mult':
if not a or not b:
# Multiplication by 0
hi = lo = to_hex(0)
......@@ -209,13 +207,11 @@ def fold_constants(block):
block.replace(1, [S('command', 'li', '$hi', hi),
S('command', 'li', '$lo', li)],
message=message)
elif s.name == 'div':
lo, hi = divmod(rs, rt)
register['$lo'], register['$hi'] = lo, hi
known += [('$lo', lo), ('$hi', hi)]
changed = True
elif s.name in ['addu', 'subu']:
elif s.name in ['addu', 'subu', 'div']:
# Addition/subtraction with constants
rd, rs, rt = s
rs_known = rs in register
......@@ -239,6 +235,11 @@ def fold_constants(block):
message = 'Constant subtraction: %d - %d = %d' \
% (rs_val, rt_val, result)
if s.name == 'div':
result = rs_val / rt_val
message = 'Constant division: %d - %d = %d' \
% (rs_val, rt_val, result)
block.replace(1, [S('command', 'li', rd, to_hex(result))],
message=message)
register[rd] = result
......
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