From 53391a660236901354e6568c4fc31a0e682e1814 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Mon, 28 Jan 2019 21:30:23 -0800 Subject: Less broken flag calulcation for sub instructions in CPU DSL --- cpu_dsl.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'cpu_dsl.py') diff --git a/cpu_dsl.py b/cpu_dsl.py index e836e08..99d94d8 100755 --- a/cpu_dsl.py +++ b/cpu_dsl.py @@ -240,7 +240,8 @@ class Op: decl,name = prog.getTemp(size) dst = prog.carryFlowDst = name prog.lastA = a - prog.lastB = b + prog.lastB = '(-' + b + ')' if op == '-' else b + prog.lastWasSub = op == '-' else: dst = params[2] return decl + '\n\t{dst} = {a} {op} {b};'.format( @@ -312,7 +313,8 @@ def _updateFlagsCImpl(prog, params, rawParams): resultBit = prog.paramSize(prog.lastDst) elif calc == 'half': resultBit = 4 - myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst) + fmt = '({a} ^ {b} ^ ~{res})' if prog.lastWasSub else '({a} ^ {b} ^ {res})' + myRes = fmt.format(a = prog.lastA, b = prog.lastB, res = lastDst) elif calc == 'overflow': resultBit = prog.paramSize(prog.lastDst) - 1 myRes = '((~({a} ^ {b})) & ({a} ^ {res}))'.format(a = prog.lastA, b = prog.lastB, res = lastDst) @@ -989,6 +991,7 @@ class Program: self.carryFlowDst = None self.lastA = None self.lastB = None + self.lastWasSub = False def __str__(self): pieces = [] -- cgit v1.2.3